# Matrix Multiplication Using oneAPI.jl Fails on Second Invocation

**URL:** <https://discourse.julialang.org/t/matrix-multiplication-using-oneapi-jl-fails-on-second-invocation/118567>\
**Category:** GPU\
**Created:** [August 24, 2024, 3:25pm UTC](https://discourse.julialang.org/t/matrix-multiplication-using-oneapi-jl-fails-on-second-invocation/118567 "2024-08-24T15:25:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcelo\_Simas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcelo_simas/32/208618_2.png) [@Marcelo\_Simas](https://discourse.julialang.org/u/Marcelo_Simas)\
**Post date:** [August 24, 2024, 3:25pm UTC](https://discourse.julialang.org/t/matrix-multiplication-using-oneapi-jl-fails-on-second-invocation/118567/1 "2024-08-24T15:25:31Z")

</div>

Been playing with oneAPI.jl to run matrix x vector multiplication using the integrated Intel GPU on my Windows laptop (WSL2) and came across a strange behavior.

The first time mul!() is invoked I get a reasonable result, all subsequent calls return zeros and when I exit Julia by calling `exit()` I get a segmentation fault.

Here’s a repro example:

```julia
using Random, Distributions, LinearAlgebra, oneAPI, BenchmarkTools 

row_count = 768
coeff_count = 80
rep_coeffs = rand(Normal(200, 20), coeff_count)
w_vals = 5 .+ (1.5 .* randn(row_count, coeff_count) .^ 2)
res = zeros(row_count)

rep_coeffs_f32 = oneArray(Float32.(rep_coeffs))
w_vals_f32 = oneArray(Float32.(w_vals))
res_f32 = oneArray(zeros(Float32, row_count))

mul!(res_f32, w_vals_f32, rep_coeffs_f32)
mul!(res, w_vals, rep_coeffs)
maximum(abs.(res - Float64.(Array(res_f32)))) < .025

mul!(res_f32, w_vals_f32, rep_coeffs_f32)
mul!(res, w_vals, rep_coeffs)
maximum(abs.(res - Float64.(Array(res_f32)))) < .025

```

Second check of maximum squared diff returns false.

Has anyone else seen this? Is there anything I am doing here that could be problematic?

---

<div class="post-metadata">

**Author:** ![Marcelo\_Simas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcelo_simas/32/208618_2.png) [@Marcelo\_Simas](https://discourse.julialang.org/u/Marcelo_Simas)\
**Post date:** [August 24, 2024, 3:27pm UTC](https://discourse.julialang.org/t/matrix-multiplication-using-oneapi-jl-fails-on-second-invocation/118567/2 "2024-08-24T15:27:13Z")

</div>

Here’s what my environment looks like:

```julia
$ julia --project=. --threads=auto
               _
   _ _ _(_)_ | Documentation: https://docs.julialang.org
  (_) | (_) (_) |
   _ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` | |
  | | |_| | | | (_| | | Version 1.10.4 (2024-06-04)
 _/ |\ __'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |

julia> using oneAPI
julia> oneAPI.versioninfo()
Binary dependencies:
- NEO: 24.22.29735+0
- libigc: 1.0.16695+0
- gmmlib: 22.3.19+0
- SPIRV_LLVM_Translator_unified: 0.4.0+0
- SPIRV_Tools: 2024.2.0+0

Toolchain:
- Julia: 1.10.4
- LLVM: 15.0.7

1 driver:
- 00000000-0000-0000-17ee-b392010371d2 (v1.3.29138, API v1.3.0)

1 device:
- Intel(R) Graphics [0x46a8]
```

---

<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:** [August 26, 2024, 7:00am UTC](https://discourse.julialang.org/t/matrix-multiplication-using-oneapi-jl-fails-on-second-invocation/118567/3 "2024-08-26T07:00:55Z")

</div>

Does it help if you run with `SYCL_PI_LEVEL_ZERO_BATCH_SIZE=1` in your environment before loading oneAPI.jl? This may be [SYCL batching causes invalid results · Issue #445 · JuliaGPU/oneAPI.jl · GitHub](https://github.com/JuliaGPU/oneAPI.jl/issues/445)

---

<div class="post-metadata">

**Author:** ![Marcelo\_Simas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marcelo_simas/32/208618_2.png) [@Marcelo\_Simas](https://discourse.julialang.org/u/Marcelo_Simas)\
**Post date:** [August 26, 2024, 3:16pm UTC](https://discourse.julialang.org/t/matrix-multiplication-using-oneapi-jl-fails-on-second-invocation/118567/4 "2024-08-26T15:16:27Z")

</div>

Yep, doing that fixed the behavior.
