Skip to content

Commit

Permalink
First modification of kernel to utilise StaticVectors.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpudig committed Dec 20, 2024
1 parent 102000e commit 151e16c
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/multilayerqg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -525,22 +525,24 @@ Compute the inverse Fourier transform of `varh` and store it in `var`.
invtransform!(var, varh, params::AbstractParams) = ldiv!(var, params.rfftplan, varh)

"""
@kernel function PVinversion_kernel!(a, b, M, nlayers)
@kernel function PVinversion_kernel!(a, b, M, ::Val{N}) where N
Kernel for the PV/stream function inversion step,
i.e., `qh = params.S * ψh` or `ψh = params.S⁻¹ qh`.
Kernel for the PV/stream function inversion step, i.e., `qh = params.S * ψh` or `ψh = params.S⁻¹ qh`.
StaticVectors are used to efficiently perform the matrix-vector multiplication.
"""
@kernel function PVinversion_kernel!(a, b, M, ::Val{nlayers}) where nlayers
@kernel function PVinversion_kernel!(a, b, M, ::Val{N}) where N
i, j = @index(Global, NTuple)

Check warning on line 534 in src/multilayerqg.jl

View check run for this annotation

Codecov / codecov/patch

src/multilayerqg.jl#L533-L534

Added lines #L533 - L534 were not covered by tests

@unroll for k = 1:nlayers
b_tuple = ntuple(Val(N)) do n
@inbounds b[i, j, n]
end

@inbounds a[i, j, k] = 0
T = eltype(a)
b_sv = SVector{N, T}(b_tuple)
a_sv = @inbounds M[i, j] * b_sv

@unroll for m = 1:nlayers
@inbounds a[i, j, k] += M[i, j][k, m] * b[i, j, m]
end

ntuple(Val(N)) do n
@inbounds a[i, j, n] = a_sv[n]
end
end

Expand Down

0 comments on commit 151e16c

Please sign in to comment.