Skip to content

GPU support #93

@AntonReinhard

Description

@AntonReinhard

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions