[CUDA] Driver changes to support CUDA compilation on MacOS.
Summary:
Compiling CUDA device code requires us to know the host toolchain,
because CUDA device-side compiles pull in e.g. host headers.
When we only supported Linux compilation, this worked because
CudaToolChain, which is responsible for device-side CUDA compilation,
inherited from the Linux toolchain. But in order to support MacOS,
CudaToolChain needs to take a HostToolChain pointer.
Because a CUDA toolchain now requires a host TC, we no longer will
create a CUDA toolchain from Driver::getToolChain -- you have to go
through CreateOffloadingDeviceToolChains. I am *pretty* sure this is
correct, and that previously any attempt to create a CUDA toolchain
through getToolChain() would eventually have resulted in us throwing
"error: unsupported use of NVPTX for host compilation".
In any case hacking getToolChain to create a CUDA+host toolchain would
be wrong, because a Driver can be reused for multiple compilations,
potentially with different host TCs, and getToolChain will cache the
result, causing us to potentially use a stale host TC.
So that's the main change in this patch.
In addition, we have to pull CudaInstallationDetector out of Generic_GCC
and into a top-level class. It's now used by the Generic_GCC and MachO
toolchains.
Reviewers: tra
Subscribers: rryan, hfinkel, sfantao
Differential Revision: https://reviews.llvm.org/D26774
llvm-svn: 287285
2016-11-18 08:41:22 +08:00
|
|
|
// Tests that ptxas and fatbinary are invoked correctly during CUDA
|
|
|
|
// compilation.
|
2016-01-15 05:41:27 +08:00
|
|
|
//
|
|
|
|
// REQUIRES: clang-driver
|
|
|
|
// REQUIRES: x86-registered-target
|
|
|
|
// REQUIRES: nvptx-registered-target
|
|
|
|
|
2016-01-20 03:52:21 +08:00
|
|
|
// Regular compiles with -O{0,1,2,3,4,fast}. -O4 and -Ofast map to ptxas O3.
|
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -O0 -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT0 %s
|
2016-01-20 03:52:21 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -O1 -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT1 %s
|
2016-01-15 05:41:27 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -O2 -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT2 %s
|
2016-01-20 03:52:21 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -O3 -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT3 %s
|
2016-01-20 03:52:21 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -O4 -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT3 %s
|
2016-01-20 03:52:21 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -Ofast -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT3 %s
|
2018-02-12 18:46:45 +08:00
|
|
|
// Generating relocatable device code
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -fgpu-rdc -c %s 2>&1 \
|
2018-02-12 18:46:45 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,RDC %s
|
2016-01-15 05:41:27 +08:00
|
|
|
|
2016-02-17 06:03:20 +08:00
|
|
|
// With debugging enabled, ptxas should be run with with no ptxas optimizations.
|
2018-04-19 00:31:09 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu --cuda-noopt-device-debug -O2 -g -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,DBG %s
|
2016-02-17 06:03:20 +08:00
|
|
|
|
2016-04-19 10:27:11 +08:00
|
|
|
// --no-cuda-noopt-device-debug overrides --cuda-noopt-device-debug.
|
2017-05-24 22:57:17 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu --cuda-noopt-device-debug \
|
|
|
|
// RUN: --no-cuda-noopt-device-debug -O2 -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT2 %s
|
2016-04-19 10:27:11 +08:00
|
|
|
|
2016-01-15 05:41:27 +08:00
|
|
|
// Regular compile without -O. This should result in us passing -O0 to ptxas.
|
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT0 %s
|
2016-01-15 05:41:27 +08:00
|
|
|
|
2016-01-20 03:52:21 +08:00
|
|
|
// Regular compiles with -Os and -Oz. For lack of a better option, we map
|
|
|
|
// these to ptxas -O3.
|
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -Os -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT2 %s
|
2016-01-20 03:52:21 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -Oz -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT2 %s
|
2016-01-20 03:52:21 +08:00
|
|
|
|
2016-01-15 05:41:27 +08:00
|
|
|
// Regular compile targeting sm_35.
|
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_35 -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM35 %s
|
2018-02-12 18:46:45 +08:00
|
|
|
// Separate compilation targeting sm_35.
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_35 -fgpu-rdc -c %s 2>&1 \
|
2018-02-12 18:46:45 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM35,RDC %s
|
2016-01-15 05:41:27 +08:00
|
|
|
|
|
|
|
// 32-bit compile.
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: %clang -### -target i386-linux-gnu -c %s 2>&1 \
|
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH32,SM20 %s
|
2018-02-12 18:46:45 +08:00
|
|
|
// 32-bit compile when generating relocatable device code.
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: %clang -### -target i386-linux-gnu -fgpu-rdc -c %s 2>&1 \
|
2018-02-12 18:46:45 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH32,SM20,RDC %s
|
2016-01-15 05:41:27 +08:00
|
|
|
|
|
|
|
// Compile with -fintegrated-as. This should still cause us to invoke ptxas.
|
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -fintegrated-as -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT0 %s
|
2018-02-12 18:46:45 +08:00
|
|
|
// Check that we still pass -c when generating relocatable device code.
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -fintegrated-as -fgpu-rdc -c %s 2>&1 \
|
2018-02-12 18:46:45 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,RDC %s
|
2016-01-15 05:41:27 +08:00
|
|
|
|
|
|
|
// Check -Xcuda-ptxas and -Xcuda-fatbinary
|
|
|
|
// RUN: %clang -### -target x86_64-linux-gnu -c -Xcuda-ptxas -foo1 \
|
|
|
|
// RUN: -Xcuda-fatbinary -bar1 -Xcuda-ptxas -foo2 -Xcuda-fatbinary -bar2 %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,SM20,PTXAS-EXTRA,FATBINARY-EXTRA %s
|
2016-01-15 05:41:27 +08:00
|
|
|
|
[CUDA] Driver changes to support CUDA compilation on MacOS.
Summary:
Compiling CUDA device code requires us to know the host toolchain,
because CUDA device-side compiles pull in e.g. host headers.
When we only supported Linux compilation, this worked because
CudaToolChain, which is responsible for device-side CUDA compilation,
inherited from the Linux toolchain. But in order to support MacOS,
CudaToolChain needs to take a HostToolChain pointer.
Because a CUDA toolchain now requires a host TC, we no longer will
create a CUDA toolchain from Driver::getToolChain -- you have to go
through CreateOffloadingDeviceToolChains. I am *pretty* sure this is
correct, and that previously any attempt to create a CUDA toolchain
through getToolChain() would eventually have resulted in us throwing
"error: unsupported use of NVPTX for host compilation".
In any case hacking getToolChain to create a CUDA+host toolchain would
be wrong, because a Driver can be reused for multiple compilations,
potentially with different host TCs, and getToolChain will cache the
result, causing us to potentially use a stale host TC.
So that's the main change in this patch.
In addition, we have to pull CudaInstallationDetector out of Generic_GCC
and into a top-level class. It's now used by the Generic_GCC and MachO
toolchains.
Reviewers: tra
Subscribers: rryan, hfinkel, sfantao
Differential Revision: https://reviews.llvm.org/D26774
llvm-svn: 287285
2016-11-18 08:41:22 +08:00
|
|
|
// MacOS spot-checks
|
|
|
|
// RUN: %clang -### -target x86_64-apple-macosx -O0 -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,OPT0 %s
|
[CUDA] Driver changes to support CUDA compilation on MacOS.
Summary:
Compiling CUDA device code requires us to know the host toolchain,
because CUDA device-side compiles pull in e.g. host headers.
When we only supported Linux compilation, this worked because
CudaToolChain, which is responsible for device-side CUDA compilation,
inherited from the Linux toolchain. But in order to support MacOS,
CudaToolChain needs to take a HostToolChain pointer.
Because a CUDA toolchain now requires a host TC, we no longer will
create a CUDA toolchain from Driver::getToolChain -- you have to go
through CreateOffloadingDeviceToolChains. I am *pretty* sure this is
correct, and that previously any attempt to create a CUDA toolchain
through getToolChain() would eventually have resulted in us throwing
"error: unsupported use of NVPTX for host compilation".
In any case hacking getToolChain to create a CUDA+host toolchain would
be wrong, because a Driver can be reused for multiple compilations,
potentially with different host TCs, and getToolChain will cache the
result, causing us to potentially use a stale host TC.
So that's the main change in this patch.
In addition, we have to pull CudaInstallationDetector out of Generic_GCC
and into a top-level class. It's now used by the Generic_GCC and MachO
toolchains.
Reviewers: tra
Subscribers: rryan, hfinkel, sfantao
Differential Revision: https://reviews.llvm.org/D26774
llvm-svn: 287285
2016-11-18 08:41:22 +08:00
|
|
|
// RUN: %clang -### -target x86_64-apple-macosx --cuda-gpu-arch=sm_35 -c %s 2>&1 \
|
2018-02-12 18:46:34 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM35 %s
|
|
|
|
// RUN: %clang -### -target i386-apple-macosx -c %s 2>&1 \
|
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH32,SM20 %s
|
[CUDA] Driver changes to support CUDA compilation on MacOS.
Summary:
Compiling CUDA device code requires us to know the host toolchain,
because CUDA device-side compiles pull in e.g. host headers.
When we only supported Linux compilation, this worked because
CudaToolChain, which is responsible for device-side CUDA compilation,
inherited from the Linux toolchain. But in order to support MacOS,
CudaToolChain needs to take a HostToolChain pointer.
Because a CUDA toolchain now requires a host TC, we no longer will
create a CUDA toolchain from Driver::getToolChain -- you have to go
through CreateOffloadingDeviceToolChains. I am *pretty* sure this is
correct, and that previously any attempt to create a CUDA toolchain
through getToolChain() would eventually have resulted in us throwing
"error: unsupported use of NVPTX for host compilation".
In any case hacking getToolChain to create a CUDA+host toolchain would
be wrong, because a Driver can be reused for multiple compilations,
potentially with different host TCs, and getToolChain will cache the
result, causing us to potentially use a stale host TC.
So that's the main change in this patch.
In addition, we have to pull CudaInstallationDetector out of Generic_GCC
and into a top-level class. It's now used by the Generic_GCC and MachO
toolchains.
Reviewers: tra
Subscribers: rryan, hfinkel, sfantao
Differential Revision: https://reviews.llvm.org/D26774
llvm-svn: 287285
2016-11-18 08:41:22 +08:00
|
|
|
|
2018-02-12 18:46:45 +08:00
|
|
|
// Check relocatable device code generation on MacOS.
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: %clang -### -target x86_64-apple-macosx -O0 -fgpu-rdc -c %s 2>&1 \
|
2018-02-12 18:46:45 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM20,RDC %s
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: %clang -### -target x86_64-apple-macosx --cuda-gpu-arch=sm_35 -fgpu-rdc -c %s 2>&1 \
|
2018-02-12 18:46:45 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH64,SM35,RDC %s
|
2018-10-03 01:48:54 +08:00
|
|
|
// RUN: %clang -### -target i386-apple-macosx -fgpu-rdc -c %s 2>&1 \
|
2018-02-12 18:46:45 +08:00
|
|
|
// RUN: | FileCheck -check-prefixes=CHECK,ARCH32,SM20,RDC %s
|
|
|
|
|
2017-08-08 04:19:23 +08:00
|
|
|
// Check that CLANG forwards the -v flag to PTXAS.
|
|
|
|
// RUN: %clang -### -save-temps -no-canonical-prefixes -v %s 2>&1 \
|
|
|
|
// RUN: | FileCheck -check-prefix=CHK-PTXAS-VERBOSE %s
|
|
|
|
|
2016-01-15 05:41:27 +08:00
|
|
|
// Match clang job that produces PTX assembly.
|
2018-02-12 18:46:34 +08:00
|
|
|
// CHECK: "-cc1"
|
|
|
|
// ARCH64-SAME: "-triple" "nvptx64-nvidia-cuda"
|
|
|
|
// ARCH32-SAME: "-triple" "nvptx-nvidia-cuda"
|
2018-10-03 01:48:54 +08:00
|
|
|
// RDC-SAME: "-fgpu-rdc"
|
|
|
|
// CHECK-NOT: "-fgpu-rdc"
|
2018-02-12 18:46:34 +08:00
|
|
|
// SM20-SAME: "-target-cpu" "sm_20"
|
|
|
|
// SM35-SAME: "-target-cpu" "sm_35"
|
|
|
|
// SM20-SAME: "-o" "[[PTXFILE:[^"]*]]"
|
|
|
|
// SM35-SAME: "-o" "[[PTXFILE:[^"]*]]"
|
2016-01-15 05:41:27 +08:00
|
|
|
|
|
|
|
// Match the call to ptxas (which assembles PTX to SASS).
|
2018-02-12 18:46:34 +08:00
|
|
|
// CHECK: ptxas
|
|
|
|
// ARCH64-SAME: "-m64"
|
|
|
|
// ARCH32-SAME: "-m32"
|
|
|
|
// OPT0-SAME: "-O0"
|
2016-02-17 06:03:20 +08:00
|
|
|
// OPT0-NOT: "-g"
|
2018-02-12 18:46:34 +08:00
|
|
|
// OPT1-SAME: "-O1"
|
2016-02-17 06:03:20 +08:00
|
|
|
// OPT1-NOT: "-g"
|
2018-02-12 18:46:34 +08:00
|
|
|
// OPT2-SAME: "-O2"
|
2016-02-17 06:03:20 +08:00
|
|
|
// OPT2-NOT: "-g"
|
2018-02-12 18:46:34 +08:00
|
|
|
// OPT3-SAME: "-O3"
|
2016-02-17 06:03:20 +08:00
|
|
|
// OPT3-NOT: "-g"
|
2018-02-12 18:46:34 +08:00
|
|
|
// DBG-SAME: "-g" "--dont-merge-basicblocks" "--return-at-end"
|
|
|
|
// SM20-SAME: "--gpu-name" "sm_20"
|
|
|
|
// SM35-SAME: "--gpu-name" "sm_35"
|
|
|
|
// SM20-SAME: "--output-file" "[[CUBINFILE:[^"]*]]"
|
|
|
|
// SM35-SAME: "--output-file" "[[CUBINFILE:[^"]*]]"
|
2016-01-15 05:41:27 +08:00
|
|
|
// CHECK-SAME: "[[PTXFILE]]"
|
2018-02-12 18:46:34 +08:00
|
|
|
// PTXAS-EXTRA-SAME: "-foo1"
|
|
|
|
// PTXAS-EXTRA-SAME: "-foo2"
|
2018-02-12 18:46:45 +08:00
|
|
|
// RDC-SAME: "-c"
|
|
|
|
// CHECK-NOT: "-c"
|
2016-01-15 05:41:27 +08:00
|
|
|
|
|
|
|
// Match the call to fatbinary (which combines all our PTX and SASS into one
|
|
|
|
// blob).
|
2018-02-12 18:46:34 +08:00
|
|
|
// CHECK: fatbinary
|
|
|
|
// CHECK-SAME-DAG: "--cuda"
|
|
|
|
// ARCH64-SAME-DAG: "-64"
|
|
|
|
// ARCH32-SAME-DAG: "-32"
|
2016-01-15 05:41:27 +08:00
|
|
|
// CHECK-DAG: "--create" "[[FATBINARY:[^"]*]]"
|
2018-02-12 18:46:34 +08:00
|
|
|
// SM20-SAME-DAG: "--image=profile=compute_20,file=[[PTXFILE]]"
|
|
|
|
// SM35-SAME-DAG: "--image=profile=compute_35,file=[[PTXFILE]]"
|
|
|
|
// SM20-SAME-DAG: "--image=profile=sm_20,file=[[CUBINFILE]]"
|
|
|
|
// SM35-SAME-DAG: "--image=profile=sm_35,file=[[CUBINFILE]]"
|
|
|
|
// FATBINARY-EXTRA-SAME: "-bar1"
|
2016-01-15 05:41:27 +08:00
|
|
|
// FATBINARY-EXTRA-SAME: "-bar2"
|
|
|
|
|
|
|
|
// Match the clang job for host compilation.
|
2018-02-12 18:46:34 +08:00
|
|
|
// CHECK: "-cc1"
|
|
|
|
// ARCH64-SAME: "-triple" "x86_64-
|
|
|
|
// ARCH32-SAME: "-triple" "i386-
|
2016-01-15 05:41:27 +08:00
|
|
|
// CHECK-SAME: "-fcuda-include-gpubinary" "[[FATBINARY]]"
|
2018-10-03 01:48:54 +08:00
|
|
|
// RDC-SAME: "-fgpu-rdc"
|
|
|
|
// CHECK-NOT: "-fgpu-rdc"
|
2017-08-08 04:19:23 +08:00
|
|
|
|
2018-02-12 18:46:34 +08:00
|
|
|
// CHK-PTXAS-VERBOSE: ptxas{{.*}}" "-v"
|