Skip to content

Commit 2b4ecc8

Browse files
Merge pull request #1839 from CliMA/ck/inbounds_stencils
Use inbounds in stencil kernels
2 parents 59121aa + 2503721 commit 2b4ecc8

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

ext/cuda/operators_finite_difference.jl

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -51,26 +51,29 @@ function Base.copyto!(
5151
end
5252

5353
function copyto_stencil_kernel!(out, bc, space, bds, Nq, Nh, Nv)
54-
gid = threadIdx().x + (blockIdx().x - 1) * blockDim().x
55-
if gid Nv * Nq * Nq * Nh
56-
(li, lw, rw, ri) = bds
57-
(v, i, j, h) = Topologies._get_idx((Nv, Nq, Nq, Nh), gid)
58-
hidx = (i, j, h)
59-
idx = v - 1 + li
60-
window =
61-
idx < lw ? LeftBoundaryWindow{Spaces.left_boundary_name(space)}() :
62-
(
63-
idx > rw ?
64-
RightBoundaryWindow{Spaces.right_boundary_name(space)}() :
65-
Interior()
54+
@inbounds begin
55+
gid = threadIdx().x + (blockIdx().x - 1) * blockDim().x
56+
if gid Nv * Nq * Nq * Nh
57+
(li, lw, rw, ri) = bds
58+
(v, i, j, h) = Topologies._get_idx((Nv, Nq, Nq, Nh), gid)
59+
hidx = (i, j, h)
60+
idx = v - 1 + li
61+
window =
62+
idx < lw ?
63+
LeftBoundaryWindow{Spaces.left_boundary_name(space)}() :
64+
(
65+
idx > rw ?
66+
RightBoundaryWindow{Spaces.right_boundary_name(space)}() :
67+
Interior()
68+
)
69+
setidx!(
70+
space,
71+
out,
72+
idx,
73+
hidx,
74+
Operators.getidx(space, bc, window, idx, hidx),
6675
)
67-
setidx!(
68-
space,
69-
out,
70-
idx,
71-
hidx,
72-
Operators.getidx(space, bc, window, idx, hidx),
73-
)
76+
end
7477
end
7578
return nothing
7679
end

0 commit comments

Comments
 (0)