Skip to content

Instantly share code, notes, and snippets.

@luraess
Created April 3, 2022 21:59
Show Gist options
  • Save luraess/9b595f66ccdbacbbffa740d33ce772f7 to your computer and use it in GitHub Desktop.
Save luraess/9b595f66ccdbacbbffa740d33ce772f7 to your computer and use it in GitHub Desktop.
Use struct in ParallelStencil
using ParallelStencil
using ParallelStencil.FiniteDifferences2D
@init_parallel_stencil(CUDA, Float64, 2)
struct myStruct{T}
val::T
end
n = 20
A = myStruct(@rand(n,n))
B = similar(A.val)
@parallel_indices (i, j) function bar!(B, A)
B[i,j] = A.val[i,j]
return nothing
end
import Adapt
function Adapt.adapt_structure(to, A::myStruct)
val = Adapt.adapt_structure(to, A.val)
myStruct(val)
end
@parallel (1:n, 1:n) bar!(B, A)
@assert all(Array(A.val) .== Array(B))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment