@@ -1740,8 +1740,7 @@ cdef class _RawKernelArg:
1740
1740
def __dealloc (self ):
1741
1741
if (self ._arg_ref):
1742
1742
DPCTLRawKernelArg_Delete(self ._arg_ref)
1743
- if (self ._is_buf):
1744
- PyBuffer_Release(& (self ._buf))
1743
+
1745
1744
1746
1745
cdef class RawKernelArg:
1747
1746
"""
@@ -1762,9 +1761,11 @@ cdef class RawKernelArg:
1762
1761
1763
1762
- If the constructor is invoked with two arguments, the first argument is
1764
1763
interpreted as the number of bytes in the binary argument, while the
1765
- second argument is interpreted as a pointer to the data. Note that the
1766
- raw kernel arg does not own or copy the data, so the pointed-to object
1767
- must be kept alive by the user until kernel launch.
1764
+ second argument is interpreted as a pointer to the data.
1765
+
1766
+ Note that construction of the ``RawKernelArg`` copies the bytes, so
1767
+ modifications made after construction of the ``RawKernelArg`` will not be
1768
+ reflected in the kernel launch.
1768
1769
1769
1770
Args:
1770
1771
args:
@@ -1778,6 +1779,8 @@ cdef class RawKernelArg:
1778
1779
cdef void * ptr = NULL
1779
1780
cdef size_t count
1780
1781
cdef int ret_code = 0
1782
+ cdef Py_buffer _buffer
1783
+ cdef bint _is_buf
1781
1784
1782
1785
if not DPCTLRawKernelArg_Available():
1783
1786
raise RuntimeError (" Raw kernel arg extension not available" )
@@ -1792,13 +1795,13 @@ cdef class RawKernelArg:
1792
1795
" expects argument to be buffer" ,
1793
1796
f" but got {type(args[0])}" )
1794
1797
1795
- ret_code = PyObject_GetBuffer(args[0 ], & (self ._buf ), PyBUF_SIMPLE | PyBUF_ANY_CONTIGUOUS)
1798
+ ret_code = PyObject_GetBuffer(args[0 ], & (_buffer ), PyBUF_SIMPLE | PyBUF_ANY_CONTIGUOUS)
1796
1799
if ret_code != 0 : # pragma: no cover
1797
1800
raise RuntimeError (" Could not access buffer" )
1798
1801
1799
- ptr = self ._buf .buf
1800
- count = self ._buf .len
1801
- self . _is_buf = True
1802
+ ptr = _buffer .buf
1803
+ count = _buffer .len
1804
+ _is_buf = True
1802
1805
else :
1803
1806
if not isinstance (args[0 ], numbers.Integral):
1804
1807
raise TypeError (" RawKernelArg constructor expects first"
@@ -1807,11 +1810,14 @@ cdef class RawKernelArg:
1807
1810
raise TypeError (" RawKernelArg constructor expects second"
1808
1811
" argument to be `int`, but got {type(args[1])}" )
1809
1812
1810
- self . _is_buf = False
1813
+ _is_buf = False
1811
1814
count = args[0 ]
1812
1815
ptr = < void * > (< unsigned long long > args[1 ])
1813
1816
1814
1817
self ._arg_ref = DPCTLRawKernelArg_Create(ptr, count)
1818
+ if (_is_buf):
1819
+ PyBuffer_Release(& (_buffer))
1820
+
1815
1821
1816
1822
""" Check whether the raw_kernel_arg extension is available"""
1817
1823
@staticmethod
0 commit comments