[Mlir-commits] [mlir] [mlir][ROCDL] Construct AMDGCN ISA control variable explicitly (PR #98912)

Fabian Mora llvmlistbot at llvm.org
Mon Jul 15 07:41:45 PDT 2024


https://github.com/fabianmcg created https://github.com/llvm/llvm-project/pull/98912

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.

>From 9d4ae2cfa7222abe914f86bbc9e24c1d78903cc7 Mon Sep 17 00:00:00 2001
From: Fabian Mora <fmora.dev at gmail.com>
Date: Mon, 15 Jul 2024 13:59:57 +0000
Subject: [PATCH] [mlir][ROCDL] Construct AMDGCN ISA control variable
 explicitly

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.
---
 mlir/lib/Target/LLVM/ROCDL/Target.cpp | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/mlir/lib/Target/LLVM/ROCDL/Target.cpp b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
index 047d214b751f1..0ea4669c17a13 100644
--- a/mlir/lib/Target/LLVM/ROCDL/Target.cpp
+++ b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
@@ -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();
@@ -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();
 }
@@ -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);



More information about the Mlir-commits mailing list