Disable rock.arch="native" by default for BUILD_FAT_LIBROCKCOMPILER#2364
Merged
umangyadav merged 1 commit intodevelopfrom May 6, 2026
Merged
Disable rock.arch="native" by default for BUILD_FAT_LIBROCKCOMPILER#2364umangyadav merged 1 commit intodevelopfrom
umangyadav merged 1 commit intodevelopfrom
Conversation
The rock.arch="native" runtime detection in AmdArchDb.cpp is the only code path in librockCompiler that needs HIP and HSA at link time. With the fat library, those undefined symbols force every consumer (e.g. MIGraphX) to DT_NEEDED libamdhip64 / libhsa-runtime64 via rocMLIR, which in turn lets libamdhip64 dlopen libamd_comgr at runtime even when the consumer only ever passes a concrete arch like "gfx942" to rocMLIR. Add a new ROCMLIR_ENABLE_NATIVE_ARCH cache option (default OFF for the fat lib build, ON for the shared-lib build) that gates: - find_package(hip)/find_package(hsa-runtime64) and the corresponding target_link_libraries on MLIRRockOps - the HIP/HSA includes and the nativeArchInfo namespace in AmdArchDb.cpp, with lookupArchInfo now reporting a clear llvm_unreachable when the "native" arch is requested in a build that doesn't support it - the AmdArchDbTests unit test, which directly includes hip_runtime_api.h - the hsa-runtime64 INTERFACE_LINK_LIBRARIES propagation and the find_dependency(hsa-runtime64) entry in the exported rocMLIRConfig.cmake, so consumers no longer pick up HSA via rocMLIR when there is no HSA in the static archive Users that still want native-arch detection with the fat lib can opt back in explicitly with -DROCMLIR_ENABLE_NATIVE_ARCH=ON. Co-authored-by: Cursor <cursoragent@cursor.com>
justinrosner
approved these changes
May 6, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a build-time switch to disable rock.arch="native" runtime arch detection by default when producing the BUILD_FAT_LIBROCKCOMPILER fat static archive, preventing transitive HIP/HSA linkage from being imposed on downstream consumers (and avoiding runtime crashes caused by multiple LLVMs in-process).
Changes:
- Add a new cache option
ROCMLIR_ENABLE_NATIVE_ARCH(default OFF forBUILD_FAT_LIBROCKCOMPILER, ON otherwise). - Gate HIP/HSA discovery/linking and the
rock.arch="native"implementation inAmdArchDb.cppbehindROCMLIR_ENABLE_NATIVE_ARCH. - Avoid exporting/propagating
hsa-runtime64to consumers (and skip the HIP-dependent unit test) when native-arch support is disabled.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| CMakeLists.txt | Defines ROCMLIR_ENABLE_NATIVE_ARCH defaults depending on fat-lib vs shared-lib builds. |
| mlir/lib/Dialect/Rock/IR/CMakeLists.txt | Gates HIP/HSA find_package + linkage and defines ROCMLIR_ENABLE_NATIVE_ARCH for the Rock ops object library when enabled. |
| mlir/lib/Dialect/Rock/IR/AmdArchDb.cpp | Compiles HIP/HSA-backed native arch detection only when enabled; otherwise native requests llvm_unreachable with a clear message. |
| mlir/tools/rocmlir-lib/CMakeLists.txt | Stops exporting/propagating hsa-runtime64 dependency for the fat archive unless native arch support is enabled. |
| mlir/unittests/Dialect/Rock/CMakeLists.txt | Skips AmdArchDbTests.cpp when native arch support is disabled (or on Windows). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dorde-antic
approved these changes
May 6, 2026
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #2364 +/- ##
===========================================
+ Coverage 79.50% 80.49% +0.98%
===========================================
Files 100 125 +25
Lines 31016 42473 +11457
Branches 4819 6990 +2171
===========================================
+ Hits 24659 34186 +9527
- Misses 4245 5663 +1418
- Partials 2112 2624 +512
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The rock.arch="native" runtime detection in AmdArchDb.cpp is the only code path in librockCompiler that needs HIP and HSA at link time. With the fat library, those undefined symbols force every consumer (e.g. MIGraphX) to DT_NEEDED libamdhip64 / libhsa-runtime64 via rocMLIR, which in turn lets libamdhip64 dlopen libamd_comgr at runtime even when the consumer only ever passes a concrete arch like "gfx942" to rocMLIR.
libamd_comgrdepends onlibLLVM. Therefore it causes two different LLVM libs active in the same process which leads to runtime crash.Technical Details
Add a new ROCMLIR_ENABLE_NATIVE_ARCH cache option (default OFF for the fat lib build, ON for the shared-lib build) that gates:
Users that still want native-arch detection with the fat lib can opt back in explicitly with -DROCMLIR_ENABLE_NATIVE_ARCH=ON.
Test Plan
Tested on the TheRock nightly builds with MIGraphX. Crash due to multiple LLVM is not happening and all tests are passing both on rocMLIR and also on MIGraphX side.