Skip to content

Refactor cuda::arch_traits - #6150

Merged
davebayer merged 8 commits into
NVIDIA:mainfrom
davebayer:remove_cuda_arch_namespace
Oct 14, 2025
Merged

davebayer merged 8 commits into
NVIDIA:mainfrom
davebayer:remove_cuda_arch_namespace

Conversation

@davebayer

Copy link
Copy Markdown
Contributor

This PR refactors the CUDA architecture traits.

  1. the cuda::arch:: namespace is removed and the functions and types are prefixed with arch_ directly
  2. the cuda::current_arch_traits() was moved to cuda::device:: namespace, because it's device-only function
  3. the cuda::device::current_arch_id() function was added

@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 2025

Copy link
Copy Markdown
Contributor

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.

@davebayer davebayer self-assigned this Oct 8, 2025
@cccl-authenticator-app cccl-authenticator-app Bot moved this from Todo to In Progress in CCCL Oct 8, 2025
@davebayer
davebayer force-pushed the remove_cuda_arch_namespace branch from 670f570 to d65db26 Compare October 8, 2025 09:56
//!
//! @note If the current architecture is unknown (too new/old), the compilation will fail.
template <class _Dummy = void>
[[nodiscard]] _CCCL_DEVICE_API inline ::cuda::arch_traits_t current_arch_traits() noexcept

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've made the function non-constexpr. As was described in the test file, it doesn't fully serve it's purpose due to missing function signatures. The advantage is that now we can be compatible with nvhpc in CUDA mode.

My idea is that we should try to go without constexpr and if users complain, we should add constexpr if possible (non nvhpc compilers).

If you don't agree with this, we can make it constexpr now, but then we will allow users to write code that is not portable among all of the CUDA compilers. And as I said, we can always add it later.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Technically nvhpc CUDA compilation is not officially supported, I am not sure we should make the nvcc case worst because of something we don't support.
But at the same time it is true that the constexpr traits are not as useful as I hoped, so maybe we don't lose much.
The question I would ask is: Later we can add a second API that serves one of those cases, would it be better to special case the constexpr traits getter or to special case traits getter for nvhpc. I thought it made more sense to special case for nvhpc, but I am fine either way. Maybe we could provide both cases already?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I know it's not officially supported now, but the thing is that it might change in the future. And users will have already their code written in a way that is not compatible with nvhpc.

I'm not against adding another API that would be constexpr, but I would like to make this the default.

And I believe that if you use the cuda::arch_trait().property in an if (...), I believe it will get optimized away, so we would be only paying the additional compilation cost.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, I am fine with that, we just need to figure out the name for the constexpr version then

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

What about current_arch_traits_static or current_static_arch_traits (similar to static_extents)?

// Confirm trait value is defined device code and usable as a reference
foo(cuda::arch::traits<Arch>().compute_capability);
foo(cuda::arch::current_traits().compute_capability);))
assert(Arch == cuda::device::current_arch_id());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

todo: make it static_assert if we decide to go with constexpr

[[maybe_unused]] __shared__ int array[cuda::arch_traits<Arch>().max_shared_memory_per_block / sizeof(int)];

// constexpr is useless and I can't use intrinsics here :(
if (cuda::device::current_arch_traits().cluster_supported)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

todo: make it if constexpr if we decide to go with constexpr

@davebayer
davebayer requested a review from pciolkosz October 8, 2025 10:03
@davebayer

Copy link
Copy Markdown
Contributor Author

/ok to test d65db26

case arch_id::sm_120a:
return ::cuda::arch_traits<arch_id::sm_120a>();
default:
::cuda::__throw_cuda_error(::cudaErrorInvalidValue, "Traits requested for an unknown architecture");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Do we want to throw cuda_error here? Don't we want to use cuda::std::invalid_argument instead?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't mind

@davebayer

Copy link
Copy Markdown
Contributor Author

/ok to test 7aece08

@davebayer

Copy link
Copy Markdown
Contributor Author

/ok to test 59f560b

@davebayer
davebayer marked this pull request as ready for review October 8, 2025 11:42
@davebayer
davebayer requested review from a team as code owners October 8, 2025 11:42
@cccl-authenticator-app cccl-authenticator-app Bot moved this from In Progress to In Review in CCCL Oct 8, 2025
@fbusato
fbusato self-requested a review October 8, 2025 15:58
@github-actions

This comment has been minimized.

[[nodiscard]] _CCCL_API inline constexpr traits_t traits_for_id(id __id)
[[nodiscard]] _CCCL_API inline constexpr bool __is_known_compute_capability(int __cc)
{
return __cc >= __lowest_known_arch && __cc <= __highest_known_arch;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

::cuda::in_range 😅 when ready

@davebayer
davebayer force-pushed the remove_cuda_arch_namespace branch 2 times, most recently from 2de0775 to a8077a0 Compare October 9, 2025 10:07
@davebayer
davebayer force-pushed the remove_cuda_arch_namespace branch from a8077a0 to 519dfec Compare October 13, 2025 14:57
@davebayer

Copy link
Copy Markdown
Contributor Author

pre-commit.ci autofix

@copy-pr-bot

copy-pr-bot Bot commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@davebayer

Copy link
Copy Markdown
Contributor Author

/ok to test 162b3e9

@davebayer
davebayer force-pushed the remove_cuda_arch_namespace branch from d3d12dc to 40f39d9 Compare October 13, 2025 16:36
@davebayer

Copy link
Copy Markdown
Contributor Author

We discussed changes in this PR with @pciolkosz and we decided to remove .arch_traits() from device_ref for now. Also, I gave up on making the cuda::device::current_mewo() functions non constexpr, so everything is simplified.

sm_110 = 110,
sm_120 = 120,
sm_121 = 121,
sm_90a = 90 * __arch_specific_id_multiplier,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for my personal knowledge, how we support f variants? e.g. sm_110f

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a question for @pciolkosz, we can add them in a separate PR, I need to merge this now

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

🥳 CI Workflow Results

🟩 Finished in 5h 28m: Pass: 100%/116 | Total: 12h 13m | Max: 29m 19s | Hits: 99%/226531

See results here.

@davebayer
davebayer merged commit d6f4c8a into NVIDIA:main Oct 14, 2025
@github-project-automation github-project-automation Bot moved this from In Review to Done in CCCL Oct 14, 2025
@github-actions

Copy link
Copy Markdown
Contributor

Backport failed for branch/3.1.x, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin branch/3.1.x
git worktree add -d .worktree/backport-6150-to-branch/3.1.x origin/branch/3.1.x
cd .worktree/backport-6150-to-branch/3.1.x
git switch --create backport-6150-to-branch/3.1.x
git cherry-pick -x d6f4c8a6b4d0dab95ad64385dc30dd97d20e0774

davebayer added a commit to davebayer/cccl that referenced this pull request Oct 14, 2025
Co-authored-by: pciolkosz <pciolkosz@nvidia.com>
(cherry picked from commit d6f4c8a)
davebayer added a commit to davebayer/cccl that referenced this pull request Oct 14, 2025
Co-authored-by: pciolkosz <pciolkosz@nvidia.com>
(cherry picked from commit d6f4c8a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants