Skip to content

Commit

Permalink
[mlir][ROCDL] Construct AMDGCN ISA control variable explicitly
Browse files Browse the repository at this point in the history
This patch constructs the AMDGCN ISA control variable explicitly instead of
linking against the library shipped with ROCm. This change prevents issue
 arising from the order in which the AMGCN libraries are linked.
  • Loading branch information
fabianmcg committed Jul 15, 2024
1 parent 4ed0f84 commit 9d4ae2c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions mlir/lib/Target/LLVM/ROCDL/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ LogicalResult SerializeGPUModuleBase::appendStandardLibs(AMDGCNLibraries libs) {
return failure();
}

// Get the ISA version.
StringRef isaVersion =
llvm::AMDGPU::getArchNameAMDGCN(llvm::AMDGPU::parseArchAMDGCN(chip));
isaVersion.consume_front("gfx");

// Helper function for adding a library.
auto addLib = [&](const Twine &lib) -> bool {
auto baseSize = path.size();
Expand All @@ -175,9 +170,7 @@ LogicalResult SerializeGPUModuleBase::appendStandardLibs(AMDGCNLibraries libs) {
if ((any(libs & AMDGCNLibraries::Ocml) && addLib("ocml.bc")) ||
(any(libs & AMDGCNLibraries::Ockl) && addLib("ockl.bc")) ||
(any(libs & AMDGCNLibraries::Hip) && addLib("hip.bc")) ||
(any(libs & AMDGCNLibraries::OpenCL) && addLib("opencl.bc")) ||
(any(libs & (AMDGCNLibraries::Ocml | AMDGCNLibraries::Ockl)) &&
addLib("oclc_isa_version_" + isaVersion + ".bc")))
(any(libs & AMDGCNLibraries::OpenCL) && addLib("opencl.bc")))
return failure();
return success();
}
Expand Down Expand Up @@ -270,6 +263,15 @@ void SerializeGPUModuleBase::addControlVariables(
// Add ocml or ockl related control variables.
if (any(libs & (AMDGCNLibraries::Ocml | AMDGCNLibraries::Ockl))) {
addControlVariable("__oclc_wavefrontsize64", wave64, 8);

// Get the ISA version.
llvm::AMDGPU::IsaVersion isaVersion =
llvm::AMDGPU::getIsaVersion(llvm::AMDGPU::parseArchAMDGCN(chip));
// Add the ISA control variable.
addControlVariable("__oclc_ISA_version",
isaVersion.Minor + 100 * isaVersion.Stepping +
1000 * isaVersion.Major,
32);
int abi = 500;
abiVer.getAsInteger(0, abi);
addControlVariable("__oclc_ABI_version", abi, 32);
Expand Down

0 comments on commit 9d4ae2c

Please sign in to comment.