@@ -4,7 +4,7 @@ using CUDA: cufunc, curand_rng
44using CUDA. CUSPARSE: CuSparseMatrix, CuSparseMatrixCSR, CuSparseMatrixCOO
55using CUDA. CUSOLVER: CuQR
66
7- export cuda_gc, gpu
7+ export cuda_gc, gpu, @gpu! , @cu!
88
99const CuBaseField{B,M,T,A<: CuArray } = BaseField{B,M,T,A}
1010
2020is_gpu_backed (:: BaseField{B,M,T,A} ) where {B,M,T,A<: CuArray } = true
2121global_rng_for (:: Type{<:CuArray} ) = curand_rng ()
2222
23+ # handy conversion functions and macros
24+ @doc doc"""
2325
26+ @gpu! x y
27+
28+ Equivalent to `x = gpu(x)`, `y = gpu(y)`, etc... for any number of
29+ listed variables. See [`gpu`](@ref).
30+ """
31+ macro gpu! (vars... )
32+ :(begin ; $ ((:($ (esc (var)) = gpu ($ (esc (var)))) for var in vars). .. ); nothing ; end )
33+ end
34+ @doc doc"""
35+
36+ gpu(x)
37+
38+ Recursively moves x to GPU, but unlike `CUDA.cu`, doesn't also convert
39+ to Float32. Equivalent to `adapt_structure(CuArray, x)`. Returns nothing.
40+ """
2441gpu (x) = adapt_structure (CuArray, x)
2542
2643
44+ @doc doc"""
45+
46+ @cu! x y
47+
48+ Equivalent to `x = cu(x)`, `y = cu(y)`, etc... for any number of
49+ listed variables. See `CUDA.cu`. Returns nothing.
50+ """
51+ macro cu! (vars... )
52+ :(begin ; $ ((:($ (esc (var)) = cu ($ (esc (var)))) for var in vars). .. ); nothing ; end )
53+ end
54+
55+
56+
2757adapt_structure (:: CUDA.Float32Adaptor , proj:: ProjLambert ) = adapt_structure (CuArray{Float32}, proj)
2858
2959
0 commit comments