Skip to content

Commit ac11083

Browse files
committed
[ssbuffer](feat) extend same depth cube merge scenario
Signed-off-by: fishofnanqi <1074959344@qq.com>
1 parent 053a63a commit ac11083

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

third_party/ascend/include/DynamicCVPipeline/ComputeBlockOpt/MergeCubeBlockPass.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class MergeCubeBlockPass
9999
BlockDependencyGraph &graph);
100100
bool checkSameSourceAndSink(int blockId1, int blockId2,
101101
BlockDependencyGraph &graph);
102+
bool hasSameDepth(int blockId1, int blockId2, BlockDependencyGraph &graph);
102103
bool checkNoCycle(int blockId1, int blockId2, BlockDependencyGraph &graph,
103104
const MemoryDependenceGraph &memGraph,
104105
ComputeBlockIdManager &bm);

third_party/ascend/lib/DynamicCVPipeline/ComputeBlockOpt/MergeCubeBlock.cpp

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -300,21 +300,28 @@ bool MergeCubeBlockPass::canMergeBlocks(
300300
}
301301

302302
// Step 2: Check if they have same source and sink with no other nodes
303-
if (!checkSameSourceAndSink(blockId1, blockId2, graph)) {
303+
if (checkSameSourceAndSink(blockId1, blockId2, graph)) {
304304
LDBG("Blocks " << blockId1 << " and " << blockId2
305-
<< " cannot merge: different source or sink\n");
306-
return false;
305+
<< " can merge: same source or sink\n");
306+
return true;
307307
}
308308

309309
// Step 3: Check if merging would create a cycle
310-
if (checkNoCycle(blockId1, blockId2, graph, memGraph, bm)) {
310+
if (!checkNoCycle(blockId1, blockId2, graph, memGraph, bm)) {
311311
LDBG("Blocks " << blockId1 << " and " << blockId2
312-
<< " can merge: no cycle detected\n");
313-
return true;
312+
<< "cannot merge: would create cycle\n");
313+
return false;
314314
}
315315

316+
// Step 4: cube block in the same depth
317+
if (hasSameDepth(blockId1, blockId2, graph)) {
318+
LDBG("Blocks " << blockId1 << " and " << blockId2
319+
<< " can merge: cube blocks have same depth\n");
320+
return true;
321+
}
322+
316323
LDBG("Blocks " << blockId1 << " and " << blockId2
317-
<< " cannot merge: would create cycle\n");
324+
<< " cannot merge: unsupport scenario\n");
318325
return false;
319326
}
320327

@@ -365,6 +372,20 @@ bool MergeCubeBlockPass::checkSameSourceAndSink(int blockId1, int blockId2,
365372
return true;
366373
}
367374

375+
bool MergeCubeBlockPass::hasSameDepth(int blockId1, int blockId2,
376+
BlockDependencyGraph &graph) {
377+
378+
// Get block nodes
379+
BlockNode *node1 = graph.getBlockNode(blockId1);
380+
BlockNode *node2 = graph.getBlockNode(blockId2);
381+
382+
if (!node1 || !node2) {
383+
return false;
384+
}
385+
386+
return node1->depth == node2->depth;
387+
}
388+
368389
llvm::SmallVector<int> MergeCubeBlockPass::filterBlocksByType(
369390
int blockId, llvm::SmallVector<int> blocks, BlockDependencyGraph &graph) {
370391

0 commit comments

Comments
 (0)