已合并
refactor: 提取 ASCIR 节点参数创建逻辑 #1759
gaoxin创建于 8月17日
refactor: 提取 ASCIR 节点参数创建逻辑 #1759
已合并
共 5 个文件变更+43-20
| @@ -57,6 +57,20 @@ AscirNodeParamsPtr GetAscirNodeParams(af::AscNodePtr node) { | |||
| 57 | return op_desc->TryGetExtAttr(kAscirNodeParams, AscirNodeParamsPtr{}); | 57 | return op_desc->TryGetExtAttr(kAscirNodeParams, AscirNodeParamsPtr{}); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | +AscirNodeParamsPtr GetOrCreateAscirNodeParams(af::AscNodePtr node) { | ||
| 61 | + GE_ASSERT_NOTNULL(node); | ||
| 62 | + auto params = GetAscirNodeParams(node); | ||
| 63 | + if (params != nullptr) { | ||
| 64 | + return params; | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + auto op_desc = node->GetOpDesc(); | ||
| 68 | + GE_ASSERT_NOTNULL(op_desc); | ||
| 69 | + params = std::make_shared<AscirNodeParams>(); | ||
| 70 | + GE_ASSERT_TRUE(op_desc->SetExtAttr(kAscirNodeParams, params), "Node:%s SetExtAttr failed", node->GetNamePtr()); | ||
| 71 | + return params; | ||
| 72 | +} | ||
| 73 | + | ||
| 60 | const codegen::ReduceSpecificParams &GetCanonicalReduceParams(const ReduceNodeParams ¶ms) { | 74 | const codegen::ReduceSpecificParams &GetCanonicalReduceParams(const ReduceNodeParams ¶ms) { |
| 61 | return params.canonical_params; | 75 | return params.canonical_params; |
| 62 | } | 76 | } |
| @@ -118,6 +118,7 @@ struct AscirNodeParams { | |||
| 118 | using AscirNodeParamsPtr = std::shared_ptr<AscirNodeParams>; | 118 | using AscirNodeParamsPtr = std::shared_ptr<AscirNodeParams>; |
| 119 | 119 | ||
| 120 | AscirNodeParamsPtr GetAscirNodeParams(af::AscNodePtr node); | 120 | AscirNodeParamsPtr GetAscirNodeParams(af::AscNodePtr node); |
| 121 | +AscirNodeParamsPtr GetOrCreateAscirNodeParams(af::AscNodePtr node); | ||
| 121 | const codegen::ReduceSpecificParams &GetCanonicalReduceParams(const ReduceNodeParams ¶ms); | 122 | const codegen::ReduceSpecificParams &GetCanonicalReduceParams(const ReduceNodeParams ¶ms); |
| 122 | ge::Expression ResolveForAtt(const ParamExprProduct &expr); | 123 | ge::Expression ResolveForAtt(const ParamExprProduct &expr); |
| 123 | af::Status ValidateReduceNodeParams(const ReduceNodeParams ¶ms); | 124 | af::Status ValidateReduceNodeParams(const ReduceNodeParams ¶ms); |
| @@ -0,0 +1,26 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include <gtest/gtest.h> | ||
| 12 | + | ||
| 13 | +#include "ascir_node_param/ascir_node_param.h" | ||
| 14 | +#include "ascir_ops.h" | ||
| 15 | + | ||
| 16 | +TEST(AscirNodeParamsStTest, GetOrCreateAscirNodeParamsStoresCreatedParams) { | ||
| 17 | + af::AscGraph graph("test_graph"); | ||
| 18 | + af::ascir_op::Add add_op("add"); | ||
| 19 | + graph.AddNode(add_op); | ||
| 20 | + auto node = graph.FindNode("add"); | ||
| 21 | + ASSERT_NE(node, nullptr); | ||
| 22 | + | ||
| 23 | + const auto params = ascir_param::GetOrCreateAscirNodeParams(node); | ||
| 24 | + ASSERT_NE(params, nullptr); | ||
| 25 | + EXPECT_EQ(ascir_param::GetAscirNodeParams(node), params); | ||
| 26 | +} | ||
| @@ -9,7 +9,6 @@ | |||
| 9 | */ | 9 | */ |
| 10 | #include "cast_v2_api_call.h" | 10 | #include "cast_v2_api_call.h" |
| 11 | 11 | ||
| 12 | -#include <memory> | ||
| 13 | #include <sstream> | 12 | #include <sstream> |
| 14 | #include "attr_utils.h" | 13 | #include "attr_utils.h" |
| 15 | #include "ascir_ops.h" | 14 | #include "ascir_ops.h" |
| @@ -30,19 +29,11 @@ using namespace af::ascir_op; | |||
| 30 | using namespace ascgen_utils; | 29 | using namespace ascgen_utils; |
| 31 | 30 | ||
| 32 | namespace { | 31 | namespace { |
| 33 | -constexpr const char *kAscirNodeParams = "AscirNodeParams"; | ||
| 34 | - | ||
| 35 | af::Status FillCastNodeParams(const af::AscNodePtr &node, const std::vector<ge::Expression> &output_dims, | 32 | af::Status FillCastNodeParams(const af::AscNodePtr &node, const std::vector<ge::Expression> &output_dims, |
| 36 | const std::vector<ge::Expression> &output_strides, | 33 | const std::vector<ge::Expression> &output_strides, |
| 37 | const std::vector<ge::Expression> &input_strides) { | 34 | const std::vector<ge::Expression> &input_strides) { |
| 38 | GE_ASSERT_NOTNULL(node); | 35 | GE_ASSERT_NOTNULL(node); |
| 39 | - auto params = ascir_param::GetAscirNodeParams(node); | 36 | + auto params = ascir_param::GetOrCreateAscirNodeParams(node); |
| 40 | - if (params == nullptr) { | ||
| 41 | - auto op_desc = node->GetOpDesc(); | ||
| 42 | - GE_ASSERT_NOTNULL(op_desc); | ||
| 43 | - params = std::make_shared<ascir_param::AscirNodeParams>(); | ||
| 44 | - GE_ASSERT_TRUE(op_desc->SetExtAttr(kAscirNodeParams, params), "Node:%s SetExtAttr failed", node->GetNamePtr()); | ||
| 45 | - } | ||
| 46 | 37 | ||
| 47 | auto *cast_params = std::get_if<ascir_param::CastNodeParams>(¶ms->specific_params); | 38 | auto *cast_params = std::get_if<ascir_param::CastNodeParams>(¶ms->specific_params); |
| 48 | if (cast_params == nullptr) { | 39 | if (cast_params == nullptr) { |
| @@ -9,7 +9,6 @@ | |||
| 9 | */ | 9 | */ |
| 10 | #include "compare_v2_api_call.h" | 10 | #include "compare_v2_api_call.h" |
| 11 | 11 | ||
| 12 | -#include <memory> | ||
| 13 | #include <sstream> | 12 | #include <sstream> |
| 14 | #include "attr_utils.h" | 13 | #include "attr_utils.h" |
| 15 | #include "ascir_ops.h" | 14 | #include "ascir_ops.h" |
| @@ -30,20 +29,12 @@ using namespace af::ascir_op; | |||
| 30 | using namespace ascgen_utils; | 29 | using namespace ascgen_utils; |
| 31 | 30 | ||
| 32 | namespace { | 31 | namespace { |
| 33 | -constexpr const char *kAscirNodeParams = "AscirNodeParams"; | ||
| 34 | - | ||
| 35 | af::Status FillCompareNodeParams(const af::AscNodePtr &node, bool is_scalar, const ge::Expression &outer_call_count, | 32 | af::Status FillCompareNodeParams(const af::AscNodePtr &node, bool is_scalar, const ge::Expression &outer_call_count, |
| 36 | const std::vector<ge::Expression> &output_dims, | 33 | const std::vector<ge::Expression> &output_dims, |
| 37 | const std::vector<ge::Expression> &output_strides, | 34 | const std::vector<ge::Expression> &output_strides, |
| 38 | const std::vector<ge::Expression> &input_strides) { | 35 | const std::vector<ge::Expression> &input_strides) { |
| 39 | GE_ASSERT_NOTNULL(node); | 36 | GE_ASSERT_NOTNULL(node); |
| 40 | - auto params = ascir_param::GetAscirNodeParams(node); | 37 | + auto params = ascir_param::GetOrCreateAscirNodeParams(node); |
| 41 | - if (params == nullptr) { | ||
| 42 | - auto op_desc = node->GetOpDesc(); | ||
| 43 | - GE_ASSERT_NOTNULL(op_desc); | ||
| 44 | - params = std::make_shared<ascir_param::AscirNodeParams>(); | ||
| 45 | - GE_ASSERT_TRUE(op_desc->SetExtAttr(kAscirNodeParams, params), "Node:%s SetExtAttr failed", node->GetNamePtr()); | ||
| 46 | - } | ||
| 47 | 38 | ||
| 48 | auto *compare_params = std::get_if<ascir_param::CompareNodeParams>(¶ms->specific_params); | 39 | auto *compare_params = std::get_if<ascir_param::CompareNodeParams>(¶ms->specific_params); |
| 49 | if (compare_params == nullptr) { | 40 | if (compare_params == nullptr) { |
🟡 Medium Priority