Implement __cuda_array_interface__#1144
Conversation
|
(Rebasing this PR on master to see if that fixes the flake8 failures in unrelated code.) |
|
@seibert Thanks for the PR! If this is ready for review, please remove the [WIP] label. Thanks! |
|
Oh right! I forgot to change the title. Two questions I do have, now that I reread it:
BTW, the dev docs for Numba describe the meaning of the attributes: http://numba.pydata.org/numba-doc/dev/cuda/cuda_array_interface.html |
|
@Crissman: Thoughts on my questions above? |
|
There is no such thing as an immutable CuPy array at this time. Can't promise that won't change in the future, but we'd review the code if we added it. Please add the unit test here: tests/cupy_tests/core_tests/test_ndarray.py When you're ready for us to review, please remove the Thanks! |
|
Sorry for the delay here. I've rewritten the patch and added tests. This is ready for review. |
|
I will review this. |
| readonly object dtype | ||
| readonly memory.MemoryPointer data | ||
| readonly ndarray base | ||
| readonly object _cuda_array_descr |
There was a problem hiding this comment.
Does this feature need cache? Creating dict is low cost. And, dict is a mutable object. Perhaps, user edit this value though return value of __cuda_array_interface__.
There was a problem hiding this comment.
It saves to 0.3 - 0.5 microseconds per array per kernel launch, which is probably not important unless you are passing many arrays to a function. I've reverted back to the safer, uncached approach.
| set(['shape', 'typestr', 'data', 'version', 'descr'])) | ||
| self.assertEqual(iface['shape'], (2,3)) | ||
| self.assertEqual(iface['typestr'], '<f8') | ||
| self.assertIsInstance(iface['data'], tuple) |
There was a problem hiding this comment.
Please add self.assertEqual(iface['data'], arr.data.ptr`)
|
And please fix style. |
|
Thanks for the review! I have updated the PR with your suggestions. |
|
|
||
| def test_cuda_array_interface_view(self): | ||
| arr = cupy.zeros(shape=(10, 20), dtype=cupy.float64) | ||
| view = arr[::2,::5] |
There was a problem hiding this comment.
Please add a white space.
- view = arr[::2,::5]
+ view = arr[::2, ::5]
|
jenkins, test this please. |
|
Jenkins CI test (for commit 53bd090, target branch master) succeeded! |
|
LGTM except a comment. |
|
whitespace change has been made |
|
jenkins, test this please. |
|
Jenkins CI test (for commit 7aebd05, target branch master) failed with status FAILURE. |
|
jenkins, test this please. |
|
Jenkins CI test (for commit 7aebd05, target branch master) succeeded! |
|
LGTM! |
__cuda_array_interface__
This implements a special CUDA array interface attribute, analogous to the
__array_interface__attribute on NumPy arrays. This attribute is specifically for advertising CUDA device-compatible pointers (actual device allocations, or managed memory) and associated metadata.This allows CuPy arrays to be used with Numba-compiled CUDA functions when combined with numba/numba#2860.