Justin Lebar | 66c4fd7 | 2016-11-18 00:41:22 +0000 | [diff] [blame] | 1 | // Tests that ptxas and fatbinary are invoked correctly during CUDA |
| 2 | // compilation. |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 3 | // |
| 4 | // REQUIRES: clang-driver |
| 5 | // REQUIRES: x86-registered-target |
| 6 | // REQUIRES: nvptx-registered-target |
| 7 | |
Justin Lebar | 2836dcd | 2016-01-19 19:52:21 +0000 | [diff] [blame] | 8 | // Regular compiles with -O{0,1,2,3,4,fast}. -O4 and -Ofast map to ptxas O3. |
| 9 | // RUN: %clang -### -target x86_64-linux-gnu -O0 -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 10 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT0 %s |
Justin Lebar | 2836dcd | 2016-01-19 19:52:21 +0000 | [diff] [blame] | 11 | // RUN: %clang -### -target x86_64-linux-gnu -O1 -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 12 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT1 %s |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 13 | // RUN: %clang -### -target x86_64-linux-gnu -O2 -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 14 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT2 %s |
Justin Lebar | 2836dcd | 2016-01-19 19:52:21 +0000 | [diff] [blame] | 15 | // RUN: %clang -### -target x86_64-linux-gnu -O3 -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 16 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT3 %s |
Justin Lebar | 2836dcd | 2016-01-19 19:52:21 +0000 | [diff] [blame] | 17 | // RUN: %clang -### -target x86_64-linux-gnu -O4 -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 18 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT3 %s |
Justin Lebar | 2836dcd | 2016-01-19 19:52:21 +0000 | [diff] [blame] | 19 | // RUN: %clang -### -target x86_64-linux-gnu -Ofast -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 20 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT3 %s |
Jonas Hahnfeld | 5379c6d | 2018-02-12 10:46:45 +0000 | [diff] [blame] | 21 | // Generating relocatable device code |
| 22 | // RUN: %clang -### -target x86_64-linux-gnu -fcuda-rdc -c %s 2>&1 \ |
| 23 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,RDC %s |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 24 | |
Artem Belevich | 0a0e54c | 2016-02-16 22:03:20 +0000 | [diff] [blame] | 25 | // With debugging enabled, ptxas should be run with with no ptxas optimizations. |
| 26 | // RUN: %clang -### -target x86_64-linux-gnu --cuda-noopt-device-debug -O2 -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 27 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,DBG %s |
Artem Belevich | 0a0e54c | 2016-02-16 22:03:20 +0000 | [diff] [blame] | 28 | |
Justin Lebar | b41f33c | 2016-04-19 02:27:11 +0000 | [diff] [blame] | 29 | // --no-cuda-noopt-device-debug overrides --cuda-noopt-device-debug. |
Serge Pavlov | b43573b | 2017-05-24 14:57:17 +0000 | [diff] [blame] | 30 | // RUN: %clang -### -target x86_64-linux-gnu --cuda-noopt-device-debug \ |
| 31 | // RUN: --no-cuda-noopt-device-debug -O2 -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 32 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT2 %s |
Justin Lebar | b41f33c | 2016-04-19 02:27:11 +0000 | [diff] [blame] | 33 | |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 34 | // Regular compile without -O. This should result in us passing -O0 to ptxas. |
| 35 | // RUN: %clang -### -target x86_64-linux-gnu -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 36 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT0 %s |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 37 | |
Justin Lebar | 2836dcd | 2016-01-19 19:52:21 +0000 | [diff] [blame] | 38 | // Regular compiles with -Os and -Oz. For lack of a better option, we map |
| 39 | // these to ptxas -O3. |
| 40 | // RUN: %clang -### -target x86_64-linux-gnu -Os -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 41 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT2 %s |
Justin Lebar | 2836dcd | 2016-01-19 19:52:21 +0000 | [diff] [blame] | 42 | // RUN: %clang -### -target x86_64-linux-gnu -Oz -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 43 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT2 %s |
Justin Lebar | 2836dcd | 2016-01-19 19:52:21 +0000 | [diff] [blame] | 44 | |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 45 | // Regular compile targeting sm_35. |
| 46 | // RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_35 -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 47 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM35 %s |
Jonas Hahnfeld | 5379c6d | 2018-02-12 10:46:45 +0000 | [diff] [blame] | 48 | // Separate compilation targeting sm_35. |
| 49 | // RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_35 -fcuda-rdc -c %s 2>&1 \ |
| 50 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM35,RDC %s |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 51 | |
| 52 | // 32-bit compile. |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 53 | // RUN: %clang -### -target i386-linux-gnu -c %s 2>&1 \ |
| 54 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH32,SM20 %s |
Jonas Hahnfeld | 5379c6d | 2018-02-12 10:46:45 +0000 | [diff] [blame] | 55 | // 32-bit compile when generating relocatable device code. |
| 56 | // RUN: %clang -### -target i386-linux-gnu -fcuda-rdc -c %s 2>&1 \ |
| 57 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH32,SM20,RDC %s |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 58 | |
| 59 | // Compile with -fintegrated-as. This should still cause us to invoke ptxas. |
| 60 | // RUN: %clang -### -target x86_64-linux-gnu -fintegrated-as -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 61 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT0 %s |
Jonas Hahnfeld | 5379c6d | 2018-02-12 10:46:45 +0000 | [diff] [blame] | 62 | // Check that we still pass -c when generating relocatable device code. |
| 63 | // RUN: %clang -### -target x86_64-linux-gnu -fintegrated-as -fcuda-rdc -c %s 2>&1 \ |
| 64 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,RDC %s |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 65 | |
| 66 | // Check -Xcuda-ptxas and -Xcuda-fatbinary |
| 67 | // RUN: %clang -### -target x86_64-linux-gnu -c -Xcuda-ptxas -foo1 \ |
| 68 | // RUN: -Xcuda-fatbinary -bar1 -Xcuda-ptxas -foo2 -Xcuda-fatbinary -bar2 %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 69 | // RUN: | FileCheck -check-prefixes=CHECK,SM20,PTXAS-EXTRA,FATBINARY-EXTRA %s |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 70 | |
Justin Lebar | 66c4fd7 | 2016-11-18 00:41:22 +0000 | [diff] [blame] | 71 | // MacOS spot-checks |
| 72 | // RUN: %clang -### -target x86_64-apple-macosx -O0 -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 73 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT0 %s |
Justin Lebar | 66c4fd7 | 2016-11-18 00:41:22 +0000 | [diff] [blame] | 74 | // RUN: %clang -### -target x86_64-apple-macosx --cuda-gpu-arch=sm_35 -c %s 2>&1 \ |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 75 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM35 %s |
| 76 | // RUN: %clang -### -target i386-apple-macosx -c %s 2>&1 \ |
| 77 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH32,SM20 %s |
Justin Lebar | 66c4fd7 | 2016-11-18 00:41:22 +0000 | [diff] [blame] | 78 | |
Jonas Hahnfeld | 5379c6d | 2018-02-12 10:46:45 +0000 | [diff] [blame] | 79 | // Check relocatable device code generation on MacOS. |
| 80 | // RUN: %clang -### -target x86_64-apple-macosx -O0 -fcuda-rdc -c %s 2>&1 \ |
| 81 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,RDC %s |
| 82 | // RUN: %clang -### -target x86_64-apple-macosx --cuda-gpu-arch=sm_35 -fcuda-rdc -c %s 2>&1 \ |
| 83 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM35,RDC %s |
| 84 | // RUN: %clang -### -target i386-apple-macosx -fcuda-rdc -c %s 2>&1 \ |
| 85 | // RUN: | FileCheck -check-prefixes=CHECK,ARCH32,SM20,RDC %s |
| 86 | |
Gheorghe-Teodor Bercea | 53431bc | 2017-08-07 20:19:23 +0000 | [diff] [blame] | 87 | // Check that CLANG forwards the -v flag to PTXAS. |
| 88 | // RUN: %clang -### -save-temps -no-canonical-prefixes -v %s 2>&1 \ |
| 89 | // RUN: | FileCheck -check-prefix=CHK-PTXAS-VERBOSE %s |
| 90 | |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 91 | // Match clang job that produces PTX assembly. |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 92 | // CHECK: "-cc1" |
| 93 | // ARCH64-SAME: "-triple" "nvptx64-nvidia-cuda" |
| 94 | // ARCH32-SAME: "-triple" "nvptx-nvidia-cuda" |
| 95 | // SM20-SAME: "-target-cpu" "sm_20" |
| 96 | // SM35-SAME: "-target-cpu" "sm_35" |
| 97 | // SM20-SAME: "-o" "[[PTXFILE:[^"]*]]" |
| 98 | // SM35-SAME: "-o" "[[PTXFILE:[^"]*]]" |
Jonas Hahnfeld | 5379c6d | 2018-02-12 10:46:45 +0000 | [diff] [blame] | 99 | // RDC-SAME: "-fcuda-rdc" |
| 100 | // CHECK-NOT: "-fcuda-rdc" |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 101 | |
| 102 | // Match the call to ptxas (which assembles PTX to SASS). |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 103 | // CHECK: ptxas |
| 104 | // ARCH64-SAME: "-m64" |
| 105 | // ARCH32-SAME: "-m32" |
| 106 | // OPT0-SAME: "-O0" |
Artem Belevich | 0a0e54c | 2016-02-16 22:03:20 +0000 | [diff] [blame] | 107 | // OPT0-NOT: "-g" |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 108 | // OPT1-SAME: "-O1" |
Artem Belevich | 0a0e54c | 2016-02-16 22:03:20 +0000 | [diff] [blame] | 109 | // OPT1-NOT: "-g" |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 110 | // OPT2-SAME: "-O2" |
Artem Belevich | 0a0e54c | 2016-02-16 22:03:20 +0000 | [diff] [blame] | 111 | // OPT2-NOT: "-g" |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 112 | // OPT3-SAME: "-O3" |
Artem Belevich | 0a0e54c | 2016-02-16 22:03:20 +0000 | [diff] [blame] | 113 | // OPT3-NOT: "-g" |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 114 | // DBG-SAME: "-g" "--dont-merge-basicblocks" "--return-at-end" |
| 115 | // SM20-SAME: "--gpu-name" "sm_20" |
| 116 | // SM35-SAME: "--gpu-name" "sm_35" |
| 117 | // SM20-SAME: "--output-file" "[[CUBINFILE:[^"]*]]" |
| 118 | // SM35-SAME: "--output-file" "[[CUBINFILE:[^"]*]]" |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 119 | // CHECK-SAME: "[[PTXFILE]]" |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 120 | // PTXAS-EXTRA-SAME: "-foo1" |
| 121 | // PTXAS-EXTRA-SAME: "-foo2" |
Jonas Hahnfeld | 5379c6d | 2018-02-12 10:46:45 +0000 | [diff] [blame] | 122 | // RDC-SAME: "-c" |
| 123 | // CHECK-NOT: "-c" |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 124 | |
| 125 | // Match the call to fatbinary (which combines all our PTX and SASS into one |
| 126 | // blob). |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 127 | // CHECK: fatbinary |
| 128 | // CHECK-SAME-DAG: "--cuda" |
| 129 | // ARCH64-SAME-DAG: "-64" |
| 130 | // ARCH32-SAME-DAG: "-32" |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 131 | // CHECK-DAG: "--create" "[[FATBINARY:[^"]*]]" |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 132 | // SM20-SAME-DAG: "--image=profile=compute_20,file=[[PTXFILE]]" |
| 133 | // SM35-SAME-DAG: "--image=profile=compute_35,file=[[PTXFILE]]" |
| 134 | // SM20-SAME-DAG: "--image=profile=sm_20,file=[[CUBINFILE]]" |
| 135 | // SM35-SAME-DAG: "--image=profile=sm_35,file=[[CUBINFILE]]" |
| 136 | // FATBINARY-EXTRA-SAME: "-bar1" |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 137 | // FATBINARY-EXTRA-SAME: "-bar2" |
| 138 | |
| 139 | // Match the clang job for host compilation. |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 140 | // CHECK: "-cc1" |
| 141 | // ARCH64-SAME: "-triple" "x86_64- |
| 142 | // ARCH32-SAME: "-triple" "i386- |
Justin Lebar | 21e5d4f | 2016-01-14 21:41:27 +0000 | [diff] [blame] | 143 | // CHECK-SAME: "-fcuda-include-gpubinary" "[[FATBINARY]]" |
Jonas Hahnfeld | 5379c6d | 2018-02-12 10:46:45 +0000 | [diff] [blame] | 144 | // RDC-SAME: "-fcuda-rdc" |
| 145 | // CHECK-NOT: "-fcuda-rdc" |
Gheorghe-Teodor Bercea | 53431bc | 2017-08-07 20:19:23 +0000 | [diff] [blame] | 146 | |
Jonas Hahnfeld | 15dd8c6 | 2018-02-12 10:46:34 +0000 | [diff] [blame] | 147 | // CHK-PTXAS-VERBOSE: ptxas{{.*}}" "-v" |