xref: /aosp_15_r20/external/clang/test/Driver/cuda-detect.cu (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // REQUIRES: clang-driver
2*67e74705SXin Li // REQUIRES: x86-registered-target
3*67e74705SXin Li // REQUIRES: nvptx-registered-target
4*67e74705SXin Li //
5*67e74705SXin Li // # Check that we properly detect CUDA installation.
6*67e74705SXin Li // RUN: %clang -v --target=i386-unknown-linux \
7*67e74705SXin Li // RUN:   --sysroot=%S/no-cuda-there 2>&1 | FileCheck %s -check-prefix NOCUDA
8*67e74705SXin Li // RUN: %clang -v --target=i386-unknown-linux \
9*67e74705SXin Li // RUN:   --sysroot=%S/Inputs/CUDA 2>&1 | FileCheck %s
10*67e74705SXin Li // RUN: %clang -v --target=i386-unknown-linux \
11*67e74705SXin Li // RUN:   --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 | FileCheck %s
12*67e74705SXin Li 
13*67e74705SXin Li // Make sure we map libdevice bitcode files to proper GPUs.
14*67e74705SXin Li // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_21 \
15*67e74705SXin Li // RUN:   --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
16*67e74705SXin Li // RUN:   | FileCheck %s -check-prefix COMMON \
17*67e74705SXin Li // RUN:     -check-prefix LIBDEVICE -check-prefix LIBDEVICE21
18*67e74705SXin Li // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
19*67e74705SXin Li // RUN:   --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
20*67e74705SXin Li // RUN:   | FileCheck %s -check-prefix COMMON -check-prefix CUDAINC \
21*67e74705SXin Li // RUN:     -check-prefix LIBDEVICE -check-prefix LIBDEVICE35
22*67e74705SXin Li // Verify that -nocudainc prevents adding include path to CUDA headers.
23*67e74705SXin Li // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
24*67e74705SXin Li // RUN:   -nocudainc --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
25*67e74705SXin Li // RUN:   | FileCheck %s -check-prefix COMMON -check-prefix NOCUDAINC \
26*67e74705SXin Li // RUN:     -check-prefix LIBDEVICE -check-prefix LIBDEVICE35
27*67e74705SXin Li // We should not add any CUDA include paths if there's no valid CUDA installation
28*67e74705SXin Li // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
29*67e74705SXin Li // RUN:   --cuda-path=%S/no-cuda-there %s 2>&1 \
30*67e74705SXin Li // RUN:   | FileCheck %s -check-prefix COMMON -check-prefix NOCUDAINC
31*67e74705SXin Li 
32*67e74705SXin Li // Verify that no options related to bitcode linking are passes if
33*67e74705SXin Li // there's no bitcode file.
34*67e74705SXin Li // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_30 \
35*67e74705SXin Li // RUN:   --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
36*67e74705SXin Li // RUN:   | FileCheck %s -check-prefix COMMON -check-prefix NOLIBDEVICE
37*67e74705SXin Li // .. or if we explicitly passed -nocudalib
38*67e74705SXin Li // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
39*67e74705SXin Li // RUN:   -nocudalib --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
40*67e74705SXin Li // RUN:   | FileCheck %s -check-prefix COMMON -check-prefix NOLIBDEVICE
41*67e74705SXin Li // Verify that we don't add include paths, link with libdevice or
42*67e74705SXin Li // -include __clang_cuda_runtime_wrapper.h without valid CUDA installation.
43*67e74705SXin Li // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
44*67e74705SXin Li // RUN:   --cuda-path=%S/no-cuda-there %s 2>&1 \
45*67e74705SXin Li // RUN:   | FileCheck %s -check-prefix COMMON \
46*67e74705SXin Li // RUN:     -check-prefix NOCUDAINC -check-prefix NOLIBDEVICE
47*67e74705SXin Li 
48*67e74705SXin Li // CHECK: Found CUDA installation: {{.*}}/Inputs/CUDA/usr/local/cuda
49*67e74705SXin Li // NOCUDA-NOT: Found CUDA installation:
50*67e74705SXin Li 
51*67e74705SXin Li // COMMON: "-triple" "nvptx-nvidia-cuda"
52*67e74705SXin Li // COMMON-SAME: "-fcuda-is-device"
53*67e74705SXin Li // LIBDEVICE-SAME: "-mlink-cuda-bitcode"
54*67e74705SXin Li // NOLIBDEVICE-NOT: "-mlink-cuda-bitcode"
55*67e74705SXin Li // LIBDEVICE21-SAME: libdevice.compute_20.10.bc
56*67e74705SXin Li // LIBDEVICE35-SAME: libdevice.compute_35.10.bc
57*67e74705SXin Li // NOLIBDEVICE-NOT: libdevice.compute_{{.*}}.bc
58*67e74705SXin Li // LIBDEVICE-SAME: "-target-feature" "+ptx42"
59*67e74705SXin Li // NOLIBDEVICE-NOT: "-target-feature" "+ptx42"
60*67e74705SXin Li // CUDAINC-SAME: "-internal-isystem" "{{.*}}/Inputs/CUDA/usr/local/cuda/include"
61*67e74705SXin Li // NOCUDAINC-NOT: "-internal-isystem" "{{.*}}/cuda/include"
62*67e74705SXin Li // CUDAINC-SAME: "-include" "__clang_cuda_runtime_wrapper.h"
63*67e74705SXin Li // NOCUDAINC-NOT: "-include" "__clang_cuda_runtime_wrapper.h"
64*67e74705SXin Li // COMMON-SAME: "-x" "cuda"
65