jpjones76 / SeisIO.jl

Julia language support for geophysical time series data
http://seisio.readthedocs.org
Other
47 stars 21 forks source link

Move NodalData :data field to AbstractArray for GPU compatiblity #56

Closed tclements closed 3 years ago

tclements commented 3 years ago

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
jpjones76 commented 3 years ago

Good point. Fixing this now.

jpjones76 commented 3 years ago

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...

jpjones76 commented 3 years ago

Fixed on dev

jpjones76 commented 3 years ago

Fixed on master and in the new release. Will close this issue as soon as Julia Registrator merges my PR(s).