-
Notifications
You must be signed in to change notification settings - Fork 38
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
Passing struct
s into @parallel
functions
#53
Comments
Hi @smartalecH, the issue you see passing a We are currently developing proper support for different kind of data types within ParallelStencil, notably for logical arrays of structs (or of small arrays) which can be either laid out in memory as arrays of structs or as structs of arrays accounting for the fact that each of these allocation approaches has its use cases where it performs best. The following shows, e.g., how an array of small arrays can be created in future using a purely declarative allocation: julia> using ParallelStencil
julia> @init_parallel_stencil(package=CUDA, ndims=2)
julia> A = @rand(2, 2, numbertype=Float16, celldims=(2,3))
2×2 CUDA.CuArray{StaticArrays.SMatrix{2, 3, Float16, 6}, 2}:
[0.877 0.7266 0.007324; 0.5176 0.3496 0.541] … [0.8716 0.7246 0.4375; 0.662 0.4355 0.2075]
[0.5244 0.2056 0.1436; 0.891 0.0757 0.882] [0.9214 0.5864 0.206; 0.2124 0.1855 0.4756]
julia> A[2,1]
2×3 StaticArrays.SMatrix{2, 3, Float16, 6} with indices SOneTo(2)×SOneTo(3):
0.5244 0.2056 0.1436
0.891 0.0757 0.882
julia> A[2,1][2]
Float16(0.891) Logical arrays of structs will be allocatable in a similar way. Note that this is not yet merged into the master branch of ParallelStencil, but should be ready within a few weeks. In any case, we plan to present this at JuliaCon 2022. Meanwhile, you will need to manually make sure to comply with the requirements of CUDA.jl. The following document documentation explains one solution: https://cuda.juliagpu.org/stable/tutorials/custom_structs/. A MWE implementing it in ParallelStencil using Regarding the
Hope this info helps. |
Wow, thank you for the very comprehensive response!
This makes sense, thanks.
Interesting. Let me know if I can help at all. Happy to contribute.
Very cool. If you get a chance, please post a link to the corresponding paper (and youtube talk once available).
Thanks for pulling this together. Very helpful!
Very much so, thanks! I'll keep this issue open then at least until the change you mention is merged into |
On a similar note, suppose I want to initialize a "geometry" array (e.g. if I were to solve the Poisson PDE, ∇⋅c∇u = f and Typically (in C/C++) I try to initialize such arrays using the same formalism as the code that operates on them, so that they get allocated nearest to the respective core (and minimize any broadcasting and communication between cores or processes). Ideally, I would also use a What do you guys typically do in these situations? Have you tried interfacing directly with external geometry libraries, or do you typically start with a native CPU array and broadcast when needed (as done here)? Thanks for all of the help! |
Up to now, our approach was to do most of initialisation using native CPU arrays as you are referring to, broadcasting the final result to Ultimately, very user is free to pick their preferred workflow, being ultimately able to broadcast the final result to the desired type and backend.
Some times, but in the above described fashion. |
I have several
@parallel
functions that each have several arguments (of typeData.Array
). To make the code cleaner, I (naively) tried passing a singlestruct
containing all of these arguments. Unfortunately, I get the following error:Fundamentally, I'm assuming this has something to do with how the
struct
lives in memory and isn't compatible with the the wayParallelStencil
distributesData.Array
s. Is there a way around this? Perhaps there's a more "canonical" way to accomplish this?Could you also explain the role of the
@within
macro, so that I can better understand the limitations of@parallel
functions (and how to properly use them)?Thanks for the great package!
The text was updated successfully, but these errors were encountered: