From efc013ec4d950a68e6f80dd98cda35e1a96a6fc8 Mon Sep 17 00:00:00 2001 From: Pushpinder Singh Date: Fri, 16 Apr 2021 08:54:06 +0000 Subject: [PATCH] Revert "[AMDGPU][OpenMP] Add amdgpu-arch tool to list AMD GPUs installed" This reverts commit 7029cffc4e78556cfe820791c612968bb15b2ffb. --- clang/include/clang/Basic/DiagnosticDriverKinds.td | 2 - clang/include/clang/Driver/Options.td | 2 - clang/lib/Driver/ToolChains/AMDGPU.cpp | 56 -------------------- clang/lib/Driver/ToolChains/AMDGPU.h | 7 --- clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp | 23 +-------- .../Inputs/amdgpu-arch/amdgpu_arch_different | 4 -- .../Driver/Inputs/amdgpu-arch/amdgpu_arch_fail | 2 - .../Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx906 | 3 -- .../Inputs/amdgpu-arch/amdgpu_arch_gfx908_gfx908 | 4 -- clang/test/Driver/amdgpu-openmp-system-arch-fail.c | 13 ----- clang/test/Driver/amdgpu-openmp-system-arch.c | 15 ------ clang/tools/CMakeLists.txt | 2 - clang/tools/amdgpu-arch/AMDGPUArch.cpp | 59 ---------------------- clang/tools/amdgpu-arch/CMakeLists.txt | 17 ------- 14 files changed, 2 insertions(+), 207 deletions(-) delete mode 100755 clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_different delete mode 100755 clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_fail delete mode 100755 clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx906 delete mode 100755 clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx908_gfx908 delete mode 100644 clang/test/Driver/amdgpu-openmp-system-arch-fail.c delete mode 100644 clang/test/Driver/amdgpu-openmp-system-arch.c delete mode 100644 clang/tools/amdgpu-arch/AMDGPUArch.cpp delete mode 100644 clang/tools/amdgpu-arch/CMakeLists.txt diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index aa3b00c..5e580cc 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -67,8 +67,6 @@ def err_drv_no_hip_runtime : Error< "cannot find HIP runtime. Provide its path via --rocm-path, or pass " "-nogpuinc to build without HIP runtime.">; -def err_drv_undetermined_amdgpu_arch : Error< - "Cannot determine AMDGPU architecture. Consider passing it via -march">; def err_drv_cuda_version_unsupported : Error< "GPU arch %0 is supported by CUDA versions between %1 and %2 (inclusive), " "but installation at %3 is %4. Use --cuda-path to specify a different CUDA " diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 5fbcd64..9e15712 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -918,8 +918,6 @@ def rocm_path_EQ : Joined<["--"], "rocm-path=">, Group, HelpText<"ROCm installation path, used for finding and automatically linking required bitcode libraries.">; def hip_path_EQ : Joined<["--"], "hip-path=">, Group, HelpText<"HIP runtime installation path, used for finding HIP version and adding HIP include path.">; -def amdgpu_arch_tool_EQ : Joined<["--"], "amdgpu-arch-tool=">, Group, - HelpText<"Tool used for detecting AMD GPU arch in the system.">; def rocm_device_lib_path_EQ : Joined<["--"], "rocm-device-lib-path=">, Group, HelpText<"ROCm device library path. Alternative to rocm-path.">; def : Joined<["--"], "hip-device-lib-path=">, Alias; diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp index 37da2c0..dc9c975 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp @@ -12,15 +12,10 @@ #include "clang/Basic/TargetID.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/DriverDiagnostic.h" -#include "clang/Driver/Options.h" #include "llvm/Option/ArgList.h" -#include "llvm/Support/FileUtilities.h" -#include "llvm/Support/LineIterator.h" #include "llvm/Support/Path.h" #include "llvm/Support/VirtualFileSystem.h" -#define AMDGPU_ARCH_PROGRAM_NAME "amdgpu-arch" - using namespace clang::driver; using namespace clang::driver::tools; using namespace clang::driver::toolchains; @@ -720,57 +715,6 @@ void AMDGPUToolChain::checkTargetID( } } -llvm::SmallVector, 1> -AMDGPUToolChain::detectSystemGPUs(const ArgList &Args) const { - std::string Program; - if (Arg *A = Args.getLastArg(options::OPT_amdgpu_arch_tool_EQ)) - Program = A->getValue(); - else - Program = GetProgramPath(AMDGPU_ARCH_PROGRAM_NAME); - llvm::SmallString<64> OutputFile; - llvm::sys::fs::createTemporaryFile("print-system-gpus", "" /* No Suffix */, - OutputFile); - llvm::FileRemover OutputRemover(OutputFile.c_str()); - llvm::Optional Redirects[] = { - {""}, - StringRef(OutputFile), - {""}, - }; - - if (llvm::sys::ExecuteAndWait(Program.c_str(), {}, {}, Redirects)) { - return {}; - } - - llvm::ErrorOr> OutputBuf = - llvm::MemoryBuffer::getFile(OutputFile.c_str()); - if (!OutputBuf) - return {}; - - llvm::SmallVector, 1> GPUArchs; - for (llvm::line_iterator LineIt(**OutputBuf); !LineIt.is_at_end(); ++LineIt) { - GPUArchs.push_back(*LineIt); - } - return GPUArchs; -} - -SmallString<8> AMDGPUToolChain::getSystemGPUArch(const ArgList &Args) const { - // detect the AMDGPU installed in system - auto GPUArchs = detectSystemGPUs(Args); - if (GPUArchs.empty()) { - return SmallString<8>(""); - } - if (GPUArchs.size() > 1) { - bool AllSame = std::all_of( - GPUArchs.begin(), GPUArchs.end(), - [&](const StringRef &GPUArch) { return GPUArch == GPUArchs.front(); }); - if (AllSame) - return GPUArchs.front(); - - return SmallString<8>(""); - } - return GPUArchs.front(); -} - void ROCMToolChain::addClangTargetOptions( const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args, Action::OffloadKind DeviceOffloadingKind) const { diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h index 1755253..1aa0849 100644 --- a/clang/lib/Driver/ToolChains/AMDGPU.h +++ b/clang/lib/Driver/ToolChains/AMDGPU.h @@ -100,19 +100,12 @@ public: /// Should skip argument. bool shouldSkipArgument(const llvm::opt::Arg *Arg) const; - /// Uses amdgpu_arch tool to get arch of the system GPU. Returns empty string - /// if unable to find one. - SmallString<8> getSystemGPUArch(const llvm::opt::ArgList &Args) const; - protected: /// Check and diagnose invalid target ID specified by -mcpu. void checkTargetID(const llvm::opt::ArgList &DriverArgs) const; /// Get GPU arch from -mcpu without checking. StringRef getGPUArch(const llvm::opt::ArgList &DriverArgs) const; - - SmallVector, 1> - detectSystemGPUs(const llvm::opt::ArgList &Args) const; }; class LLVM_LIBRARY_VISIBILITY ROCMToolChain : public AMDGPUToolChain { diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp index 625dda9..38abd2f 100644 --- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp +++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp @@ -10,7 +10,6 @@ #include "AMDGPU.h" #include "CommonArgs.h" #include "InputInfo.h" -#include "clang/Basic/DiagnosticDriver.h" #include "clang/Driver/Compilation.h" #include "clang/Driver/Driver.h" #include "clang/Driver/DriverDiagnostic.h" @@ -146,19 +145,10 @@ void AMDGCN::OpenMPLinker::ConstructJob(Compilation &C, const JobAction &JA, const InputInfoList &Inputs, const ArgList &Args, const char *LinkingOutput) const { - const ToolChain &TC = getToolChain(); assert(getToolChain().getTriple().isAMDGCN() && "Unsupported target"); - const toolchains::AMDGPUOpenMPToolChain &AMDGPUOpenMPTC = - static_cast(TC); StringRef GPUArch = Args.getLastArgValue(options::OPT_march_EQ); - if (GPUArch.empty()) { - GPUArch = AMDGPUOpenMPTC.getSystemGPUArch(Args); - } - if (GPUArch.empty()) { - TC.getDriver().Diag(diag::err_drv_undetermined_amdgpu_arch); - return; - } + assert(GPUArch.startswith("gfx") && "Unsupported sub arch"); // Prefix for temporary file name. std::string Prefix; @@ -197,16 +187,7 @@ void AMDGPUOpenMPToolChain::addClangTargetOptions( HostTC.addClangTargetOptions(DriverArgs, CC1Args, DeviceOffloadingKind); StringRef GpuArch = DriverArgs.getLastArgValue(options::OPT_march_EQ); - if (GpuArch.empty()) { - // in case no GPU arch is passed via -march, then try to detect - // the system gpu - GpuArch = getSystemGPUArch(DriverArgs); - } - if (GpuArch.empty()) { - getDriver().Diag(diag::err_drv_undetermined_amdgpu_arch); - return; - } - + assert(!GpuArch.empty() && "Must have an explicit GPU arch."); assert(DeviceOffloadingKind == Action::OFK_OpenMP && "Only OpenMP offloading kinds are supported."); diff --git a/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_different b/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_different deleted file mode 100755 index 6e30711..0000000 --- a/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_different +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh -echo gfx908 -echo gfx906 -return 0 \ No newline at end of file diff --git a/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_fail b/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_fail deleted file mode 100755 index 360ac43..0000000 --- a/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_fail +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env sh -return 1 \ No newline at end of file diff --git a/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx906 b/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx906 deleted file mode 100755 index fdc0886..0000000 --- a/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx906 +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh -echo "gfx906" -return 0 diff --git a/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx908_gfx908 b/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx908_gfx908 deleted file mode 100755 index 83c5847..0000000 --- a/clang/test/Driver/Inputs/amdgpu-arch/amdgpu_arch_gfx908_gfx908 +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env sh -echo gfx908 -echo gfx908 -return 0 diff --git a/clang/test/Driver/amdgpu-openmp-system-arch-fail.c b/clang/test/Driver/amdgpu-openmp-system-arch-fail.c deleted file mode 100644 index 8e97fab..0000000 --- a/clang/test/Driver/amdgpu-openmp-system-arch-fail.c +++ /dev/null @@ -1,13 +0,0 @@ -// REQUIRES: system-linux -// REQUIRES: x86-registered-target -// REQUIRES: amdgpu-registered-target - -// case when amdgpu_arch returns nothing or fails -// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib --amdgpu-arch-tool=%S/Inputs/amdgpu-arch/amdgpu_arch_fail %s 2>&1 \ -// RUN: | FileCheck %s --check-prefix=NO-OUTPUT-ERROR -// NO-OUTPUT-ERROR: error: Cannot determine AMDGPU architecture. Consider passing it via -march - -// case when amdgpu_arch returns multiple gpus but all are different -// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib --amdgpu-arch-tool=%S/Inputs/amdgpu-arch/amdgpu_arch_different %s 2>&1 \ -// RUN: | FileCheck %s --check-prefix=MULTIPLE-OUTPUT-ERROR -// MULTIPLE-OUTPUT-ERROR: error: Cannot determine AMDGPU architecture. Consider passing it via -march diff --git a/clang/test/Driver/amdgpu-openmp-system-arch.c b/clang/test/Driver/amdgpu-openmp-system-arch.c deleted file mode 100644 index 48d0ecc..0000000 --- a/clang/test/Driver/amdgpu-openmp-system-arch.c +++ /dev/null @@ -1,15 +0,0 @@ -// REQUIRES: system-linux -// REQUIRES: x86-registered-target -// REQUIRES: amdgpu-registered-target -// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib --amdgpu-arch-tool=%S/Inputs/amdgpu-arch/amdgpu_arch_gfx906 %s 2>&1 \ -// RUN: | FileCheck %s -// CHECK: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-target-cpu" "[[GFX:gfx906]]" -// CHECK: llvm-link{{.*}}"-o" "{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-linked-{{.*}}.bc" -// CHECK: llc{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-linked-{{.*}}.bc" "-mtriple=amdgcn-amd-amdhsa" "-mcpu=[[GFX]]" "-filetype=obj" "-o"{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-{{.*}}.o" - -// case when amdgpu_arch returns multiple gpus but of same arch -// RUN: %clang -### --target=x86_64-unknown-linux-gnu -fopenmp -fopenmp-targets=amdgcn-amd-amdhsa -nogpulib --amdgpu-arch-tool=%S/Inputs/amdgpu-arch/amdgpu_arch_gfx908_gfx908 %s 2>&1 \ -// RUN: | FileCheck %s --check-prefix=CHECK-MULTIPLE -// CHECK-MULTIPLE: clang{{.*}}"-cc1"{{.*}}"-triple" "amdgcn-amd-amdhsa"{{.*}}"-target-cpu" "[[GFX:gfx908]]" -// CHECK-MULTIPLE: llvm-link{{.*}}"-o" "{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-linked-{{.*}}.bc" -// CHECK-MULTIPLE: llc{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-linked-{{.*}}.bc" "-mtriple=amdgcn-amd-amdhsa" "-mcpu=[[GFX]]" "-filetype=obj" "-o"{{.*}}amdgpu-openmp-system-arch-{{.*}}-[[GFX]]-{{.*}}.o" diff --git a/clang/tools/CMakeLists.txt b/clang/tools/CMakeLists.txt index 3235917..52fd025 100644 --- a/clang/tools/CMakeLists.txt +++ b/clang/tools/CMakeLists.txt @@ -43,5 +43,3 @@ add_llvm_external_project(clang-tools-extra extra) # libclang may require clang-tidy in clang-tools-extra. add_clang_subdirectory(libclang) - -add_clang_subdirectory(amdgpu-arch) diff --git a/clang/tools/amdgpu-arch/AMDGPUArch.cpp b/clang/tools/amdgpu-arch/AMDGPUArch.cpp deleted file mode 100644 index 29f9c8b..0000000 --- a/clang/tools/amdgpu-arch/AMDGPUArch.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//===- AMDGPUArch.cpp - list AMDGPU installed ----------*- C++ -*---------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file implements a tool for detecting name of AMDGPU installed in system -// using HSA. This tool is used by AMDGPU OpenMP driver. -// -//===----------------------------------------------------------------------===// - -#include -#include -#include - -static hsa_status_t iterateAgentsCallback(hsa_agent_t Agent, void *Data) { - hsa_device_type_t DeviceType; - hsa_status_t Status = - hsa_agent_get_info(Agent, HSA_AGENT_INFO_DEVICE, &DeviceType); - - // continue only if device type if GPU - if (Status != HSA_STATUS_SUCCESS || DeviceType != HSA_DEVICE_TYPE_GPU) { - return Status; - } - - std::vector *GPUs = - static_cast *>(Data); - char GPUName[64]; - Status = hsa_agent_get_info(Agent, HSA_AGENT_INFO_NAME, GPUName); - if (Status != HSA_STATUS_SUCCESS) { - return Status; - } - GPUs->push_back(GPUName); - return HSA_STATUS_SUCCESS; -} - -int main() { - hsa_status_t Status = hsa_init(); - if (Status != HSA_STATUS_SUCCESS) { - return 1; - } - - std::vector GPUs; - Status = hsa_iterate_agents(iterateAgentsCallback, &GPUs); - if (Status != HSA_STATUS_SUCCESS) { - return 1; - } - - for (const auto &GPU : GPUs) - printf("%s\n", GPU.c_str()); - - if (GPUs.size() < 1) - return 1; - - hsa_shut_down(); - return 0; -} diff --git a/clang/tools/amdgpu-arch/CMakeLists.txt b/clang/tools/amdgpu-arch/CMakeLists.txt deleted file mode 100644 index fca58c4..0000000 --- a/clang/tools/amdgpu-arch/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -# //===----------------------------------------------------------------------===// -# // -# // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -# // See https://llvm.org/LICENSE.txt for details. -# // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# // -# //===----------------------------------------------------------------------===// - -find_package(hsa-runtime64 QUIET 1.2.0 HINTS ${CMAKE_INSTALL_PREFIX} PATHS /opt/rocm) -if (NOT ${hsa-runtime64_FOUND}) - message(STATUS "Not building amdgpu-arch: hsa-runtime64 not found") - return() -endif() - -add_clang_tool(amdgpu-arch AMDGPUArch.cpp) - -clang_target_link_libraries(amdgpu-arch PRIVATE hsa-runtime64::hsa-runtime64) -- 2.7.4