diff --git a/pyopencl/array.py b/pyopencl/array.py index e09f9e3a5540024f5da37e7ca9ca38bf1c3f21fd..851a0bb4393da4c0e37a64583bca1e9d44bd1861 100644 --- a/pyopencl/array.py +++ b/pyopencl/array.py @@ -50,6 +50,11 @@ from numbers import Number SCALAR_CLASSES = (Number, np.bool_, bool) +if cl.get_cl_header_version() >= (2, 0): + _SVMPointer_or_nothing = cl.SVMPointer +else: + _SVMPointer_or_nothing = () + _COMMON_DTYPE_CACHE = {} @@ -254,6 +259,7 @@ class _copy_queue: # noqa _ARRAY_GET_SIZES_CACHE = {} _BOOL_DTYPE = np.dtype(np.int8) +_NOT_PRESENT = object() class Array: @@ -590,6 +596,16 @@ class Array: self.context = context self._flags = _flags + if __debug__: + if queue is not None and isinstance( + self.base_data, _SVMPointer_or_nothing): + mem_queue = getattr(self.base_data, "_queue", _NOT_PRESENT) + if mem_queue is not _NOT_PRESENT and mem_queue != queue: + warn("Array has different queue from backing SVM memory. " + "This may lead to the array getting deallocated sooner " + "than expected, potentially leading to crashes.", + InconsistentOpenCLQueueWarning, stacklevel=2) + @property def ndim(self): return len(self.shape)