已合并
统一规范各类插件的源码收集流程 #3830
yang-di52创建于 4月15日
统一规范各类插件的源码收集流程 #3830
已合并
共 10 个文件变更+25-119
| @@ -481,6 +481,8 @@ function(add_modules_sources) | |||
| 481 | endif() | 481 | endif() |
| 482 | 482 | ||
| 483 | add_tf_plugin_sources() | 483 | add_tf_plugin_sources() |
| 484 | + add_graph_plugin_sources() | ||
| 485 | + add_onnx_plugin_sources() | ||
| 484 | 486 | ||
| 485 | file(GLOB OPINFER_SRCS ${SOURCE_DIR}/*_infershape*.cpp) | 487 | file(GLOB OPINFER_SRCS ${SOURCE_DIR}/*_infershape*.cpp) |
| 486 | if(OPINFER_SRCS) | 488 | if(OPINFER_SRCS) |
| @@ -625,8 +627,12 @@ function(add_kernel_sources) | |||
| 625 | endfunction() | 627 | endfunction() |
| 626 | 628 | ||
| 627 | # usage: add_graph_plugin_sources() | 629 | # usage: add_graph_plugin_sources() |
| 628 | -macro(add_graph_plugin_sources) | 630 | +function(add_graph_plugin_sources) |
Y | |||
| 629 | - set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | 631 | + if(NOT "${OP_DIR}x" STREQUAL "x") |
| 632 | + set(SOURCE_DIR ${OP_DIR}/op_graph) | ||
| 633 | + else() | ||
| 634 | + set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 635 | + endif() | ||
| 630 | 636 | ||
| 631 | # 获取算子层级目录名称,判断是否编译该算子 | 637 | # 获取算子层级目录名称,判断是否编译该算子 |
| 632 | get_filename_component(PARENT_DIR ${SOURCE_DIR} DIRECTORY) | 638 | get_filename_component(PARENT_DIR ${SOURCE_DIR} DIRECTORY) |
| @@ -646,7 +652,7 @@ macro(add_graph_plugin_sources) | |||
| 646 | if(GRAPH_PLUGIN_PROTO_HEADERS) | 652 | if(GRAPH_PLUGIN_PROTO_HEADERS) |
| 647 | target_sources(${GRAPH_PLUGIN_NAME}_proto_headers INTERFACE ${GRAPH_PLUGIN_PROTO_HEADERS}) | 653 | target_sources(${GRAPH_PLUGIN_NAME}_proto_headers INTERFACE ${GRAPH_PLUGIN_PROTO_HEADERS}) |
| 648 | endif() | 654 | endif() |
| 649 | -endmacro() | 655 | +endfunction() |
| 650 | 656 | ||
| 651 | # ###################################################################################################################### | 657 | # ###################################################################################################################### |
| 652 | # get operating system info | 658 | # get operating system info |
| @@ -898,17 +904,19 @@ function(add_cube_utils_plugin_modules) | |||
| 898 | endif() | 904 | endif() |
| 899 | endfunction() | 905 | endfunction() |
| 900 | 906 | ||
| 901 | -macro(add_onnx_plugin_sources) | 907 | +function(add_onnx_plugin_sources) |
| 902 | - set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | 908 | + if(NOT "${OP_DIR}x" STREQUAL "x") |
| 909 | + set(SOURCE_DIR ${OP_DIR}/framework) | ||
| 910 | + else() | ||
| 911 | + set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 912 | + endif() | ||
| 903 | 913 | ||
| 904 | file(GLOB ONNX_PLUGIN_SRCS ${SOURCE_DIR}/*_onnx_plugin.cpp) | 914 | file(GLOB ONNX_PLUGIN_SRCS ${SOURCE_DIR}/*_onnx_plugin.cpp) |
| 905 | if(ONNX_PLUGIN_SRCS) | 915 | if(ONNX_PLUGIN_SRCS) |
| 906 | add_onnx_plugin_modules() | 916 | add_onnx_plugin_modules() |
| 907 | target_sources(${ONNX_PLUGIN_NAME}_obj PRIVATE ${ONNX_PLUGIN_SRCS}) | 917 | target_sources(${ONNX_PLUGIN_NAME}_obj PRIVATE ${ONNX_PLUGIN_SRCS}) |
| 908 | - else() | ||
| 909 | - message(STATUS "ONNX_PLUGIN_SRCS is empty") | ||
| 910 | endif() | 918 | endif() |
| 911 | -endmacro() | 919 | +endfunction() |
| 912 | 920 | ||
| 913 | # TF plugin 初始化函数(顶层调用一次,内部条件检查) | 921 | # TF plugin 初始化函数(顶层调用一次,内部条件检查) |
| 914 | function(init_tf_plugin_modules) | 922 | function(init_tf_plugin_modules) |
| @@ -12,28 +12,6 @@ | |||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | namespace ge { | 14 | namespace ge { |
| 15 | - | ||
| 16 | -/** | ||
| 17 | - * @brief Applies a 2D adaptive average pooling over | ||
| 18 | - * an input signal composed of several input planes. | ||
| 19 | - * @par Inputs: | ||
| 20 | - * One input, including: | ||
| 21 | - * @li x: A Tensor. Must be one of the following data types: | ||
| 22 | - * float16, float32. \n | ||
| 23 | - * @par Attributes: | ||
| 24 | - * @li output_size: A required list of 2 ints | ||
| 25 | - * specifying the size (H,W) of the output tensor. \n | ||
| 26 | - * @par Outputs: | ||
| 27 | - * @li y: A Tensor. Has the same data type as "x" \n | ||
| 28 | - * @par Third-party framework compatibility | ||
| 29 | - * Compatible with the Pytorch operator AdaptiveAvgPool2d. | ||
| 30 | - */ | ||
| 31 | -REG_OP(AdaptiveAvgPool2d) | ||
| 32 | - .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16})) | ||
| 33 | - .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16})) | ||
| 34 | - .REQUIRED_ATTR(output_size, ListInt) | ||
| 35 | - .OP_END_FACTORY_REG(AdaptiveAvgPool2d) | ||
| 36 | - | ||
| 37 | /** | 15 | /** |
| 38 | * @brief Applies a 2D adaptive max pooling over an input signal conposed of several input planes. | 16 | * @brief Applies a 2D adaptive max pooling over an input signal conposed of several input planes. |
| 39 | * The output is of size H x W, for any input size. | 17 | * The output is of size H x W, for any input size. |
| @@ -16,10 +16,10 @@ | |||
| 16 | 16 | ||
| 17 | namespace ge { | 17 | namespace ge { |
| 18 | 18 | ||
| 19 | -#define INPLACE_INDEX_FILL_SUPPORT_TYPES { | 19 | +#define INPLACE_INDEX_FILL_SUPPORT_TYPES { \ |
| 20 | - ge::DT_FLOAT, ge::DT_DOUBLE, ge::DT_FLOAT16, ge::DT_BF16, ge::DT_INT8, | 20 | + ge::DT_FLOAT, ge::DT_DOUBLE, ge::DT_FLOAT16, ge::DT_BF16, ge::DT_INT8, \ |
| 21 | - ge::DT_UINT8, ge::DT_INT16, ge::DT_INT32, ge::DT_INT64, ge::DT_BOOL, | 21 | + ge::DT_UINT8, ge::DT_INT16, ge::DT_INT32, ge::DT_INT64, ge::DT_BOOL, \ |
| 22 | - ge::DT_FLOAT, ge::DT_DOUBLE, ge::DT_FLOAT16, ge::DT_BF16, ge::DT_INT8, | 22 | + ge::DT_FLOAT, ge::DT_DOUBLE, ge::DT_FLOAT16, ge::DT_BF16, ge::DT_INT8, \ |
| 23 | ge::DT_UINT8, ge::DT_INT16, ge::DT_INT32, ge::DT_INT64, ge::DT_BOOL} | 23 | ge::DT_UINT8, ge::DT_INT16, ge::DT_INT32, ge::DT_INT64, ge::DT_BOOL} |
| 24 | REG_OP(InplaceIndexFill) | 24 | REG_OP(InplaceIndexFill) |
| 25 | .INPUT(x, TensorType(INPLACE_INDEX_FILL_SUPPORT_TYPES)) | 25 | .INPUT(x, TensorType(INPLACE_INDEX_FILL_SUPPORT_TYPES)) |
Rloss/binary_cross_entropy_grad/examples/test_aclnn_binary_cross_entropy_backward.cpp→loss/binary_cross_entropy_grad/examples/arch35/test_aclnn_binary_cross_entropy_backward.cpp+0-0
文件重命名但无更改。
| @@ -48,7 +48,7 @@ REG_OP(BinaryCrossEntropyGrad) | |||
| 48 | .OPTIONAL_INPUT(weight, TensorType({DT_FLOAT, DT_FLOAT16, DT_BF16})) | 48 | .OPTIONAL_INPUT(weight, TensorType({DT_FLOAT, DT_FLOAT16, DT_BF16})) |
| 49 | .OUTPUT(output, TensorType({DT_FLOAT, DT_FLOAT16, DT_BF16})) | 49 | .OUTPUT(output, TensorType({DT_FLOAT, DT_FLOAT16, DT_BF16})) |
| 50 | .ATTR(reduction, String, "mean") | 50 | .ATTR(reduction, String, "mean") |
| 51 | - .OP_END_FACTORY_REG(BinaryCrossEntropyGrad)(BinaryCrossEntropy) | 51 | + .OP_END_FACTORY_REG(BinaryCrossEntropyGrad) |
| 52 | 52 | ||
| 53 | } // namespace ge | 53 | } // namespace ge |
| 54 | 54 | ||
Rloss/smooth_l1_loss_grad_v2/examples/test_aclnn_smooth_l1_loss_backward.cpp→loss/smooth_l1_loss_grad_v2/examples/arch35/test_aclnn_smooth_l1_loss_backward.cpp+0-0
文件重命名但无更改。
| @@ -29,5 +29,5 @@ static ge::graphStatus InferDataTypeForSmoothL1LossGradV2(gert::InferDataTypeCon | |||
| 29 | return ge::GRAPH_SUCCESS; | 29 | return ge::GRAPH_SUCCESS; |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | -IMPL_OP_INFERSHAPE(SmoothL1LossGradV2).InferDataType(InferDataTypeForSmoothL1LossGradV2); | 32 | +IMPL_OP(SmoothL1LossGradV2).InferDataType(InferDataTypeForSmoothL1LossGradV2); |
| 33 | } // namespace ops | 33 | } // namespace ops |
Dpooling/max_pool3d_grad/op_graph/max_pool3d_grad_with_argmax_proto.h+0-79
| @@ -1,79 +0,0 @@ | |||
| 1 | - /** | ||
| 2 | - * Copyright (c) 2025 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 | -/*! | ||
| 12 | - * \file max_pool3d_grad_proto.h | ||
| 13 | - * \brief | ||
| 14 | - */ | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | - | ||
| 22 | -namespace ge { | ||
| 23 | - | ||
| 24 | -/** | ||
| 25 | -* @brief Performs the backpropagation of MaxPool3DGrad. | ||
| 26 | - | ||
| 27 | -* @par Inputs: | ||
| 28 | -* Three inputs, including: | ||
| 29 | -* @li orig_x: An 5D Tensor. Supported type:float16, bfloat16, float32 | ||
| 30 | -* Must set the format, supported format list ["NCDHW, NDHWC"]. | ||
| 31 | -* @li orig_y: An 5D Tensor. Supported type:float16, bfloat16, float32 | ||
| 32 | -* Must set the format, supported format list ["NCDHW, NDHWC"]. | ||
| 33 | -* @li grads: An 5D Tensor. Supported type:float16, bfloat16, float32 | ||
| 34 | -* Must set the format, supported format list ["NCDHW, NDHWC"]. \n | ||
| 35 | - | ||
| 36 | -* @par Attributes: | ||
| 37 | -* @li ksize: A required list of int8, int16, int32, or int64 values, | ||
| 38 | -* specifying the size of the window for each dimension (D/H/W) of the input tensor. | ||
| 39 | -* @li strides: A required list of int8, int16, int32, or int64 values, | ||
| 40 | -* specifying the strides of the sliding window for each dimension (D/H/W) of the input tensor. | ||
| 41 | -* @li padding: A string specifying the padding algorithm for the input feature map. | ||
| 42 | -* @li pads: A required list of int8, int16, int32, or int64 values, | ||
| 43 | -* specifying the pads of the sliding window for each dimension of the input tensor. | ||
| 44 | -* @li data_format: An optional string, supported values: ["NCDHW", "NDHWC"], | ||
| 45 | -* default value: ["NCDHW"]. \n | ||
| 46 | - | ||
| 47 | -* @par Outputs: | ||
| 48 | -* y: A Tensor. Has the same dtype, shape and format as input "x". | ||
| 49 | - | ||
| 50 | -* @attention Constraints: | ||
| 51 | -* @li "ksize" is a list that has length 1 or 3(one value for each of D/H/W), | ||
| 52 | -* every element in the list must be a numeric greater than 0. | ||
| 53 | -* @li "strides" is a list that has length 0 or 1 or 3(one value for each of D/H/W), | ||
| 54 | -* length 0 means use default ksize for each of D/H/W, | ||
| 55 | -* every element in the list must be a numeric greater than 0. | ||
| 56 | -* @li padding: a string must be either "SAME" or "VALID". | ||
| 57 | -* @li "pads" is a list that has length 1 or 3(one value for each of D/H/W), | ||
| 58 | -* every element in the list must be a numeric greater than or equal to 0. | ||
| 59 | -* additionally, two strict size limits apply: \n | ||
| 60 | -* 1. Each pads value (pD/pH/pW for D/H/W dimensions) must be less than or equal to half of the corresponding "ksize" value (kD/kH/kW / 2). \n | ||
| 61 | -* 2. Each pads value (pD/pH/pW) must be less than or equal to ((corresponding ksize - 1) * corresponding dilation + 1) / 2 | ||
| 62 | -* (i.e., pD ≤ ((kD - 1) * dD + 1) / 2, pH ≤ ((kH - 1) * dH + 1) / 2, pW ≤ ((kW - 1) * dW + 1) / 2). | ||
| 63 | - | ||
| 64 | -* @par Third-party framework compatibility | ||
| 65 | -* Compatible with the Torch operator MaxPool3DGrad. | ||
| 66 | -*/ | ||
| 67 | -REG_OP(MaxPool3DGrad) | ||
| 68 | - .INPUT(orig_x, TensorType::RealNumberType()) | ||
| 69 | - .INPUT(orig_y, TensorType::RealNumberType()) | ||
| 70 | - .INPUT(grads, TensorType::RealNumberType()) | ||
| 71 | - .OUTPUT(y, TensorType::RealNumberType()) | ||
| 72 | - .REQUIRED_ATTR(ksize, ListInt) | ||
| 73 | - .REQUIRED_ATTR(strides, ListInt) | ||
| 74 | - .ATTR(padding, String, "SAME") | ||
| 75 | - .REQUIRED_ATTR(pads, ListInt) | ||
| 76 | - .ATTR(data_format, String, "NDHWC") | ||
| 77 | - .OP_END_FACTORY_REG(MaxPool3DGrad) | ||
| 78 | -} // namespace ge | ||
| 79 | - | ||
| @@ -41,10 +41,9 @@ def match_op_proto(file_path): | |||
| 41 | 41 | ||
| 42 | def merge_op_proto(protos_path, output_file): | 42 | def merge_op_proto(protos_path, output_file): |
| 43 | op_defs = [] | 43 | op_defs = [] |
| 44 | - for proto_path in protos_path: | 44 | + for proto_path in list(dict.fromkeys(protos_path)): |
| 45 | - if not proto_path.endswith("_proto.h"): | 45 | + if not proto_path.endswith("_proto.h") and not proto_path.endswith("_proto_extend.h"): |
| 46 | continue | 46 | continue |
| 47 | - print(f"proto_path: {proto_path}") | ||
| 48 | op_def = match_op_proto(proto_path) | 47 | op_def = match_op_proto(proto_path) |
| 49 | if op_def: | 48 | if op_def: |
| 50 | op_defs.append(op_def) | 49 | op_defs.append(op_def) |
风险(一般):OP_DIR 未设时仍走 CMAKE_CURRENT_SOURCE_DIR,行为应与旧版一致;若某些子目录曾依赖 macro 就地展开污染外层变量,现在要确认没有遗留(通常这类工程会依赖 function 作用域)。 建议验证:在 带 OP_DIR 的整库/插件构建路径下编一次;任选少量含 graph/onnx plugin 的算子目录做 smoke。