@@ -36,7 +36,7 @@ Convert a native (CPU) `Geometry` to CUDA GPU types.
3636- `SparseMatrixCSC{T,Int}` → `CuSparseMatrixCSR{T,Int32}`
3737- Dense `Matrix{T}` operators → `CuMatrix{T}` (spectral)
3838"""
39- function MultiGridBarrier. native_to_cuda (g:: Geometry{T, Array{T,3}, Vector{T}, SparseMatrixCSC{T,Int}, SparseMatrixCSC{T,Int}, Discretization} ;
39+ function MultiGridBarrier. native_to_cuda (g:: Geometry{T, Array{T,3}, Vector{T}, SparseMatrixCSC{T,Int}, Discretization} ;
4040 Ti:: Type{<:Integer} = Int32) where {T, Discretization}
4141 x_cuda = CuArray {T,3} (g. x)
4242 w_cuda = CuVector {T} (g. w)
@@ -51,21 +51,15 @@ function MultiGridBarrier.native_to_cuda(g::Geometry{T, Array{T,3}, Vector{T}, S
5151 operators_cuda[key] = convert_sparse (g. operators[key])
5252 end
5353
54- subspaces_cuda = Dict {Symbol, MType} ()
55- for key in sort (collect (keys (g. subspaces)))
56- subspaces_cuda[key] = convert_sparse (g. subspaces[key])
57- end
58-
59- Geometry {T, CuArray{T,3}, CuVector{T}, MType, MType, Discretization} (
60- g. discretization, x_cuda, w_cuda, subspaces_cuda, operators_cuda)
54+ Geometry {T, CuArray{T,3}, CuVector{T}, MType, Discretization} (
55+ g. discretization, x_cuda, w_cuda, operators_cuda)
6156end
6257
6358# BlockDiag-operator variant: FEM Geometry whose `operators` came in via
6459# `subdivide` (or `geometric_mg(...; structured=true).geometry`). Carry the
6560# BlockDiag to GPU as a CuArray-backed BlockDiag; subspaces stay sparse CSR.
6661function MultiGridBarrier. native_to_cuda (g:: Geometry {T, Array{T,3 }, Vector{T},
6762 MultiGridBarrier. BlockDiag{T, A3},
68- SparseMatrixCSC{T,Int},
6963 Discretization};
7064 Ti:: Type{<:Integer} = Int32) where {T, A3<: Array{T,3} , Discretization}
7165 x_cuda = CuArray {T,3} (g. x)
@@ -76,24 +70,18 @@ function MultiGridBarrier.native_to_cuda(g::Geometry{T, Array{T,3}, Vector{T},
7670 MultiGridBarrier. BlockDiag {T, typeof(gpu_data)} (op. p, op. q, op. N, gpu_data)
7771 end
7872
79- sparse_to_gpu = op -> CuSparseMatrixCSR (
80- SparseMatrixCSC {T,Ti} (op. m, op. n, Ti .(op. colptr), Ti .(op. rowval), op. nzval))
81-
8273 sample_op = op_to_gpu (first (values (g. operators)))
8374 OpType = typeof (sample_op)
84- SubType = CuSparseMatrixCSR{T,Ti}
8575
8676 operators_cuda = Dict {Symbol, OpType} (
8777 key => op_to_gpu (g. operators[key]) for key in keys (g. operators))
88- subspaces_cuda = Dict {Symbol, SubType} (
89- key => sparse_to_gpu (g. subspaces[key]) for key in keys (g. subspaces))
9078
91- Geometry {T, CuArray{T,3}, CuVector{T}, OpType, SubType, Discretization} (
92- g. discretization, x_cuda, w_cuda, subspaces_cuda, operators_cuda)
79+ Geometry {T, CuArray{T,3}, CuVector{T}, OpType, Discretization} (
80+ g. discretization, x_cuda, w_cuda, operators_cuda)
9381end
9482
9583# Dense spectral variant.
96- function MultiGridBarrier. native_to_cuda (g:: Geometry{T, Array{T,3}, Vector{T}, Matrix{T}, Matrix{T}, Discretization} ;
84+ function MultiGridBarrier. native_to_cuda (g:: Geometry{T, Array{T,3}, Vector{T}, Matrix{T}, Discretization} ;
9785 kwargs... ) where {T, Discretization}
9886 x_cuda = CuArray {T,3} (g. x)
9987 w_cuda = CuVector {T} (g. w)
@@ -103,13 +91,8 @@ function MultiGridBarrier.native_to_cuda(g::Geometry{T, Array{T,3}, Vector{T}, M
10391 operators_cuda[key] = CuMatrix {T} (g. operators[key])
10492 end
10593
106- subspaces_cuda = Dict {Symbol, CuMatrix{T}} ()
107- for key in sort (collect (keys (g. subspaces)))
108- subspaces_cuda[key] = CuMatrix {T} (g. subspaces[key])
109- end
110-
111- Geometry {T, CuArray{T,3}, CuVector{T}, CuMatrix{T}, CuMatrix{T}, Discretization} (
112- g. discretization, x_cuda, w_cuda, subspaces_cuda, operators_cuda)
94+ Geometry {T, CuArray{T,3}, CuVector{T}, CuMatrix{T}, Discretization} (
95+ g. discretization, x_cuda, w_cuda, operators_cuda)
11396end
11497
11598# ============================================================================
204187
205188# Sparse FEM Geometry (CSR operators).
206189function MultiGridBarrier. cuda_to_native (g:: Geometry {T, <: CuArray{T,3} , <: CuVector{T} ,
207- <: CuSparseMatrixCSR{T} , <: CuSparseMatrixCSR{T} ,
190+ <: CuSparseMatrixCSR{T} ,
208191 Discretization}) where {T, Discretization}
209192 x_native = Array {T,3} (Array (g. x))
210193 w_native = Vector {T} (Array (g. w))
@@ -219,18 +202,13 @@ function MultiGridBarrier.cuda_to_native(g::Geometry{T, <:CuArray{T,3}, <:CuVect
219202 operators_native[key] = convert_back (g. operators[key])
220203 end
221204
222- subspaces_native = Dict {Symbol, SparseMatrixCSC{T,Ti}} ()
223- for key in sort (collect (keys (g. subspaces)))
224- subspaces_native[key] = convert_back (g. subspaces[key])
225- end
226-
227- Geometry {T, Array{T,3}, Vector{T}, SparseMatrixCSC{T,Ti}, SparseMatrixCSC{T,Ti}, Discretization} (
228- g. discretization, x_native, w_native, subspaces_native, operators_native)
205+ Geometry {T, Array{T,3}, Vector{T}, SparseMatrixCSC{T,Ti}, Discretization} (
206+ g. discretization, x_native, w_native, operators_native)
229207end
230208
231209# Dense spectral Geometry.
232210function MultiGridBarrier. cuda_to_native (g:: Geometry {T, <: CuArray{T,3} , <: CuVector{T} ,
233- <: CuMatrix{T} , <: CuMatrix{T} ,
211+ <: CuMatrix{T} ,
234212 Discretization}) where {T, Discretization}
235213 x_native = Array {T,3} (Array (g. x))
236214 w_native = Vector {T} (Array (g. w))
@@ -240,18 +218,13 @@ function MultiGridBarrier.cuda_to_native(g::Geometry{T, <:CuArray{T,3}, <:CuVect
240218 operators_native[key] = Matrix {T} (Array (g. operators[key]))
241219 end
242220
243- subspaces_native = Dict {Symbol, Matrix{T}} ()
244- for key in sort (collect (keys (g. subspaces)))
245- subspaces_native[key] = Matrix {T} (Array (g. subspaces[key]))
246- end
247-
248- Geometry {T, Array{T,3}, Vector{T}, Matrix{T}, Matrix{T}, Discretization} (
249- g. discretization, x_native, w_native, subspaces_native, operators_native)
221+ Geometry {T, Array{T,3}, Vector{T}, Matrix{T}, Discretization} (
222+ g. discretization, x_native, w_native, operators_native)
250223end
251224
252225# Structured FEM Geometry (block ops).
253226function MultiGridBarrier. cuda_to_native (g:: Geometry {T, <: CuArray{T,3} , <: CuVector{T} ,
254- <: Any , <: Any , Discretization}) where {T, Discretization}
227+ <: Any , Discretization}) where {T, Discretization}
255228 x_native = Array {T,3} (Array (g. x))
256229 w_native = Vector {T} (Array (g. w))
257230
@@ -267,13 +240,8 @@ function MultiGridBarrier.cuda_to_native(g::Geometry{T, <:CuArray{T,3}, <:CuVect
267240 operators_native[key] = convert_to_native (g. operators[key])
268241 end
269242
270- subspaces_native = Dict {Symbol, SparseMatrixCSC{T,Ti}} ()
271- for key in sort (collect (keys (g. subspaces)))
272- subspaces_native[key] = convert_to_native (g. subspaces[key])
273- end
274-
275- Geometry {T, Array{T,3}, Vector{T}, SparseMatrixCSC{T,Ti}, SparseMatrixCSC{T,Ti}, Discretization} (
276- g. discretization, x_native, w_native, subspaces_native, operators_native)
243+ Geometry {T, Array{T,3}, Vector{T}, SparseMatrixCSC{T,Ti}, Discretization} (
244+ g. discretization, x_native, w_native, operators_native)
277245end
278246
279247# MultiGrid cuda → native (sparse FEM).
0 commit comments