已合并
修改aicpu算子的opgen自动生成算子工程的脚本及样例 #1098
Hou_jialin创建于 2月3日
修改aicpu算子的opgen自动生成算子工程的脚本及样例 #1098
已合并
共 14 个文件变更+31-82
| @@ -103,8 +103,13 @@ else() | |||
| 103 | endforeach() | 103 | endforeach() |
| 104 | endif() | 104 | endif() |
| 105 | 105 | ||
| 106 | -if("${ASCEND_OP_NAME}" STREQUAL "add_example") | 106 | +set(_orig_ops "${ASCEND_OP_NAME}") |
| 107 | - add_subdirectory(examples) | 107 | +list(LENGTH _orig_ops _orig_len) |
| 108 | +set(_filtered_ops "${_orig_ops}") | ||
| 109 | +list(FILTER _filtered_ops INCLUDE REGEX "add_example") | ||
| 110 | +list(LENGTH _filtered_ops _filtered_len) | ||
| 111 | +if(_filtered_len EQUAL _orig_len) | ||
| 112 | + add_subdirectory(examples) | ||
| 108 | endif() | 113 | endif() |
| 109 | 114 | ||
| 110 | if(ENABLE_TEST) | 115 | if(ENABLE_TEST) |
| @@ -11,7 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | -#include "aclnn_add_example_aicpu.h" | 14 | +#include "aclnn_add_example.h" |
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | do { \ | 17 | do { \ |
| @@ -43,7 +43,7 @@ void PrintOutResult(std::vector<int64_t>& shape, void** deviceAddr) | |||
| 43 | ACL_MEMCPY_DEVICE_TO_HOST); | 43 | ACL_MEMCPY_DEVICE_TO_HOST); |
| 44 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return); | 44 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("copy result from device to host failed. ERROR: %d\n", ret); return); |
| 45 | for (int64_t i = 0; i < size; i++) { | 45 | for (int64_t i = 0; i < size; i++) { |
| 46 | - LOG_PRINT("mean result[%ld] is: %f\n", i, resultData[i]); | 46 | + LOG_PRINT("add_example result[%ld] is: %f\n", i, resultData[i]); |
| 47 | } | 47 | } |
| 48 | } | 48 | } |
| 49 | 49 | ||
| @@ -26,9 +26,7 @@ | |||
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | -#include "experiment_ops.h" | 29 | +#include "../op_graph/add_example_proto.h" |
| 30 | - | ||
| 31 | - | ||
| 32 | 30 | ||
| 33 | 31 | ||
| 34 | 32 | ||
| @@ -179,7 +177,7 @@ int CreateOppInGraph(DataType inDtype, std::vector<ge::Tensor> &input, std::vect | |||
| 179 | { | 177 | { |
| 180 | Status ret = SUCCESS; | 178 | Status ret = SUCCESS; |
| 181 | // 自定义代码:添加单算子定义到图中 | 179 | // 自定义代码:添加单算子定义到图中 |
| 182 | - auto add1 = op::AddExample("add1"); | 180 | + auto add1 = op::AddExampleAicpu("add1"); |
| 183 | std::vector<int64_t> xShape = {32,4,4,4}; | 181 | std::vector<int64_t> xShape = {32,4,4,4}; |
| 184 | ADD_INPUT(1, x1, inDtype, xShape); | 182 | ADD_INPUT(1, x1, inDtype, xShape); |
| 185 | ADD_INPUT(2, x2, inDtype, xShape); | 183 | ADD_INPUT(2, x2, inDtype, xShape); |
| @@ -33,6 +33,6 @@ static ge::graphStatus InferDataTypeAddExample(gert::InferDataTypeContext* conte | |||
| 33 | return GRAPH_SUCCESS; | 33 | return GRAPH_SUCCESS; |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | -IMPL_OP(AddExample).InferDataType(InferDataTypeAddExample); | 36 | +IMPL_OP(AddExampleAicpu).InferDataType(InferDataTypeAddExample); |
| 37 | 37 | ||
| 38 | }; // namespace ops | 38 | }; // namespace ops |
| @@ -32,11 +32,11 @@ namespace ge { | |||
| 32 | *@par Third-party framework compatibility | 32 | *@par Third-party framework compatibility |
| 33 | *Compatible with the TensorFlow operator Add. | 33 | *Compatible with the TensorFlow operator Add. |
| 34 | */ | 34 | */ |
| 35 | -REG_OP(AddExample) | 35 | +REG_OP(AddExampleAicpu) |
| 36 | .INPUT(x1, TensorType({DT_FLOAT, DT_INT32})) | 36 | .INPUT(x1, TensorType({DT_FLOAT, DT_INT32})) |
| 37 | .INPUT(x2, TensorType({DT_FLOAT, DT_INT32})) | 37 | .INPUT(x2, TensorType({DT_FLOAT, DT_INT32})) |
| 38 | .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32})) | 38 | .OUTPUT(y, TensorType({DT_FLOAT, DT_INT32})) |
| 39 | - .OP_END_FACTORY_REG(AddExample) | 39 | + .OP_END_FACTORY_REG(AddExampleAicpu) |
| 40 | 40 | ||
| 41 | } // namespace ge | 41 | } // namespace ge |
| 42 | 42 | ||
Dexamples/add_example_aicpu/op_host/add_example_def.cpp+0-54
| @@ -1,54 +0,0 @@ | |||
| 1 | - | ||
| 2 | -/** | ||
| 3 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | - * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 5 | - * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 6 | - * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 7 | - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 8 | - * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 9 | - * See LICENSE in the root of the software repository for the full text of the License. | ||
| 10 | - */ | ||
| 11 | - | ||
| 12 | -/*! | ||
| 13 | - * \file add_example_aicpu_def.cpp | ||
| 14 | - * \brief | ||
| 15 | - */ | ||
| 16 | - | ||
| 17 | - | ||
| 18 | -namespace ops { | ||
| 19 | -class AddExample : public OpDef { | ||
| 20 | -public: | ||
| 21 | - explicit AddExample(const char* name) : OpDef(name) | ||
| 22 | - { | ||
| 23 | - this->Input("x1") // 输入x1定义 | ||
| 24 | - .ParamType(REQUIRED) // 必选输入 | ||
| 25 | - .DataType({ge::DT_FLOAT, ge::DT_INT32}) // 支持数据类型 | ||
| 26 | - .Format({ge::FORMAT_ND, ge::FORMAT_ND}) // 支持format格式 | ||
| 27 | - .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND}) // 未确定大小shape对应format格式 | ||
| 28 | - .AutoContiguous(); // 内存自动连续化 | ||
| 29 | - this->Input("x2") // 输入x2定义 | ||
| 30 | - .ParamType(REQUIRED) | ||
| 31 | - .DataType({ge::DT_FLOAT, ge::DT_INT32}) | ||
| 32 | - .Format({ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 33 | - .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 34 | - .AutoContiguous(); | ||
| 35 | - this->Output("y") // 输出y定义 | ||
| 36 | - .ParamType(REQUIRED) | ||
| 37 | - .DataType({ge::DT_FLOAT, ge::DT_INT32}) | ||
| 38 | - .Format({ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 39 | - .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 40 | - .AutoContiguous(); | ||
| 41 | - | ||
| 42 | - OpAICpuConfig aicpuConfig; | ||
| 43 | - aicpuConfig.DynamicCompileStaticFlag(true) | ||
| 44 | - .DynamicFormatFlag(false) | ||
| 45 | - .DynamicRankSupportFlag(true) | ||
| 46 | - .DynamicShapeSupportFlag(true) | ||
| 47 | - .NeedCheckSupportFlag(false) | ||
| 48 | - .PrecisionReduceFlag(true) | ||
| 49 | - .ExtendCfgInfo("opFile.value", "add_example_aicpu"); // 这里制定的值会对应到kernel入口文件名.cpp | ||
| 50 | - this->AICpu().AddConfig("ascend910b", aicpuConfig); // 其他的soc版本补充部分配置项 | ||
| 51 | - } | ||
| 52 | -}; | ||
| 53 | -OP_ADD(AddExample); // 添加算子信息库 | ||
| 54 | -} // namespace ops | ||
| @@ -44,5 +44,5 @@ static ge::graphStatus InferShapeAddExample(gert::InferShapeContext* context) | |||
| 44 | return GRAPH_SUCCESS; | 44 | return GRAPH_SUCCESS; |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | -IMPL_OP_INFERSHAPE(AddExample).InferShape(InferShapeAddExample); | 47 | +IMPL_OP_INFERSHAPE(AddExampleAicpu).InferShape(InferShapeAddExample); |
| 48 | } // namespace ops | 48 | } // namespace ops |
| @@ -1,5 +1,5 @@ | |||
| 1 | { | 1 | { |
| 2 | - "AddExample":{ | 2 | + "AddExampleAicpu":{ |
| 3 | "opInfo":{ | 3 | "opInfo":{ |
| 4 | "computeCost":"100", | 4 | "computeCost":"100", |
| 5 | "engine":"DNN_VM_AICPU", | 5 | "engine":"DNN_VM_AICPU", |
| @@ -19,10 +19,10 @@ | |||
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | 21 | ||
| 22 | -#include "cust_cpu_utils.h" | 22 | +#include "log.h" |
| 23 | 23 | ||
| 24 | namespace { | 24 | namespace { |
| 25 | -const char* const kAddExample = "AddExample"; | 25 | +const char* const kAddExample = "AddExampleAicpu"; |
| 26 | const uint32_t kFirstInputIndex = 0; | 26 | const uint32_t kFirstInputIndex = 0; |
| 27 | const uint32_t kSecondInputIndex = 1; | 27 | const uint32_t kSecondInputIndex = 1; |
| 28 | const uint32_t kFirstOutputIndex = 0; | 28 | const uint32_t kFirstOutputIndex = 0; |
| @@ -29,7 +29,7 @@ class TEST_AddExample_UT : public testing::Test {}; | |||
| 29 | 29 | ||
| 30 | 30 | ||
| 31 | auto node_def = CpuKernelUtils::CpuKernelUtils::CreateNodeDef(); \ | 31 | auto node_def = CpuKernelUtils::CpuKernelUtils::CreateNodeDef(); \ |
| 32 | - NodeDefBuilder(node_def.get(), "AddExample", "AddExample") \ | 32 | + NodeDefBuilder(node_def.get(), "AddExampleAicpu", "AddExampleAicpu") \ |
| 33 | .Input({"x1", data_types[0], shapes[0], datas[0]}) \ | 33 | .Input({"x1", data_types[0], shapes[0], datas[0]}) \ |
| 34 | .Input({"x2", data_types[1], shapes[1], datas[1]}) \ | 34 | .Input({"x2", data_types[1], shapes[1], datas[1]}) \ |
| 35 | .Output({"y", data_types[2], shapes[2], datas[2]}); | 35 | .Output({"y", data_types[2], shapes[2], datas[2]}); |
| @@ -1,5 +1,5 @@ | |||
| 1 | { | 1 | { |
| 2 | - "AddExample":{ | 2 | + "AddExampleAicpu":{ |
| 3 | "opInfo":{ | 3 | "opInfo":{ |
| 4 | "computeCost":"100", | 4 | "computeCost":"100", |
| 5 | "engine":"DNN_VM_AICPU", | 5 | "engine":"DNN_VM_AICPU", |
| @@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | 16 | ||
| 17 | namespace { | 17 | namespace { |
| 18 | -const char* const kAddExample = "AddExample"; | 18 | +const char* const kAddExample = "AddExampleAicpu"; |
| 19 | const uint32_t kFirstInputIndex = 0; | 19 | const uint32_t kFirstInputIndex = 0; |
| 20 | const uint32_t kSecondInputIndex = 1; | 20 | const uint32_t kSecondInputIndex = 1; |
| 21 | const uint32_t kSuccess = 0; | 21 | const uint32_t kSuccess = 0; |


代码结构与可维护性: IMPL_OP宏调用的操作符名称从'AddExample'修改为'AddExampleAicpu',但对应的InferDataType函数名称仍为'InferDataTypeAddExample',函数命名与操作符名称不一致。虽然这不会导致编译或运行时错误,但会影响代码的可读性和维护性。当其他开发者查看代码时,可能会困惑于函数命名与操作符名称的不匹配。
问题类型: 代码结构与可维护性 文件路径:
examples/add_example_aicpu/op_graph/add_example_graph_infer.cpp行号: 36 问题代码:IMPL_OP(AddExampleAicpu).InferDataType(InferDataTypeAddExample);修改建议:
此评论由代码审查工具自动生成