Skip to content

[AIROCMLIR-494] Added verifier for migraphx.dot#2238

Merged
Mr-Anyone merged 4 commits intodevelopfrom
pr-migraphx-dot-verifier
Feb 12, 2026
Merged

[AIROCMLIR-494] Added verifier for migraphx.dot#2238
Mr-Anyone merged 4 commits intodevelopfrom
pr-migraphx-dot-verifier

Conversation

@Mr-Anyone
Copy link
Member

@Mr-Anyone Mr-Anyone commented Feb 11, 2026

Motivation

Add invariant for migraphx.dot operations. Previously, it was possible to lower A {3, 2, 2, 2} dot B {2, 3, 2, 2} invalid operation under the migraphx->tosa lowering path. Adding this verifier prevents that.

func.func @dot_invalid_broadcast(%arg0: !migraphx.shaped<3x2x2x2xf32, 8x4x2x1>, %arg1: !migraphx.shaped<2x3x2x2xf32, 12x4x2x1>) -> !migraphx.shaped<3x2x2x2xf32, 8x4x2x1> attributes {kernel, arch="gfx950"} {
  %0 = migraphx.dot %arg0, %arg1 : <3x2x2x2xf32, 8x4x2x1>, <2x3x2x2xf32, 12x4x2x1> -> <3x2x2x2xf32, 8x4x2x1>
  func.return %0 : !migraphx.shaped<3x2x2x2xf32, 8x4x2x1>
}

Technical Details

  1. Add shape verification to migraphx.dot and migraphx.quant_dot ops via a shared isValidDotOp helper
  2. Validates that all operands have rank >= 2
  3. Validates that the contraction dimension (last dim of A, second-to-last dim of B) matches
  4. Validates batch dimension compatibility: batch dims must either exactly match, or operand B may have all-ones batch dims (broadcasting), or have no batch dims at all (rank 2)
  5. Add positive tests in ops.mlir for valid broadcasting patterns (no batch on B, leading-ones batch on B)
  6. Add negative tests in invalid.mlir for rank < 2, incompatible inner dimensions, and mismatched batch dimensions

This implementation allows for A {3, 2, 2, 2} dot B {1, 2, 2}. Notice that the rank of A and B does not match, but B only has leading ones except the last two dimensions.

Test Plan

Added a lit test

Test Result

Passed lit test.

Submission Checklist

@Mr-Anyone Mr-Anyone requested a review from causten as a code owner February 11, 2026 22:41
@Mr-Anyone Mr-Anyone requested review from umangyadav and removed request for causten February 11, 2026 22:41
@umangyadav umangyadav requested a review from Copilot February 12, 2026 00:12
Copy link
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

Adds a verifier for migraphx.dot (and reuses it for migraphx.quant_dot) to prevent invalid dot shapes—especially invalid batch broadcasting—from being accepted during lowering.

Changes:

  • Introduce shared isValidDotOp verifier logic and wire it into dot/quant_dot.
  • Add positive MLIR tests for allowed broadcast patterns.
  • Add negative MLIR tests for rank/inner-dim/batch-dim mismatches.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
mlir/lib/Dialect/MIGraphX/IR/MIGraphX.cpp Adds shared dot verification logic and hooks it into DotOp and QuantDotOp.
mlir/include/mlir/Dialect/MIGraphX/IR/MIGraphX.td Enables verifier generation for migraphx.dot via hasVerifier.
mlir/test/Dialect/MIGraphX/ops.mlir Adds positive tests for valid dot broadcasting cases.
mlir/test/Dialect/MIGraphX/invalid.mlir Adds negative tests expecting verifier failures for invalid dot shapes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Mr-Anyone Mr-Anyone force-pushed the pr-migraphx-dot-verifier branch from 059bded to 38d85b4 Compare February 12, 2026 15:49
@Mr-Anyone Mr-Anyone merged commit 5d8f415 into develop Feb 12, 2026
7 of 14 checks passed
@Mr-Anyone Mr-Anyone deleted the pr-migraphx-dot-verifier branch February 12, 2026 19:32
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.

3 participants