[BUG]: Compilation error when both NVTX v2 and CUB are included
- Dominant language
- C++
- Stars
- 2.5k
- Forks
- 486
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 295
Description
### Is this a duplicate?
- [x] I confirmed there appear to be no [duplicate issues](https://github.com/NVIDIA/cccl/issues) for this bug and that I agree to the [Code of Conduct](CODE_OF_CONDUCT.md)
### Type of Bug
Compile-time Error
### Component
CUB
### Describe the bug
As of CUDA 12.6, CUB includes NVTX version 3 headers. If a source file includes an earlier version of NVTX and then includes a CUB header, then the NVTX version 3 header will `#error` out with "Trying to #include NVTX version 3 in a source file where an older NVTX version has already been included." The CUDA Toolkit contains headers for NVTX version 2, so it is quite easy for users to hit this compilation error. (See the steps to reproduce for a trivial example.)
### How to Reproduce
```
$ cat nvtx.cu
#include
#include
int main() { }
```
```
$ /proj/cuda/12.6/Linux_x86_64/bin/nvcc nvtx.cu
In file included from /proj/cuda/12.6.0.560/Linux_x86_64/targets/x86_64-linux/include/cub/detail/nvtx3.hpp:635,
from /proj/cuda/12.6/Linux_x86_64/bin/../targets/x86_64-linux/include/cub/detail/nvtx.cuh:49,
from /proj/cuda/12.6/Linux_x86_64/bin/../targets/x86_64-linux/include/cub/device/device_reduce.cuh:46,
from /proj/cuda/12.6/Linux_x86_64/bin/../targets/x86_64-linux/include/thrust/system/cuda/detail/reduce.h:43,
from /proj/cuda/12.6/Linux_x86_64/bin/../targets/x86_64-linux/include/thrust/system/detail/adl/reduce.h:50,
from /proj/cuda/12.6/Linux_x86_64/bin/../targets/x86_64-linux/include/thrust/detail/reduce.inl:31,
from /proj/cuda/12.6/Linux_x86_64/bin/../targets/x86_64-linux/include/thrust/reduce.h:763,
from nvtx.cu:2:
/proj/cuda/12.6/Linux_x86_64/bin/../targets/x86_64-linux/include/nvtx3/nvToolsExt.h:179:2: error: #error "Trying to #include NVTX version 3 in a source file where an older NVTX version has already been included. If you are not directly using NVTX (the NVIDIA Tools Extension library), you are getting this error because libraries you are using have included different versions of NVTX. Suggested solutions are: (1) reorder #includes so the newest NVTX version is included first, (2) avoid using the conflicting libraries in the same .c/.cpp file, or (3) update the library using the older NVTX version to use the newer version instead."
179 | #error "Trying to #include NVTX version 3 in a source file where an older NVTX version has already been included. If you are not directly using NVTX (the NVIDIA Tools Extension library), you are getting this error because libraries you are using have included different versions of NVTX. Suggested solutions are: (1) reorder #includes so the newest NVTX version is included first, (2) avoid using the conflicting libraries in the same .c/.cpp file, or (3) update the library using the older NVTX version to use the newer version instead."
| ^~~~~
```
### Expected behavior
CUB should not fail with a compilation error if `` has been included before CUB is included.
### Reproduction link
_No response_
### Operating System
_No response_
### nvidia-smi output
_No response_
### NVCC version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Fri_Jun_14_16:34:21_PDT_2024
Cuda compilation tools, release 12.6, V12.6.20
Build cuda_12.6.r12.6/compiler.34431801_0
Contributor guide
Assessment
This issue has not been assessed yet.