]> granicus.if.org Git - clang/commitdiff
[HIP] Enable specifying different default gpu arch for HIP/CUDA.
authorMichael Liao <michael.hliao@gmail.com>
Thu, 3 Oct 2019 17:49:20 +0000 (17:49 +0000)
committerMichael Liao <michael.hliao@gmail.com>
Thu, 3 Oct 2019 17:49:20 +0000 (17:49 +0000)
Reviewers: tra, yaxunl

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D68394

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@373634 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/Driver.cpp
test/Driver/hip-default-gpu-arch.hip [new file with mode: 0644]

index 8fc3db8c8348c94165957cc5b71559345019f1de..73b258331f798340c19c324869c989f5ece11907 100644 (file)
@@ -2329,6 +2329,10 @@ class OffloadingActionBuilder final {
 
     /// Flag for -fgpu-rdc.
     bool Relocatable = false;
+
+    /// Default GPU architecture if there's no one specified.
+    CudaArch DefaultCudaArch = CudaArch::UNKNOWN;
+
   public:
     CudaActionBuilderBase(Compilation &C, DerivedArgList &Args,
                           const Driver::InputList &Inputs,
@@ -2518,7 +2522,7 @@ class OffloadingActionBuilder final {
       // supported GPUs.  sm_20 code should work correctly, if
       // suboptimally, on all newer GPUs.
       if (GpuArchList.empty())
-        GpuArchList.push_back(CudaArch::SM_20);
+        GpuArchList.push_back(DefaultCudaArch);
 
       return Error;
     }
@@ -2530,7 +2534,9 @@ class OffloadingActionBuilder final {
   public:
     CudaActionBuilder(Compilation &C, DerivedArgList &Args,
                       const Driver::InputList &Inputs)
-        : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_Cuda) {}
+        : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_Cuda) {
+      DefaultCudaArch = CudaArch::SM_20;
+    }
 
     ActionBuilderReturnCode
     getDeviceDependences(OffloadAction::DeviceDependences &DA,
@@ -2645,7 +2651,9 @@ class OffloadingActionBuilder final {
   public:
     HIPActionBuilder(Compilation &C, DerivedArgList &Args,
                      const Driver::InputList &Inputs)
-        : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_HIP) {}
+        : CudaActionBuilderBase(C, Args, Inputs, Action::OFK_HIP) {
+      DefaultCudaArch = CudaArch::GFX803;
+    }
 
     bool canUseBundlerUnbundler() const override { return true; }
 
diff --git a/test/Driver/hip-default-gpu-arch.hip b/test/Driver/hip-default-gpu-arch.hip
new file mode 100644 (file)
index 0000000..56e3688
--- /dev/null
@@ -0,0 +1,7 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang -### -x hip -c %s 2>&1 | FileCheck %s
+
+// CHECK: {{.*}}clang{{.*}}"-target-cpu" "gfx803"