Move NodalData :data field to AbstractArray for GPU compatiblity
tclements opened this issue · 4 comments
Thinking about our move to the GPU, the :data
field of the NodalData
struct will need to be of type AbstractArray{Float32, 2}
to allow for transfer of data from CPU <-> GPU with Adapt.jl because:
julia> using CUDA
julia> CuArray <: AbstractArray
true
julia> CuArray <: Array
false
I think the :x
field will work as is because FloatArray
is Union{AbstractArray{Float32,1}, AbstractArray{Float64,1}}
and views work the same on the CPU and GPU though using :x
on the GPU will be quite inefficient:
julia> using CUDA, SeisIO
julia> mutable struct TEST
x::Array{SeisIO.FloatArray,1}
end
julia> A = [CUDA.rand(3) for _ = 1:2]
2-element Array{CuArray{Float32,1},1}:
Float32[0.95912075, 0.19107753, 0.60729915]
Float32[0.81118095, 0.5209754, 0.29273564]
julia> t = TEST(A)
TEST(Union{AbstractArray{Float32,1}, AbstractArray{Float64,1}}[Float32[0.95912075, 0.19107753, 0.60729915], Float32[0.81118095, 0.5209754, 0.29273564]])
julia> t.x
2-element Array{Union{AbstractArray{Float32,1}, AbstractArray{Float64,1}},1}:
Float32[0.95912075, 0.19107753, 0.60729915]
Float32[0.81118095, 0.5209754, 0.29273564]
julia> t.x[1]
3-element CuArray{Float32,1}:
0.95912075
0.19107753
0.60729915
Good point. Fixing this now.
In the future, we'll need to add an initialization method that creates a CuArray. I think that's as simple as importing SeisIO.NodalData to your GPU module and defining a new initialization function, but I haven't tested it...
Fixed on dev
Fixed on master and in the new release. Will close this issue as soon as Julia Registrator merges my PR(s).