Skip to content

Commit 01bd794

Browse files
committed
compiler: Cast only product transfer bounds to long, update 01_gpu notebook
Applying as_long unconditionally also rewrote plain per-dimension extents (IndexedPointer leaves), churning every non-linearized transfer pragma and breaking the openacc codegen tests and the 01_gpu notebook. Only a product of 32-bit sizes can overflow int, so restrict the promotion to Mul bounds and update the notebook's reference output for the linearized transfer clauses that legitimately gained the casts.
1 parent 2f40313 commit 01bd794

2 files changed

Lines changed: 11 additions & 7 deletions

File tree

‎devito/passes/iet/parpragma.py‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,10 +495,14 @@ def _generate(self):
495495
# is a product of the Function's 32-bit per-dimension sizes (e.g.
496496
# `size[0]*size[1]*size[2]`); for a Function with more than ~2**31
497497
# elements this product overflows `int` before being used as an array
498-
# bound, producing a bogus transfer size (#2777). `as_long` promotes the
499-
# size's symbolic leaves to 64-bit so the multiplication is carried out
500-
# in 64-bit arithmetic.
501-
sections = ''.join([f'[{ccode(i)}:{ccode(as_long(j))}]'
498+
# bound, producing a bogus transfer size (#2777). Promote such products
499+
# to 64-bit with `as_long` so the multiplication is carried out in
500+
# 64-bit arithmetic. Non-product bounds (a single size, an offset, a
501+
# constant) cannot overflow and are left untouched so that the
502+
# generated code doesn't change where the cast serves no purpose.
503+
def cast(e):
504+
return as_long(e) if getattr(e, 'is_Mul', False) else e
505+
sections = ''.join([f'[{ccode(cast(i))}:{ccode(cast(j))}]'
502506
for i, j in self.sections])
503507
arguments = [ccode(i) for i in self.arguments]
504508
return self.pragma % (self.function.name, sections, *arguments)

‎examples/performance/01_gpu.ipynb‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@
289289
"\n",
290290
" float *u = (float *) u_vec->data;\n",
291291
"\n",
292-
" #pragma omp target enter data map(to: u[0:u_vec->size[0]*u_vec->size[1]*u_vec->size[2]])\n",
292+
" #pragma omp target enter data map(to: u[0:(long)(u_vec->size[2])*(long)(u_vec->size[1])*(long)(u_vec->size[0])])\n",
293293
"\n",
294294
" const int x_fsz0 = u_vec->size[1];\n",
295295
" const int y_fsz0 = u_vec->size[2];\n",
@@ -315,8 +315,8 @@
315315
" STOP(section0,timers)\n",
316316
" }\n",
317317
"\n",
318-
" #pragma omp target update from(u[0:u_vec->size[0]*u_vec->size[1]*u_vec->size[2]])\n",
319-
" #pragma omp target exit data map(release: u[0:u_vec->size[0]*u_vec->size[1]*u_vec->size[2]]) if(devicerm)\n",
318+
" #pragma omp target update from(u[0:(long)(u_vec->size[2])*(long)(u_vec->size[1])*(long)(u_vec->size[0])])\n",
319+
" #pragma omp target exit data map(release: u[0:(long)(u_vec->size[2])*(long)(u_vec->size[1])*(long)(u_vec->size[0])]) if(devicerm)\n",
320320
"\n",
321321
" return 0;\n",
322322
"}\n",

0 commit comments

Comments
 (0)