-
Notifications
You must be signed in to change notification settings - Fork 216
Use CCCL's mdspan implementation #2836
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: branch-25.12
Are you sure you want to change the base?
Conversation
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
|
||
// Padded layout shims compatible with CCCL mdspan mappings | ||
template <size_t PaddingStride> | ||
struct layout_left_padded_impl { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marking this for closer review.
This feature has been requested in CCCL, in NVIDIA/cccl#2808.
Should this be detail
so that it's not in a public namespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a good idea.
raft::device_vector_view<T1> rows, | ||
raft::device_vector_view<T1> columns, | ||
raft::device_vector_view<T2> values, | ||
raft::device_vector_view<T1, int64_t> rows, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check if this change is correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is explicit but unnecessary.
}; | ||
|
||
template <typename T1, typename T2> | ||
template <typename T1, typename T2, typename DenseVectorView, typename ResultVectorView> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to check if this change is correct.
namespace "raft": | ||
ctypedef layout_right row_major | ||
ctypedef layout_left col_major | ||
cdef cppclass row_major: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is equivalent, Cython probably compiles the old and new code the same way.
/ok to test |
"std::experimental::padding ValueType has to be provided without " | ||
"const or volatile specifiers."); | ||
static_assert(ByteAlignment % sizeof(ValueType) == 0 || sizeof(ValueType) % ByteAlignment == 0, | ||
"std::experimental::padding sizeof(ValueType) has to be multiple or " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not quite sure where this std::experimental::padding
comes from, though it was preexisting. There's another instance of this above.
using cuda::std::dynamic_extent; | ||
using cuda::std::extents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're using these using
declarations anyway, then should we consider just using them consistently for all cuda::std
namespace symbols we want to use in namespace raft
, so that we don't have to type cuda::std
(and so that we could change the namespace in one place, instead of touching all the files)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to have these using
declarations. I'd like to keep all the types in cuda::std
namespace. But we can deal with this in a follow-up issue to keep the diff as minimal as possible. Please do not bring in any more types in raft::
namespace than what are already there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I'm re-reading Mark's comment and I think what he is saying is a good idea. We using raft::
namespace outside of this header and bring cuda::std::
symbols in raft::
namespace in this header.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing that's happening now is that there are using
declarations in the raft
namespace, AND code in the raft
namespace uses explicit namespace qualification (e.g., ::cuda::std::extents
). I don't think it makes sense to do both. On the other hand, fixing that is perhaps out of scope of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed. Code outside this header should use types from the raft namespace.
using extent_5d = cuda::std::extents<IndexType, | ||
dynamic_extent, | ||
dynamic_extent, | ||
dynamic_extent, | ||
dynamic_extent, | ||
dynamic_extent>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The more concise way to spell this is
using extent_5d = cuda::std::extents<IndexType, | |
dynamic_extent, | |
dynamic_extent, | |
dynamic_extent, | |
dynamic_extent, | |
dynamic_extent>; | |
using extent_5d = cuda::std::dims<5, IndexType>; |
but dims<5, IndexType>
is more concise than extent_5d<IndexType>
anyway; should we consider just using dims
?
thrust::sequence(rmm::exec_policy(stream), a.begin(), a.end()); | ||
stdex::mdspan<float, stdex::extents<int, raft::dynamic_extent, raft::dynamic_extent>> span{ | ||
a.data(), 4, 4}; | ||
cuda::std::mdspan<float, cuda::std::extents<int, raft::dynamic_extent, raft::dynamic_extent>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cuda::std::mdspan<float, cuda::std::extents<int, raft::dynamic_extent, raft::dynamic_extent>> | |
cuda::std::mdspan<float, cuda::std::dims<2, int>> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The preferred option, though, would be to use CTAD.
cuda::std::mdspan{a.data(), cuda::std::dims<2, int>{4, 4}}
void test_mdarray_basic() | ||
{ | ||
using matrix_extent = stdex::extents<int, dynamic_extent, dynamic_extent>; | ||
using matrix_extent = cuda::std::extents<int, dynamic_extent, dynamic_extent>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using matrix_extent = cuda::std::extents<int, dynamic_extent, dynamic_extent>; | |
using matrix_extent = cuda::std::dims<2, int>; |
{ | ||
raft::resources handle; | ||
using matrix_extent = stdex::extents<size_t, dynamic_extent, dynamic_extent>; | ||
using matrix_extent = cuda::std::extents<size_t, dynamic_extent, dynamic_extent>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using matrix_extent = cuda::std::extents<size_t, dynamic_extent, dynamic_extent>; | |
using matrix_extent = cuda::std::dims<2>; |
(Default index type is size_t
.)
TEST(MDArray, CopyMove) | ||
{ | ||
using matrix_extent = stdex::extents<size_t, dynamic_extent, dynamic_extent>; | ||
using matrix_extent = cuda::std::extents<size_t, dynamic_extent, dynamic_extent>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using matrix_extent = cuda::std::extents<size_t, dynamic_extent, dynamic_extent>; | |
using matrix_extent = cuda::std::dims<2>; |
void test_mdarray_padding() | ||
{ | ||
using extents_type = stdex::extents<size_t, dynamic_extent, dynamic_extent>; | ||
using extents_type = cuda::std::extents<size_t, dynamic_extent, dynamic_extent>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using extents_type = cuda::std::extents<size_t, dynamic_extent, dynamic_extent>; | |
using extents_type = cuda::std::dims<2>; |
// use simple 1D array to allocate some space | ||
auto s = rmm::cuda_stream_default; | ||
using extent_1d = stdex::extents<size_t, dynamic_extent>; | ||
using extent_1d = cuda::std::extents<size_t, dynamic_extent>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using extent_1d = cuda::std::extents<size_t, dynamic_extent>; | |
using extent_1d = cuda::std::dims<1>; |
|
||
// Padded layout shims compatible with CCCL mdspan mappings | ||
template <size_t PaddingStride> | ||
struct layout_left_padded_impl { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a good idea.
using cuda::std::dynamic_extent; | ||
using cuda::std::extents; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer not to have these using
declarations. I'd like to keep all the types in cuda::std
namespace. But we can deal with this in a follow-up issue to keep the diff as minimal as possible. Please do not bring in any more types in raft::
namespace than what are already there.
*/ | ||
using padded_layout_row_major = | ||
stdex::layout_right_padded<detail::padding<float, alignment_bytes>::value>; | ||
raft::layout_right_padded_impl<detail::padding<float, alignment_bytes>::value>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this use raft::layout_right_padded<float>
?
raft::device_vector_view<T1> rows, | ||
raft::device_vector_view<T1> columns, | ||
raft::device_vector_view<T2> values, | ||
raft::device_vector_view<T1, int64_t> rows, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is explicit but unnecessary.
This PR adopts CCCL's
mdspan
implementation and deletes the vendored implementation.Closes #1616.
Note
This branch was meant to be a stress test of Cursor with GPT-5, and I did not anticipate it becoming a PR worth opening. To my surprise, it got to a state that actually compiles (with a lot of retries). After skimming over the changes, I think it's fairly close to what we might actually want.