已合并
【PR】: [feat] 只对Load节点做L2CacheHint #2011
xchu42创建于 9月8日
【PR】: [feat] 只对Load节点做L2CacheHint #2011
已合并
共 1 个文件变更+20-4
| @@ -53,6 +53,24 @@ bool IsSmallTensor(const af::AscNodePtr &node) { | |||
| 53 | return is_small; | 53 | return is_small; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | +bool NeedSkipL2CacheHint(const af::AscNodePtr &node) { | ||
| 57 | + const auto &out_data_nodes = node->GetOutDataNodes(); | ||
| 58 | + if (out_data_nodes.empty()) { | ||
| 59 | + return false; | ||
| 60 | + } | ||
| 61 | + const auto out_node = std::dynamic_pointer_cast<af::AscNode>(out_data_nodes.at(0)); | ||
| 62 | + GE_ASSERT_NOTNULL(out_node); | ||
| 63 | + GE_CHK_BOOL_RET_SPECIAL_STATUS(out_data_nodes.size() > 1UL, true, | ||
| 64 | + "NeedSkipL2CacheHint node[%s] has multiple out data nodes.", node->GetNamePtr()); | ||
| 65 | + GE_CHK_BOOL_RET_SPECIAL_STATUS(ascgen_utils::IsNodeCacheable(out_data_nodes.at(0)), true, | ||
| 66 | + "NeedSkipL2CacheHint node[%s] out node is cacheable.", node->GetNamePtr()); | ||
| 67 | + GE_CHK_BOOL_RET_SPECIAL_STATUS(IsSmallTensor(out_node), true, | ||
| 68 | + "NeedSkipL2CacheHint node[%s] out node is small tensor.", node->GetNamePtr()); | ||
| 69 | + GE_CHK_BOOL_RET_SPECIAL_STATUS(!af::ops::IsOps<af::ascir_op::Load>(out_node), true, | ||
| 70 | + "NeedSkipL2CacheHint node[%s] out node is not Load.", node->GetNamePtr()); | ||
| 71 | + return false; | ||
| 72 | +} | ||
| 73 | + | ||
| 56 | // 按index属性建立的IO节点映射: index -> 节点 | 74 | // 按index属性建立的IO节点映射: index -> 节点 |
| 57 | struct IoNodeIndexMap { | 75 | struct IoNodeIndexMap { |
| 58 | std::map<int64_t, af::NodePtr> inputs; | 76 | std::map<int64_t, af::NodePtr> inputs; |
| @@ -380,7 +398,7 @@ af::Status L2CacheHintManager::MarkInternal(af::AscGraph &impl_graph) { | |||
| 380 | index_to_data_nodes[index].emplace_back(std::dynamic_pointer_cast<af::AscNode>(node)); | 398 | index_to_data_nodes[index].emplace_back(std::dynamic_pointer_cast<af::AscNode>(node)); |
| 381 | } | 399 | } |
| 382 | 400 | ||
| 383 | - // 再次遍历所有Data节点: 若该节点的index对应多个Data节点, 或该节点有多个OutDataNodes, 则标记_skip_l2_cache_hint | 401 | + // 再次遍历所有Data节点: 若该节点的index对应多个Data节点, 或其输出节点满足跳过条件(见NeedSkipL2CacheHint), 则标记 |
| 384 | for (const auto &node : impl_graph.GetAllNodes()) { | 402 | for (const auto &node : impl_graph.GetAllNodes()) { |
| 385 | GE_ASSERT_NOTNULL(node, "MarkInternal node is nullptr."); | 403 | GE_ASSERT_NOTNULL(node, "MarkInternal node is nullptr."); |
| 386 | if (!af::ops::IsOps<af::ascir_op::Data>(node)) { | 404 | if (!af::ops::IsOps<af::ascir_op::Data>(node)) { |
| @@ -392,9 +410,7 @@ af::Status L2CacheHintManager::MarkInternal(af::AscGraph &impl_graph) { | |||
| 392 | if (out_data_nodes.empty()) { | 410 | if (out_data_nodes.empty()) { |
| 393 | continue; | 411 | continue; |
| 394 | } | 412 | } |
| 395 | - const auto out_node = std::dynamic_pointer_cast<af::AscNode>(out_data_nodes.at(0)); | 413 | + const bool need_skip = (index_to_data_nodes[index].size() > 1UL) || NeedSkipL2CacheHint(node); |
| 396 | - const bool need_skip = (index_to_data_nodes[index].size() > 1UL) || (out_data_nodes.size() > 1UL) || | ||
| 397 | - ascgen_utils::IsNodeCacheable(out_data_nodes.at(0)) || IsSmallTensor(out_node); | ||
| 398 | if (!need_skip) { | 414 | if (!need_skip) { |
| 399 | continue; | 415 | continue; |
| 400 | } | 416 | } |