]> granicus.if.org Git - clang/commitdiff
[CUDA] Fixes minor cuda-related issues in the driver
authorArtem Belevich <tra@google.com>
Tue, 22 Sep 2015 17:23:09 +0000 (17:23 +0000)
committerArtem Belevich <tra@google.com>
Tue, 22 Sep 2015 17:23:09 +0000 (17:23 +0000)
* 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

lib/Driver/Driver.cpp
test/Driver/cuda-options.cu

index 2f58c42a63be35ef7268cce03b9f758a111b37ca..ebf8b7d953dcb20c0bdea1bbc360312d06219d34 100644 (file)
@@ -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<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 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)
index 2ac4fbf34c6c7c47c68441b46a8b86e9e88f94f8..23ba2967e8d49fb7f6566f97e9a1fef6f624cf38 100644 (file)
@@ -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 \
 // 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 \