@@ -403,8 +403,11 @@ def generate_buffers(clusters, key, sregistry, options, **kwargs):
403403 # Finally create the actual buffer
404404 cls = callback or Array
405405 name = sregistry .make_name (prefix = '%sb' % f .name )
406+ # We specify the padding to match the input Function's one, so that
407+ # the array can be used in place of the Function with valid strides
406408 mapper [f ] = cls (name = name , dimensions = dimensions , dtype = f .dtype ,
407- grid = f .grid , halo = f .halo , space = 'mapped' , mapped = f , f = f )
409+ padding = f .padding , grid = f .grid , halo = f .halo ,
410+ space = 'mapped' , mapped = f , f = f )
408411
409412 return mapper
410413
@@ -439,8 +442,27 @@ def __init__(self, f, b, clusters):
439442 # The IterationSpace within which the buffer will be accessed
440443 # NOTE: The `key` is to avoid Clusters including `f` but not directly
441444 # using it in an expression, such as HaloTouch Clusters
442- key = lambda c : any (i in c .ispace .dimensions for i in self .bdims )
443- ispaces = {c .ispace for c in clusters if key (c )}
445+ def key (c ):
446+ bufferdim = any (i in c .ispace .dimensions for i in self .bdims )
447+ timeonly = all (d .is_Time for d in c .ispace .dimensions )
448+ return bufferdim or timeonly
449+
450+ ispaces = set ()
451+ for c in clusters :
452+ if not key (c ):
453+ continue
454+
455+ # Skip wild clusters (e.g. HaloTouch Clusters)
456+ if c .is_wild :
457+ continue
458+ # Iterations space and buffering dims
459+ ispace = c .ispace
460+ edims = [d for d in self .bdims if d not in ispace .dimensions ]
461+ if not edims :
462+ ispaces .add (ispace )
463+ else :
464+ # Add all missing buffering dimensions
465+ ispaces .add (ispace .insert (self .dim , edims ).reorder ())
444466
445467 if len (ispaces ) > 1 :
446468 # Best effort to make buffering work in the presence of multiple
@@ -449,6 +471,7 @@ def __init__(self, f, b, clusters):
449471 ispaces = {i .lift (self .bdims , v = stamp ) for i in ispaces }
450472
451473 if len (ispaces ) > 1 :
474+ print (ispaces )
452475 raise CompilationError ("Unsupported `buffering` over different "
453476 "IterationSpaces" )
454477
0 commit comments