Compilation Errors with CUDA and MSVC: Identifiers from <atomic> Undefined

93 Views Asked by At

I'm working on a CUDA project using cl as the host compiler (Visual Studio 2019, MSVC v14.29.30133). I encountered an error related to the C++11 <atomic> header in CUDA standard library atomic_prelude.h. The input is

$ mingw32-make -f Makefile
D:/za/mingw/mingw64/bin/mingw32-make -f Makefile.Release
mingw32-make[1]: Entering directory 'D:/za/conformal_flow/flo/flo'
"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3/bin/nvcc" -ccbin "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl" -arch=sm_61 -Xptxas -O3 --use_fast_math --restrict --expt-relaxed-constexpr --expt-extended-lambda -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DTHRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_CUDA  -Xcudafe --display_error_number -Xcudafe --diag_suppress=2906 -Xcudafe --diag_suppress=186  -ID:/za/conformal_flow/flo/dep/eigen -ID:/za/conformal_flow/flo/dep/libigl/include -ID:/za/conformal_flow/flo/flo/include -I"D:/za/conformal_flow/flo/dep/cusplibrary" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3/include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3/include/cuda"  src/flo/device/adjacency_matrix_indices.cu -o cudaobj/adjacency_matrix_indices.o -L"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3/lib/x64" -lcudart -lcurand -licudata -lcudart_static -lcudadevrt -lcusparse -lcusolver -dc

Here's the errors I'm getting:

C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v12.3\include\cuda\std\detail\libcxx\include\__cuda/atomic_prelude.h(21): error: identifier "ATOMIC_**XXX**_LOCK_FREE" is undefined
      static_assert(ATOMIC_**XXX**_LOCK_FREE == 2, "");
                    ^
C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.3/include\cub/util_device.cuh(237): error: namespace "std" has no member "atomic"
          std::atomic<DeviceEntryStatus> flag;
               ^
C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.3/include\cub/util_device.cuh(237): error: this declaration has no storage class or type specifier
          std::atomic<DeviceEntryStatus> flag;
          ^

C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.3/include\cub/util_device.cuh(237): error: expected a ";"
          std::atomic<DeviceEntryStatus> flag;
                     ^

C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.3/include\cub/util_device.cuh(266): error: class "cub::CUB_200200_610_NS::PerDeviceAttributeCache::DeviceEntry" has no member "flag"
          auto& flag    = entry.flag;
                                ^

where XXX represents BOOL, CHAR, CHAR16_T ......

The file atomic_prelude.h includes <atomic>, and I can confirm that this header exists in the MSVC include path at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\include. Interestingly, there are no errors reported on the line #include <atomic>, but only on the subsequent usage of the contents from <atomic>. It seems like the compiler finds and includes the header but fails to recognize the definitions within it.

Any insights into why these errors are occurring and how to resolve them would be greatly appreciated!

I tried "Xcompiler -std=c++11" but had no effect.

1

There are 1 best solutions below

0
user725757 On

I add NVIDIA GPU Computing Toolkit\CUDA\v12.3\include\cuda\std\detail\libcxx\include to INCLUDEPATH and the problem was resolved. CUDA has its own std library, not the c++ std library.