|
| 1 | +import ClimaCore: DataLayouts, Spaces, Geometry, RecursiveApply, DataLayouts |
| 2 | +import CUDA |
| 3 | +import ClimaCore.Operators: return_eltype, get_local_geometry |
| 4 | + |
| 5 | +Base.@propagate_inbounds function fd_operator_shmem( |
| 6 | + space, |
| 7 | + ::Val{Nvt}, |
| 8 | + op::Operators.DivergenceF2C, |
| 9 | + args..., |
| 10 | +) where {Nvt} |
| 11 | + # allocate temp output |
| 12 | + RT = return_eltype(op, args...) |
| 13 | + Ju³ = CUDA.CuStaticSharedArray(RT, (Nvt,)) |
| 14 | + return Ju³ |
| 15 | +end |
| 16 | + |
| 17 | +Base.@propagate_inbounds function fd_operator_fill_shmem_interior!( |
| 18 | + op::Operators.DivergenceF2C, |
| 19 | + Ju³, |
| 20 | + loc, # can be any location |
| 21 | + space, |
| 22 | + idx::Utilities.PlusHalf, |
| 23 | + hidx, |
| 24 | + arg, |
| 25 | +) |
| 26 | + @inbounds begin |
| 27 | + vt = threadIdx().x |
| 28 | + lg = Geometry.LocalGeometry(space, idx, hidx) |
| 29 | + u³ = Operators.getidx(space, arg, loc, idx, hidx) |
| 30 | + Ju³[vt] = Geometry.Jcontravariant3(u³, lg) |
| 31 | + end |
| 32 | + return nothing |
| 33 | +end |
| 34 | + |
| 35 | +Base.@propagate_inbounds function fd_operator_fill_shmem_left_boundary!( |
| 36 | + op::Operators.DivergenceF2C, |
| 37 | + bc::Operators.SetValue, |
| 38 | + Ju³, |
| 39 | + loc, |
| 40 | + space, |
| 41 | + idx::Utilities.PlusHalf, |
| 42 | + hidx, |
| 43 | + arg, |
| 44 | +) |
| 45 | + idx == Operators.left_face_boundary_idx(space) || |
| 46 | + error("Incorrect left idx") |
| 47 | + @inbounds begin |
| 48 | + vt = threadIdx().x |
| 49 | + lg = Geometry.LocalGeometry(space, idx, hidx) |
| 50 | + u³ = Operators.getidx(space, bc.val, loc, nothing, hidx) |
| 51 | + Ju³[vt] = Geometry.Jcontravariant3(u³, lg) |
| 52 | + end |
| 53 | + return nothing |
| 54 | +end |
| 55 | + |
| 56 | +Base.@propagate_inbounds function fd_operator_fill_shmem_right_boundary!( |
| 57 | + op::Operators.DivergenceF2C, |
| 58 | + bc::Operators.SetValue, |
| 59 | + Ju³, |
| 60 | + loc, |
| 61 | + space, |
| 62 | + idx::Utilities.PlusHalf, |
| 63 | + hidx, |
| 64 | + arg, |
| 65 | +) |
| 66 | + # The right boundary is called at `idx + 1`, so we need to subtract 1 from idx (shmem is loaded at vt+1) |
| 67 | + idx == Operators.right_face_boundary_idx(space) || |
| 68 | + error("Incorrect right idx") |
| 69 | + @inbounds begin |
| 70 | + vt = threadIdx().x |
| 71 | + lg = Geometry.LocalGeometry(space, idx, hidx) |
| 72 | + u³ = Operators.getidx(space, bc.val, loc, nothing, hidx) |
| 73 | + Ju³[vt] = Geometry.Jcontravariant3(u³, lg) |
| 74 | + end |
| 75 | + return nothing |
| 76 | +end |
| 77 | + |
| 78 | +Base.@propagate_inbounds function fd_operator_evaluate( |
| 79 | + op::Operators.DivergenceF2C, |
| 80 | + Ju³, |
| 81 | + loc, |
| 82 | + space, |
| 83 | + idx::Integer, |
| 84 | + hidx, |
| 85 | + args..., |
| 86 | +) |
| 87 | + @inbounds begin |
| 88 | + vt = threadIdx().x |
| 89 | + local_geometry = Geometry.LocalGeometry(space, idx, hidx) |
| 90 | + Ju³₋ = Ju³[vt] # corresponds to idx - half |
| 91 | + Ju³₊ = Ju³[vt + 1] # corresponds to idx + half |
| 92 | + return (Ju³₊ ⊟ Ju³₋) ⊠ local_geometry.invJ |
| 93 | + end |
| 94 | +end |
0 commit comments