Issue 244194
Summary [CUDA][Driver] `-nocudalib` omits `-target-sdk-version`, breaking kernel launches
Labels new issue
Assignees
Reporter RealXuChe
    ## Summary

Appending `-nocudalib` to a valid CUDA compilation command causes all `<<<...>>>` kernel launches to fail with `error: use of undeclared identifier cudaConfigureCall`.

## Steps to Reproduce

### My Environment

(This issue occurs with all recent CUDA versions. Unless you don't have CUDA installed, you'll probably want to skip this part. I'm only including it to be a bit more rigorous, I suppose.)

```bash
mkdir cuda
curl -fLO 'https://developer.download.nvidia.com/compute/cuda/12.4.1/local_installers/cuda_12.4.1_550.54.15_linux.run'
sh cuda_12.4.1_550.54.15_linux.run --toolkit "--toolkitpath=$(realpath ./cuda)"
```

```console
$ clang++ --version
clang version 23.1.5
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```

### Reproduction

Create a minimal CUDA source file `a.cu`:

```c++
__global__ void k() {}

void f() {
    k<<<1, 1>>>();
}
```

Run syntax checking first; it exits cleanly and everything works fine so far:

```console
$ clang++ -fsyntax-only --cuda-path=./cuda a.cu
(exits successfully with no output)
```

Now add `-nocudalib`. Since we are only running a syntax check and exiting right after building the AST without ever touching IR bitcode, this should still succeed, yet it fails:

```console
$ clang++ -fsyntax-only --cuda-path=./cuda -nocudalib a.cu
a.cu:4:6: error: use of undeclared identifier cudaConfigureCall
    4 |     k<<<1, 1>>>();
      |      ^
1 error generated when compiling for sm_52.
```

`cudaConfigureCall` here already strongly hints at what went wrong. `cudaConfigureCall` is a function from very old CUDA versions and is no longer defined in modern CUDA environments. In old CUDA versions, a `<<<...>>>` kernel launch was lowered to a `cudaConfigureCall` call. So what is happening here looks clear: the device-side `cc1` assumes a very old CUDA version is in use and tries to emit a `cudaConfigureCall` call, which no longer exists in modern CUDA.

Passing the SDK version explicitly fixes it, which clearly confirms the cause:

```console
$ clang++ -fsyntax-only --cuda-path=./cuda -nocudalib -Xclang -target-sdk-version=12.4 a.cu
(works fine again)
```

## Root Cause

https://github.com/llvm/llvm-project/blob/07e7c3133855e47cc416bf79cf2d9a890c6f29b6/clang/lib/Driver/ToolChains/Cuda.cpp#L953-L956

Here, the Driver passes the CUDA version to the device-side `cc1`. However, right before this, there are 4 conditional branches that may `return` early from this function:

https://github.com/llvm/llvm-project/blob/07e7c3133855e47cc416bf79cf2d9a890c6f29b6/clang/lib/Driver/ToolChains/Cuda.cpp#L931-L946

Regardless of whether `OPT_offloadlib` is enabled or not, the CUDA version should obviously still be passed. In the current implementation, passing `-nocudalib` skips the code below it, leaving the device-side `cc1` unaware of the CUDA version.

## Note

#86660 reported the same error back in 2024 without further activity. Just sharing a minimal reproducer and the root cause here.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to