NVIDIA / NVIDIA/cccl

Replace uses of `__CUDA_ARCH__` and `__NVCOMPILER_CUDA_ARCH__` for compile time target version checks

Open
#976 1 comment 0 reactions 0 assignees View on GitHub
libcu++
Dominant language
C++
Stars
2.5k
Forks
487
Avg merge
2d 7h
Merged PRs (30d)
296

Description

We currently use `__CUDA_ARCH__`/`__NVCOMPILER_CUDA_ARCH__` in a few places that are difficult to replace with `if target`:
* For some headers like `` and ``, we need to produce a compile time error if the header is being compiled for an older SM target.
* There are also some `memcpy_async` implementation details that are `#if`'d out for older SM targets. I think we should probably just allow these to be present for all SM targets.
* https://github.com/NVIDIA/libcudacxx/blob/feature/nvcxx-compatibility/include/cuda/std/barrier#L307
* `atomic_flag`'s wait/notify member functions is only defined for newer targets. Note that we do NOT do this for `atomic`, which is strange.
* https://github.com/NVIDIA/libcudacxx/blob/feature/nvcxx-compatibility/libcxx/include/atomic#L2600

Possible solutions:
* Don't emit an error for older SMs with NVC++. This would lead to (possibly cryptic) compile time failures in some cases and runtime failures in some cases.
* Add some sort of compile time "do all targets provide"/"do any target provide" mechanism to `` that uses `NV_TARGET_SM_INTEGER_LIST` instead to detect if any of the SMs in the list don't meet the requirements of the feature. This would require some preprocessor logic.
* Add some sort of `static_assert_target` facility to NVC++. This wouldn't solve the case of the `memcpy_async` overloads that should only be present for newer targets.

Contributor guide

Open the contributing guide

Research direction

Start by tracing the target checks in around line 307 and libcxx/include/atomic around line 2600, then locate the other __CUDA_ARCH__ and __NVCOMPILER_CUDA_ARCH__ uses. Compare the proposed mechanisms in the issue, including NV_TARGET_SM_INTEGER_LIST and static_assert_target. Done means the selected approach consistently handles header errors, memcpy_async availability, and atomic_flag wait/notify behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.