blob: c4bfda903d9e13b9f80df8ac63c1f41e080c2f3f [file] [log] [blame]
Artem Belevich0ff05cd2015-07-13 23:27:56 +00001// Tests CUDA compilation pipeline construction in Driver.
2// REQUIRES: clang-driver
Artem Belevichb73313d2015-07-14 18:49:17 +00003// REQUIRES: x86-registered-target
4// REQUIRES: nvptx-registered-target
Artem Belevich0ff05cd2015-07-13 23:27:56 +00005
Justin Lebar388579f2016-01-13 01:24:35 +00006// Simple compilation case. Compile device-side to PTX assembly and make sure
7// we use it on the host side.
Artem Belevichdf7cd312015-07-16 17:24:18 +00008// RUN: %clang -### -target x86_64-linux-gnu -c %s 2>&1 \
Justin Lebar388579f2016-01-13 01:24:35 +00009// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
10// RUN: -check-prefix HOST -check-prefix INCLUDES-DEVICE \
11// RUN: -check-prefix NOLINK %s
Artem Belevich0ff05cd2015-07-13 23:27:56 +000012
Justin Lebar388579f2016-01-13 01:24:35 +000013// Typical compilation + link case.
Artem Belevichdf7cd312015-07-16 17:24:18 +000014// RUN: %clang -### -target x86_64-linux-gnu %s 2>&1 \
Justin Lebar388579f2016-01-13 01:24:35 +000015// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
16// RUN: -check-prefix HOST -check-prefix INCLUDES-DEVICE \
17// RUN: -check-prefix LINK %s
Artem Belevich0ff05cd2015-07-13 23:27:56 +000018
Justin Lebar388579f2016-01-13 01:24:35 +000019// Verify that --cuda-host-only disables device-side compilation, but doesn't
20// disable host-side compilation/linking.
Artem Belevichdf7cd312015-07-16 17:24:18 +000021// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only %s 2>&1 \
Justin Lebar388579f2016-01-13 01:24:35 +000022// RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \
23// RUN: -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s
Artem Belevich0ff05cd2015-07-13 23:27:56 +000024
Justin Lebar388579f2016-01-13 01:24:35 +000025// Verify that --cuda-device-only disables host-side compilation and linking.
Artem Belevichdf7cd312015-07-16 17:24:18 +000026// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only %s 2>&1 \
Justin Lebar388579f2016-01-13 01:24:35 +000027// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
28// RUN: -check-prefix NOHOST -check-prefix NOLINK %s
Artem Belevich0ff05cd2015-07-13 23:27:56 +000029
Justin Lebardc3c5042016-04-19 02:27:07 +000030// 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 \
Justin Lebar388579f2016-01-13 01:24:35 +000045// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
46// RUN: -check-prefix NOHOST -check-prefix NOLINK %s
Artem Belevich23256752015-09-22 17:23:09 +000047
Justin Lebardc3c5042016-04-19 02:27:07 +000048// 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
Justin Lebar388579f2016-01-13 01:24:35 +000065// Verify that --cuda-gpu-arch option passes the correct GPU archtecture to
66// device compilation.
Artem Belevicha424e882016-12-09 22:59:17 +000067// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_30 -c %s 2>&1 \
Justin Lebar388579f2016-01-13 01:24:35 +000068// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
Artem Belevicha424e882016-12-09 22:59:17 +000069// RUN: -check-prefix DEVICE-SM30 -check-prefix HOST \
Justin Lebar388579f2016-01-13 01:24:35 +000070// RUN: -check-prefix INCLUDES-DEVICE -check-prefix NOLINK %s
Artem Belevich0ff05cd2015-07-13 23:27:56 +000071
Justin Lebar388579f2016-01-13 01:24:35 +000072// Verify that there is one device-side compilation per --cuda-gpu-arch args
Artem Belevich0ff05cd2015-07-13 23:27:56 +000073// and that all results are included on the host side.
Artem Belevichf8144ab2015-08-27 18:10:41 +000074// RUN: %clang -### -target x86_64-linux-gnu \
Justin Lebar388579f2016-01-13 01:24:35 +000075// 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 \
Artem Belevicha424e882016-12-09 22:59:17 +000077// RUN: -check-prefix DEVICE2 -check-prefix DEVICE-SM30 \
78// RUN: -check-prefix DEVICE2-SM35 -check-prefix HOST \
Justin Lebar388579f2016-01-13 01:24:35 +000079// RUN: -check-prefix HOST-NOSAVE -check-prefix INCLUDES-DEVICE \
Justin Lebar21e5d4f2016-01-14 21:41:27 +000080// RUN: -check-prefix NOLINK %s
Artem Belevich0ff05cd2015-07-13 23:27:56 +000081
Justin Lebar388579f2016-01-13 01:24:35 +000082// Verify that device-side results are passed to the correct tool when
83// -save-temps is used.
Artem Belevichf8144ab2015-08-27 18:10:41 +000084// RUN: %clang -### -target x86_64-linux-gnu -save-temps -c %s 2>&1 \
Justin Lebar388579f2016-01-13 01:24:35 +000085// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-SAVE \
86// RUN: -check-prefix HOST -check-prefix HOST-SAVE -check-prefix NOLINK %s
Artem Belevichf8144ab2015-08-27 18:10:41 +000087
Justin Lebar388579f2016-01-13 01:24:35 +000088// Verify that device-side results are passed to the correct tool when
89// -fno-integrated-as is used.
Artem Belevichf8144ab2015-08-27 18:10:41 +000090// RUN: %clang -### -target x86_64-linux-gnu -fno-integrated-as -c %s 2>&1 \
Justin Lebar388579f2016-01-13 01:24:35 +000091// 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
Artem Belevichf8144ab2015-08-27 18:10:41 +000094
Artem Belevicha424e882016-12-09 22:59:17 +000095// 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
Justin Lebar388579f2016-01-13 01:24:35 +0000154// 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"
Artem Belevich5e2a3ec2015-11-17 22:28:40 +0000159
Justin Lebar388579f2016-01-13 01:24:35 +0000160// 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"
Artem Belevich5e2a3ec2015-11-17 22:28:40 +0000164
Justin Lebar388579f2016-01-13 01:24:35 +0000165// 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"
Artem Belevicha424e882016-12-09 22:59:17 +0000169// DEVICE-SM30-SAME: "-target-cpu" "sm_30"
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000170// DEVICE-SAME: "-o" "[[PTXFILE:[^"]*]]"
Justin Lebar388579f2016-01-13 01:24:35 +0000171// DEVICE-NOSAVE-SAME: "-x" "cuda"
172// DEVICE-SAVE-SAME: "-x" "ir"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000173
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000174// Match the call to ptxas (which assembles PTX to SASS).
175// DEVICE:ptxas
Artem Belevicha424e882016-12-09 22:59:17 +0000176// DEVICE-SM30-DAG: "--gpu-name" "sm_30"
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000177// DEVICE-DAG: "--output-file" "[[CUBINFILE:[^"]*]]"
178// DEVICE-DAG: "[[PTXFILE]]"
179
Justin Lebar388579f2016-01-13 01:24:35 +0000180// 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"
Artem Belevicha424e882016-12-09 22:59:17 +0000184// DEVICE2-SM35-SAME: "-target-cpu" "sm_35"
Justin Lebar388579f2016-01-13 01:24:35 +0000185// DEVICE2-SAME: "-o" "[[GPUBINARY2:[^"]*]]"
186// DEVICE2-SAME: "-x" "cuda"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000187
Justin Lebar388579f2016-01-13 01:24:35 +0000188// Match no device-side compilation.
189// NODEVICE-NOT: "-cc1" "-triple" "nvptx64-nvidia-cuda"
Paul Robinson4abe94f2016-02-10 02:08:24 +0000190// NODEVICE-NOT: "-fcuda-is-device"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000191
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000192// 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
Justin Lebar388579f2016-01-13 01:24:35 +0000197// 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"
Paul Robinson4abe94f2016-02-10 02:08:24 +0000200// HOST-SAVE-NOT: "-fcuda-is-device"
Justin Lebar388579f2016-01-13 01:24:35 +0000201// HOST-SAVE-SAME: "-x" "cuda"
Artem Belevichf8144ab2015-08-27 18:10:41 +0000202
Justin Lebar388579f2016-01-13 01:24:35 +0000203// Match host-side compilation.
204// HOST: "-cc1" "-triple" "x86_64--linux-gnu"
205// HOST-SAME: "-aux-triple" "nvptx64-nvidia-cuda"
Paul Robinson4abe94f2016-02-10 02:08:24 +0000206// HOST-NOT: "-fcuda-is-device"
Justin Lebar388579f2016-01-13 01:24:35 +0000207// HOST-SAME: "-o" "[[HOSTOUTPUT:[^"]*]]"
208// HOST-NOSAVE-SAME: "-x" "cuda"
209// HOST-SAVE-SAME: "-x" "cuda-cpp-output"
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000210// INCLUDES-DEVICE-SAME: "-fcuda-include-gpubinary" "[[FATBINARY]]"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000211
Justin Lebar388579f2016-01-13 01:24:35 +0000212// Match external assembler that uses compilation output.
213// HOST-AS: "-o" "{{.*}}.o" "[[HOSTOUTPUT]]"
Artem Belevichf8144ab2015-08-27 18:10:41 +0000214
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000215// Match no GPU code inclusion.
Justin Lebar388579f2016-01-13 01:24:35 +0000216// NOINCLUDES-DEVICE-NOT: "-fcuda-include-gpubinary"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000217
Justin Lebar388579f2016-01-13 01:24:35 +0000218// Match no host compilation.
219// NOHOST-NOT: "-cc1" "-triple"
Paul Robinson4abe94f2016-02-10 02:08:24 +0000220// NOHOST-NOT: "-x" "cuda"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000221
Justin Lebar388579f2016-01-13 01:24:35 +0000222// Match linker.
223// LINK: "{{.*}}{{ld|link}}{{(.exe)?}}"
224// LINK-SAME: "[[HOSTOUTPUT]]"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000225
Justin Lebar388579f2016-01-13 01:24:35 +0000226// Match no linker.
227// NOLINK-NOT: "{{.*}}{{ld|link}}{{(.exe)?}}"