Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 1 addition & 66 deletions clang/lib/Driver/ToolChains/AMDGPU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,6 @@ using namespace clang::driver::toolchains;
using namespace clang;
using namespace llvm::opt;

// Look for sub-directory starts with PackageName under ROCm candidate path.
// If there is one and only one matching sub-directory found, append the
// sub-directory to Path. If there is no matching sub-directory or there are
// more than one matching sub-directories, diagnose them. Returns the full
// path of the package if there is only one matching sub-directory, otherwise
// returns an empty string.
llvm::SmallString<0>
RocmInstallationDetector::findSPACKPackage(const Candidate &Cand,
StringRef PackageName) {
if (!Cand.isSPACK())
return {};
std::error_code EC;
std::string Prefix = Twine(PackageName + "-" + Cand.SPACKReleaseStr).str();
llvm::SmallVector<llvm::SmallString<0>> SubDirs;
for (llvm::vfs::directory_iterator File = D.getVFS().dir_begin(Cand.Path, EC),
FileEnd;
File != FileEnd && !EC; File.increment(EC)) {
llvm::StringRef FileName = llvm::sys::path::filename(File->path());
if (FileName.starts_with(Prefix)) {
SubDirs.push_back(FileName);
if (SubDirs.size() > 1)
break;
}
}
if (SubDirs.size() == 1) {
auto PackagePath = Cand.Path;
llvm::sys::path::append(PackagePath, SubDirs[0]);
return PackagePath;
}
if (SubDirs.size() == 0 && Verbose) {
llvm::errs() << "SPACK package " << Prefix << " not found at " << Cand.Path
<< '\n';
return {};
}

if (SubDirs.size() > 1 && Verbose) {
llvm::errs() << "Cannot use SPACK package " << Prefix << " at " << Cand.Path
<< " due to multiple installations for the same version\n";
}
return {};
}

