Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GPU support #93

Open
AntonReinhard opened this issue Sep 6, 2024 · 0 comments
Open

GPU support #93

AntonReinhard opened this issue Sep 6, 2024 · 0 comments

Comments

@AntonReinhard
Copy link

I've been using this project to circumvent the world age problems when generating functions and it has worked great so far.

Now I'm trying to also generate functions to run on the GPU, CUDA for now to be specific. There are two ways that I've tried to do that. The first is simply broadcasting the function on a CuVector, however, this does not work because RuntimeGeneratedFunctions are not isbits, which CUDA.jl does not like:

julia> func.(cu_inputs)
ERROR: GPU compilation of MethodInstance for (::GPUArrays.var"#34#36")(::CUDA.CuKernelContext, ::CuDeviceVector{ComplexF64, 1}, ::Base.Broadcast.Broadcasted{CUDA.CuArrayStyle{…}, Tuple{…}, RuntimeGeneratedFunction{…}, Tuple{…}}, ::Int64) failed
KernelError: passing and using non-bitstype argument

Argument 4 to your kernel function is of type Base.Broadcast.Broadcasted{CUDA.CuArrayStyle{1, CUDA.Mem.DeviceBuffer}, Tuple{Base.OneTo{Int64}}, RuntimeGeneratedFunction{(:data_input,), ComputableDAGs.var"#_RGF_ModTag", var"#_RGF_ModTag", (0x3d86ea6b, 0x46940344, 0xf0c50769, 0x501ce261, 0x5c3fa2fa), Expr}, Tuple{Base.Broadcast.Extruded{CuDeviceVector{<LongArgumentType...>, 1}, Tuple{Bool}, Tuple{Int64}}}}, which is not isbits:
  .f is of type RuntimeGeneratedFunction{(:data_input,), ComputableDAGs.var"#_RGF_ModTag", var"#_RGF_ModTag", (0x3d86ea6b, 0x46940344, 0xf0c50769, 0x501ce261, 0x5c3fa2fa), Expr} which is not isbits.
    .body is of type Expr which is not isbits.
      .head is of type Symbol which is not isbits.
      .args is of type Vector{Any} which is not isbits.

The other option is to use @cuda and call a (generated) kernel. However, this also does not work as RuntimeGeneratedFunctions seem to always return an Any, and GPU kernels are not allowed to return anything:

julia> @cuda kernel(cu_inputs, cu_outputs, 1000)
ERROR: GPU compilation of MethodInstance for (::RuntimeGeneratedFunction{(:input_vector, :output_vector, :n), CUDAExt.var"#_RGF_ModTag", var"#_RGF_ModTag", (0x26ea8e24, 0xf73e2d2a, 0xb1e0f07e, 0x53860e81, 0xc0771049), Expr})(::CuDeviceVector{PhaseSpacePoint{…}, 1}, ::CuDeviceVector{Float64, 1}, ::Int64) failed
KernelError: kernel returns a value of type `Any`

Make sure your kernel function ends in `return`, `return nothing` or `nothing`.

It would be great if compatibility for GPU broadcasting and kernels could be added. Looking at the code in this package, I don't understand how it is doing what it is doing so I don't think I can add support myself. It seems that fixing the return nothing problem with kernels might not be too hard though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant