Skip to content

Commit f67f2b0

Browse files
authoredMar 18, 2025··
Merge pull request #2555 from devitocodes/tweak-idg-construction-2
compiler: Enhance IR for GPU codegen
2 parents 3efd0c0 + b3c2589 commit f67f2b0

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed
 

‎devito/ir/support/basic.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -1266,6 +1266,7 @@ def translated(self, other, dims=None):
12661266
dims = set(as_tuple(dims))
12671267

12681268
# Check bases and offsets
1269+
distances = {}
12691270
for i in ['Tbases', 'Toffsets']:
12701271
Ti0 = getattr(self, i)
12711272
Ti1 = getattr(other, i)
@@ -1288,13 +1289,16 @@ def translated(self, other, dims=None):
12881289

12891290
distance = set(o0 - o1)
12901291
if len(distance) != 1:
1291-
return False
1292+
return {}
1293+
v = distance.pop()
12921294

12931295
if not d._defines & dims:
1294-
if distance.pop() != 0:
1295-
return False
1296+
if v != 0:
1297+
return {}
1298+
1299+
distances[d] = v
12961300

1297-
return True
1301+
return distances
12981302

12991303
@cached_property
13001304
def iinstances(self):

‎devito/types/array.py

+18-12
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,18 @@ class Array(ArrayBasic):
9090
to 'local'. Used to override `_mem_local` and `_mem_mapped`.
9191
scope : str, optional
9292
The scope in the given memory space. Allowed values: 'heap', 'stack',
93-
'static', 'constant', 'shared', 'shared-remote'. 'static' refers to a
94-
static array in a C/C++ sense. 'constant' and 'shared' mean that the
95-
Array represents an object allocated in so called constant and shared
96-
memory, respectively, which are typical of device architectures. If
97-
'shared' is specified but the underlying architecture doesn't have
98-
something akin to shared memory, the behaviour is unspecified. If
99-
'constant' is specified but the underlying architecture doesn't have
100-
something akin to constant memory, the Array falls back to a global,
101-
const, static array in a C/C++ sense. Note that not all scopes make
102-
sense for a given space.
93+
'static', 'constant', 'shared', 'shared-remote', 'registers'.
94+
'static' refers to a static array in a C/C++ sense. 'constant' and
95+
'shared' mean that the Array represents an object allocated in so
96+
called constant and shared memory, respectively, which are typical of
97+
device architectures. If 'shared' is specified but the underlying
98+
architecture doesn't have something akin to shared memory, the
99+
behaviour is unspecified. If 'constant' is specified but the underlying
100+
architecture doesn't have something akin to constant memory, the Array
101+
falls back to a global, const, static array in a C/C++ sense.
102+
'registers' is used to indicate that the Array has a small static size
103+
and, as such, it could be allocated in registers. Defaults to 'heap'.
104+
Note that not all scopes make sense for a given space.
103105
grid : Grid, optional
104106
Only necessary for distributed-memory parallelism; a Grid contains
105107
information about the distributed Dimensions, hence it is necessary
@@ -133,7 +135,7 @@ def __init_finalize__(self, *args, **kwargs):
133135

134136
self._scope = kwargs.get('scope', 'heap')
135137
assert self._scope in ['heap', 'stack', 'static', 'constant', 'shared',
136-
'shared-remote']
138+
'shared-remote', 'registers']
137139

138140
self._initvalue = kwargs.get('initvalue')
139141
assert self._initvalue is None or self._scope != 'heap'
@@ -166,7 +168,7 @@ def _C_ctype(self):
166168

167169
@property
168170
def _mem_stack(self):
169-
return self._scope in ('stack', 'shared')
171+
return self._scope in ('stack', 'shared', 'registers')
170172

171173
@property
172174
def _mem_heap(self):
@@ -180,6 +182,10 @@ def _mem_shared(self):
180182
def _mem_shared_remote(self):
181183
return self._scope == 'shared-remote'
182184

185+
@property
186+
def _mem_registers(self):
187+
return self._scope == 'registers'
188+
183189
@property
184190
def _mem_constant(self):
185191
return self._scope == 'constant'

0 commit comments

Comments
 (0)
Please sign in to comment.