Skip to content

yvals_core.h: reports unexpected CUDA version when being compiled with clang++ #2359

@mojca

Description

@mojca

Describe the bug

I fetched the latest sources from https://github.com/llvm/llvm-project.git, compiled clang and tried to run

> clang++.exe --cuda-path='C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4' hello.cu
In file included from <built-in>:1:
In file included from C:\Programs\llvm-project\build\vs-2019-x86_64\Debug\lib\clang\14.0.0\include\__clang_cuda_runtime_wrapper.h:41:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.31.30818\include\cmath:9:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.31.30818\include\yvals.h:9:
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.31.30818\include\yvals_core.h:582:2: error: STL1002: Unexpected compiler version,
      expected CUDA 10.1 Update 2 or newer.
#error STL1002: Unexpected compiler version, expected CUDA 10.1 Update 2 or newer.
 ^

The problem is that the following code from https://github.com/microsoft/STL/blob/main/stl/inc/yvals_core.h#L576-L582 assumes that it's being compiled by nvcc and fails.

#ifndef _ALLOW_COMPILER_AND_STL_VERSION_MISMATCH
#ifdef __CUDACC__
#if __CUDACC_VER_MAJOR__ < 10      \
    || (__CUDACC_VER_MAJOR__ == 10 \
        && (__CUDACC_VER_MINOR__ < 1 || (__CUDACC_VER_MINOR__ == 1 && __CUDACC_VER_BUILD__ < 243)))
#error STL1002: Unexpected compiler version, expected CUDA 10.1 Update 2 or newer.
#endif // ^^^ old CUDA ^^^

It doesn't take into account that the code might have been compiled with nvcc, see also see also https://www.llvm.org/docs/CompileCudaWithLLVM.html#detecting-clang-vs-nvcc-from-code

By running clang++.exe -x cuda /dev/null -dM -E I see that __CUDACC__ is defined, and the value of CUDA_VERSION is 11040, but __CUDACC_VER_MAJOR__ is missing.

For the time being I work around it by calling clang++.exe -D_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH ..., but that doesn't sound correct. Could the above code be reworked a bit to account for clang as well?

See also #1544, @StephanTLavavej.

Command-line test case

C:\Temp> type hello.cu
__global__ void cuda_hello () {
    const int a = 42;
}

int main() {
    cuda_hello<<<1,1>>>();
    return 0;
}

C:\Temp> clang++.exe --cuda-path='C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.4' hello.cu
In file included from <built-in>:1:
In file included from C:\Programs\llvm-project\build\vs-2019-x86_64\Debug\lib\clang\14.0.0\include\__clang_cuda_runtime_wrapper.h:41:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.31.30818\include\cmath:9:
In file included from C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.31.30818\include\yvals.h:9:
C:\Program Files\Microsoft Visual Studio\2022\Preview\VC\Tools\MSVC\14.31.30818\include\yvals_core.h:582:2: error: STL1002: Unexpected compiler version,
      expected CUDA 10.1 Update 2 or newer.
#error STL1002: Unexpected compiler version, expected CUDA 10.1 Update 2 or newer.
 ^
1 error generated when compiling for sm_35.

Expected behavior
No error when compiling the sources.

STL version

Microsoft Visual Studio Community 2022 Preview
Version 17.1.0 Preview 1.1

(I'm generally using 2019 Preview, and I used that one for compiling clang as well, but for some reason clang automatically picks up the headers from 2022.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions