Skip to content
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

[FEA]: CUDA vector types should implement the C++ tuple protocol #1406

Closed
1 task done
jaredhoberock opened this issue Feb 19, 2024 · 1 comment · Fixed by #1410
Closed
1 task done

[FEA]: CUDA vector types should implement the C++ tuple protocol #1406

jaredhoberock opened this issue Feb 19, 2024 · 1 comment · Fixed by #1410
Labels
feature request New feature or request.

Comments

@jaredhoberock
Copy link

Is this a duplicate?

Area

Not sure

Is your feature request related to a problem? Please describe.

The CUDA types like int3 defined in <vector_types.h> represent points. They are definitions in the global namespace and are automatically defined in every CUDA C++ program. There is no way for a CUDA C++ program to prevent their definition because these types participate in fundamental CUDA functionality like kernel launch and built-in variables. These are broadly-useful types with nice names and we are stuck with them in the global namespace.

The CUDA vector types are essentially tuples and they should behave like tuples. At the moment, they don't behave like tuples, because CUDA vector types don't implement the tuple protocol [1].

It's possible for third party libraries to implement the tuple protocol for these types themselves, but they must not do so. Firstly, because it is not their responsibility, but more importantly, because these implementations would inevitably collide when such libraries are combined.

CUDA has enhanced C++ support for these vector types in the past when constructors for these types were introduced. Making these types full-fledged tuples that can transparently participate in tuple-based libraries like CuTE and similar also makes sense.

[1] https://en.cppreference.com/w/cpp/utility/tuple/tuple-like

Describe the solution you'd like

I believe that three things are necessary for CUDA vector types to implement the tuple protocol:

  1. Provide customizations of get
  2. Provide specializations of std::tuple_element
  3. Provide specializations of std::tuple_size.

Describe alternatives you've considered

It's possible for third party libraries to implement the solution described above, but they cannot coexist when those libraries are combined in a single program.

Additional context

Many libraries, including the C++ Standard Library, present interfaces for tuple-like types. It's inconvenient for users that the CUDA vector types do not conform to these interfaces.

@jaredhoberock jaredhoberock added the feature request New feature or request. label Feb 19, 2024
miscco added a commit to miscco/cccl that referenced this issue Feb 20, 2024
This specializes the `std::tuple_size` and `std::tuple_element` traits so that they are usable with cuda vector types.

We also provide overloads for `std::get`, which together enables structured bindings support in C++17 onwards.

Fixes NVIDIA#1406
@miscco
Copy link
Collaborator

miscco commented Feb 20, 2024

I have opened a PR that enables full support for the various cuda vector types.

That said, there is a significant cost in code size that this carries. We will discuss this in our next team meeting

miscco added a commit to miscco/cccl that referenced this issue Feb 20, 2024
This specializes the `std::tuple_size` and `std::tuple_element` traits so that they are usable with cuda vector types.

We also provide overloads for `std::get`, which together enables structured bindings support in C++17 onwards.

Fixes NVIDIA#1406
miscco added a commit to miscco/cccl that referenced this issue Feb 21, 2024
This specializes the `std::tuple_size` and `std::tuple_element` traits so that they are usable with cuda vector types.

We also provide overloads for `std::get`, which together enables structured bindings support in C++17 onwards.

Fixes NVIDIA#1406
miscco added a commit to miscco/cccl that referenced this issue Apr 2, 2024
This specializes the `std::tuple_size` and `std::tuple_element` traits so that they are usable with cuda vector types.

We also provide overloads for `std::get`, which together enables structured bindings support in C++17 onwards.

Fixes NVIDIA#1406
miscco added a commit that referenced this issue Apr 9, 2024
* Implement tuple interface for cuda vector types

This specializes the `std::tuple_size` and `std::tuple_element` traits so that they are usable with cuda vector types.

We also provide overloads for `std::get`, which together enables structured bindings support in C++17 onwards.

Fixes #1406
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants