Skip to content

Commit 19cbe35

Browse files
committed
compiler: Add arity field to struct array
1 parent f3d7aca commit 19cbe35

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

devito/passes/iet/definitions.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,12 @@ def _alloc_mapped_array_on_high_bw_mem(self, site, obj, storage, *args):
177177
"""
178178
decl = Definition(obj)
179179

180+
# NOTE: the `arity` is calculated such as `sizeof(float3)/sizeof(float)`
181+
# for portability reasons (since we don't know the size of compound
182+
# types a priori)
180183
arity_param = Symbol(name='arity', dtype=size_t)
181-
arity_arg = SizeOf(obj.indexed._C_typedata)
184+
arity_arg = (SizeOf(obj.indexed._C_typedata) /
185+
SizeOf(obj.c0.indexed._C_typedata))
182186
ndims_param = Symbol(name='ndims', dtype=size_t)
183187
ndims_arg = obj.ndim
184188
shape_param = Array(name=f'{obj.name}_shape', dtype=np.uint64,
@@ -189,6 +193,7 @@ def _alloc_mapped_array_on_high_bw_mem(self, site, obj, storage, *args):
189193
ffp1 = FieldFromPointer(obj._C_field_shape, obj._C_symbol)
190194
ffp2 = FieldFromPointer(obj._C_field_size, obj._C_symbol)
191195
ffp3 = FieldFromPointer(obj._C_field_nbytes, obj._C_symbol)
196+
ffp4 = FieldFromPointer(obj._C_field_arity, obj._C_symbol)
192197

193198
# Allocate the Array struct
194199
memptr = VOID(Byref(obj._C_symbol), '**')
@@ -213,6 +218,7 @@ def _alloc_mapped_array_on_high_bw_mem(self, site, obj, storage, *args):
213218
ndims_param - 1,
214219
))
215220
init.append(DummyExpr(ffp3, ffp2*arity_param))
221+
init.append(DummyExpr(ffp4, arity_param))
216222

217223
# Allocate the underlying host data
218224
memptr = VOID(Byref(ffp0), '**')
@@ -254,8 +260,12 @@ def _alloc_bundle_struct_on_high_bw_mem(self, site, obj, storage):
254260
"""
255261
decl = Definition(obj)
256262

263+
# NOTE: the `arity` is calculated such as `sizeof(float3)/sizeof(float)`
264+
# for portability reasons (since we don't know the size of compound
265+
# types a priori)
257266
arity_param = Symbol(name='arity', dtype=size_t)
258-
arity_arg = SizeOf(obj.indexed._C_typedata)
267+
arity_arg = (SizeOf(obj.indexed._C_typedata) /
268+
SizeOf(obj.c0.indexed._C_typedata))
259269
ndims_param = Symbol(name='ndims', dtype=size_t)
260270
ndims_arg = obj.ndim
261271
shape_param = Array(name=f'{obj.name}_shape', dtype=np.uint64,
@@ -265,6 +275,7 @@ def _alloc_bundle_struct_on_high_bw_mem(self, site, obj, storage):
265275
ffp1 = FieldFromPointer(obj._C_field_shape, obj._C_symbol)
266276
ffp2 = FieldFromPointer(obj._C_field_size, obj._C_symbol)
267277
ffp3 = FieldFromPointer(obj._C_field_nbytes, obj._C_symbol)
278+
ffp4 = FieldFromPointer(obj._C_field_arity, obj._C_symbol)
268279

269280
# Allocate the Bundle struct
270281
memptr = VOID(Byref(obj._C_symbol), '**')
@@ -289,6 +300,7 @@ def _alloc_bundle_struct_on_high_bw_mem(self, site, obj, storage):
289300
ndims_param - 1,
290301
))
291302
init.append(DummyExpr(ffp3, ffp2*arity_param))
303+
init.append(DummyExpr(ffp4, arity_param))
292304

293305
# Free all of the allocated data
294306
frees = [self.langbb['host-free'](ffp1),

devito/types/array.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class MappedArrayMixin:
223223
_C_field_shape = 'shape'
224224
_C_field_size = 'size'
225225
_C_field_nbytes = 'nbytes'
226+
_C_field_arity = 'arity'
226227

227228
_C_size_type = c_uint64
228229

@@ -231,7 +232,8 @@ class MappedArrayMixin:
231232
(_C_field_dmap, c_void_p),
232233
(_C_field_shape, POINTER(_C_size_type)),
233234
(_C_field_size, _C_size_type),
234-
(_C_field_nbytes, _C_size_type)]}))
235+
(_C_field_nbytes, _C_size_type),
236+
(_C_field_arity, _C_size_type)]}))
235237

236238

237239
class ArrayMapped(MappedArrayMixin, Array):

0 commit comments

Comments
 (0)