clean up exceptions in __del__ everywhere (#3165)

This commit is contained in:
nimlgen
2024-01-18 19:34:09 +03:00
committed by GitHub
parent 0338903429
commit 992067399e
3 changed files with 6 additions and 6 deletions

View File

@@ -64,8 +64,8 @@ class CUDAGraph:
return et
def __del__(self):
check(cuda.cuGraphDestroy(self.graph))
check(cuda.cuGraphExecDestroy(self.instance))
if hasattr(self, 'graph'): check(cuda.cuGraphDestroy(self.graph))
if hasattr(self, 'instance'): check(cuda.cuGraphExecDestroy(self.instance))
def set_device(self): pass
def encode_args_info(self): return (cuda.CUdeviceptr_v2, (1,2,0))

View File

@@ -7,8 +7,8 @@ from tinygrad.runtime.graph.cuda import CUDAGraph
class HIPGraph(CUDAGraph):
def __del__(self):
check(hip.hipGraphDestroy(self.graph))
check(hip.hipGraphExecDestroy(self.instance))
if hasattr(self, 'graph'): check(hip.hipGraphDestroy(self.graph))
if hasattr(self, 'instance'): check(hip.hipGraphExecDestroy(self.instance))
def set_device(self): check(hip.hipSetDevice(self.device))
def encode_args_info(self): return (hip.hipDeviceptr_t, (1,2,3))
def graph_create(self): return init_c_var(hip.hipGraph_t(), lambda x: check(hip.hipGraphCreate(ctypes.byref(x), 0)))

View File

@@ -39,8 +39,8 @@ class CLProgram:
self.kernel = checked(cl.clCreateKernel(self.program, name.encode(), ctypes.byref(status := ctypes.c_int32())), status)
def __del__(self):
check(cl.clReleaseKernel(self.kernel))
check(cl.clReleaseProgram(self.program))
if hasattr(self, 'kernel'): check(cl.clReleaseKernel(self.kernel))
if hasattr(self, 'program'): check(cl.clReleaseProgram(self.program))
def __call__(self, *bufs:cl.cl_mem, global_size:Tuple[int,...], local_size:Optional[Tuple[int,...]]=None, vals:Tuple[int, ...]=(), wait=False) -> Optional[float]: # noqa: E501
for i,b in enumerate(bufs): cl.clSetKernelArg(self.kernel, i, ctypes.sizeof(b), ctypes.byref(b))