Skip to content

Add support for __tuple_like for ::std::{array, pair, tuple}#7129

Open
miscco wants to merge 3 commits intoNVIDIA:mainfrom
miscco:mdspan_P3633
Open

Add support for __tuple_like for ::std::{array, pair, tuple}#7129
miscco wants to merge 3 commits intoNVIDIA:mainfrom
miscco:mdspan_P3633

Conversation

@miscco
Copy link
Contributor

@miscco miscco commented Jan 8, 2026

This allows us to use standard library types with submdspan

Fixes [BUG]: CUDA 13.1 cuda::std::mdspan does not implement P3663 Fixes #7110

@miscco miscco requested a review from a team as a code owner January 8, 2026 14:11
@miscco miscco requested a review from pciolkosz January 8, 2026 14:11
@github-project-automation github-project-automation bot moved this to Todo in CCCL Jan 8, 2026
@cccl-authenticator-app cccl-authenticator-app bot moved this from Todo to In Review in CCCL Jan 8, 2026
@miscco miscco requested a review from davebayer January 8, 2026 14:12
return __get_complex_impl<_Tp>::template get<_Index>(::cuda::std::move(__z));
}

#if _CCCL_HAS_HOST_STD_LIB()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@davebayer do we want to centralize those into a single file?

Copy link
Contributor

Choose a reason for hiding this comment

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

No, I don't think so

Copy link
Contributor

Choose a reason for hiding this comment

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

I would put them right next to the cuda::std:: variants

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 wrote the test and the issue with that is that we would need to include the right folder for that and not only just <cuda/std/tuple> but also <cuda/std/array>

Copy link
Contributor

@davebayer davebayer left a comment

Choose a reason for hiding this comment

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

Shouldn't we add tests for

[[nodiscard]] _CCCL_API constexpr decltype(auto) __get_slice_at(_Slices&&... __slices) noexcept
{
return ::cuda::std::get<_Index>(::cuda::std::forward_as_tuple(::cuda::std::forward<_Slices>(__slices)...));
// Pull in `::std::get` via ADL for host library types
Copy link
Contributor

@mhoemmen mhoemmen Jan 8, 2026

Choose a reason for hiding this comment

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

P3663 means that any type for which structured binding into two things, both convertible to index_type, is well-formed will work as a slice specifier. For example, the following type works.

struct Foo {
  int bar;
  int xyzzy;
};

Note that this type is not tuple-like and that std::get does not work on it.

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 am not sure whether this is something we can easily implement in C++17 will for now just add this to make sure we can handle the standard types

Copy link
Contributor

Choose a reason for hiding this comment

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

... just add this to make sure we can handle the standard types

That's not a complete fix for the bug.

If you go to the canonical-slice function definition and look at the implementation following paragraph 7 ("Effects: Equivalent to"), you can make it valid C++17 code by not using designated initializers.

The point of canonical-slice is to turn every "pair of indices" slice into strided_slice with compile-time stride of 1. The implementation shown in paragraph 7 implements the Mandates in paragraph 6 ("Mandates: S is a submdspan slice type for IndexType). It's certainly possible in C++17 to test whether some type T is a specialization of strided_slice.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I need to rewrite the commit message for github to not force close the issue

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll say more concisely: canonical-slice exists so that you don't need a tuple-like test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, but that is a much larger change and I am not 100% sure we can emulate it in Cüü17, so I want this in because it is something we would want anyway

Copy link
Contributor

Choose a reason for hiding this comment

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

@miscco That's fine; just please be aware that this is not a complete implementation of P3663, as the branch name might otherwise suggest. Thanks!

@github-actions

This comment has been minimized.

@miscco miscco force-pushed the mdspan_P3633 branch 6 times, most recently from a59e722 to 16b3306 Compare January 12, 2026 14:23
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Comment on lines +32 to +38
# if _CCCL_HOST_STD_LIB(STL)
template <class _Tp, size_t _Size>
class array;
# else // ^^^ _CCCL_HOST_STD_LIB(STL) ^^^ / vvv !_CCCL_HOST_STD_LIB(STL) vvv
template <class _Tp, size_t _Size>
struct array;
# endif // !_CCCL_HOST_STD_LIB(STL)
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, why should anyone bother following the standard..

@miscco miscco force-pushed the mdspan_P3633 branch 3 times, most recently from 23a74ac to c56c5c0 Compare January 21, 2026 08:53
@github-actions

This comment has been minimized.

@github-actions
Copy link
Contributor

😬 CI Workflow Results

🟥 Finished in 2h 53m: Pass: 91%/95 | Total: 3d 17h | Max: 2h 53m | Hits: 47%/249814

See results here.

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

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

[BUG]: CUDA 13.1 cuda::std::mdspan does not implement P3663

3 participants