@@ -265,12 +265,23 @@ def compile(self, kernel_instance):
265
265
if platform .system () == "Darwin" :
266
266
lib_extension = ".dylib"
267
267
268
- subprocess .check_call ([self .compiler , "-c" , source_file ] + compiler_options + ["-o" , filename + ".o" ])
269
- subprocess .check_call (
268
+ subprocess .run (
269
+ [self .compiler , "-c" , source_file ] + compiler_options + ["-o" , filename + ".o" ],
270
+ stdout = subprocess .PIPE ,
271
+ stderr = subprocess .PIPE ,
272
+ text = True ,
273
+ check = True
274
+ )
275
+
276
+ subprocess .run (
270
277
[self .compiler , filename + ".o" ]
271
278
+ compiler_options
272
279
+ ["-shared" , "-o" , filename + lib_extension ]
273
- + lib_args
280
+ + lib_args ,
281
+ stdout = subprocess .PIPE ,
282
+ stderr = subprocess .PIPE ,
283
+ text = True ,
284
+ check = True
274
285
)
275
286
276
287
self .lib = np .ctypeslib .load_library (filename , "." )
@@ -396,10 +407,16 @@ def memcpy_htod(self, dest, src):
396
407
397
408
def cleanup_lib (self ):
398
409
"""unload the previously loaded shared library"""
410
+ if self .lib is None :
411
+ return
412
+
399
413
if not self .using_openmp and not self .using_openacc :
400
414
# this if statement is necessary because shared libraries that use
401
415
# OpenMP will core dump when unloaded, this is a well-known issue with OpenMP
402
416
logging .debug ("unloading shared library" )
403
- _ctypes .dlclose (self .lib ._handle )
417
+ try :
418
+ _ctypes .dlclose (self .lib ._handle )
419
+ finally :
420
+ self .lib = None
404
421
405
422
units = {}
0 commit comments