Debian Codegraph @

clang/test/Driver/cuda-cross-compiling.c

raw
1 // Tests the driver when targeting the NVPTX architecture directly without a
2 // host toolchain to perform CUDA mappings.
3
4 //
5 // Test the generated phases when targeting NVPTX.
6 //
7 // RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-phases %s 2>&1 \
8 // RUN: | FileCheck -check-prefix=PHASES %s
9
10 // PHASES: 0: input, "[[INPUT:.+]]", c
11 // PHASES-NEXT: 1: preprocessor, {0}, cpp-output
12 // PHASES-NEXT: 2: compiler, {1}, ir
13 // PHASES-NEXT: 3: backend, {2}, assembler
14 // PHASES-NEXT: 4: assembler, {3}, object
15 // PHASES-NEXT: 5: linker, {4}, image
16
17 //
18 // Test the generated bindings when targeting NVPTX.
19 //
20 // RUN: %clang -target nvptx64-nvidia-cuda -ccc-print-bindings %s 2>&1 \
21 // RUN: | FileCheck -check-prefix=BINDINGS %s
22
23 // BINDINGS: "nvptx64-nvidia-cuda" - "clang", inputs: ["[[INPUT:.+]]"], output: "[[PTX:.+]].s"
24 // BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Assembler", inputs: ["[[PTX]].s"], output: "[[CUBIN:.+]].o"
25 // BINDINGS-NEXT: "nvptx64-nvidia-cuda" - "NVPTX::Linker", inputs: ["[[CUBIN]].o"], output: "a.out"
26
27 //
28 // Test the generated arguments to the CUDA binary utils when targeting NVPTX.
29 // Ensure that the '.o' files are converted to '.cubin' if produced internally.
30 //
31 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %s 2>&1 \
32 // RUN: | FileCheck -check-prefix=ARGS %s
33
34 // ARGS: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
35 // ARGS-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[CUBIN:.+]].o" "[[PTX]].s" "-c"
36 // ARGS-NEXT: clang-nvlink-wrapper{{.*}}"-o" "a.out" "-arch" "sm_61"{{.*}}"[[CUBIN]].o"
37
38 //
39 // Test the generated arguments to the CUDA binary utils when targeting NVPTX.
40 // Ensure that we emit '.o' files if compiled with '-c'
41 //
42 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -c -### %s 2>&1 \
43 // RUN: | FileCheck -check-prefix=OBJECT %s
44 // RUN: %clang -target nvptx64-nvidia-cuda -save-temps -march=sm_61 -c -### %s 2>&1 \
45 // RUN: | FileCheck -check-prefix=OBJECT %s
46
47 // OBJECT: -cc1" "-triple" "nvptx64-nvidia-cuda" "-S" {{.*}} "-target-cpu" "sm_61" "-target-feature" "+ptx{{[0-9]+}}" {{.*}} "-o" "[[PTX:.+]].s"
48 // OBJECT-NEXT: ptxas{{.*}}"-m64" "-O0" "--gpu-name" "sm_61" "--output-file" "[[OBJ:.+]].o" "[[PTX]].s" "-c"
49
50 //
51 // Test the generated arguments to the CUDA binary utils when targeting NVPTX.
52 // Ensure that we copy input '.o' files to '.cubin' files when linking.
53 //
54 // RUN: touch %t.o
55 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_61 -### %t.o 2>&1 \
56 // RUN: | FileCheck -check-prefix=LINK %s
57
58 // LINK: clang-nvlink-wrapper{{.*}}"-o" "a.out" "-arch" "sm_61"{{.*}}[[CUBIN:.+]].o
59
60 //
61 // Test to ensure that we enable handling global constructors in a freestanding
62 // Nvidia compilation.
63 //
64 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_70 %s -### 2>&1 \
65 // RUN: | FileCheck -check-prefix=LOWERING %s
66
67 // LOWERING: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-mllvm" "--nvptx-lower-global-ctor-dtor"
68
69 //
70 // Test passing arguments directly to nvlink.
71 //
72 // RUN: %clang -target nvptx64-nvidia-cuda -Wl,-v -Wl,a,b -march=sm_52 -### %s 2>&1 \
73 // RUN: | FileCheck -check-prefix=LINKER-ARGS %s
74
75 // LINKER-ARGS: clang-nvlink-wrapper{{.*}}"-v"{{.*}}"a" "b"
76
77 // Tests for handling a missing architecture.
78 //
79 // RUN: not %clang -target nvptx64-nvidia-cuda %s -### 2>&1 \
80 // RUN: | FileCheck -check-prefix=MISSING %s
81 // RUN: not %clang -target nvptx64-nvidia-cuda -march=generic %s -### 2>&1 \
82 // RUN: | FileCheck -check-prefix=MISSING %s
83
84 // MISSING: error: must pass in an explicit nvptx64 gpu architecture to 'ptxas'
85 // MISSING: error: must pass in an explicit nvptx64 gpu architecture to 'nvlink'
86
87 // RUN: %clang -target nvptx64-nvidia-cuda -flto -c %s -### 2>&1 \
88 // RUN: | FileCheck -check-prefix=GENERIC %s
89 // RUN: %clang -target nvptx64-nvidia-cuda -march=sm_52 -march=generic -flto -c %s -### 2>&1 \
90 // RUN: | FileCheck -check-prefix=GENERIC %s
91
92 // GENERIC-NOT: -cc1" "-triple" "nvptx64-nvidia-cuda" {{.*}} "-target-cpu"