# oneAPI.jl @sync bug?

**URL:** https://discourse.julialang.org/t/oneapi-jl-sync-bug/50696
**Category:** GPU
**Created:** [November 24, 2020, 4:16pm UTC](https://discourse.julialang.org/t/oneapi-jl-sync-bug/50696 "2020-11-24T16:16:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [November 24, 2020, 4:16pm UTC](https://discourse.julialang.org/t/oneapi-jl-sync-bug/50696/1 "2020-11-24T16:16:36Z")

</div>

Hi,  
I am trying the oneAPI.jl package and I have an issue with timing:

The following MWE gives me incredible speed-ups and I guess that oneAPI.@sync may not work properly…

```julia
using oneAPI
using BenchmarkTools

n=2^25

oneAPI.allowscalar(false)

x=rand(Float32,n)
y=rand(Float32,n)

ox=oneArray(x)
oy=oneArray(y)

vadd(x,y) = @. y+=x

vadd(x,y)
vadd(ox,oy)

@show sum(y),sum(oy)
 
tcpu = @belapsed $vadd($x,$y)
tgpu = @belapsed oneAPI.@sync $vadd($ox,$oy)

println("tcpu=$tcpu, tgpu=$tgpu, SpUp=$(tcpu/tgpu)") 

```

returns

```julia
(sum(y), sum(oy)) = (3.3554044f7, 3.3554044f7)
tcpu=0.01556782, tgpu=6.7038e-5, SpUp=232.22381335958707

```

The same code with CUDA.jl seems to work fine:

> **Summary**
>
> ```julia
> 
> using CUDA
> using BenchmarkTools
> 
> n=2^25
> 
> CUDA.allowscalar(false)
> 
> x=rand(Float32,n)
> y=rand(Float32,n)
> 
> ox=CuArray(x)
> oy=CuArray(y)
> 
> vadd(x,y) = @. y+=x
> 
> vadd(x,y)
> vadd(ox,oy)
> 
> @show sum(y),sum(oy)
>  
> tcpu = @belapsed $vadd($x,$y)
> tgpu = @belapsed CUDA.@sync $vadd($ox,$oy)
> 
> println("tcpu=$tcpu, tgpu=$tgpu, SpUp=$(tcpu/tgpu)")
> 
> ```

returns:

```julia
(sum(y), sum(oy)) = (3.3550048f7, 3.355005f7)
tcpu=0.015513745, tgpu=0.003838915, SpUp=4.041179604132939

```

Any hints ?

---

<div class="post-metadata">

### Author: ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)
#### Post date: [November 24, 2020, 4:27pm UTC](https://discourse.julialang.org/t/oneapi-jl-sync-bug/50696/2 "2020-11-24T16:27:52Z")

</div>

There is no `oneAPI.@sync`, you’re just calling `Base.@sync`. Use `synchronize()` instead, but you can file a feature request issue to add a macro like that too.

---

<div class="post-metadata">

### Author: ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)
#### Post date: [November 24, 2020, 4:32pm UTC](https://discourse.julialang.org/t/oneapi-jl-sync-bug/50696/3 "2020-11-24T16:32:19Z")

</div>

Thank you very much !  
`synchronize()` is fine. Can I use this function with CUDA.jl too ?

I also found that the sum function was pretty slow with Gen9. Do you think that there is still room for improvement for reduction implementation with oneAPI ?

---

<div class="post-metadata">

### Author: ![maleadt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maleadt/32/10097_2.png) [@maleadt](https://discourse.julialang.org/u/maleadt)
#### Post date: [November 24, 2020, 4:38pm UTC](https://discourse.julialang.org/t/oneapi-jl-sync-bug/50696/4 "2020-11-24T16:38:48Z")

</div>

> [@LaurentPlagne](#):
>
> `synchronize()` is fine. Can I use this function with CUDA.jl too ?

Yeah, but it’s a different function, so you’ll have to specify if you import both.

> [@LaurentPlagne](#):
>
> I also found that the sum function was pretty slow with Gen9. Do you think that there is still room for improvement for reduction implementation with oneAPI ?

Probably lots; oneAPI.jl hasn’t been profiled or optimized yet.
