r248297 - [CUDA] Fixes minor cuda-related issues in the driver
Artem Belevich via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 22 10:23:10 PDT 2015
Author: tra
Date: Tue Sep 22 12:23:09 2015
New Revision: 248297
URL: http://llvm.org/viewvc/llvm-project?rev=248297&view=rev
Log:
[CUDA] Fixes minor cuda-related issues in the driver
* Only the last of the --cuda-host-only/--cuda-device-only options has effect.
* CudaHostAction always wraps host-side compilation now.
* Fixed printing of empty action lists.
Differential Revision: http://reviews.llvm.org/D12892
Modified:
cfe/trunk/lib/Driver/Driver.cpp
cfe/trunk/test/Driver/cuda-options.cu
Modified: cfe/trunk/lib/Driver/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Driver.cpp?rev=248297&r1=248296&r2=248297&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Driver.cpp (original)
+++ cfe/trunk/lib/Driver/Driver.cpp Tue Sep 22 12:23:09 2015
@@ -920,12 +920,15 @@ static unsigned PrintActions1(const Comp
} else
AL = &A->getInputs();
- const char *Prefix = "{";
- for (Action *PreRequisite : *AL) {
- os << Prefix << PrintActions1(C, PreRequisite, Ids);
- Prefix = ", ";
- }
- os << "}";
+ if (AL->size()) {
+ const char *Prefix = "{";
+ for (Action *PreRequisite : *AL) {
+ os << Prefix << PrintActions1(C, PreRequisite, Ids);
+ Prefix = ", ";
+ }
+ os << "}";
+ } else
+ os << "{}";
}
unsigned Id = Ids.size();
@@ -1243,6 +1246,13 @@ static std::unique_ptr<Action>
buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args,
const Arg *InputArg, std::unique_ptr<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))
+ return std::unique_ptr<Action>(
+ new CudaHostAction(std::move(HostAction), {}));
// Collect all cuda_gpu_arch parameters, removing duplicates.
SmallVector<const char *, 4> GpuArchList;
@@ -1288,7 +1298,7 @@ buildCudaActions(const Driver &D, const
// Figure out what to do with device actions -- pass them as inputs to the
// host action or run each of them independently.
- bool DeviceOnlyCompilation = Args.hasArg(options::OPT_cuda_device_only);
+ bool DeviceOnlyCompilation = PartialCompilationArg != nullptr;
if (PartialCompilation || DeviceOnlyCompilation) {
// 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
@@ -1421,11 +1431,8 @@ void Driver::BuildActions(const ToolChai
continue;
}
- phases::ID CudaInjectionPhase;
- bool InjectCuda = (InputType == types::TY_CUDA &&
- !Args.hasArg(options::OPT_cuda_host_only));
- CudaInjectionPhase = FinalPhase;
- for (auto &Phase : PL)
+ phases::ID CudaInjectionPhase = FinalPhase;
+ for (const auto &Phase : PL)
if (Phase <= FinalPhase && Phase == phases::Compile) {
CudaInjectionPhase = Phase;
break;
@@ -1457,7 +1464,7 @@ void Driver::BuildActions(const ToolChai
// Otherwise construct the appropriate action.
Current = ConstructPhaseAction(TC, Args, Phase, std::move(Current));
- if (InjectCuda && Phase == CudaInjectionPhase) {
+ if (InputType == types::TY_CUDA && Phase == CudaInjectionPhase) {
Current = buildCudaActions(*this, TC, Args, InputArg,
std::move(Current), Actions);
if (!Current)
Modified: cfe/trunk/test/Driver/cuda-options.cu
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-options.cu?rev=248297&r1=248296&r2=248297&view=diff
==============================================================================
--- cfe/trunk/test/Driver/cuda-options.cu (original)
+++ cfe/trunk/test/Driver/cuda-options.cu Tue Sep 22 12:23:09 2015
@@ -21,7 +21,7 @@
// Then link things.
// RUN: -check-prefix CUDA-L %s
-// Verify that -cuda-no-device disables device-side compilation and linking
+// Verify that --cuda-host-only disables device-side compilation and linking
// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only %s 2>&1 \
// Make sure we didn't run device-side compilation.
// RUN: | FileCheck -check-prefix CUDA-ND \
@@ -30,11 +30,29 @@
// Linking is allowed to happen, even if we're missing GPU code.
// RUN: -check-prefix CUDA-L %s
-// Verify that -cuda-no-host disables host-side compilation and linking
+// Same test as above, but with preceeding --cuda-device-only to make
+// sure only last option has effect.
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-device-only --cuda-host-only %s 2>&1 \
+// Make sure we didn't run device-side compilation.
+// RUN: | FileCheck -check-prefix CUDA-ND \
+// Then compile host side and make sure we don't attempt to incorporate GPU code.
+// RUN: -check-prefix CUDA-H -check-prefix CUDA-H-NI \
+// Linking is allowed to happen, even if we're missing GPU code.
+// RUN: -check-prefix CUDA-L %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 \
// Compile device-side to PTX assembly
// RUN: | FileCheck -check-prefix CUDA-D1 -check-prefix CUDA-D1NS\
// Make sure there are no host cmpilation or linking.
+// RUN: -check-prefix CUDA-NH -check-prefix CUDA-NL %s
+
+// Same test as above, but with preceeding --cuda-host-only to make
+// sure only last option has effect.
+// RUN: %clang -### -target x86_64-linux-gnu --cuda-host-only --cuda-device-only %s 2>&1 \
+// Compile device-side to PTX assembly
+// RUN: | FileCheck -check-prefix CUDA-D1 -check-prefix CUDA-D1NS\
+// Make sure there are no host cmpilation or linking.
// RUN: -check-prefix CUDA-NH -check-prefix CUDA-NL %s
// Verify that with -S we compile host and device sides to assembly
More information about the cfe-commits
mailing list