@@ -168,11 +168,7 @@ def _alloc_mapped_array_on_high_bw_mem(self, site, obj, storage, *args):
168168 """
169169 decl = Definition (obj )
170170
171- # Allocating a mapped Array on the high bandwidth memory requires
172- # multiple statements, hence we implement it as a generic Callable
173- # to minimize code size, since different arrays will ultimately be
174- # able to reuse the same abstract Callable
175-
171+ # Allocate the Array struct
176172 memptr = VOID (Byref (obj ._C_symbol ), '**' )
177173 alignment = obj ._data_alignment
178174 nbytes = SizeOf (obj ._C_typedata )
@@ -181,10 +177,12 @@ def _alloc_mapped_array_on_high_bw_mem(self, site, obj, storage, *args):
181177 nbytes_param = Symbol (name = 'nbytes' , dtype = np .uint64 , is_const = True )
182178 nbytes_arg = SizeOf (obj .indexed ._C_typedata )* obj .size
183179
180+ # Allocate the underlying host data
184181 ffp0 = FieldFromPointer (obj ._C_field_data , obj ._C_symbol )
185182 memptr = VOID (Byref (ffp0 ), '**' )
186183 allocs .append (self .lang ['host-alloc-pin' ](memptr , alignment , nbytes_param ))
187184
185+ # Initialize the Array struct
188186 ffp1 = FieldFromPointer (obj ._C_field_nbytes , obj ._C_symbol )
189187 init0 = DummyExpr (ffp1 , nbytes_param )
190188 ffp2 = FieldFromPointer (obj ._C_field_size , obj ._C_symbol )
@@ -193,8 +191,7 @@ def _alloc_mapped_array_on_high_bw_mem(self, site, obj, storage, *args):
193191 frees = [self .lang ['host-free-pin' ](ffp0 ),
194192 self .lang ['host-free' ](obj ._C_symbol )]
195193
196- # Not all backends require explicit allocation/deallocation of the
197- # `dmap` field
194+ # Allocate the underlying device data, if required by the backend
198195 alloc , free = self ._make_dmap_allocfree (obj , nbytes_param )
199196
200197 # Chain together all allocs and frees
@@ -203,13 +200,16 @@ def _alloc_mapped_array_on_high_bw_mem(self, site, obj, storage, *args):
203200
204201 ret = Return (obj ._C_symbol )
205202
203+ # Wrap everything in a Callable so that we can reuse the same code
204+ # for equivalent Array structs
206205 name = self .sregistry .make_name (prefix = 'alloc' )
207206 body = (decl , * allocs , init0 , init1 , ret )
208207 efunc0 = make_callable (name , body , retval = obj )
209208 args = list (efunc0 .parameters )
210209 args [args .index (nbytes_param )] = nbytes_arg
211210 alloc = Call (name , args , retobj = obj )
212211
212+ # Same story for the frees
213213 name = self .sregistry .make_name (prefix = 'free' )
214214 efunc1 = make_callable (name , frees )
215215 free = Call (name , efunc1 .parameters )
@@ -222,6 +222,7 @@ def _alloc_bundle_struct_on_high_bw_mem(self, site, obj, storage):
222222 """
223223 decl = Definition (obj )
224224
225+ # Allocate the Bundle struct
225226 memptr = VOID (Byref (obj ._C_symbol ), '**' )
226227 alignment = obj ._data_alignment
227228 nbytes = SizeOf (obj ._C_typedata )
@@ -230,6 +231,7 @@ def _alloc_bundle_struct_on_high_bw_mem(self, site, obj, storage):
230231 nbytes_param = Symbol (name = 'nbytes' , dtype = np .uint64 , is_const = True )
231232 nbytes_arg = SizeOf (obj .indexed ._C_typedata )* obj .size
232233
234+ # Initialize the Bundle struct
233235 ffp1 = FieldFromPointer (obj ._C_field_nbytes , obj ._C_symbol )
234236 init0 = DummyExpr (ffp1 , nbytes_param )
235237 ffp2 = FieldFromPointer (obj ._C_field_size , obj ._C_symbol )
@@ -239,6 +241,8 @@ def _alloc_bundle_struct_on_high_bw_mem(self, site, obj, storage):
239241
240242 ret = Return (obj ._C_symbol )
241243
244+ # Wrap everything in a Callable so that we can reuse the same code
245+ # for equivalent Bundle structs
242246 name = self .sregistry .make_name (prefix = 'alloc' )
243247 body = (decl , alloc , init0 , init1 , ret )
244248 efunc0 = make_callable (name , body , retval = obj )
0 commit comments