JuliaORNL / JACC.jl

CPU/GPU parallel performance portable layer in Julia via functions as arguments
MIT License
21 stars 13 forks source link

`JACCPreferences.backend` is not enforced #98

Open kmp5VT opened 4 months ago

kmp5VT commented 4 months ago

The backend preference does not constrain the code to only use any specific background . For example

julia> using JACC: JACC
julia> JACC.JACCPreferences.backend
cuda
julia> JACC.Array
Array
julia> begin
  function f(x, a)
    @inbounds a[x] += 5.0
  end

  dims = (10)
  a = round.(rand(Float32, dims) * 100)
  a_expected = a .+ 5.0

  a = JACC.Array(a)
  JACC.parallel_for(10, f, a)
end
julia> a≈a_expected rtol=1e-5
true
julia> typeof(a)
Vector{Float32} (alias for Array{Float32, 1})

Another issue arises when loading backends

julia> using JACC: JACC
julia> using CUDA
julia> JACC.JACCPreferences.backend
"threads"
julia> JACC.Array
CuArray

This makes it impossible to load a backend and use threads.

williamfgc commented 4 months ago

The mechanism to enforce a back end is given by Julia's Weak Dependencies. The goal of preferences was never to enforce it since the mechanism exists in Julia, but to provide a convenient way to import required back ends at the user level.