1 // REQUIRES: x86-registered-target
2 // REQUIRES: nvptx-registered-target
4 // Check that we properly detect CUDA installation.
5 // RUN: %clang -v --target=i386-unknown-linux \
6 // RUN: --sysroot=%S/no-cuda-there --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA
7 // RUN: %clang -v --target=i386-apple-macosx \
8 // RUN: --sysroot=%S/no-cuda-there --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA
9 // RUN: %clang -v --target=x86_64-unknown-linux \
10 // RUN: --sysroot=%S/no-cuda-there --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA
11 // RUN: %clang -v --target=x86_64-apple-macosx \
12 // RUN: --sysroot=%S/no-cuda-there --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA
15 // RUN: %clang -v --target=i386-unknown-linux \
16 // RUN: --sysroot=%S/Inputs/CUDA --cuda-path-ignore-env 2>&1 | FileCheck %s
17 // RUN: %clang -v --target=i386-apple-macosx \
18 // RUN: --sysroot=%S/Inputs/CUDA --cuda-path-ignore-env 2>&1 | FileCheck %s
20 // RUN: %clang -v --target=i386-unknown-linux \
21 // RUN: --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 | FileCheck %s
22 // RUN: %clang -v --target=i386-apple-macosx \
23 // RUN: --cuda-path=%S/Inputs/CUDA/usr/local/cuda 2>&1 | FileCheck %s
25 // Check that we don't find a CUDA installation without libdevice ...
26 // RUN: %clang -v --target=i386-unknown-linux \
27 // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA
28 // RUN: %clang -v --target=i386-apple-macosx \
29 // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA
30 // RUN: %clang -v --target=x86_64-unknown-linux \
31 // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA
32 // RUN: %clang -v --target=x84_64-apple-macosx \
33 // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NOCUDA
35 // ... unless the user doesn't need libdevice
36 // RUN: %clang -v --target=i386-unknown-linux -nocudalib \
37 // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NO-LIBDEVICE
38 // RUN: %clang -v --target=i386-apple-macosx -nocudalib \
39 // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NO-LIBDEVICE
40 // RUN: %clang -v --target=x86_64-unknown-linux -nocudalib \
41 // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NO-LIBDEVICE
42 // RUN: %clang -v --target=x86_64-apple-macosx -nocudalib \
43 // RUN: --sysroot=%S/Inputs/CUDA-nolibdevice --cuda-path-ignore-env 2>&1 | FileCheck %s -check-prefix NO-LIBDEVICE
46 // Make sure we map libdevice bitcode files to proper GPUs. These
47 // tests use Inputs/CUDA_80 which has full set of libdevice files.
48 // However, libdevice mapping only matches CUDA-7.x at the moment.
49 // sm_2x, sm_32 -> compute_20
50 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_21 \
51 // RUN: --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
52 // RUN: | FileCheck %s -check-prefix COMMON \
53 // RUN: -check-prefixes PTX42,LIBDEVICE,LIBDEVICE20
54 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_32 \
55 // RUN: --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
56 // RUN: | FileCheck %s -check-prefix COMMON \
57 // RUN: -check-prefixes PTX42,LIBDEVICE,LIBDEVICE20
58 // sm_30, sm_6x map to compute_30.
59 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_30 \
60 // RUN: --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
61 // RUN: | FileCheck %s -check-prefix COMMON \
62 // RUN: -check-prefixes PTX42,LIBDEVICE,LIBDEVICE30
63 // sm_5x is a special case. Maps to compute_30 for cuda-7.x only.
64 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_50 \
65 // RUN: --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
66 // RUN: | FileCheck %s -check-prefix COMMON \
67 // RUN: -check-prefixes PTX42,LIBDEVICE,LIBDEVICE30
68 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_60 \
69 // RUN: --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
70 // RUN: | FileCheck %s -check-prefix COMMON \
71 // RUN: -check-prefixes PTX42,LIBDEVICE,LIBDEVICE30
72 // sm_35 and sm_37 -> compute_35
73 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
74 // RUN: --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
75 // RUN: | FileCheck %s -check-prefix COMMON -check-prefix CUDAINC \
76 // RUN: -check-prefixes PTX42,LIBDEVICE,LIBDEVICE35
77 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_37 \
78 // RUN: --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
79 // RUN: | FileCheck %s -check-prefix COMMON -check-prefix CUDAINC \
80 // RUN: -check-prefixes PTX42,LIBDEVICE,LIBDEVICE35
81 // sm_5x -> compute_50 for CUDA-8.0 and newer.
82 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_50 \
83 // RUN: --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
84 // RUN: | FileCheck %s -check-prefix COMMON \
85 // RUN: -check-prefixes PTX42,LIBDEVICE,LIBDEVICE50
87 // CUDA-9+ uses the same libdevice for all GPU variants:
88 // RUN: %clang -### -v --target=x86_64-unknown-linux --cuda-gpu-arch=sm_30 \
89 // RUN: --cuda-path=%S/Inputs/CUDA_90/usr/local/cuda %s 2>&1 \
90 // RUN: | FileCheck %s -check-prefix COMMON64 \
91 // RUN: -check-prefixes PTX60,LIBDEVICE,LIBDEVICE10
92 // RUN: %clang -### -v --target=x86_64-unknown-linux --cuda-gpu-arch=sm_50 \
93 // RUN: --cuda-path=%S/Inputs/CUDA_90/usr/local/cuda %s 2>&1 \
94 // RUN: | FileCheck %s -check-prefix COMMON64 \
95 // RUN: -check-prefixes PTX60,LIBDEVICE,LIBDEVICE10
96 // RUN: %clang -### -v --target=x86_64-unknown-linux --cuda-gpu-arch=sm_60 \
97 // RUN: --cuda-path=%S/Inputs/CUDA_90/usr/local/cuda %s 2>&1 \
98 // RUN: | FileCheck %s -check-prefix COMMON64 \
99 // RUN: -check-prefixes PTX60,LIBDEVICE,LIBDEVICE10
102 // Verify that -nocudainc prevents adding include path to CUDA headers.
103 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
104 // RUN: -nocudainc --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
105 // RUN: | FileCheck %s -check-prefix COMMON -check-prefix NOCUDAINC \
106 // RUN: -check-prefixes PTX42,LIBDEVICE,LIBDEVICE35
107 // RUN: %clang -### -v --target=i386-apple-macosx --cuda-gpu-arch=sm_35 \
108 // RUN: -nocudainc --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
109 // RUN: | FileCheck %s -check-prefix COMMON -check-prefix NOCUDAINC \
110 // RUN: -check-prefixes PTX42,LIBDEVICE,LIBDEVICE35
112 // We should not add any CUDA include paths if there's no valid CUDA installation
113 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
114 // RUN: --cuda-path=%S/no-cuda-there %s 2>&1 \
115 // RUN: | FileCheck %s -check-prefix COMMON -check-prefix NOCUDAINC
116 // RUN: %clang -### -v --target=i386-apple-macosx --cuda-gpu-arch=sm_35 \
117 // RUN: --cuda-path=%S/no-cuda-there %s 2>&1 \
118 // RUN: | FileCheck %s -check-prefix COMMON -check-prefix NOCUDAINC
120 // Verify that we get an error if there's no libdevice library to link with.
121 // NOTE: Inputs/CUDA deliberately does *not* have libdevice.compute_20 for this purpose.
122 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_20 \
123 // RUN: --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
124 // RUN: | FileCheck %s -check-prefix COMMON -check-prefix MISSINGLIBDEVICE
125 // RUN: %clang -### -v --target=i386-apple-macosx --cuda-gpu-arch=sm_20 \
126 // RUN: --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
127 // RUN: | FileCheck %s -check-prefix COMMON -check-prefix MISSINGLIBDEVICE
129 // Verify that -nocudalib prevents linking libdevice bitcode in.
130 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
131 // RUN: -nocudalib --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
132 // RUN: | FileCheck %s -check-prefix COMMON
133 // RUN: %clang -### -v --target=i386-apple-macosx --cuda-gpu-arch=sm_35 \
134 // RUN: -nocudalib --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
135 // RUN: | FileCheck %s -check-prefix COMMON
137 // Verify that we don't add include paths, link with libdevice or
138 // -include __clang_cuda_runtime_wrapper.h without valid CUDA installation.
139 // RUN: %clang -### -v --target=i386-unknown-linux --cuda-gpu-arch=sm_35 \
140 // RUN: --cuda-path=%S/no-cuda-there %s 2>&1 \
141 // RUN: | FileCheck %s -check-prefix COMMON \
142 // RUN: -check-prefix NOCUDAINC
143 // RUN: %clang -### -v --target=i386-apple-macosx --cuda-gpu-arch=sm_35 \
144 // RUN: --cuda-path=%S/no-cuda-there %s 2>&1 \
145 // RUN: | FileCheck %s -check-prefix COMMON \
146 // RUN: -check-prefix NOCUDAINC
148 // Verify that C++ include paths are passed for both host and device frontends.
149 // RUN: %clang -### --target=x86_64-linux-gnu %s \
150 // RUN: --stdlib=libstdc++ --sysroot=%S/Inputs/ubuntu_14.04_multiarch_tree2 \
151 // RUN: --gcc-toolchain="" 2>&1 \
152 // RUN: | FileCheck %s --check-prefix CHECK-CXXINCLUDE
154 // Verify that CUDA SDK version is propagated to the CC1 compilations.
155 // RUN: %clang -### -v --target=x86_64-linux-gnu --cuda-gpu-arch=sm_50 \
156 // RUN: --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda %s 2>&1 \
157 // RUN: | FileCheck %s -check-prefix CUDA80
159 // Verify that if no version file is found, we report the default of 7.0.
160 // RUN: %clang -### -v --target=x86_64-linux-gnu --cuda-gpu-arch=sm_50 \
161 // RUN: --cuda-path=%S/Inputs/CUDA/usr/local/cuda %s 2>&1 \
162 // RUN: | FileCheck %s -check-prefix CUDA70
164 // CHECK: Found CUDA installation: {{.*}}/Inputs/CUDA/usr/local/cuda
165 // NO-LIBDEVICE: Found CUDA installation: {{.*}}/Inputs/CUDA-nolibdevice/usr/local/cuda
166 // NOCUDA-NOT: Found CUDA installation:
168 // MISSINGLIBDEVICE: error: cannot find libdevice for sm_20;
170 // COMMON: "-triple" "nvptx-nvidia-cuda"
171 // COMMON64: "-triple" "nvptx64-nvidia-cuda"
172 // COMMON-SAME: "-fcuda-is-device"
173 // LIBDEVICE-SAME: "-mlink-builtin-bitcode"
174 // LIBDEVICE10-SAME: libdevice.10.bc
175 // LIBDEVICE20-SAME: libdevice.compute_20.10.bc
176 // LIBDEVICE30-SAME: libdevice.compute_30.10.bc
177 // LIBDEVICE35-SAME: libdevice.compute_35.10.bc
178 // LIBDEVICE50-SAME: libdevice.compute_50.10.bc
179 // PTX42-SAME: "-target-feature" "+ptx42"
180 // PTX60-SAME: "-target-feature" "+ptx60"
181 // CUDAINC-SAME: "-include" "__clang_cuda_runtime_wrapper.h"
182 // NOCUDAINC-NOT: "-include" "__clang_cuda_runtime_wrapper.h"
183 // CUDAINC-SAME: "-internal-isystem" "{{.*}}/Inputs/CUDA{{[_0-9]+}}/usr/local/cuda/include"
184 // NOCUDAINC-NOT: "-internal-isystem" "{{.*}}/cuda/include"
185 // -internal-externc-isystem flags must come *after* the cuda include flags,
186 // because we must search the cuda include directory first.
187 // CUDAINC-SAME: "-internal-externc-isystem"
188 // COMMON-SAME: "-x" "cuda"
189 // CHECK-CXXINCLUDE: "-cc1" "-triple" "nvptx64-nvidia-cuda"
190 // CHECK-CXXINCLUDE-SAME: {{.*}}"-internal-isystem" "{{.+}}/include/c++/4.8"
191 // CHECK-CXXINCLUDE: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
192 // CHECK-CXXINCLUDE-SAME: {{.*}}"-internal-isystem" "{{.+}}/include/c++/4.8"
193 // CHECK-CXXINCLUDE: ld{{.*}}"
195 // CUDA80: "-cc1" "-triple" "nvptx64-nvidia-cuda"
196 // CUDA80-SAME: -target-sdk-version=8.0
197 // CUDA80: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
198 // CUDA80-SAME: -target-sdk-version=8.0
201 // CUDA70: "-cc1" "-triple" "nvptx64-nvidia-cuda"
202 // CUDA70-SAME: -target-sdk-version=7.0
203 // CUDA70: "-cc1" "-triple" "x86_64-unknown-linux-gnu"
204 // CUDA70-SAME: -target-sdk-version=7.0