void RocmInstallationDetector::scanLibDevicePath(llvm::StringRef Path) {
assert(!Path.empty());

Expand Down Expand Up @@ -187,10 +145,7 @@ RocmInstallationDetector::getInstallationPathCandidates() {
auto DoPrintROCmSearchDirs = [&]() {
if (PrintROCmSearchDirs)
for (auto Cand : ROCmSearchDirs) {
llvm::errs() << "ROCm installation search path";
if (Cand.isSPACK())
llvm::errs() << " (Spack " << Cand.SPACKReleaseStr << ")";
llvm::errs() << ": " << Cand.Path << '\n';
llvm::errs() << "ROCm installation search path: " << Cand.Path << '\n';
}
};

Expand Down Expand Up @@ -226,22 +181,6 @@ RocmInstallationDetector::getInstallationPathCandidates() {
ParentName = llvm::sys::path::filename(ParentDir);
}

// Detect ROCm packages built with SPACK.
// clang is installed at
// <rocm_root>/llvm-amdgpu-<rocm_release_string>-<hash>/bin directory.
// We only consider the parent directory of llvm-amdgpu package as ROCm
// installation candidate for SPACK.
if (ParentName.starts_with("llvm-amdgpu-")) {
auto SPACKPostfix =
ParentName.drop_front(strlen("llvm-amdgpu-")).split('-');
auto SPACKReleaseStr = SPACKPostfix.first;
if (!SPACKReleaseStr.empty()) {
ParentDir = llvm::sys::path::parent_path(ParentDir);
return Candidate(ParentDir.str(), /*StrictChecking=*/true,
SPACKReleaseStr);
}
}

// Some versions of the rocm llvm package install to /opt/rocm/llvm/bin
// Some versions of the aomp package install to /opt/rocm/aomp/bin
if (ParentName == "llvm" || ParentName.starts_with("aomp"))
Expand Down Expand Up @@ -462,10 +401,6 @@ void RocmInstallationDetector::detectHIPRuntime() {
InstallPath = Candidate.Path;
if (InstallPath.empty() || !FS.exists(InstallPath))
continue;
// HIP runtime built by SPACK is installed to
// <rocm_root>/hip-<rocm_release_string>-<hash> directory.
auto SPACKPath = findSPACKPackage(Candidate, "hip");
InstallPath = SPACKPath.empty() ? InstallPath : SPACKPath;

BinPath = InstallPath;
llvm::sys::path::append(BinPath, "bin");
Expand Down

This file was deleted.

47 changes: 0 additions & 47 deletions clang/test/Driver/rocm-detect.hip
Original file line number Diff line number Diff line change
Expand Up @@ -94,33 +94,6 @@
// RUN: --print-rocm-search-dirs %s 2>&1 \
// RUN: | FileCheck -check-prefixes=ROCM-REL %s

// Test ROCm installation built by SPACK by invoke clang at %t/rocm-spack/llvm-amdgpu-*
// directory through a soft link.

// RUN: rm -rf %t/rocm-spack
// RUN: cp -r %S/Inputs/rocm-spack %t
// RUN: ln -fs %clang %t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang
// RUN: %t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### -no-canonical-prefixes -v \
// RUN: -resource-dir=%t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/lib/clang \
// RUN: -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 --print-rocm-search-dirs %s 2>&1 \
// RUN: | FileCheck -check-prefixes=SPACK %s

// Test SPACK installation with multiple hip and rocm-device-libs packages of the same
// ROCm release. --hip-path and --rocm-device-lib-path can be used to specify them.

// RUN: cp -r %t/rocm-spack/hip-* %t/rocm-spack/hip-4.0.0-abcd
// RUN: %t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang -### -no-canonical-prefixes -v \
// RUN: -target x86_64-linux-gnu --cuda-gpu-arch=gfx900 \
// RUN: --hip-path=%t/rocm-spack/hip-4.0.0-abcd \
// RUN: %s 2>&1 | FileCheck -check-prefixes=SPACK-SET %s

// Test invalid SPACK ROCm installation missing hip and rocm-device-libs packages.

// RUN: rm -rf %t/rocm-spack/hip-*
// RUN: rm -rf %t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn
// RUN: %t/rocm-spack/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin/clang --version 2>&1 \
// RUN: | FileCheck -check-prefixes=SPACK-MISS-SILENT %s

// GFX902-DEFAULTLIBS: error: cannot find ROCm device library for gfx902; provide its path via '--rocm-path' or '--rocm-device-lib-path', or pass '-nogpulib' to build without ROCm device library

// NODEFAULTLIBS-NOT: error: cannot find
Expand All @@ -145,23 +118,3 @@

// ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm
// ROCM-REL: ROCm installation search path: {{.*}}/opt/rocm-3.10.0

// SPACK: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
// SPACK: ROCm installation search path (Spack 4.0.0): [[DIR]]
// SPACK: ROCm installation search path: [[CLANG:.*]]
// SPACK: ROCm installation search path: [[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z
// SPACK: ROCm installation search path: [[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/lib/clang
// SPACK: ROCm installation search path: /opt/rocm
// SPACK: Found HIP installation: [[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5, version 4.0.20214-a2917cd
// SPACK: "-triple" "amdgcn-amd-amdhsa"
// SPACK-SAME: "-mlink-builtin-bitcode" "[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"
// SPACK-SAME: "-idirafter" "[[DIR]]/hip-4.0.0-5f63slrursbrvfe2txrrjkynbsywsob5/include"

// SPACK-SET: InstalledDir: [[DIR:.*]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/bin
// SPACK-SET: Found HIP installation: [[DIR]]/hip-4.0.0-abcd, version 4.0.20214-a2917cd
// SPACK-SET: "-triple" "amdgcn-amd-amdhsa"
// SPACK-SET-SAME: "-mlink-builtin-bitcode" "[[DIR]]/llvm-amdgpu-4.0.0-ieagcs7inf7runpyfvepqkurasoglq4z/amdgcn/bitcode/hip.bc"
// SPACK-SET-SAME: "-idirafter" "[[DIR]]/hip-4.0.0-abcd/include"

// SPACK-MISS-SILENT-NOT: SPACK package hip-{{.*}} not found at
// SPACK-MISS-SILENT-NOT: Found HIP installation