diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index 3c4a448481ec451318c70b9624b1fa1fa0d435a9..c1848a1e1d1b9b77ba20ef519b3acbe59932451d 100644 --- a/pyopencl/cffi_cl.py +++ b/pyopencl/cffi_cl.py @@ -575,6 +575,14 @@ class Error(Exception): def what(self): return self.args[0].what() + def is_out_of_memory(self): + # matches C implementation in src/c_wrapper/error.h + val = self.args[0] + + return (val.code == status_code.MEM_OBJECT_ALLOCATION_FAILURE + or val.code == status_code.OUT_OF_RESOURCES + or val.code == status_code.OUT_OF_HOST_MEMORY) + class MemoryError(Error): pass diff --git a/src/c_wrapper/error.h b/src/c_wrapper/error.h index 0346fcd63def77a08cff6232df001eb21c2bc7e1..33f2ae76e62f9b93ab0d8fbb0633104db820f93f 100644 --- a/src/c_wrapper/error.h +++ b/src/c_wrapper/error.h @@ -67,6 +67,7 @@ public: PYOPENCL_INLINE bool is_out_of_memory() const { + // matches Python implementation in pyopencl/cffi_cl.py return (code() == CL_MEM_OBJECT_ALLOCATION_FAILURE || code() == CL_OUT_OF_RESOURCES || code() == CL_OUT_OF_HOST_MEMORY);