* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*/
* \file add_example_def.cpp
* \brief Add算子的定义
*
* 本文件定义了Add算子的接口,包括输入输出规格、支持的数据类型、格式以及AI Core编译配置。
* 算子定义对于在CANN框架中注册和验证算子是必需的。
*/
#include "register/op_def_registry.h"
namespace ops {
* \brief Add算子类定义
*
* 该类定义了执行元素级加法的Add算子,接收两个输入张量并产生一个相同形状的输出张量。
*
* 支持的数据类型: FLOAT, INT32
* 支持的格式: ND (n维格式)
*/
class AddExample : public OpDef
{
public:
* \brief Add算子的构造函数
* \param name 算子实例的名称
*
* 定义算子接口,包括:
* - 两个必需输入 (x1, x2)
* - 一个必需输出 (y)
* - 支持的数据类型和格式
* - 针对不同SOC版本的AI Core编译配置
*/
explicit AddExample(const char* name) : OpDef(name)
{
this->Input("x1")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT, ge::DT_INT32})
.Format({ge::FORMAT_ND, ge::FORMAT_ND})
.UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND})
.AutoContiguous();
this->Input("x2")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT, ge::DT_INT32})
.Format({ge::FORMAT_ND, ge::FORMAT_ND})
.UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND})
.AutoContiguous();
this->Output("y")
.ParamType(REQUIRED)
.DataType({ge::DT_FLOAT, ge::DT_INT32})
.Format({ge::FORMAT_ND, ge::FORMAT_ND})
.UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND})
.AutoContiguous();
OpAICoreConfig aicoreConfig;
aicoreConfig.DynamicCompileStaticFlag(true)
.DynamicFormatFlag(false)
.DynamicRankSupportFlag(true)
.DynamicShapeSupportFlag(true)
.NeedCheckSupportFlag(false)
.PrecisionReduceFlag(true)
.ExtendCfgInfo("opFile.value", "add_example");
this->AICore().AddConfig("ascend910b", aicoreConfig);
this->AICore().AddConfig("ascend910_93", aicoreConfig);
this->AICore().AddConfig("ascend950", aicoreConfig);
}
};
OP_ADD(AddExample);
}