2222
2323#include " ascend/include/DynamicCVPipeline/AnalyzeDataFlow.h"
2424#include " ascend/include/DynamicCVPipeline/Common/Utils.h"
25+ #include " bishengir/Dialect/HIVM/IR/HIVM.h"
26+ #include " bishengir/Dialect/Scope/IR/Scope.h"
27+ #include " mlir/Dialect/Arith/IR/Arith.h"
2528#include " mlir/Dialect/Func/IR/FuncOps.h"
29+ #include " mlir/Dialect/Linalg/IR/Linalg.h"
2630#include " mlir/Dialect/SCF/IR/SCF.h"
2731#include " mlir/IR/BuiltinTypes.h"
2832#include " llvm/ADT/DenseMap.h"
@@ -45,8 +49,7 @@ using namespace triton;
4549namespace {
4650
4751static constexpr llvm::StringLiteral containedFunc[]{
48- " chunk_gated_delta_rule_bwd_kernel_dhu_k128_blockdim128" ,
49- " fused_chunk_fwd_kernel" ,
52+ " fused_chunk_ttt_linear_bwd_kernel_h" ,
5053};
5154
5255static LogicalResult isInterceptedModule (ModuleOp module ) {
@@ -201,6 +204,87 @@ bool checkTensorArgsInMainLoop(ModuleOp module) {
201204 return shouldReturn;
202205}
203206
207+ // Check VECTOR main_loop forOps: if a tensor arith.subf op has both operands
208+ // from linalg.broadcast ops sharing the same source, and the subf op's
209+ // block_id differs from the source op's block_id, fallback.
210+ static bool checkSubfBroadcastMismatchInVectorMainLoop (ModuleOp module ) {
211+ bool shouldFallback = false ;
212+
213+ module .walk ([&](Operation *op) -> WalkResult {
214+ if (!op->hasAttr (CVPipeline::kMainLoop )) {
215+ return WalkResult::advance ();
216+ }
217+ auto forOp = dyn_cast<scf::ForOp>(op);
218+ if (!forOp) {
219+ return WalkResult::advance ();
220+ }
221+
222+ scope::ScopeOp scopeOp = forOp->getParentOfType <scope::ScopeOp>();
223+ if (!scopeOp) {
224+ return WalkResult::advance ();
225+ }
226+ auto tcoreAttr =
227+ scopeOp->getAttrOfType <hivm::TCoreTypeAttr>(CVPipeline::kTcoreType );
228+ if (!tcoreAttr || tcoreAttr.getTcoretype () != hivm::TCoreType::VECTOR ) {
229+ return WalkResult::advance ();
230+ }
231+
232+ Block *body = forOp.getBody ();
233+ if (!body) {
234+ return WalkResult::advance ();
235+ }
236+
237+ for (Operation &bodyOp : body->without_terminator ()) {
238+ auto subfOp = dyn_cast<arith::SubFOp>(&bodyOp);
239+ if (!subfOp || !isa<RankedTensorType>(subfOp.getType ())) {
240+ continue ;
241+ }
242+
243+ Operation *lhsDef = subfOp.getLhs ().getDefiningOp ();
244+ Operation *rhsDef = subfOp.getRhs ().getDefiningOp ();
245+ if (!lhsDef || !rhsDef) {
246+ continue ;
247+ }
248+
249+ auto lhsBroadcast = dyn_cast<linalg::BroadcastOp>(lhsDef);
250+ auto rhsBroadcast = dyn_cast<linalg::BroadcastOp>(rhsDef);
251+ if (!lhsBroadcast || !rhsBroadcast) {
252+ continue ;
253+ }
254+
255+ Value lhsInput = lhsBroadcast.getInput ();
256+ Value rhsInput = rhsBroadcast.getInput ();
257+ if (lhsInput != rhsInput) {
258+ continue ;
259+ }
260+
261+ Operation *sourceOp = lhsInput.getDefiningOp ();
262+ if (!sourceOp) {
263+ continue ;
264+ }
265+
266+ auto subfBlockIdAttr =
267+ subfOp->getAttrOfType <IntegerAttr>(CVPipeline::kBlockId );
268+ auto sourceBlockIdAttr =
269+ sourceOp->getAttrOfType <IntegerAttr>(CVPipeline::kBlockId );
270+ if (!subfBlockIdAttr || !sourceBlockIdAttr) {
271+ continue ;
272+ }
273+
274+ if (subfBlockIdAttr.getInt () != sourceBlockIdAttr.getInt ()) {
275+ LDBG (" [INFO]: Found subf and broadcast source with different "
276+ " block_ids in VECTOR main_loop!\n " );
277+ shouldFallback = true ;
278+ return WalkResult::interrupt ();
279+ }
280+ }
281+
282+ return WalkResult::advance ();
283+ });
284+
285+ return shouldFallback;
286+ }
287+
204288void AnalyzeArgsPass::runOnOperation () {
205289 ModuleOp module = getOperation ();
206290
@@ -211,10 +295,12 @@ void AnalyzeArgsPass::runOnOperation() {
211295 LDBG (" Before AnalyzeArgs:\n " << module << " \n " );
212296
213297 if (failed (isInterceptedModule (module ))) {
298+ CVPipeline::setFallbackAttr (module , CVPipeline::ERRCODE_IGNORED );
214299 return ;
215300 }
216301
217- if (checkTensorArgsInMainLoop (module )) {
302+ if (checkTensorArgsInMainLoop (module ) &&
303+ checkSubfBroadcastMismatchInVectorMainLoop (module )) {
218304 CVPipeline::setFallbackAttr (module , CVPipeline::ERRCODE_IGNORED );
219305 return ;
220306 }
0 commit comments