Commit 2276637
committed
Enforce rocmlirMIGraphXAttentionCreate input contract in release builds
The previous round of C API hardening guarded the entry-point arguments
with assert(), which compiles to a no-op under NDEBUG. Release-build
callers that violated the contract (NULL queries / keys / values, NULL
preSoftmaxElemWiseInputs with a non-zero count, negative splitKV /
slidingWindowSize / numPreSoftmaxInputs, NULL resultType) would still
fall through to the same confusing failure modes the assertions were
meant to prevent: NULL deref while iterating the inputs array, "no Q
operand" diagnostics on a half-built op, or splitKV silently dropped.
Replace the asserts with `if (...) return reject(msg)` checks that fire
uniformly in debug and release builds, write a
"rocmlirMIGraphXAttentionCreate: <reason>" line to stderr (matching the
existing `mlirMIGraphXAddBackendPipeline` diagnostic style in this
file), and return a null MlirOperation. Callers can detect the failure
with mlirOperationIsNull. The order of checks now also catches a
negative numPreSoftmaxInputs before it is used as a loop bound, fixing
a subtle order-of-evaluation hazard in the previous assert chain.
Document the new contract in mlir-c/Dialect/MIGraphX.h: list every
condition that returns null and clarify that all *other* invariants
(operand element types, shape compatibility, feature/operand
consistency) are still enforced by the AttentionOp verifier rather
than by the C API. This matches what the implementation actually does
and lets callers distinguish "I gave it garbage" (null return,
detectable here) from "the verifier rejected my IR" (verified op
returned but parsing/verification fails later).
Existing CAPI tests (mlir/test/CAPI/mixr_attention.c) continue to pass
unchanged because they always provide valid inputs.
Made-with: Cursor1 parent 2bc70e5 commit 2276637
2 files changed
Lines changed: 40 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
108 | 119 | | |
109 | 120 | | |
110 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
170 | 170 | | |
171 | 171 | | |
172 | 172 | | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | | - | |
184 | | - | |
185 | | - | |
186 | | - | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
187 | 202 | | |
188 | 203 | | |
189 | 204 | | |
| |||
0 commit comments