# @tturbo on function call

**URL:** <https://discourse.julialang.org/t/tturbo-on-function-call/126224>\
**Category:** Performance\
**Tags:** question, loopvectorization, tturbo\
**Created:** [February 23, 2025, 10:39pm UTC](https://discourse.julialang.org/t/tturbo-on-function-call/126224 "2025-02-23T22:39:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [February 23, 2025, 10:39pm UTC](https://discourse.julialang.org/t/tturbo-on-function-call/126224/1 "2025-02-23T22:39:11Z")

</div>

```julia
a=randn(5*10^7)
b=randn(5*10^7)

f(a::Float64,b::Float64)::Float64 = sin(a) + cos(b)

@time @tturbo @. sin(a) + cos(b) # .05 seconds
@time @tturbo @. f(a,b) # 1 second

```

Is it possible to get the @tturbo speedup using the function `f()` version?

---

<div class="post-metadata">

**Author:** ![nsajko](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nsajko/32/221187_2.png) [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Post date:** [February 23, 2025, 11:12pm UTC](https://discourse.julialang.org/t/tturbo-on-function-call/126224/2 "2025-02-23T23:12:53Z")

</div>

`@tturbo`, as a macro, doesn’t see the definition of the method of `f`, which is only available _after_ the macro is expanded. So I’d say the answer is no.

---

<div class="post-metadata">

**Author:** ![dubosipsl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dubosipsl/32/52998_2.png) [@dubosipsl](https://discourse.julialang.org/u/dubosipsl)\
**Post date:** [February 24, 2025, 8:10am UTC](https://discourse.julialang.org/t/tturbo-on-function-call/126224/3 "2025-02-24T08:10:31Z")

</div>

You may want to have a look at:

> **[GitHub - ClimFlows/LoopManagers.jl: LoopManagers is the companion package of...](https://github.com/ClimFlows/LoopManagers.jl)**
>
> LoopManagers is the companion package of ManagedLoops. It provides managers to execute loops with SIMD, on multiple threads or on GPUs.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [February 24, 2025, 3:09pm UTC](https://discourse.julialang.org/t/tturbo-on-function-call/126224/4 "2025-02-24T15:09:23Z")

</div>

Try `f(a, b) = sin(a) + cos(b)` instead.  
`@tturbo` does not support being restricted `Float64` inputs/outputs, as it transforms the loop to use SIMD types. If the `f` doesn’t work with these SIMD types, it’ll execute the original code without applying transforms.

Feel free to make a PR adding this to the README or docs.  
`@tturbo` used to error out with a `MethodError`, which was more helpful in diagnosing this than silently falling back to scalar code.  
It’s a tradeoff between being informative and explicit, vs making it easier to write generic code.

---

<div class="post-metadata">

**Author:** ![Elrod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/elrod/32/22461_2.png) [@Elrod](https://discourse.julialang.org/u/Elrod)\
**Post date:** [February 24, 2025, 3:15pm UTC](https://discourse.julialang.org/t/tturbo-on-function-call/126224/5 "2025-02-24T15:15:28Z")

</div>

It does see `f`, but the only thing it sees is that it isn’t valid to call it with SIMD types.  
Otherwise, if it were callable with SIMD types, it’d treat `f` as an expensive black box function, which is a reasonable way to treat it if `f` is calling something like `sin` and/or `cos`. It wouldn’t be reasonable if `f` were just cheap functions like `+`.
