Skip to content

[AIROCMLIR-602] Add MHAL dialect lit coverage#2394

Draft
bogdan-petkovic wants to merge 6 commits into
developfrom
users/bpetkovi/AIROCMLIR-602-mhal-coverage
Draft

[AIROCMLIR-602] Add MHAL dialect lit coverage#2394
bogdan-petkovic wants to merge 6 commits into
developfrom
users/bpetkovi/AIROCMLIR-602-mhal-coverage

Conversation

@bogdan-petkovic
Copy link
Copy Markdown
Contributor

@bogdan-petkovic bogdan-petkovic commented Jun 1, 2026

Motivation

The MHAL dialect (vendored under external/mlir-hal/) currently has very thin lit coverage, roughly 32% of its source lines are exercised, and one of its conversion passes (--convert-mhal-to-gpu) was not even reachable from rocmlir-opt because its tablegen-generated registration function was never called. This PR closes both gaps:

  1. Wires registerMHALConversionPasses() into rocMLIR's CLI-pass registration entry point, so --convert-mhal-to-gpu is now discoverable from rocmlir-opt --help and can be driven by lit tests.

  2. Adds eight new lit tests under mlir/test/Dialect/MHAL/ that systematically exercise every MHAL transform pass, the MHAL→GPU conversion pass, and all three custom MHAL attributes (round-trip).

The goal is to catch regressions in MHAL parsing/printing and in the pass pipeline at lit time, instead of requiring a full host+device E2E build, and to make any future refactor in external/mlir-hal/lib/Dialect/MHAL/Transforms/ and lib/Conversion/MHALToGPU/ immediately observable.

Technical Details

Source change — mlir/include/mlir/InitRocMLIRPasses.h (+5 lines)
MHAL declares its passes in two separate tablegen groups: Dialect/MHAL/Transforms/Passes.td (registered via registerMHALPasses() in vendored InitMHALPasses.h) and Conversion/MHALPasses.td with -name MHALConversion (registered via the generated registerMHALConversionPasses()). The conversion group was implemented but never wired into any registration entry point, so --convert-mhal-to-gpu was unreachable from rocmlir-opt. This PR adds the missing registerMHALConversionPasses() call inside registerRocMLIRPasses(), with an inline comment explaining the asymmetric tablegen grouping.

The fix is intentionally in rocMLIR-owned code (not in external/mlir-hal/) so the whole patch stays under a single AIROCMLIR-602 commit and adds no merge surface to the in-flight MHAL decoupling work (#2333, #2325).

Tests — 8 new files under mlir/test/Dialect/MHAL/ (+~1000 lines)
attrs-roundtrip.mlir — Custom parse/print for #mhal.target_obj, #mhal.kernel_pkg, #mhal.prefill. Pretty- and generic-printer round-trip; all TargetObjectType and TargetType keywords.

bufferize.mlir — --mhal-bufferize post-#2333 no-op path; preserves MHAL arg attrs and mhal.targets.

convert-mhal-to-gpu.mlir — --convert-mhal-to-gpu: alloc / memcpy / launch / wait; write_access copy-back; GPU-over-CPU selection; explicit negative checks for no-targets and CPU-only callees; scalar operand path.

drop-metadata.mlir — --mhal-drop-binary-metadata: strips properties/kernels; fat-binary across two arches; idempotence; top-level-only isolation.

package-targets.mlir — --mhal-package-targets: single-arch and multi-arch (CHECK-DAG); multiple binaries per kernel module; unmarked nested module and dangling original_func skipped.

prefill.mlir — --mhal-prefill: one/many prefills; f16/i8/i32 element-type matching with non-zero argIdx; missing properties key/dict; mixed-attr dyn_cast filter.

select-targets.mlir — --mhal-select-targets happy paths (4 RUN configurations): arch filter, type filter, last-match-wins, empty target-types wildcard, triple-vs-chip-only SystemDevice::isCompatible.

select-targets-error.mlir — --mhal-select-targets error path with --verify-diagnostics: CPU-only-with-GPU-required, GPU-arch-mismatch, multi-non-matching-packages.

Each test file's leading // COM: comments cite the exact external/mlir-hal/lib/... source file (and line numbers, where relevant) being exercised.

Test Plan

PR CI

Test Result

  • PR CI

Submission Checklist

Signed-off-by: bogdan-petkovic <bpetkovi@amd.com>
@bogdan-petkovic bogdan-petkovic self-assigned this Jun 1, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2394      +/-   ##
===========================================
+ Coverage    79.50%   82.40%   +2.89%     
===========================================
  Files          100      120      +20     
  Lines        31016    42830   +11814     
  Branches      4819     7112    +2293     
===========================================
+ Hits         24659    35291   +10632     
- Misses        4245     4881     +636     
- Partials      2112     2658     +546     
Flag Coverage Δ
gfx950 82.28% <100.00%> (?)
mfma 82.27% <100.00%> (+2.77%) ⬆️

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

Files with missing lines Coverage Δ
mlir/include/mlir/InitRocMLIRPasses.h 100.00% <100.00%> (ø)

... and 122 files with indirect coverage changes

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

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.

1 participant