]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/Driver/cuda-options.cu
Vendor import of clang trunk r290819:
[FreeBSD/FreeBSD.git] / test / Driver / cuda-options.cu
1 // Tests CUDA compilation pipeline construction in Driver.
2 // REQUIRES: clang-driver
3 // REQUIRES: x86-registered-target
4 // REQUIRES: nvptx-registered-target
5
6 // Simple compilation case. Compile device-side to PTX assembly and make sure
7 // we use it on the host side.
8 // RUN: %clang -### -target x86_64-linux-gnu -c %s 2>&1 \
9 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
10 // RUN:    -check-prefix HOST -check-prefix INCLUDES-DEVICE \
11 // RUN:    -check-prefix NOLINK %s
12
13 // Typical compilation + link case.
14 // RUN: %clang -### -target x86_64-linux-gnu %s 2>&1 \
15 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
16 // RUN:    -check-prefix HOST -check-prefix INCLUDES-DEVICE \
17 // RUN:    -check-prefix LINK %s
18
19 // Verify that --cuda-host-only disables device-side compilation, but doesn't
20 // disable host-side compilation/linking.
21 // RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only %s 2>&1 \
22 // RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \
23 // RUN:    -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s
24
25 // Verify that --cuda-device-only disables host-side compilation and linking.
26 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only %s 2>&1 \
27 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
28 // RUN:    -check-prefix NOHOST -check-prefix NOLINK %s
29
30 // Check that the last of --cuda-compile-host-device, --cuda-host-only, and
31 // --cuda-device-only wins.
32
33 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
34 // RUN:    --cuda-host-only %s 2>&1 \
35 // RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \
36 // RUN:    -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s
37
38 // RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device \
39 // RUN:    --cuda-host-only %s 2>&1 \
40 // RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \
41 // RUN:    -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s
42
43 // RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only \
44 // RUN:    --cuda-device-only %s 2>&1 \
45 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
46 // RUN:    -check-prefix NOHOST -check-prefix NOLINK %s
47
48 // RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device \
49 // RUN:    --cuda-device-only %s 2>&1 \
50 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
51 // RUN:    -check-prefix NOHOST -check-prefix NOLINK %s
52
53 // RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only \
54 // RUN:   --cuda-compile-host-device %s 2>&1 \
55 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
56 // RUN:    -check-prefix HOST -check-prefix INCLUDES-DEVICE \
57 // RUN:    -check-prefix LINK %s
58
59 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
60 // RUN:   --cuda-compile-host-device %s 2>&1 \
61 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
62 // RUN:    -check-prefix HOST -check-prefix INCLUDES-DEVICE \
63 // RUN:    -check-prefix LINK %s
64
65 // Verify that --cuda-gpu-arch option passes the correct GPU archtecture to
66 // device compilation.
67 // RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_30 -c %s 2>&1 \
68 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
69 // RUN:    -check-prefix DEVICE-SM30 -check-prefix HOST \
70 // RUN:    -check-prefix INCLUDES-DEVICE -check-prefix NOLINK %s
71
72 // Verify that there is one device-side compilation per --cuda-gpu-arch args
73 // and that all results are included on the host side.
74 // RUN: %clang -### -target x86_64-linux-gnu \
75 // RUN:   --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30 -c %s 2>&1 \
76 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
77 // RUN:    -check-prefix DEVICE2 -check-prefix DEVICE-SM30 \
78 // RUN:    -check-prefix DEVICE2-SM35 -check-prefix HOST \
79 // RUN:    -check-prefix HOST-NOSAVE -check-prefix INCLUDES-DEVICE \
80 // RUN:    -check-prefix NOLINK %s
81
82 // Verify that device-side results are passed to the correct tool when
83 // -save-temps is used.
84 // RUN: %clang -### -target x86_64-linux-gnu -save-temps -c %s 2>&1 \
85 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-SAVE \
86 // RUN:    -check-prefix HOST -check-prefix HOST-SAVE -check-prefix NOLINK %s
87
88 // Verify that device-side results are passed to the correct tool when
89 // -fno-integrated-as is used.
90 // RUN: %clang -### -target x86_64-linux-gnu -fno-integrated-as -c %s 2>&1 \
91 // RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
92 // RUN:    -check-prefix HOST -check-prefix HOST-NOSAVE \
93 // RUN:    -check-prefix HOST-AS -check-prefix NOLINK %s
94
95 // Verify that --[no-]cuda-gpu-arch arguments are handled correctly.
96 // a) --no-cuda-gpu-arch=X negates preceeding --cuda-gpu-arch=X
97 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
98 // RUN:   --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30 \
99 // RUN:   --no-cuda-gpu-arch=sm_35 \
100 // RUN:   -c %s 2>&1 \
101 // RUN: | FileCheck -check-prefixes NOARCH-SM20,ARCH-SM30,NOARCH-SM35 %s
102
103 // b) --no-cuda-gpu-arch=X negates more than one preceeding --cuda-gpu-arch=X
104 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
105 // RUN:   --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30 \
106 // RUN:   --no-cuda-gpu-arch=sm_35 \
107 // RUN:   -c %s 2>&1 \
108 // RUN: | FileCheck -check-prefixes NOARCH-SM20,ARCH-SM30,NOARCH-SM35 %s
109
110 // c) if --no-cuda-gpu-arch=X negates all preceeding --cuda-gpu-arch=X
111 //    we default to sm_20 -- same as if no --cuda-gpu-arch were passed.
112 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
113 // RUN:   --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30 \
114 // RUN:   --no-cuda-gpu-arch=sm_35 --no-cuda-gpu-arch=sm_30 \
115 // RUN:   -c %s 2>&1 \
116 // RUN: | FileCheck -check-prefixes ARCH-SM20,NOARCH-SM30,NOARCH-SM35 %s
117
118 // d) --no-cuda-gpu-arch=X is a no-op if there's no preceding --cuda-gpu-arch=X
119 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
120 // RUN:   --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30\
121 // RUN:   --no-cuda-gpu-arch=sm_50 \
122 // RUN:   -c %s 2>&1 \
123 // RUN: | FileCheck -check-prefixes NOARCH-SM20,ARCH-SM30,ARCH-SM35 %s
124
125 // e) --no-cuda-gpu-arch=X does not affect following --cuda-gpu-arch=X
126 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
127 // RUN:   --no-cuda-gpu-arch=sm_35 --no-cuda-gpu-arch=sm_30 \
128 // RUN:   --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30 \
129 // RUN:   -c %s 2>&1 \
130 // RUN: | FileCheck -check-prefixes NOARCH-SM20,ARCH-SM30,ARCH-SM35 %s
131
132 // f) --no-cuda-gpu-arch=all negates all preceding --cuda-gpu-arch=X
133 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
134 // RUN:   --cuda-gpu-arch=sm_20 --cuda-gpu-arch=sm_30 \
135 // RUN:   --no-cuda-gpu-arch=all \
136 // RUN:   --cuda-gpu-arch=sm_35 \
137 // RUN:   -c %s 2>&1 \
138 // RUN: | FileCheck -check-prefixes NOARCH-SM20,NOARCH-SM30,ARCH-SM35 %s
139
140 // g) There's no --cuda-gpu-arch=all
141 // RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
142 // RUN:   --cuda-gpu-arch=all \
143 // RUN:   -c %s 2>&1 \
144 // RUN: | FileCheck -check-prefix ARCHALLERROR %s
145
146 // ARCH-SM20: "-cc1"{{.*}}"-target-cpu" "sm_20"
147 // NOARCH-SM20-NOT: "-cc1"{{.*}}"-target-cpu" "sm_20"
148 // ARCH-SM30: "-cc1"{{.*}}"-target-cpu" "sm_30"
149 // NOARCH-SM30-NOT: "-cc1"{{.*}}"-target-cpu" "sm_30"
150 // ARCH-SM35: "-cc1"{{.*}}"-target-cpu" "sm_35"
151 // NOARCH-SM35-NOT: "-cc1"{{.*}}"-target-cpu" "sm_35"
152 // ARCHALLERROR: error: Unsupported CUDA gpu architecture: all
153
154 // Match device-side preprocessor and compiler phases with -save-temps.
155 // DEVICE-SAVE: "-cc1" "-triple" "nvptx64-nvidia-cuda"
156 // DEVICE-SAVE-SAME: "-aux-triple" "x86_64--linux-gnu"
157 // DEVICE-SAVE-SAME: "-fcuda-is-device"
158 // DEVICE-SAVE-SAME: "-x" "cuda"
159
160 // DEVICE-SAVE: "-cc1" "-triple" "nvptx64-nvidia-cuda"
161 // DEVICE-SAVE-SAME: "-aux-triple" "x86_64--linux-gnu"
162 // DEVICE-SAVE-SAME: "-fcuda-is-device"
163 // DEVICE-SAVE-SAME: "-x" "cuda-cpp-output"
164
165 // Match the job that produces PTX assembly.
166 // DEVICE: "-cc1" "-triple" "nvptx64-nvidia-cuda"
167 // DEVICE-NOSAVE-SAME: "-aux-triple" "x86_64--linux-gnu"
168 // DEVICE-SAME: "-fcuda-is-device"
169 // DEVICE-SM30-SAME: "-target-cpu" "sm_30"
170 // DEVICE-SAME: "-o" "[[PTXFILE:[^"]*]]"
171 // DEVICE-NOSAVE-SAME: "-x" "cuda"
172 // DEVICE-SAVE-SAME: "-x" "ir"
173
174 // Match the call to ptxas (which assembles PTX to SASS).
175 // DEVICE:ptxas
176 // DEVICE-SM30-DAG: "--gpu-name" "sm_30"
177 // DEVICE-DAG: "--output-file" "[[CUBINFILE:[^"]*]]"
178 // DEVICE-DAG: "[[PTXFILE]]"
179
180 // Match another device-side compilation.
181 // DEVICE2: "-cc1" "-triple" "nvptx64-nvidia-cuda"
182 // DEVICE2-SAME: "-aux-triple" "x86_64--linux-gnu"
183 // DEVICE2-SAME: "-fcuda-is-device"
184 // DEVICE2-SM35-SAME: "-target-cpu" "sm_35"
185 // DEVICE2-SAME: "-o" "[[GPUBINARY2:[^"]*]]"
186 // DEVICE2-SAME: "-x" "cuda"
187
188 // Match no device-side compilation.
189 // NODEVICE-NOT: "-cc1" "-triple" "nvptx64-nvidia-cuda"
190 // NODEVICE-NOT: "-fcuda-is-device"
191
192 // INCLUDES-DEVICE:fatbinary
193 // INCLUDES-DEVICE-DAG: "--create" "[[FATBINARY:[^"]*]]"
194 // INCLUDES-DEVICE-DAG: "--image=profile=sm_{{[0-9]+}},file=[[CUBINFILE]]"
195 // INCLUDES-DEVICE-DAG: "--image=profile=compute_{{[0-9]+}},file=[[PTXFILE]]"
196
197 // Match host-side preprocessor job with -save-temps.
198 // HOST-SAVE: "-cc1" "-triple" "x86_64--linux-gnu"
199 // HOST-SAVE-SAME: "-aux-triple" "nvptx64-nvidia-cuda"
200 // HOST-SAVE-NOT: "-fcuda-is-device"
201 // HOST-SAVE-SAME: "-x" "cuda"
202
203 // Match host-side compilation.
204 // HOST: "-cc1" "-triple" "x86_64--linux-gnu"
205 // HOST-SAME: "-aux-triple" "nvptx64-nvidia-cuda"
206 // HOST-NOT: "-fcuda-is-device"
207 // HOST-SAME: "-o" "[[HOSTOUTPUT:[^"]*]]"
208 // HOST-NOSAVE-SAME: "-x" "cuda"
209 // HOST-SAVE-SAME: "-x" "cuda-cpp-output"
210 // INCLUDES-DEVICE-SAME: "-fcuda-include-gpubinary" "[[FATBINARY]]"
211
212 // Match external assembler that uses compilation output.
213 // HOST-AS: "-o" "{{.*}}.o" "[[HOSTOUTPUT]]"
214
215 // Match no GPU code inclusion.
216 // NOINCLUDES-DEVICE-NOT: "-fcuda-include-gpubinary"
217
218 // Match no host compilation.
219 // NOHOST-NOT: "-cc1" "-triple"
220 // NOHOST-NOT: "-x" "cuda"
221
222 // Match linker.
223 // LINK: "{{.*}}{{ld|link}}{{(.exe)?}}"
224 // LINK-SAME: "[[HOSTOUTPUT]]"
225
226 // Match no linker.
227 // NOLINK-NOT: "{{.*}}{{ld|link}}{{(.exe)?}}"