NVIDIA / cccl

CUDA Core Compute Libraries
https://nvidia.github.io/cccl/
Other
1.17k stars 139 forks source link

<cuda/std/atomic> is incompatible with host compilation on Windows #968

Open nvibd opened 3 years ago

nvibd commented 3 years ago

As a minimal example, save the following as main.cpp and compile with MSVC / cl.exe, e.g.:

cl main.cpp -I "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include"

#include <cuda/std/atomic>

The same code will compile fine with nvcc (given arch >= 70 flags), but it will generate a bunch of errors and one warning when compiled with MSVC. I've added them at the end of the post.

This seems in conflict with libcu++'s claim: "It provides a heterogeneous implementation of the C++ Standard Library that can be used in and between CPU and GPU code". In our application, this creates a problem as we include <cuda/std/atomic> indirectly together with pybind for Python bindings, which itself cannot be compiled with nvcc for unrelated reasons.

Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29336 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

main.cpp
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(13): error C2059: syntax error: 'volatile'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(13): error C2589: ':': illegal token on right side of '::'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(14): error C2059: syntax error: 'volatile'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(14): error C2589: ':': illegal token on right side of '::'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(15): error C2059: syntax error: 'volatile'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(15): error C2589: ':': illegal token on right side of '::'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(742): error C2059: syntax error: 'volatile'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(742): error C2589: ':': illegal token on right side of '::'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(743): error C2059: syntax error: 'volatile'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(743): error C2589: ':': illegal token on right side of '::'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(744): error C2059: syntax error: 'volatile'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(744): error C2589: ':': illegal token on right side of '::'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(1471): error C2059: syntax error: 'volatile'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(1471): error C2589: ':': illegal token on right side of '::'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(1472): error C2059: syntax error: 'volatile'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(1472): error C2589: ':': illegal token on right side of '::'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(1473): error C2059: syntax error: 'volatile'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_generated(1473): error C2589: ':': illegal token on right side of '::'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_derived(151): error C2059: syntax error: 'volatile'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\__atomic_derived(151): error C2589: ':': illegal token on right side of '::'
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.2\include\cuda\std\detail\../chrono(33): warning C4068: unknown pragma 'diag_suppress'
nvibd commented 3 years ago

The libcu++ version is the one included with CUDA 11.2.

cl.exe version: Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29336 for x64 nvcc.exe version: Cuda compilation tools, release 11.2, V11.2.67

jrhemstad commented 3 years ago

There currently isn't a guarantee that libcu++ can be compiled solely by a host compiler. See https://github.com/NVIDIA/cccl/issues/940

nvibd commented 3 years ago

Thanks for bringing awareness to that previous ticket. I've added a comment there.