Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HIP] change default offload archs #139281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions clang/include/clang/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,10 @@ class ToolChain {
virtual Expected<SmallVector<std::string>>
getSystemGPUArchs(const llvm::opt::ArgList &Args) const;

/// getHIPDefaultOffloadArchs - Get the default offload arch's for HIP.
virtual SmallVector<StringRef>
getHIPDefaultOffloadArchs(const llvm::opt::ArgList &Args) const;

/// addProfileRTLibs - When -fprofile-instr-profile is specified, try to pass
/// a suitable profile runtime library to the linker.
virtual void addProfileRTLibs(const llvm::opt::ArgList &Args,
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3503,6 +3503,9 @@ class OffloadingActionBuilder final {
GpuArchList.push_back(OffloadArch::AMDGCNSPIRV);
else
GpuArchList.push_back(OffloadArch::Generic);
} else if (AssociatedOffloadKind == Action::OFK_HIP) {
for (auto A : ToolChains.front()->getHIPDefaultOffloadArchs(Args))
GpuArchList.push_back(A.data());
} else {
GpuArchList.push_back(DefaultOffloadArch);
}
Expand Down Expand Up @@ -4825,7 +4828,8 @@ Driver::getOffloadArchs(Compilation &C, const llvm::opt::DerivedArgList &Args,
if (Kind == Action::OFK_Cuda) {
Archs.insert(OffloadArchToString(OffloadArch::CudaDefault));
} else if (Kind == Action::OFK_HIP) {
Archs.insert(OffloadArchToString(OffloadArch::HIPDefault));
for (auto A : TC->getHIPDefaultOffloadArchs(Args))
Archs.insert(A);
} else if (Kind == Action::OFK_SYCL) {
Archs.insert(StringRef());
} else if (Kind == Action::OFK_OpenMP) {
Expand Down
26 changes: 26 additions & 0 deletions clang/lib/Driver/ToolChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,6 +1574,32 @@ ToolChain::getSystemGPUArchs(const llvm::opt::ArgList &Args) const {
return SmallVector<std::string>();
}

SmallVector<StringRef>
ToolChain::getHIPDefaultOffloadArchs(const llvm::opt::ArgList &Args) const {
if (getTriple().isSPIRV()) {
if (getTriple().getVendor() == llvm::Triple::AMD)
return {OffloadArchToString(OffloadArch::AMDGCNSPIRV)};
return {OffloadArchToString(OffloadArch::Generic)};
}

if (!getTriple().isAMDGPU())
return {};

SmallVector<StringRef> GpuArchList;
auto GPUsOrErr = getSystemGPUArchs(Args);
if (GPUsOrErr) {
for (auto &G : *GPUsOrErr)
GpuArchList.push_back(Args.MakeArgString(G));
return GpuArchList;
}
llvm::consumeError(GPUsOrErr.takeError());
auto Prog = GetProgramPath("amd-llvm-spirv");
if (!Prog.empty() && llvm::sys::fs::can_execute(Prog))
return {OffloadArchToString(OffloadArch::AMDGCNSPIRV)};

return {OffloadArchToString(OffloadArch::HIPDefault)};
}

SanitizerMask ToolChain::getSupportedSanitizers() const {
// Return sanitizers which don't require runtime support and are not
// platform dependent.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/hip-default-gpu-arch.hip
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// RUN: %clang -### -nogpulib -nogpuinc -c %s 2>&1 | FileCheck %s

// CHECK: {{.*}}clang{{.*}}"-target-cpu" "gfx906"
// CHECK: {{.*}}clang{{.*}}"-triple" "{{amdgcn|spirv64}}-amd-amdhsa"{{.*}} "-target-cpu" "{{amdgcnspirv|gfx.*}}"