diff --git a/test/test_ocl.py b/test/test_ocl.py index aed44f1233..728ff051a4 100644 --- a/test/test_ocl.py +++ b/test/test_ocl.py @@ -1,13 +1,20 @@ import unittest from tinygrad import Device from tinygrad.helpers import CI -from tinygrad.runtime.ops_gpu import CLDevice, CLAllocator +from tinygrad.runtime.ops_gpu import CLDevice, CLAllocator, CLCompiler, CLProgram -@unittest.skipUnless(Device.DEFAULT in ["GPU"] and not CI, "Runs only on OpenCL (GPU)") -class TestOCLOOM(unittest.TestCase): - def test_opencl_oom(self): +@unittest.skipUnless(Device.DEFAULT == "GPU", "Runs only on OpenCL (GPU)") +class TestCLError(unittest.TestCase): + @unittest.skipIf(CI, "dangerous for CI, it allocates tons of memory") + def test_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" + + def test_invalid_kernel_name(self): + device = Device[Device.DEFAULT] + with self.assertRaises(RuntimeError) as err: + CLProgram(device, name="", lib=CLCompiler(device, "test").compile("__kernel void test(__global int* a) { a[0] = 1; }")) + assert str(err.exception) == "OpenCL Error -46: CL_INVALID_KERNEL_NAME" diff --git a/tinygrad/runtime/ops_gpu.py b/tinygrad/runtime/ops_gpu.py index 92747c8352..e82452f80e 100644 --- a/tinygrad/runtime/ops_gpu.py +++ b/tinygrad/runtime/ops_gpu.py @@ -9,7 +9,7 @@ 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} +cl_errors = {attr: k for k in dir(cl) if k.startswith("CL_") and (attr:=getattr(cl, k)) <= 0} def check(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]