From: Artem Belevich Date: Tue, 22 Sep 2015 17:23:09 +0000 (+0000) Subject: [CUDA] Fixes minor cuda-related issues in the driver X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f19dfb574dc20cf3564784cde62a30535ef86325;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@248297 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index 2f58c42a63..ebf8b7d953 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -920,12 +920,15 @@ static unsigned PrintActions1(const Compilation &C, Action *A, } 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 buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args, const Arg *InputArg, std::unique_ptr 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( + new CudaHostAction(std::move(HostAction), {})); // Collect all cuda_gpu_arch parameters, removing duplicates. SmallVector GpuArchList; @@ -1288,7 +1298,7 @@ buildCudaActions(const Driver &D, const ToolChain &TC, DerivedArgList &Args, // 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 ToolChain &TC, DerivedArgList &Args, 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 ToolChain &TC, DerivedArgList &Args, // 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) diff --git a/test/Driver/cuda-options.cu b/test/Driver/cuda-options.cu index 2ac4fbf34c..23ba2967e8 100644 --- a/test/Driver/cuda-options.cu +++ b/test/Driver/cuda-options.cu @@ -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,13 +30,31 @@ // 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 // and incorporate device code on the host side. // RUN: %clang -### -target x86_64-linux-gnu -S -c %s 2>&1 \