From cf1d0a67047a3061c9d281a64197cd8aff798834 Mon Sep 17 00:00:00 2001 From: nimlgen <138685161+nimlgen@users.noreply.github.com> Date: Sat, 13 Jan 2024 20:03:55 +0300 Subject: [PATCH] no exceptions in __del__ when module creation is failed in hip/cuda (#3107) --- tinygrad/runtime/ops_cuda.py | 2 +- tinygrad/runtime/ops_hip.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tinygrad/runtime/ops_cuda.py b/tinygrad/runtime/ops_cuda.py index cd23c1fc11..669349b1d2 100644 --- a/tinygrad/runtime/ops_cuda.py +++ b/tinygrad/runtime/ops_cuda.py @@ -50,7 +50,7 @@ class CUDAProgram: self.prg = prg if not CUDACPU else lib def __del__(self): - if not CUDACPU: check(cuda.cuModuleUnload(self.module)) + if hasattr(self, 'module'): check(cuda.cuModuleUnload(self.module)) def __call__(self, *bufs, global_size:Tuple[int,int,int], local_size:Tuple[int,int,int], vals:Tuple[int, ...]=(), wait=False): if not CUDACPU: check(cuda.cuCtxSetCurrent(self.device.context)) diff --git a/tinygrad/runtime/ops_hip.py b/tinygrad/runtime/ops_hip.py index 5f09b374a7..75b8034325 100644 --- a/tinygrad/runtime/ops_hip.py +++ b/tinygrad/runtime/ops_hip.py @@ -33,7 +33,7 @@ class HIPProgram: self.prg = init_c_var(hip.hipFunction_t(), lambda x: check(hip.hipModuleGetFunction(ctypes.byref(x), self.module, name.encode("utf-8")))) def __del__(self): - if not MOCKHIP: check(hip.hipModuleUnload(self.module)) + if hasattr(self, 'module'): check(hip.hipModuleUnload(self.module)) def __call__(self, *args, global_size:Tuple[int,int,int], local_size:Tuple[int,int,int], vals:Tuple[int, ...]=(), wait=False): if MOCKHIP: return float("inf")