Make a package and add CUDA support
This updates StructsOfArrays to work with Julia 1.4.1 and turns it into a package. In addition basic CUDA support has been added (thanks @vchuravy!) so that StructOfArrays can be passed into kernels, e.g.,
using CuArrays, CUDAnative, StaticArrays, StructsOfArrays
CuArrays.allowscalar(false)
A = rand(SArray{Tuple{3},Float64,1,3}, 10, 10)
B = replace_storage(CuArray, convert(StructOfArrays, A))
function kernel!(A)
i = (blockIdx().x-1)*blockDim().x + threadIdx().x
if i <= length(A)
A[i] += A[i]
end
return nothing
end
threads = 256
blocks = cld(length(B), threads)
@cuda threads=threads blocks=blocks kernel!(B)
and used in broadcasting statements, e.g.,
using LinearAlgebra
n = norm.(B)
B .+= B
I first tried to add this functionality to StructArrays.jl but found it hard to get CUDA compatible getindex and setindex! functions.
If this pr gets accepted I would also like to register this as a package. If needed I am happy to help maintain this code.
cc: @vchuravy @simonbyrne
Why not use StructArrays?
@cossio I tried, see https://github.com/JuliaArrays/StructArrays.jl/issues/86,
https://github.com/JuliaArrays/StructArrays.jl/pull/87, and https://github.com/JuliaArrays/StructArrays.jl/pull/114
but I could not get it to work for my use case, see https://github.com/JuliaArrays/StructArrays.jl/pull/114#issuecomment-571244310. The recursive nature of foreachfield is causing problems in StructArrays. That recursion needs to happen at compile time and not run time.