Skip to content

Commit 465cacf

Browse files
committed
[ssbuffer](feat) extend scenario of merge cube block
Signed-off-by: fishofnanqi <1074959344@qq.com>
1 parent 62d45bb commit 465cacf

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
@@ -303,21 +303,28 @@ bool MergeCubeBlockPass::canMergeBlocks(
303303
}
304304

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

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

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

@@ -368,6 +375,20 @@ bool MergeCubeBlockPass::checkSameSourceAndSink(int blockId1, int blockId2,
368375
return true;
369376
}
370377

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

0 commit comments

Comments
 (0)