From 1184a63cd54afb5242decc79a9fee83d81678209 Mon Sep 17 00:00:00 2001 From: kirmatam Date: Sat, 1 Aug 2026 11:43:54 -0500 Subject: [PATCH 1/2] fix(promote-strided): include hip.npi_* ops in strided-input promotion Co-Authored-By: Claude --- lib/Dialect/Transforms/PromoteStridedHipOperands.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Dialect/Transforms/PromoteStridedHipOperands.cpp b/lib/Dialect/Transforms/PromoteStridedHipOperands.cpp index 46bccbef6..b74d80656 100644 --- a/lib/Dialect/Transforms/PromoteStridedHipOperands.cpp +++ b/lib/Dialect/Transforms/PromoteStridedHipOperands.cpp @@ -147,8 +147,17 @@ void PromoteStridedHipOperandsPass::runOnOperation() { // ops) does not invalidate the walk. SmallVector consumers; funcOp.walk([&](DestinationStyleOpInterface dpsOp) { + // Include all HIP-namespace DPS ops: the upstream HipDialect ops AND any + // NPI plugin ops (hip.npi_quantize, hip.npi_dequantize, etc.) that live in + // NpiDialect but use the hip.* namespace and the same contiguous-pointer ABI. + // Excluding NPI ops causes strided subview inputs (e.g. the K/V slices from + // onnx.Split → memref.subview) to be passed directly to hip.npi_quantize, + // whose kernel reads them as flat arrays, silently producing wrong values. + // Accept HipDialect ops AND NPI plugin ops (dialect namespace "npi" but + // op name "hip.npi_*"). Both use the hip.* namespace and the same ABI. Operation *op = dpsOp.getOperation(); - if (op->getDialect() != op->getContext()->getLoadedDialect()) + llvm::StringRef fullOpName = op->getName().getStringRef(); + if (!fullOpName.starts_with("hip.")) return; consumers.push_back(dpsOp); }); @@ -162,7 +171,6 @@ void PromoteStridedHipOperandsPass::runOnOperation() { continue; tmps.push_back(materializeContiguousCopy(*input, consumer)); } - // Emit deallocs in the same order as the allocations (TA, TB, ...). // Without anchoring, repeated `setInsertionPointAfter(consumer)` would // push each new dealloc directly after the consumer, reversing the From 07eedbcc3ca9f84c51ccf640c15d81765ac66b4e Mon Sep 17 00:00:00 2001 From: kirmatam Date: Sun, 2 Aug 2026 16:22:12 -0500 Subject: [PATCH 2/2] fix(promote-strided): tighten comment and restore blank line Collapse the duplicate comment block into a single coherent explanation and restore the blank line between the copy-materialization loop and the dealloc-emission comment that was inadvertently removed. Co-Authored-By: Claude --- .../Transforms/PromoteStridedHipOperands.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Dialect/Transforms/PromoteStridedHipOperands.cpp b/lib/Dialect/Transforms/PromoteStridedHipOperands.cpp index b74d80656..b6120b744 100644 --- a/lib/Dialect/Transforms/PromoteStridedHipOperands.cpp +++ b/lib/Dialect/Transforms/PromoteStridedHipOperands.cpp @@ -147,14 +147,12 @@ void PromoteStridedHipOperandsPass::runOnOperation() { // ops) does not invalidate the walk. SmallVector consumers; funcOp.walk([&](DestinationStyleOpInterface dpsOp) { - // Include all HIP-namespace DPS ops: the upstream HipDialect ops AND any - // NPI plugin ops (hip.npi_quantize, hip.npi_dequantize, etc.) that live in - // NpiDialect but use the hip.* namespace and the same contiguous-pointer ABI. - // Excluding NPI ops causes strided subview inputs (e.g. the K/V slices from - // onnx.Split → memref.subview) to be passed directly to hip.npi_quantize, - // whose kernel reads them as flat arrays, silently producing wrong values. - // Accept HipDialect ops AND NPI plugin ops (dialect namespace "npi" but - // op name "hip.npi_*"). Both use the hip.* namespace and the same ABI. + // Match on op-name prefix rather than dialect object: NPI plugin ops + // (hip.npi_quantize, hip.npi_dequantize, etc.) live in NpiDialect but + // carry "hip.*" names and the same contiguous-pointer ABI. The old + // dialect-object check excluded them, causing strided subview inputs + // (e.g. Q/K/V slices from onnx.Split) to be passed uncopied to NPI + // kernels that read them as flat arrays, producing wrong values. Operation *op = dpsOp.getOperation(); llvm::StringRef fullOpName = op->getName().getStringRef(); if (!fullOpName.starts_with("hip.")) @@ -171,6 +169,7 @@ void PromoteStridedHipOperandsPass::runOnOperation() { continue; tmps.push_back(materializeContiguousCopy(*input, consumer)); } + // Emit deallocs in the same order as the allocations (TA, TB, ...). // Without anchoring, repeated `setInsertionPointAfter(consumer)` would // push each new dealloc directly after the consumer, reversing the