From 7b0693d79162eca545845a8b2a82143ae955c1df Mon Sep 17 00:00:00 2001 From: Yaxun Liu Date: Wed, 6 Jun 2018 19:44:10 +0000 Subject: [PATCH] [HIP] Fix unbundling HIP uses clang-offload-bundler to bundle intermediate files for host and different gpu archs together. When a file is unbundled, clang-offload-bundler should be called only once, and the objects for host and different gpu archs should be passed to the next jobs. This is because Driver maintains CachedResults which maps triple-arch string to output files for each job. This patch fixes a bug in Driver::BuildJobsForActionNoCache which uses incorrect key for CachedResults for HIP which causes clang-offload-bundler being called mutiple times and incorrect output files being used. It only affects HIP. Differential Revision: https://reviews.llvm.org/D47555 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@334128 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Driver.cpp | 17 +++++++++++++---- test/Driver/hip-binding.hip | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 test/Driver/hip-binding.hip diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp index c3ff9341a8..d0858764e7 100644 --- a/lib/Driver/Driver.cpp +++ b/lib/Driver/Driver.cpp @@ -2808,7 +2808,7 @@ public: C.MakeAction(HostAction); UnbundlingHostAction->registerDependentActionInfo( C.getSingleOffloadToolChain(), - /*BoundArch=*/StringRef(), Action::OFK_Host); + /*BoundArch=*/"all", Action::OFK_Host); HostAction = UnbundlingHostAction; } @@ -3880,9 +3880,18 @@ InputInfo Driver::BuildJobsForActionNoCache( // Get the unique string identifier for this dependence and cache the // result. - CachedResults[{A, GetTriplePlusArchString( - UI.DependentToolChain, BoundArch, - UI.DependentOffloadKind)}] = CurI; + StringRef Arch; + if (TargetDeviceOffloadKind == Action::OFK_HIP) { + if (UI.DependentOffloadKind == Action::OFK_Host) + Arch = "all"; + else + Arch = UI.DependentBoundArch; + } else + Arch = BoundArch; + + CachedResults[{A, GetTriplePlusArchString(UI.DependentToolChain, Arch, + UI.DependentOffloadKind)}] = + CurI; } // Now that we have all the results generated, select the one that should be diff --git a/test/Driver/hip-binding.hip b/test/Driver/hip-binding.hip new file mode 100644 index 0000000000..c08cc67362 --- /dev/null +++ b/test/Driver/hip-binding.hip @@ -0,0 +1,15 @@ +// REQUIRES: clang-driver +// REQUIRES: x86-registered-target +// REQUIRES: amdgpu-registered-target + +// RUN: touch %t.o +// RUN: %clang --hip-link -ccc-print-bindings -target x86_64-linux-gnu \ +// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 %t.o\ +// RUN: 2>&1 | FileCheck %s + +// CHECK: # "amdgcn-amd-amdhsa" - "offload bundler", inputs: ["[[IN:.*o]]"], outputs: ["[[OBJ1:.*o]]", "[[OBJ2:.*o]]", "[[OBJ3:.*o]]"] +// CHECK: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[OBJ2]]"], output: "[[IMG2:.*out]]" +// CHECK-NOT: offload bundler +// CHECK: # "amdgcn-amd-amdhsa" - "AMDGCN::Linker", inputs: ["[[OBJ3]]"], output: "[[IMG3:.*out]]" +// CHECK-NOT: offload bundler +// CHECK: # "x86_64--linux-gnu" - "GNU::Linker", inputs: ["[[OBJ1]]", "[[IMG2]]", "[[IMG3]]"], output: "a.out" -- 2.40.0