@@ -8,6 +8,8 @@ using Oceananigans.Grids
8
8
9
9
using Oceananigans. Grids: AbstractGrid
10
10
11
+ import Base
12
+
11
13
struct KernelParameters{S, O} end
12
14
13
15
"""
152
154
153
155
# ####
154
156
# #### Extension to KA for offset indices: to remove when implemented in KA
155
- # #### Allows to call a kernel with kernel(dev, workgroup, worksize, offsets)
157
+ # #### Allows to use `launch!` with offsets, e.g.:
158
+ # #### `launch!(arch, grid, KernelParameters(size, offsets), kernel!; kernel_args...)`
156
159
# #### where offsets is a tuple containing the offset to pass to @index
160
+ # #### Note that this syntax is only usable in conjunction with the `launch!` function and
161
+ # #### will have no effect if the kernel is launched with `kernel!` directly.
162
+ # #### To achieve the same result with kernel launching, the correct syntax is:
163
+ # #### `kernel!(arch, StaticSize(size), OffsetStaticSize(contiguousrange(size, offset)))`
164
+ # #### Using offsets is (at the moment) incompatible with dynamic workgroup sizes: in case of offset dynamic kernels
165
+ # #### offsets will have to be passed manually.
157
166
# ####
158
167
159
168
# TODO : when offsets are implemented in KA so that we can call `kernel(dev, group, size, offsets)`, remove all of this
@@ -193,7 +202,14 @@ import KernelAbstractions: get, expand
193
202
@inline worksize (i:: Int ) = i
194
203
@inline worksize (i:: UnitRange ) = length (i)
195
204
196
- const OffsetNDRange{N} = NDRange{N, <: StaticSize , <: StaticSize , <: Any , <: Tuple } where N
205
+ """ a type used to store offsets in `NDRange` types"""
206
+ struct KernelOffsets{O}
207
+ offsets :: O
208
+ end
209
+
210
+ Base. getindex (o:: KernelOffsets , args... ) = getindex (o. offsets, args... )
211
+
212
+ const OffsetNDRange{N} = NDRange{N, <: StaticSize , <: StaticSize , <: Any , <: KernelOffsets } where N
197
213
198
214
# NDRange has been modified to have offsets in place of workitems: Remember, dynamic offset kernels are not possible with this extension!!
199
215
@inline function expand (ndrange:: OffsetNDRange{N} , groupidx:: CartesianIndex{N} , idx:: CartesianIndex{N} ) where {N}
@@ -243,7 +259,7 @@ function partition(kernel::OffsetKernel, inrange, ingroupsize)
243
259
static_blocks = StaticSize{blocks}
244
260
static_workgroupsize = StaticSize{groupsize} # we might have padded workgroupsize
245
261
246
- iterspace = NDRange {length(range), static_blocks, static_workgroupsize} (blocks, offsets)
262
+ iterspace = NDRange {length(range), static_blocks, static_workgroupsize} (blocks, KernelOffsets ( offsets) )
247
263
248
264
return iterspace, dynamic
249
265
end
0 commit comments