r266707 - [CUDA] Add --cuda-compile-host-device, which overrides --cuda-host-only and --cuda-device-only.
Justin Lebar via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 18 19:27:08 PDT 2016
Author: jlebar
Date: Mon Apr 18 21:27:07 2016
New Revision: 266707
URL: http://llvm.org/viewvc/llvm-project?rev=266707&view=rev
Log:
[CUDA] Add --cuda-compile-host-device, which overrides --cuda-host-only and --cuda-device-only.
Summary:
This completes the flag's tristate, letting you override it at will on
the command line.
Reviewers: tra
Subscribers: cfe-commits, jhen
Differential Revision: http://reviews.llvm.org/D19248
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/test/Driver/cuda-options.cu
cfe/trunk/test/Driver/cuda-unused-arg-warning.cu
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=266707&r1=266706&r2=266707&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Apr 18 21:27:07 2016
@@ -375,11 +375,15 @@ def cxx_isystem : JoinedOrSeparate<["-"]
def c : Flag<["-"], "c">, Flags<[DriverOption]>,
HelpText<"Only run preprocess, compile, and assemble steps">;
def cuda_device_only : Flag<["--"], "cuda-device-only">,
- HelpText<"Do device-side CUDA compilation only">;
+ HelpText<"Compile CUDA code for device only">;
+def cuda_host_only : Flag<["--"], "cuda-host-only">,
+ HelpText<"Compile CUDA code for host only. Has no effect on non-CUDA "
+ "compilations.">;
+def cuda_compile_host_device : Flag<["--"], "cuda-compile-host-device">,
+ HelpText<"Compile CUDA code for both host and device (default). Has no "
+ "effect on non-CUDA compilations.">;
def cuda_gpu_arch_EQ : Joined<["--"], "cuda-gpu-arch=">, Flags<[DriverOption]>,
HelpText<"CUDA GPU architecture (e.g. sm_35). May be specified more than once.">;
-def cuda_host_only : Flag<["--"], "cuda-host-only">,
- HelpText<"Do host-side CUDA compilation only">;
def cuda_noopt_device_debug : Flag<["--"], "cuda-noopt-device-debug">,
HelpText<"Enable device-side debug info generation. Disables ptxas optimizations.">;
def cuda_path_EQ : Joined<["--"], "cuda-path=">, Group<i_Group>,
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=266707&r1=266706&r2=266707&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Mon Apr 18 21:27:07 2016
@@ -1316,11 +1316,17 @@ void Driver::BuildInputs(const ToolChain
static Action *buildCudaActions(Compilation &C, DerivedArgList &Args,
const Arg *InputArg, Action *HostAction,
ActionList &Actions) {
- Arg *PartialCompilationArg = Args.getLastArg(options::OPT_cuda_host_only,
- options::OPT_cuda_device_only);
- // Host-only compilation case.
- if (PartialCompilationArg &&
- PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only))
+ Arg *PartialCompilationArg = Args.getLastArg(
+ options::OPT_cuda_host_only, options::OPT_cuda_device_only,
+ options::OPT_cuda_compile_host_device);
+ bool CompileHostOnly =
+ PartialCompilationArg &&
+ PartialCompilationArg->getOption().matches(options::OPT_cuda_host_only);
+ bool CompileDeviceOnly =
+ PartialCompilationArg &&
+ PartialCompilationArg->getOption().matches(options::OPT_cuda_device_only);
+
+ if (CompileHostOnly)
return C.MakeAction<CudaHostAction>(HostAction, ActionList());
// Collect all cuda_gpu_arch parameters, removing duplicates.
@@ -1364,15 +1370,14 @@ static Action *buildCudaActions(Compilat
// Figure out what to do with device actions -- pass them as inputs to the
// host action or run each of them independently.
- bool DeviceOnlyCompilation = PartialCompilationArg != nullptr;
- if (PartialCompilation || DeviceOnlyCompilation) {
+ if (PartialCompilation || CompileDeviceOnly) {
// In case of partial or device-only compilation results of device actions
// are not consumed by the host action device actions have to be added to
// top-level actions list with AtTopLevel=true and run independently.
// -o is ambiguous if we have more than one top-level action.
if (Args.hasArg(options::OPT_o) &&
- (!DeviceOnlyCompilation || GpuArchList.size() > 1)) {
+ (!CompileDeviceOnly || GpuArchList.size() > 1)) {
C.getDriver().Diag(
clang::diag::err_drv_output_argument_with_multiple_files);
return nullptr;
@@ -1383,7 +1388,7 @@ static Action *buildCudaActions(Compilat
GpuArchList[I],
/* AtTopLevel */ true));
// Kill host action in case of device-only compilation.
- if (DeviceOnlyCompilation)
+ if (CompileDeviceOnly)
return nullptr;
return HostAction;
}
@@ -1647,9 +1652,10 @@ void Driver::BuildActions(Compilation &C
// Claim ignored clang-cl options.
Args.ClaimAllArgs(options::OPT_cl_ignored_Group);
- // Claim --cuda-host-only arg which may be passed to non-CUDA
- // compilations and should not trigger warnings there.
+ // Claim --cuda-host-only and --cuda-compile-host-device, which may be passed
+ // to non-CUDA compilations and should not trigger warnings there.
Args.ClaimAllArgs(options::OPT_cuda_host_only);
+ Args.ClaimAllArgs(options::OPT_cuda_compile_host_device);
}
Action *Driver::ConstructPhaseAction(Compilation &C, const ArgList &Args,
Modified: cfe/trunk/test/Driver/cuda-options.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-options.cu?rev=266707&r1=266706&r2=266707&view=diff
==============================================================================
--- cfe/trunk/test/Driver/cuda-options.cu (original)
+++ cfe/trunk/test/Driver/cuda-options.cu Mon Apr 18 21:27:07 2016
@@ -22,23 +22,46 @@
// RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \
// RUN: -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s
-// Same test as above, but with preceeding --cuda-device-only to make sure only
-// the last option has an effect.
-// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only --cuda-host-only %s 2>&1 \
+// Verify that --cuda-device-only disables host-side compilation and linking.
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only %s 2>&1 \
+// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
+// RUN: -check-prefix NOHOST -check-prefix NOLINK %s
+
+// Check that the last of --cuda-compile-host-device, --cuda-host-only, and
+// --cuda-device-only wins.
+
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
+// RUN: --cuda-host-only %s 2>&1 \
// RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \
// RUN: -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s
-// Verify that --cuda-device-only disables host-side compilation and linking.
-// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only %s 2>&1 \
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device \
+// RUN: --cuda-host-only %s 2>&1 \
+// RUN: | FileCheck -check-prefix NODEVICE -check-prefix HOST \
+// RUN: -check-prefix NOINCLUDES-DEVICE -check-prefix LINK %s
+
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only \
+// RUN: --cuda-device-only %s 2>&1 \
// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
// RUN: -check-prefix NOHOST -check-prefix NOLINK %s
-// Same test as above, but with preceeding --cuda-host-only to make sure only
-// the last option has an effect.
-// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only --cuda-device-only %s 2>&1 \
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device \
+// RUN: --cuda-device-only %s 2>&1 \
// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
// RUN: -check-prefix NOHOST -check-prefix NOLINK %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only \
+// RUN: --cuda-compile-host-device %s 2>&1 \
+// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
+// RUN: -check-prefix HOST -check-prefix INCLUDES-DEVICE \
+// RUN: -check-prefix LINK %s
+
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only \
+// RUN: --cuda-compile-host-device %s 2>&1 \
+// RUN: | FileCheck -check-prefix DEVICE -check-prefix DEVICE-NOSAVE \
+// RUN: -check-prefix HOST -check-prefix INCLUDES-DEVICE \
+// RUN: -check-prefix LINK %s
+
// Verify that --cuda-gpu-arch option passes the correct GPU archtecture to
// device compilation.
// RUN: %clang -### -target x86_64-linux-gnu --cuda-gpu-arch=sm_35 -c %s 2>&1 \
Modified: cfe/trunk/test/Driver/cuda-unused-arg-warning.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-unused-arg-warning.cu?rev=266707&r1=266706&r2=266707&view=diff
==============================================================================
--- cfe/trunk/test/Driver/cuda-unused-arg-warning.cu (original)
+++ cfe/trunk/test/Driver/cuda-unused-arg-warning.cu Mon Apr 18 21:27:07 2016
@@ -4,11 +4,16 @@
// REQUIRES: x86-registered-target
// REQUIRES: nvptx-registered-target
-// --cuda-host-only should never trigger unused arg warning.
+// --cuda-host-only and --cuda-compile-host-device should never trigger an
+// unused arg warning.
// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only -c %s 2>&1 | \
// RUN: FileCheck %s
// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only -x c -c %s 2>&1 | \
// RUN: FileCheck %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device -c %s 2>&1 | \
+// RUN: FileCheck %s
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-compile-host-device -x c -c %s 2>&1 | \
+// RUN: FileCheck %s
// --cuda-device-only should warn during non-CUDA compilation.
// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only -x c -c %s 2>&1 | \
@@ -19,5 +24,6 @@
// RUN: FileCheck -check-prefix NO-UNUSED-WARNING %s
// CHECK-NOT: warning: argument unused during compilation: '--cuda-host-only'
+// CHECK-NOT: warning: argument unused during compilation: '--cuda-compile-host-device'
// UNUSED-WARNING: warning: argument unused during compilation: '--cuda-device-only'
// NO-UNUSED-WARNING-NOT: warning: argument unused during compilation: '--cuda-device-only'
More information about the cfe-commits
mailing list