From 8613c9b6a27a92babfb8c134253805da381074d0 Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 28 Sep 2016 17:21:16 -0500 Subject: [PATCH] Revive Error.is_out_of_memory --- pyopencl/cffi_cl.py | 8 ++++++++ src/c_wrapper/error.h | 1 + 2 files changed, 9 insertions(+) diff --git a/pyopencl/cffi_cl.py b/pyopencl/cffi_cl.py index 3c4a4484..c1848a1e 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 0346fcd6..33f2ae76 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); -- GitLab