diff --git a/test/test_ocl.py b/test/test_ocl.py new file mode 100644 index 0000000000..eeb15299bb --- /dev/null +++ b/test/test_ocl.py @@ -0,0 +1,12 @@ +import unittest +from tinygrad import Device +from tinygrad.runtime.ops_gpu import CLDevice, CLAllocator + +@unittest.skipUnless(Device.DEFAULT in ["GPU"], "Runs only on OpenCL (GPU)") +class TestOCLOOM(unittest.TestCase): + def test_opencl_oom(self): + with self.assertRaises(RuntimeError) as err: + allocator = CLAllocator(CLDevice()) + for i in range(1_000_000): + allocator.alloc(1_000_000_000) + assert str(err.exception) == "OpenCL Error -6: CL_OUT_OF_HOST_MEMORY" diff --git a/tinygrad/runtime/ops_gpu.py b/tinygrad/runtime/ops_gpu.py index bb27dad6d2..92747c8352 100644 --- a/tinygrad/runtime/ops_gpu.py +++ b/tinygrad/runtime/ops_gpu.py @@ -9,8 +9,9 @@ from tinygrad.device import BufferOptions, LRUAllocator, Compiled, Compiler, Com # see test/external/external_osx_profiling.py to determine this ratio. it's in like GPU clocks or something OSX_TIMING_RATIO = (125/3) if OSX else 1.0 +cl_errors = {getattr(cl, k): k for k in filter(lambda e: e.startswith("CL_"), dir(cl)) if getattr(cl, k) <= 0} def check(status): - if status != 0: raise RuntimeError(f"OpenCL Error {status}") + if status != 0: raise RuntimeError(f"OpenCL Error {status}: {cl_errors.get(status, 'Unknown error')}") def checked(ret, status): return (check(status.value), ret)[1] class CLCompiler(Compiler):