Repository navigation
Support viewing CuPy arrays as cuda::std::mdspan on host/device - #9525
Conversation
|
This pull request is now in conflicts. Could you fix it @leofang? 🙏 |
|
Thanks to Mark for offline discussion. This PR is ready for review. I'll expand the PR description tonight/tomorrow. |
cuda::std::mdspan on host/devicecuda::std::mdspan on host/device
seberg
left a comment
There was a problem hiding this comment.
I lost a bit focus on the tests, but this looks good to me. Adding mdspan seems fine. And I think I'll brush away my API concerns, by considering that we can add a layout="auto" in some future (and if we care a lot, we can probably pull off transitioning to it as the default too).
A few small comments, nits otherwise.
| name_expressions=name_expressions | ||
| ) | ||
|
|
||
| # TODO(leofang): it does not seem 'AK' makes any difference here? |
There was a problem hiding this comment.
You would need to transpose a 3-D array and shaped_random has no logic to intentionally mangle it up.
I.e. if you truly want this, you need to test 3-D and then parametrize a transpose with (0, 1, 2), (2, 1, 0), (2, 0, 1) where the last would be neither C nor F.
(There is a helper for "contiguous axes", but I am not sure there is one for this.)
| # would cause cyclic cimport dependencies. | ||
| cdef _carray.mdspan carr = _carray.mdspan.__new__(_carray.mdspan) | ||
| cdef int index_itemsize | ||
| if index_type == cupy.int32: |
There was a problem hiding this comment.
The speed discussion (from elsewhere) made me realize that technically, this should use get_type(index_type) == cupy.int32 maybe? Then we also allow writing "int32", but mainly we can't run into problems because np.int != np.long even when they are both 32bit.
|
/test mini |
|
(timeouts here as well) /test mini |
seberg
left a comment
There was a problem hiding this comment.
Thanks, I am happy with the latest changes and much more comfortable with forcing to pass the index type!
|
Fixed test failures due to changing /test mini |
|
LGTM. Ignoring timeouts. |
|
/test force-skip |
|
The following tests were force-skipped:
|
Support viewing CuPy arrays as `cuda::std::mdspan` on host/device
This PR introduces a way for CuPy to interoperate with CUDA C++, by supporting emitting
cuda::std::mdspanon the host that can be passed by value to the device. Same as how we have been treating CArray over the years, we exploit thecuda::std::mdspanABI stability to allow dynamically generating the struct.With this PR, it really helps reduce overhead of generating kernel args (compared to e.g. DLPack which has O(1 us) overhead):
xref: NVIDIA/cuda-python#1387