Skip to content

Disable rock.arch="native" by default for BUILD_FAT_LIBROCKCOMPILER#2364

Merged
umangyadav merged 1 commit intodevelopfrom
disableHIP
May 6, 2026
Merged

Disable rock.arch="native" by default for BUILD_FAT_LIBROCKCOMPILER#2364
umangyadav merged 1 commit intodevelopfrom
disableHIP

Conversation

@umangyadav
Copy link
Copy Markdown
Member

@umangyadav umangyadav commented May 6, 2026

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_comgr depends on libLLVM. 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:

  • 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.

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.

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>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 for BUILD_FAT_LIBROCKCOMPILER, ON otherwise).
  • Gate HIP/HSA discovery/linking and the rock.arch="native" implementation in AmdArchDb.cpp behind ROCMLIR_ENABLE_NATIVE_ARCH.
  • Avoid exporting/propagating hsa-runtime64 to 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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 2026

Codecov Report

❌ Patch coverage is 0% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/lib/Dialect/Rock/IR/AmdArchDb.cpp 0.00% 3 Missing ⚠️
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     
Flag Coverage Δ
gfx950 80.37% <0.00%> (?)
mfma ?
navi4x 80.33% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
mlir/lib/Dialect/Rock/IR/AmdArchDb.cpp 73.77% <0.00%> (ø)

... and 104 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@umangyadav umangyadav merged commit 1f6c419 into develop May 6, 2026
11 of 19 checks passed
@umangyadav umangyadav deleted the disableHIP branch May 6, 2026 22:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants