MCPcopy Create free account
hub / github.com/apache/arrow / test_numba_memalloc

Function test_numba_memalloc

python/pyarrow/tests/test_cuda_numba_interop.py:163–180  ·  view source on GitHub ↗
(c, dtype)

Source from the content-addressed store, hash-verified

161 ids=context_choice_ids)
162@pytest.mark.parametrize("dtype", dtypes, ids=dtypes)
163def test_numba_memalloc(c, dtype):
164 ctx, nb_ctx = context_choices[c]
165 dtype = np.dtype(dtype)
166 # Allocate memory using numba context
167 # Warning: this will not be reflected in pyarrow context manager
168 # (e.g bytes_allocated does not change)
169 size = 10
170 mem = nb_ctx.memalloc(size * dtype.itemsize)
171 darr = DeviceNDArray((size,), (dtype.itemsize,), dtype, gpu_data=mem)
172 darr[:5] = 99
173 darr[5:] = 88
174 np.testing.assert_equal(darr.copy_to_host()[:5], 99)
175 np.testing.assert_equal(darr.copy_to_host()[5:], 88)
176
177 # wrap numba allocated memory with CudaBuffer
178 cbuf = cuda.CudaBuffer.from_numba(mem)
179 arr2 = np.frombuffer(cbuf.copy_to_host(), dtype=dtype)
180 np.testing.assert_equal(arr2, darr.copy_to_host())
181
182
183@pytest.mark.parametrize("c", range(len(context_choice_ids)),

Callers

nothing calls this directly

Calls 1

dtypeMethod · 0.80

Tested by

no test coverage detected