blob: 67d4fdeae2c0e080c48a3626d01be07017451d4b [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 \
Jonas Hahnfelde7681322018-02-28 17:53:46 +000076// RUN: | FileCheck -check-prefixes DEVICE,DEVICE-NOSAVE,DEVICE2 \
77// RUN: -check-prefixes DEVICE-SM30,DEVICE2-SM35 \
78// RUN: -check-prefixes INCLUDES-DEVICE,INCLUDES-DEVICE2 \
79// RUN: -check-prefixes HOST,HOST-NOSAVE,NOLINK %s
Artem Belevich0ff05cd2015-07-13 23:27:56 +000080
Justin Lebar388579f2016-01-13 01:24:35 +000081// Verify that device-side results are passed to the correct tool when
82// -save-temps is used.
Artem Belevichf8144ab2015-08-27 18:10:41 +000083// RUN: %clang -### -target x86_64-linux-gnu -save-temps -c %s 2>&1 \
Justin Lebar388579f2016-01-13 01:24:35 +000084// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-SAVE \
85// RUN: -check-prefix HOST -check-prefix HOST-SAVE -check-prefix NOLINK %s
Artem Belevichf8144ab2015-08-27 18:10:41 +000086
Justin Lebar388579f2016-01-13 01:24:35 +000087// Verify that device-side results are passed to the correct tool when
88// -fno-integrated-as is used.
Artem Belevichf8144ab2015-08-27 18:10:41 +000089// RUN: %clang -### -target x86_64-linux-gnu -fno-integrated-as -c %s 2>&1 \
Justin Lebar388579f2016-01-13 01:24:35 +000090// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
91// RUN: -check-prefix HOST -check-prefix HOST-NOSAVE \
92// RUN: -check-prefix HOST-AS -check-prefix NOLINK %s
Artem Belevichf8144ab2015-08-27 18:10:41 +000093
Artem Belevicha424e882016-12-09 22:59:17 +000094// Verify that --[no-]cuda-gpu-arch arguments are handled correctly.
95// a) --no-cuda-gpu-arch=X negates preceeding --cuda-gpu-arch=X
96// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
97// RUN: --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30 \
98// RUN: --no-cuda-gpu-arch=sm_35 \
99// RUN: -c %s 2>&1 \
100// RUN: | FileCheck -check-prefixes NOARCH-SM20,ARCH-SM30,NOARCH-SM35 %s
101
102// b) --no-cuda-gpu-arch=X negates more than one preceeding --cuda-gpu-arch=X
103// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
104// RUN: --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30 \
105// RUN: --no-cuda-gpu-arch=sm_35 \
106// RUN: -c %s 2>&1 \
107// RUN: | FileCheck -check-prefixes NOARCH-SM20,ARCH-SM30,NOARCH-SM35 %s
108
109// c) if --no-cuda-gpu-arch=X negates all preceeding --cuda-gpu-arch=X
110// we default to sm_20 -- same as if no --cuda-gpu-arch were passed.
111// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
112// RUN: --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30 \
113// RUN: --no-cuda-gpu-arch=sm_35 --no-cuda-gpu-arch=sm_30 \
114// RUN: -c %s 2>&1 \
115// RUN: | FileCheck -check-prefixes ARCH-SM20,NOARCH-SM30,NOARCH-SM35 %s
116
117// d) --no-cuda-gpu-arch=X is a no-op if there's no preceding --cuda-gpu-arch=X
118// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
119// RUN: --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30\
120// RUN: --no-cuda-gpu-arch=sm_50 \
121// RUN: -c %s 2>&1 \
122// RUN: | FileCheck -check-prefixes NOARCH-SM20,ARCH-SM30,ARCH-SM35 %s
123
124// e) --no-cuda-gpu-arch=X does not affect following --cuda-gpu-arch=X
125// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
126// RUN: --no-cuda-gpu-arch=sm_35 --no-cuda-gpu-arch=sm_30 \
127// RUN: --cuda-gpu-arch=sm_35 --cuda-gpu-arch=sm_30 \
128// RUN: -c %s 2>&1 \
129// RUN: | FileCheck -check-prefixes NOARCH-SM20,ARCH-SM30,ARCH-SM35 %s
130
131// f) --no-cuda-gpu-arch=all negates all preceding --cuda-gpu-arch=X
132// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
133// RUN: --cuda-gpu-arch=sm_20 --cuda-gpu-arch=sm_30 \
134// RUN: --no-cuda-gpu-arch=all \
135// RUN: --cuda-gpu-arch=sm_35 \
136// RUN: -c %s 2>&1 \
137// RUN: | FileCheck -check-prefixes NOARCH-SM20,NOARCH-SM30,ARCH-SM35 %s
138
139// g) There's no --cuda-gpu-arch=all
140// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
141// RUN: --cuda-gpu-arch=all \
142// RUN: -c %s 2>&1 \
143// RUN: | FileCheck -check-prefix ARCHALLERROR %s
144
145// ARCH-SM20: "-cc1"{{.*}}"-target-cpu" "sm_20"
146// NOARCH-SM20-NOT: "-cc1"{{.*}}"-target-cpu" "sm_20"
147// ARCH-SM30: "-cc1"{{.*}}"-target-cpu" "sm_30"
148// NOARCH-SM30-NOT: "-cc1"{{.*}}"-target-cpu" "sm_30"
149// ARCH-SM35: "-cc1"{{.*}}"-target-cpu" "sm_35"
150// NOARCH-SM35-NOT: "-cc1"{{.*}}"-target-cpu" "sm_35"
151// ARCHALLERROR: error: Unsupported CUDA gpu architecture: all
152
Justin Lebar388579f2016-01-13 01:24:35 +0000153// Match device-side preprocessor and compiler phases with -save-temps.
154// DEVICE-SAVE: "-cc1" "-triple" "nvptx64-nvidia-cuda"
155// DEVICE-SAVE-SAME: "-aux-triple" "x86_64--linux-gnu"
156// DEVICE-SAVE-SAME: "-fcuda-is-device"
157// DEVICE-SAVE-SAME: "-x" "cuda"
Artem Belevich5e2a3ec2015-11-17 22:28:40 +0000158
Justin Lebar388579f2016-01-13 01:24:35 +0000159// DEVICE-SAVE: "-cc1" "-triple" "nvptx64-nvidia-cuda"
160// DEVICE-SAVE-SAME: "-aux-triple" "x86_64--linux-gnu"
161// DEVICE-SAVE-SAME: "-fcuda-is-device"
162// DEVICE-SAVE-SAME: "-x" "cuda-cpp-output"
Artem Belevich5e2a3ec2015-11-17 22:28:40 +0000163
Justin Lebar388579f2016-01-13 01:24:35 +0000164// Match the job that produces PTX assembly.
165// DEVICE: "-cc1" "-triple" "nvptx64-nvidia-cuda"
166// DEVICE-NOSAVE-SAME: "-aux-triple" "x86_64--linux-gnu"
167// DEVICE-SAME: "-fcuda-is-device"
Artem Belevicha424e882016-12-09 22:59:17 +0000168// DEVICE-SM30-SAME: "-target-cpu" "sm_30"
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000169// DEVICE-SAME: "-o" "[[PTXFILE:[^"]*]]"
Justin Lebar388579f2016-01-13 01:24:35 +0000170// DEVICE-NOSAVE-SAME: "-x" "cuda"
171// DEVICE-SAVE-SAME: "-x" "ir"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000172
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000173// Match the call to ptxas (which assembles PTX to SASS).
174// DEVICE:ptxas
Artem Belevicha424e882016-12-09 22:59:17 +0000175// DEVICE-SM30-DAG: "--gpu-name" "sm_30"
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000176// DEVICE-DAG: "--output-file" "[[CUBINFILE:[^"]*]]"
177// DEVICE-DAG: "[[PTXFILE]]"
178
Justin Lebar388579f2016-01-13 01:24:35 +0000179// Match another device-side compilation.
180// DEVICE2: "-cc1" "-triple" "nvptx64-nvidia-cuda"
181// DEVICE2-SAME: "-aux-triple" "x86_64--linux-gnu"
182// DEVICE2-SAME: "-fcuda-is-device"
Artem Belevicha424e882016-12-09 22:59:17 +0000183// DEVICE2-SM35-SAME: "-target-cpu" "sm_35"
Jonas Hahnfelde7681322018-02-28 17:53:46 +0000184// DEVICE2-SAME: "-o" "[[PTXFILE2:[^"]*]]"
Justin Lebar388579f2016-01-13 01:24:35 +0000185// DEVICE2-SAME: "-x" "cuda"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000186
Jonas Hahnfelde7681322018-02-28 17:53:46 +0000187// Match another call to ptxas.
188// DEVICE2: ptxas
189// DEVICE2-SM35-DAG: "--gpu-name" "sm_35"
190// DEVICE2-DAG: "--output-file" "[[CUBINFILE2:[^"]*]]"
191// DEVICE2-DAG: "[[PTXFILE2]]"
192
Justin Lebar388579f2016-01-13 01:24:35 +0000193// Match no device-side compilation.
194// NODEVICE-NOT: "-cc1" "-triple" "nvptx64-nvidia-cuda"
Paul Robinson4abe94f2016-02-10 02:08:24 +0000195// NODEVICE-NOT: "-fcuda-is-device"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000196
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000197// INCLUDES-DEVICE:fatbinary
198// INCLUDES-DEVICE-DAG: "--create" "[[FATBINARY:[^"]*]]"
199// INCLUDES-DEVICE-DAG: "--image=profile=sm_{{[0-9]+}},file=[[CUBINFILE]]"
200// INCLUDES-DEVICE-DAG: "--image=profile=compute_{{[0-9]+}},file=[[PTXFILE]]"
Jonas Hahnfelde7681322018-02-28 17:53:46 +0000201// INCLUDES-DEVICE2-DAG: "--image=profile=sm_{{[0-9]+}},file=[[CUBINFILE2]]"
202// INCLUDES-DEVICE2-DAG: "--image=profile=compute_{{[0-9]+}},file=[[PTXFILE2]]"
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000203
Justin Lebar388579f2016-01-13 01:24:35 +0000204// Match host-side preprocessor job with -save-temps.
205// HOST-SAVE: "-cc1" "-triple" "x86_64--linux-gnu"
206// HOST-SAVE-SAME: "-aux-triple" "nvptx64-nvidia-cuda"
Paul Robinson4abe94f2016-02-10 02:08:24 +0000207// HOST-SAVE-NOT: "-fcuda-is-device"
Justin Lebar388579f2016-01-13 01:24:35 +0000208// HOST-SAVE-SAME: "-x" "cuda"
Artem Belevichf8144ab2015-08-27 18:10:41 +0000209
Justin Lebar388579f2016-01-13 01:24:35 +0000210// Match host-side compilation.
211// HOST: "-cc1" "-triple" "x86_64--linux-gnu"
212// HOST-SAME: "-aux-triple" "nvptx64-nvidia-cuda"
Paul Robinson4abe94f2016-02-10 02:08:24 +0000213// HOST-NOT: "-fcuda-is-device"
Justin Lebar388579f2016-01-13 01:24:35 +0000214// HOST-SAME: "-o" "[[HOSTOUTPUT:[^"]*]]"
215// HOST-NOSAVE-SAME: "-x" "cuda"
216// HOST-SAVE-SAME: "-x" "cuda-cpp-output"
Jonas Hahnfelde7681322018-02-28 17:53:46 +0000217// There is only one GPU binary after combining it with fatbinary!
218// INCLUDES-DEVICE2-NOT: "-fcuda-include-gpubinary"
Justin Lebar21e5d4f2016-01-14 21:41:27 +0000219// INCLUDES-DEVICE-SAME: "-fcuda-include-gpubinary" "[[FATBINARY]]"
Jonas Hahnfelde7681322018-02-28 17:53:46 +0000220// There is only one GPU binary after combining it with fatbinary.
221// INCLUDES-DEVICE2-NOT: "-fcuda-include-gpubinary"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000222
Justin Lebar388579f2016-01-13 01:24:35 +0000223// Match external assembler that uses compilation output.
224// HOST-AS: "-o" "{{.*}}.o" "[[HOSTOUTPUT]]"
Artem Belevichf8144ab2015-08-27 18:10:41 +0000225
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000226// Match no GPU code inclusion.
Justin Lebar388579f2016-01-13 01:24:35 +0000227// NOINCLUDES-DEVICE-NOT: "-fcuda-include-gpubinary"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000228
Justin Lebar388579f2016-01-13 01:24:35 +0000229// Match no host compilation.
230// NOHOST-NOT: "-cc1" "-triple"
Paul Robinson4abe94f2016-02-10 02:08:24 +0000231// NOHOST-NOT: "-x" "cuda"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000232
Justin Lebar388579f2016-01-13 01:24:35 +0000233// Match linker.
234// LINK: "{{.*}}{{ld|link}}{{(.exe)?}}"
235// LINK-SAME: "[[HOSTOUTPUT]]"
Artem Belevich0ff05cd2015-07-13 23:27:56 +0000236
Justin Lebar388579f2016-01-13 01:24:35 +0000237// Match no linker.
238// NOLINK-NOT: "{{.*}}{{ld|link}}{{(.exe)?}}"