Skip to content

[Target] Adopt kernel triple and data layout for device libraries - #2467

Open
ppetrovi-amd wants to merge 1 commit into
developfrom
users/ppetrovi/device-lib-triple-layout
Open

ppetrovi-amd wants to merge 1 commit into
developfrom
users/ppetrovi/device-lib-triple-layout

Conversation

@ppetrovi-amd

@ppetrovi-amd ppetrovi-amd commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

When rocMLIR is built against a ROCm install whose device libraries were compiled by a newer LLVM than rocMLIR's own, every kernel that calls OCML/OCKL prints two IR linker warnings. The libraries use the amdgpu-amd-amdhsa triple and a data layout with extra address spaces (p10–p15), which do not match the kernel module.

Technical Details

Libraries loaded from disk already go through SerializeGPUModuleBase::handleBitcodeFile, which sets our triple and data layout. The packaged device libraries in AMDGPUSerializer::loadBitcodeFiles skipped it; they now go through handleBitcodeFile too.
Generated instructions are unchanged. As for libraries loaded from disk, the packaged libraries' llvm.ident and opencl.ocl.version metadata are now dropped, so kernels using OCML/OCKL no longer report OpenCL C as their language.

Test Plan

  • Ran a MIGraphX model (gfrg-v3-fp32-512x512) with rocMLIR built against a ROCm install with newer device libraries, before and after the change.
  • New lit test mlir/test/Target/packaged-device-libs.mlir. Built against newer device libraries, it reproduces both warnings without the fix and passes with it.
  • PR CI

Test Result

  • Linker warnings no longer printed; inference time unchanged.
  • PR CI

Submission Checklist

@ppetrovi-amd
ppetrovi-amd requested a balanced review from Copilot and removed request for causten September 30, 2026 15:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

The packaged-library normalization lacks automated regression coverage.

Review effort: Balanced
Findings: 1 Low severity

Open (1)
What changed in this PR

Updates AMDGPU device-library linking to suppress LLVM triple and data-layout mismatch warnings.

Changes:

  • Applies the kernel module’s target triple and data layout to loaded device libraries.
File Description
mlir/​lib/​Target/​Target.cpp Normalizes device-library target metadata before linking.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread mlir/lib/Target/Target.cpp Outdated
Comment on lines +150 to +152
for (std::unique_ptr<llvm::Module> &library : bcFiles) {
library->setTargetTriple(module.getTargetTriple());
library->setDataLayout(module.getDataLayout());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added mlir/test/Target/packaged-device-libs.mlir. It links the packaged OCML through gpu-module-to-binary and checks that no "Linking two modules" warning is printed.

While writing it I found that libraries loaded from disk already go through handleBitcodeFile, which sets our triple and data layout; only the packaged path skipped it. The fix now calls handleBitcodeFile for packaged libraries instead of normalizing every library.

The test only fails on a regression when rocMLIR is built against device libraries from a newer LLVM; with matching libraries there's no mismatch to warn about.

Libraries loaded from disk go through handleBitcodeFile, which gives
them our triple and data layout, but packaged device libraries skipped
it. When those are built by a newer LLVM than ours (amdgpu-amd-amdhsa
triple, extra address spaces in the data layout), the IR linker warned
twice for every kernel that calls OCML/OCKL. Run packaged libraries
through handleBitcodeFile too.

Generated instructions are unchanged. As for libraries loaded from
disk, the packaged libraries' llvm.ident and opencl.ocl.version
metadata are now dropped, so kernels using OCML/OCKL no longer report
OpenCL C as their language.
@ppetrovi-amd
ppetrovi-amd force-pushed the users/ppetrovi/device-lib-triple-layout branch from 46f22a9 to 4dd432e Compare October 1, 2026 12:43
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.

2 participants