Skip to content
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

[mlir][ROCDL] Construct AMDGCN ISA control variable explicitly #98912

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

fabianmcg
Copy link
Contributor

@fabianmcg fabianmcg commented Jul 15, 2024

This patch constructs the AMDGCN ISA control variable explicitly instead of linking against the library shipped with ROCm. This change prevents issues arising from the order in which the AMDGCN libraries are linked.

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.
@fabianmcg fabianmcg marked this pull request as ready for review July 15, 2024 15:05
@fabianmcg fabianmcg requested a review from krzysz00 July 15, 2024 15:05
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 15, 2024

@llvm/pr-subscribers-mlir-llvm

@llvm/pr-subscribers-mlir

Author: Fabian Mora (fabianmcg)

Changes

This patch constructs the AMDGCN ISA control variable explicitly instead of linking against the library shipped with ROCm. This change prevents issues arising from the order in which the AMGCN libraries are linked.


Full diff: https://github.com/llvm/llvm-project/pull/98912.diff

1 Files Affected:

  • (modified) mlir/lib/Target/LLVM/ROCDL/Target.cpp (+9-8)
diff --git a/mlir/lib/Target/LLVM/ROCDL/Target.cpp b/mlir/lib/Target/LLVM/ROCDL/Target.cpp
index 047d214b751f1..70d6bcd76285a 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,14 @@ 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(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);

Copy link
Contributor

@krzysz00 krzysz00 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice find!

@fabianmcg fabianmcg merged commit 16dd75b into llvm:main Jul 16, 2024
11 checks passed
sayhaan pushed a commit to sayhaan/llvm-project that referenced this pull request Jul 16, 2024
…98912)

Summary:
This patch constructs the AMDGCN ISA control variable explicitly instead
of linking against the library shipped with ROCm. This change prevents
issues arising from the order in which the AMDGCN libraries are linked.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D59822356
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary:
This patch constructs the AMDGCN ISA control variable explicitly instead
of linking against the library shipped with ROCm. This change prevents
issues arising from the order in which the AMDGCN libraries are linked.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251532
@fabianmcg fabianmcg deleted the pr-fix-amdgcn-isa branch August 5, 2024 12:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants