Skip to content

Commit 7e03dd5

Browse files
committed
Fix kernel arg lifetimes in isoFDModelling example
Keep pointer arrays alive through launches to avoid free-threaded Python misaligned-address failures caused by temporary argument buffers.
1 parent dbfa3db commit 7e03dd5

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

‎cuda_bindings/examples/extra/isoFDModelling_test.py‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ def createSource(self, kernel):
310310
freq = np.array(self.params.freqMax, dtype=np.float32)
311311

312312
args = [buf, dt, freq, nt]
313-
args = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
313+
argsp = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
314314
checkCudaErrors(cuda.cuCtxSetCurrent(self.context))
315315
checkCudaErrors(
316316
cuda.cuLaunchKernel(
@@ -323,7 +323,7 @@ def createSource(self, kernel):
323323
1, # block dim
324324
0,
325325
self.streamHalo, # shared mem and stream
326-
args.ctypes.data,
326+
argsp.ctypes.data,
327327
0,
328328
)
329329
) # arguments
@@ -351,7 +351,7 @@ def injectSource(self, kernel, iter):
351351
np_it = np.array(iter, dtype=np.uint32)
352352

353353
args = [wavein + offset_sourceInject, src, np_it]
354-
args = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
354+
argsp = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
355355
checkCudaErrors(
356356
cuda.cuLaunchKernel(
357357
kernel.injectSource,
@@ -363,7 +363,7 @@ def injectSource(self, kernel, iter):
363363
1, # block dim
364364
0,
365365
self.streamHalo, # shared mem and stream
366-
args.ctypes.data,
366+
argsp.ctypes.data,
367367
0,
368368
)
369369
) # arguments
@@ -391,7 +391,7 @@ def createVelocity(self, kernel):
391391
np_stride = np.array(stride, dtype=np.uint32)
392392

393393
args = [vel + offset_velocity, np_dx_dt2, np_nz, np_nx, np_stride]
394-
args = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
394+
argsp = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
395395

396396
checkCudaErrors(cuda.cuCtxSetCurrent(self.context))
397397

@@ -407,7 +407,7 @@ def createVelocity(self, kernel):
407407
1, # block dim
408408
0,
409409
self.streamHalo, # shared mem and stream
410-
args.ctypes.data,
410+
argsp.ctypes.data,
411411
0,
412412
)
413413
) # arguments
@@ -448,7 +448,7 @@ def executeCenter(self, kernel):
448448
np_nx,
449449
np_stride,
450450
]
451-
args = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
451+
argsp = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
452452

453453
# do center propagation from 2 * fd_order to nz - 2 * fd_order
454454
checkCudaErrors(
@@ -462,7 +462,7 @@ def executeCenter(self, kernel):
462462
1, # block dim
463463
0,
464464
self.streamCenter, # shared mem and stream
465-
args.ctypes.data,
465+
argsp.ctypes.data,
466466
0,
467467
)
468468
) # arguments
@@ -503,7 +503,7 @@ def executeHalo(self, kernel):
503503
np_nx,
504504
np_stride,
505505
]
506-
args = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
506+
argsp = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
507507

508508
# do halo up
509509
checkCudaErrors(
@@ -517,7 +517,7 @@ def executeHalo(self, kernel):
517517
1, # block dim
518518
0,
519519
self.streamHalo, # shared mem and stream
520-
args.ctypes.data,
520+
argsp.ctypes.data,
521521
0,
522522
)
523523
) # arguments
@@ -541,7 +541,7 @@ def executeHalo(self, kernel):
541541
np_nx,
542542
np_stride,
543543
]
544-
args = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
544+
argsp = np.array([arg.ctypes.data for arg in args], dtype=np.uint64)
545545
checkCudaErrors(
546546
cuda.cuLaunchKernel(
547547
kernel.fdPropag,
@@ -553,7 +553,7 @@ def executeHalo(self, kernel):
553553
1, # block dim
554554
0,
555555
self.streamHalo, # shared mem and stream
556-
args.ctypes.data,
556+
argsp.ctypes.data,
557557
0,
558558
)
559559
) # arguments

0 commit comments

Comments
 (0)