Skip to content

Conversation

bdice
Copy link
Contributor

@bdice bdice commented Oct 14, 2025

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.

Copy link

copy-pr-bot bot commented Oct 14, 2025

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 {
Copy link
Contributor Author

@bdice bdice Oct 14, 2025

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?

Copy link
Member

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,
Copy link
Contributor Author

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.

Copy link
Member

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>
Copy link
Contributor Author

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:
Copy link
Contributor Author

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.

@bdice
Copy link
Contributor Author

bdice commented Oct 14, 2025

/ok to test

@bdice bdice added feature request New feature or request breaking Breaking change labels Oct 14, 2025
"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 "
Copy link
Contributor

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.

Comment on lines +23 to +24
using cuda::std::dynamic_extent;
using cuda::std::extents;
Copy link
Contributor

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)?

Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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.

Comment on lines +67 to +72
using extent_5d = cuda::std::extents<IndexType,
dynamic_extent,
dynamic_extent,
dynamic_extent,
dynamic_extent,
dynamic_extent>;
Copy link
Contributor

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

Suggested change
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>>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
cuda::std::mdspan<float, cuda::std::extents<int, raft::dynamic_extent, raft::dynamic_extent>>
cuda::std::mdspan<float, cuda::std::dims<2, int>>

Copy link
Contributor

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>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 {
Copy link
Member

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.

Comment on lines +23 to +24
using cuda::std::dynamic_extent;
using cuda::std::extents;
Copy link
Member

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>;
Copy link
Member

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,
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking Breaking change feature request New feature or request

Development

Successfully merging this pull request may close these issues.

[FEA] Use mdspan from CCCL

3 participants