Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make a package and add CUDA support #17

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Conversation

lcw
Copy link

@lcw lcw commented Apr 21, 2020

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

vchuravy and others added 9 commits April 14, 2020 08:35
Changes:
- Accepts primitive types (e.g. types with no fields).
  This allows broadcast to produce SoA arrays starting
  from something like `SoA{Float32, 2}`.
- Supports multiple storage array types. Most notably
  `CuArrays` and `CuDeviceArray`.
In this process the broadcasting was updated to work and most of the
tests were updated to run.
Here we have updated the README to include the new way of constructing
`StructOfArrays` and have removed dated information.
This adds basic support for broadcasting a `StructOfArrays` with `CuArray`
storage.  I could not figure out how to reuse the functionality from
GPUArrays without copying it here.
@lcw lcw mentioned this pull request Apr 21, 2020
@cossio
Copy link

cossio commented Apr 21, 2020

Why not use StructArrays?

@lcw
Copy link
Author

lcw commented Apr 21, 2020

@cossio I tried, see JuliaArrays/StructArrays.jl#86,
JuliaArrays/StructArrays.jl#87, and JuliaArrays/StructArrays.jl#114
but I could not get it to work for my use case, see JuliaArrays/StructArrays.jl#114 (comment). The recursive nature of foreachfield is causing problems in StructArrays. That recursion needs to happen at compile time and not run time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants