Can I use StaticArrays in a kernel function? I wanted to use registers allocated for each thread. I thought that SVector would do that for me so I tried the following simple function. But, it says the kernel is returning Union{}. I do not understand why the body of the code is supposed to return Union{}.
julia> using CUDA
julia> using StaticArrays
julia> function register()
x = SVector{3,Float64}
x[1] = 1.0
return nothing
end
register (generic function with 1 method)
julia> @device_code_warntype @cuda threads=64 blocks=1 register()
PTX CompilerJob of kernel register() for sm_70
Variables
#self#::Core.Compiler.Const(register, false)
x::Type{SArray{Tuple{3},Float64,1,3}}
Body::Union{}
1 ─ (x = Core.apply_type(Main.SVector, 3, Main.Float64))
│ Base.setindex!(x::Core.Compiler.Const(SArray{Tuple{3},Float64,1,3}, false), 1.0, 1)
└── Core.Compiler.Const(:(return Main.nothing), false)
ERROR: GPU compilation of kernel register() failed
KernelError: kernel returns a value of type `Union{}`
Make sure your kernel function ends in `return`, `return nothing` or `nothing`.
If the returned value is of type `Union{}`, your Julia code probably throws an exception.
Inspect the code with `@device_code_warntype` for more details.