已合并
新增950算子 #1641
huangyuxiaaaaa创建于 3月12日
新增950算子 #1641
已合并
共 114 个文件变更+6917-2448
| @@ -1,11 +1,15 @@ | |||
| 1 | -# --------------------------------------------------------------------------------------------------------- | 1 | +# ---------------------------------------------------------------------------- |
| 2 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 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, | 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. | 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. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 9 | -# --------------------------------------------------------------------------------------------------------- | 9 | +# ---------------------------------------------------------------------------- |
| 10 | 10 | ||
| 11 | -add_all_modules_sources(OPTYPE atan ACLNNTYPE aclnn_exclude) | 11 | +# 设置算子定义时支持的芯片类型 |
| 12 | +set(SUPPORT_COMPUTE_UNIT "ascend950" "mc62cm12a") | ||
| 13 | +# 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 | ||
| 14 | +set(SUPPORT_TILING_DIR "arch35" "arch35") | ||
| 15 | +add_all_modules_sources(OPTYPE atan ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE) | ||
| @@ -1,25 +1,25 @@ | |||
| 1 | -/* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. | 1 | +/** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 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, | 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. | 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. | 8 | + * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | - */ | 9 | + */ |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | using namespace ge; | 14 | using namespace ge; |
| 15 | namespace ops { | 15 | namespace ops { |
| 16 | -static ge::graphStatus InferDataTypeForAtan(gert::InferDataTypeContext* context) { | 16 | +static ge::graphStatus InferDataTypeForAtan(gert::InferDataTypeContext* context) |
| 17 | - OP_LOGI("Begin InferDataTypeForAtan"); | 17 | +{ |
| 18 | - const ge::DataType xDataType = context->GetInputDataType(0); | 18 | + OP_LOGI("Begin InferDataTypeForAtan"); |
| 19 | - context->SetOutputDataType(0, xDataType); | 19 | + const ge::DataType xDataType = context->GetInputDataType(0); |
| 20 | - return ge::GRAPH_SUCCESS; | 20 | + context->SetOutputDataType(0, xDataType); |
| 21 | + return ge::GRAPH_SUCCESS; | ||
| 21 | } | 22 | } |
| 22 | 23 | ||
| 23 | IMPL_OP(Atan).InferDataType(InferDataTypeForAtan); | 24 | IMPL_OP(Atan).InferDataType(InferDataTypeForAtan); |
| 24 | -} | 25 | +} // namespace ops |
| 25 | -// namespace ops | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -17,8 +17,7 @@ | |||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | -namespace ge | 20 | +namespace ge { |
| 21 | -{ | ||
| 22 | /** | 21 | /** |
| 23 | *@brief Computes the trignometric inverse tangent of x element-wise. | 22 | *@brief Computes the trignometric inverse tangent of x element-wise. |
| 24 | * The atan operation returns the inverse of tan, such that if y = tan(x) then, x = atan(y). | 23 | * The atan operation returns the inverse of tan, such that if y = tan(x) then, x = atan(y). |
| @@ -0,0 +1,159 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file atan_tiling_arch35.cpp | ||
| 13 | + * \brief atan_tiling source file | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + | ||
| 31 | +using namespace ge; | ||
| 32 | +using namespace AtanOp; | ||
| 33 | +using namespace Ops::Math::OpTiling; | ||
| 34 | + | ||
| 35 | +namespace optiling { | ||
| 36 | +constexpr int64_t ASCEND_API_BUFFER = 122880; | ||
| 37 | +const int64_t ASCEND_WORKSPACE = 16 * 1024 * 1024; | ||
| 38 | + | ||
| 39 | +ge::graphStatus AtanTiling::CalcInputDtype() | ||
| 40 | +{ | ||
| 41 | + auto inputDesc = tilingContext->GetInputDesc(0); | ||
| 42 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputDesc); | ||
| 43 | + this->inputDtype = inputDesc->GetDataType(); | ||
| 44 | + OP_CHECK_IF( | ||
| 45 | + this->inputDtype != ge::DT_FLOAT16 && this->inputDtype != ge::DT_BF16 && this->inputDtype != ge::DT_FLOAT, | ||
| 46 | + OP_LOGE( | ||
| 47 | + tilingContext->GetNodeName(), | ||
| 48 | + "input x dtype [%s] not supported, only support [DT_FLOAT16, DT_BF16, DT_FLOAT]", | ||
| 49 | + ge::TypeUtils::DataTypeToSerialString(this->inputDtype).c_str()), | ||
| 50 | + return ge::GRAPH_FAILED); | ||
| 51 | + return ge::GRAPH_SUCCESS; | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +ge::graphStatus AtanTiling::CalcOutputDtype() | ||
| 55 | +{ | ||
| 56 | + auto outputDesc = tilingContext->GetOutputDesc(0); | ||
| 57 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputDesc); | ||
| 58 | + this->outputDtype = outputDesc->GetDataType(); | ||
| 59 | + OP_CHECK_IF( | ||
| 60 | + this->outputDtype != ge::DT_FLOAT16 && this->outputDtype != ge::DT_BF16 && this->outputDtype != ge::DT_FLOAT, | ||
| 61 | + OP_LOGE( | ||
| 62 | + tilingContext->GetNodeName(), | ||
| 63 | + "output y dtype [%s] not supported, only support [DT_FLOAT16, DT_BF16, DT_FLOAT]", | ||
| 64 | + ge::TypeUtils::DataTypeToSerialString(this->outputDtype).c_str()), | ||
| 65 | + return ge::GRAPH_FAILED); | ||
| 66 | + OP_CHECK_IF( | ||
| 67 | + this->outputDtype != this->inputDtype, | ||
| 68 | + OP_LOGE( | ||
| 69 | + tilingContext->GetNodeName(), "input x dtype [%s] should be the same as output y dtype [%s]", | ||
| 70 | + ge::TypeUtils::DataTypeToSerialString(this->inputDtype).c_str(), | ||
| 71 | + ge::TypeUtils::DataTypeToSerialString(this->outputDtype).c_str()), | ||
| 72 | + return ge::GRAPH_FAILED); | ||
| 73 | + return ge::GRAPH_SUCCESS; | ||
| 74 | +} | ||
| 75 | + | ||
| 76 | +ge::graphStatus AtanTiling::CheckShape() | ||
| 77 | +{ | ||
| 78 | + auto inputStorageShape = tilingContext->GetInputShape(0); | ||
| 79 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputStorageShape); | ||
| 80 | + const gert::Shape& inputXShape = EnsureNotScalar(inputStorageShape->GetStorageShape()); | ||
| 81 | + | ||
| 82 | + auto outputStorageShape = tilingContext->GetOutputShape(0); | ||
| 83 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputStorageShape); | ||
| 84 | + const gert::Shape& outputYShape = EnsureNotScalar(outputStorageShape->GetStorageShape()); | ||
| 85 | + | ||
| 86 | + OP_CHECK_IF( | ||
| 87 | + inputXShape != outputYShape, OP_LOGE(tilingContext->GetNodeName(), "input x and output y shape not same"), | ||
| 88 | + return ge::GRAPH_FAILED); | ||
| 89 | + return ge::GRAPH_SUCCESS; | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +ge::graphStatus AtanTiling::RunTiling() | ||
| 93 | +{ | ||
| 94 | + OP_LOGD(tilingContext->GetNodeName(), "Enter TilingForAtan"); | ||
| 95 | + ElewiseBaseTiling elewiseBaseTiling(tilingContext); | ||
| 96 | + OP_CHECK_IF( | ||
| 97 | + CalcInputDtype() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "get input dtype failed"), | ||
| 98 | + return ge::GRAPH_FAILED); | ||
| 99 | + OP_CHECK_IF( | ||
| 100 | + CalcOutputDtype() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "get output dtype failed"), | ||
| 101 | + return ge::GRAPH_FAILED); | ||
| 102 | + OP_CHECK_IF( | ||
| 103 | + CheckShape() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "check shape failed"), return ge::GRAPH_FAILED); | ||
| 104 | + | ||
| 105 | + auto tiling = tilingContext->GetTilingData<EleBaseTilingDataV2>(); | ||
| 106 | + OP_CHECK_IF( | ||
| 107 | + (tiling == nullptr), OP_LOGE(tilingContext->GetNodeName(), "Get AtanTiling from GE context failed"), | ||
| 108 | + return ge::GRAPH_FAILED); | ||
| 109 | + | ||
| 110 | + ge::graphStatus ret = ge::GRAPH_SUCCESS; | ||
| 111 | + | ||
| 112 | + if (inputDtype == ge::DT_FLOAT) { | ||
| 113 | + dType = TPL_FP32; | ||
| 114 | + ret = elewiseBaseTiling.DoTiling<AtanOp::AtanDag<float>::OpDag>(*tiling, ASCEND_API_BUFFER); | ||
| 115 | + } else if (inputDtype == ge::DT_FLOAT16) { | ||
| 116 | + dType = TPL_FP16; | ||
| 117 | + ret = elewiseBaseTiling.DoTiling<AtanOp::AtanDag<half>::OpDag>(*tiling, ASCEND_API_BUFFER); | ||
| 118 | + } else if (inputDtype == ge::DT_BF16) { | ||
| 119 | + dType = TPL_BF16; | ||
| 120 | + ret = elewiseBaseTiling.DoTiling<AtanOp::AtanDag<bfloat16_t>::OpDag>(*tiling, ASCEND_API_BUFFER); | ||
| 121 | + } else { | ||
| 122 | + OP_LOGE( | ||
| 123 | + tilingContext->GetNodeName(), | ||
| 124 | + "Input dtype is only support fp16, bf16, fp32, " | ||
| 125 | + "while got %s!", | ||
| 126 | + ge::TypeUtils::DataTypeToSerialString(this->inputDtype).c_str()); | ||
| 127 | + return ge::GRAPH_FAILED; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + OP_CHECK_IF(ret == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "elewiseBaseTiling failed"), return ge::GRAPH_FAILED); | ||
| 131 | + | ||
| 132 | + // set workspace/tilingkey/blockdim | ||
| 133 | + size_t* currentWorkspace = tilingContext->GetWorkspaceSizes(1); | ||
| 134 | + currentWorkspace[0] = ASCEND_WORKSPACE; | ||
| 135 | + const uint64_t tilingKey = GET_TPL_TILING_KEY(static_cast<uint64_t>(tiling->scheMode), dType); | ||
| 136 | + OP_LOGD(tilingContext->GetNodeName(), "[TilingData] : tilingKey=%lu.", tilingKey); | ||
| 137 | + tilingContext->SetTilingKey(tilingKey); | ||
| 138 | + tilingContext->SetBlockDim(tiling->blockNum); | ||
| 139 | + | ||
| 140 | + return ret; | ||
| 141 | +} | ||
| 142 | + | ||
| 143 | +ge::graphStatus TilingForAtan(gert::TilingContext* context) | ||
| 144 | +{ | ||
| 145 | + OP_LOGD(context->GetNodeName(), "Tiling4Atan rt2.0 is running."); | ||
| 146 | + auto compileInfo = reinterpret_cast<const ElewiseCompileInfo*>(context->GetCompileInfo()); | ||
| 147 | + OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo); | ||
| 148 | + AtanTiling baseOpTiling(context); | ||
| 149 | + return baseOpTiling.RunTiling(); | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +static ge::graphStatus TilingPrepareForAtan([[maybe_unused]] gert::TilingParseContext* context) | ||
| 153 | +{ | ||
| 154 | + return ge::GRAPH_SUCCESS; | ||
| 155 | +} | ||
| 156 | + | ||
| 157 | +IMPL_OP_OPTILING(Atan).Tiling(TilingForAtan).TilingParse<ElewiseCompileInfo>(TilingPrepareForAtan); | ||
| 158 | + | ||
| 159 | +} // namespace optiling | ||
| @@ -0,0 +1,41 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file atan_tiling_arch35.h | ||
| 13 | + * \brief atan_tiling head file | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +namespace optiling { | ||
| 22 | + | ||
| 23 | +class AtanTiling { | ||
| 24 | +public: | ||
| 25 | + explicit AtanTiling(gert::TilingContext* context) : tilingContext(context) | ||
| 26 | + {} | ||
| 27 | + ge::graphStatus RunTiling(); | ||
| 28 | + | ||
| 29 | +protected: | ||
| 30 | + ge::graphStatus CalcOutputDtype(); | ||
| 31 | + ge::graphStatus CalcInputDtype(); | ||
| 32 | + ge::graphStatus CheckShape(); | ||
| 33 | + | ||
| 34 | +private: | ||
| 35 | + uint64_t dType = 0; | ||
| 36 | + gert::TilingContext* tilingContext; | ||
| 37 | + ge::DataType inputDtype; | ||
| 38 | + ge::DataType outputDtype; | ||
| 39 | +}; | ||
| 40 | +} // namespace optiling | ||
| 41 | + | ||
| @@ -0,0 +1,49 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file atan_def.cpp | ||
| 13 | + * \brief atan def | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +namespace ops { | ||
| 20 | +class Atan : public OpDef { | ||
| 21 | +public: | ||
| 22 | + explicit Atan(const char* name) : OpDef(name) | ||
| 23 | + { | ||
| 24 | + this->Input("x") | ||
| 25 | + .ParamType(REQUIRED) | ||
| 26 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}) | ||
| 27 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 28 | + .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 29 | + this->Output("y") | ||
| 30 | + .ParamType(REQUIRED) | ||
| 31 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}) | ||
| 32 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 33 | + .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 34 | + | ||
| 35 | + OpAICoreConfig aicoreConfig; | ||
| 36 | + aicoreConfig.DynamicCompileStaticFlag(true) | ||
| 37 | + .DynamicFormatFlag(false) | ||
| 38 | + .DynamicRankSupportFlag(true) | ||
| 39 | + .DynamicShapeSupportFlag(true) | ||
| 40 | + .NeedCheckSupportFlag(false) | ||
| 41 | + .PrecisionReduceFlag(true) | ||
| 42 | + .ExtendCfgInfo("opFile.value", "atan_apt"); | ||
| 43 | + this->AICore().AddConfig("ascend950", aicoreConfig); | ||
| 44 | + this->AICore().AddConfig("mc62cm12a", aicoreConfig); | ||
| 45 | + } | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | +OP_ADD(Atan); | ||
| 49 | +} // namespace ops | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | -/* Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. | 1 | +/** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -14,11 +14,11 @@ | |||
| 14 | 14 | ||
| 15 | using namespace ge; | 15 | using namespace ge; |
| 16 | namespace ops { | 16 | namespace ops { |
| 17 | -static ge::graphStatus InferShapeForAtan(gert::InferShapeContext *context) { | 17 | +static ge::graphStatus InferShapeForAtan(gert::InferShapeContext* context) |
| 18 | - OP_LOGI("Begin InferShapeForAtan"); | 18 | +{ |
| 19 | - return Ops::Base::InferShape4Elewise(context); | 19 | + OP_LOGI("Begin InferShapeForAtan"); |
| 20 | + return Ops::Base::InferShape4Elewise(context); | ||
| 20 | } | 21 | } |
| 21 | 22 | ||
| 22 | IMPL_OP_INFERSHAPE(Atan).InferShape(InferShapeForAtan); | 23 | IMPL_OP_INFERSHAPE(Atan).InferShape(InferShapeForAtan); |
| 23 | -} | 24 | +} // namespace ops |
| 24 | -// namespace ops | ||
| @@ -0,0 +1,92 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "Atan", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "Atan_bfloat16", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "x", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "bfloat16", | ||
| 11 | + "format": "ND", | ||
| 12 | + "paramType": "required", | ||
| 13 | + "shape": [ | ||
| 14 | + -2 | ||
| 15 | + ], | ||
| 16 | + "format_match_mode": "FormatAgnostic" | ||
| 17 | + } | ||
| 18 | + ], | ||
| 19 | + "outputs": [ | ||
| 20 | + { | ||
| 21 | + "name": "y", | ||
| 22 | + "index": 0, | ||
| 23 | + "dtype": "bfloat16", | ||
| 24 | + "format": "ND", | ||
| 25 | + "paramType": "required", | ||
| 26 | + "shape": [ | ||
| 27 | + -2 | ||
| 28 | + ], | ||
| 29 | + "format_match_mode": "FormatAgnostic" | ||
| 30 | + } | ||
| 31 | + ] | ||
| 32 | + }, | ||
| 33 | + { | ||
| 34 | + "bin_filename": "Atan_float16", | ||
| 35 | + "inputs": [ | ||
| 36 | + { | ||
| 37 | + "name": "x", | ||
| 38 | + "index": 0, | ||
| 39 | + "dtype": "float16", | ||
| 40 | + "format": "ND", | ||
| 41 | + "paramType": "required", | ||
| 42 | + "shape": [ | ||
| 43 | + -2 | ||
| 44 | + ], | ||
| 45 | + "format_match_mode": "FormatAgnostic" | ||
| 46 | + } | ||
| 47 | + ], | ||
| 48 | + "outputs": [ | ||
| 49 | + { | ||
| 50 | + "name": "y", | ||
| 51 | + "index": 0, | ||
| 52 | + "dtype": "float16", | ||
| 53 | + "format": "ND", | ||
| 54 | + "paramType": "required", | ||
| 55 | + "shape": [ | ||
| 56 | + -2 | ||
| 57 | + ], | ||
| 58 | + "format_match_mode": "FormatAgnostic" | ||
| 59 | + } | ||
| 60 | + ] | ||
| 61 | + }, | ||
| 62 | + { | ||
| 63 | + "bin_filename": "Atan_float32", | ||
| 64 | + "inputs": [ | ||
| 65 | + { | ||
| 66 | + "name": "x", | ||
| 67 | + "index": 0, | ||
| 68 | + "dtype": "float32", | ||
| 69 | + "format": "ND", | ||
| 70 | + "paramType": "required", | ||
| 71 | + "shape": [ | ||
| 72 | + -2 | ||
| 73 | + ], | ||
| 74 | + "format_match_mode": "FormatAgnostic" | ||
| 75 | + } | ||
| 76 | + ], | ||
| 77 | + "outputs": [ | ||
| 78 | + { | ||
| 79 | + "name": "y", | ||
| 80 | + "index": 0, | ||
| 81 | + "dtype": "float32", | ||
| 82 | + "format": "ND", | ||
| 83 | + "paramType": "required", | ||
| 84 | + "shape": [ | ||
| 85 | + -2 | ||
| 86 | + ], | ||
| 87 | + "format_match_mode": "FormatAgnostic" | ||
| 88 | + } | ||
| 89 | + ] | ||
| 90 | + } | ||
| 91 | + ] | ||
| 92 | +} | ||
| @@ -0,0 +1,2 @@ | |||
| 1 | +[Atan] | ||
| 2 | +default=0 | ||
| @@ -1,95 +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 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | -extern "C" { | ||
| 18 | - | ||
| 19 | - | ||
| 20 | -/** | ||
| 21 | - * @brief aclnnAtan的第一段接口,根据具体的计算流程,计算workspace大小。 | ||
| 22 | - * @domain aclnn_math | ||
| 23 | - * 功能描述:从输入矩阵的每一个元素进行反正切操作后输出。 | ||
| 24 | - * 计算公式: | ||
| 25 | - * out_{i}=tan^{-1}(input_{i}) | ||
| 26 | - * 参数描述: | ||
| 27 | - * @param [in] input | ||
| 28 | - * 输入Tensor,数据类型支持INT8,INT16,INT32,INT64,UINT8,BOOL,FLOAT,FLOAT16,DOUBLE,BFLOAT16。支持非连续Tensor,数据格式支持ND。 | ||
| 29 | - * @param [in] out | ||
| 30 | - * 输出Tensor,数据类型支持FLOAT,BFLOAT16, FLOAT16,DOUBLE。支持非连续Tensor,数据格式支持ND。 | ||
| 31 | - * @param [out] workspaceSize 返回用户需要在npu device侧申请的workspace大小。 | ||
| 32 | - * @param [out] executor 返回op执行器,包含了算子计算流程。 | ||
| 33 | - * @return aclnnStatus 返回状态码 | ||
| 34 | - */ | ||
| 35 | -ACLNN_API aclnnStatus aclnnAtanGetWorkspaceSize(const aclTensor* input, aclTensor* out, uint64_t* workspaceSize, | ||
| 36 | - aclOpExecutor** executor); | ||
| 37 | -/** | ||
| 38 | - * @brief aclnnAtan的第二段接口,用于执行计算。 | ||
| 39 | - * 功能描述:从输入矩阵的每一个元素进行反正切操作后输出。。 | ||
| 40 | - * 计算公式: | ||
| 41 | - * out_{i}=tan^{-1}(input_{i}) | ||
| 42 | - * 实现说明: | ||
| 43 | - * api计算的基本路径: | ||
| 44 | -```mermaid | ||
| 45 | -graph LR | ||
| 46 | - A[(Self)] -->B([l0op::Contiguous]) | ||
| 47 | - B --> C([l0op::Atan]) | ||
| 48 | - C --> G([l0op::Cast]) | ||
| 49 | - G --> E([l0op::ViewCopy]) | ||
| 50 | - E --> S[(Out)] | ||
| 51 | -``` | ||
| 52 | - * @param [in] workspace: 在npu device侧申请的workspace内存起址。 | ||
| 53 | - * @param [in] workspaceSize: 在npu device侧申请的workspace大小,由第一段接口aclnnAddGetWorkspaceSize获取。 | ||
| 54 | - * @param [in] stream: acl stream流。 | ||
| 55 | - * @param [in] executor: op执行器,包含了算子计算流程。 | ||
| 56 | - * @return aclnnStatus: 返回状态码。 | ||
| 57 | - */ | ||
| 58 | -ACLNN_API aclnnStatus aclnnAtan(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, | ||
| 59 | - const aclrtStream stream); | ||
| 60 | - | ||
| 61 | -/** | ||
| 62 | - * @brief aclnnInplaceAtan的第一段接口,根据具体的计算流程,计算workspace大小。 | ||
| 63 | - * @domain aclnn_math | ||
| 64 | - * 功能描述:从输入矩阵的每一个元素进行反余弦操作后输出。 | ||
| 65 | - * 计算公式: | ||
| 66 | - * out_{i}=tan^{-1}(input_{i}) | ||
| 67 | - * 参数描述: | ||
| 68 | - * @param [in] input | ||
| 69 | - * 输入Tensor,数据类型支持INT8,INT16,INT32,INT64,UINT8,BOOL,FLOAT,FLOAT16,DOUBLE。支持非连续Tensor,数据格式支持ND。 | ||
| 70 | - * @param [in] out | ||
| 71 | - * 输出Tensor,数据类型支持FLOAT,FLOAT16,DOUBLE。支持非连续Tensor,数据格式支持ND。 | ||
| 72 | - * @param [out] workspaceSize 返回用户需要在npu device侧申请的workspace大小。 | ||
| 73 | - * @param [out] executor 返回op执行器,包含了算子计算流程。 | ||
| 74 | - * @return aclnnStatus 返回状态码 | ||
| 75 | - */ | ||
| 76 | -ACLNN_API aclnnStatus aclnnInplaceAtanGetWorkspaceSize(aclTensor* inputRef, uint64_t* workspaceSize, | ||
| 77 | - aclOpExecutor** executor); | ||
| 78 | - | ||
| 79 | -/** | ||
| 80 | - * @brief: aclnnInplaceAtan的第二段接口,用于执行计算 | ||
| 81 | - * | ||
| 82 | - * 算子功能: 对输入Tensor原地完成atan操作 | ||
| 83 | - * @param [in] workspace: 在npu device侧申请的workspace内存起址。 | ||
| 84 | - * @param [in] workspaceSize: 在npu device侧申请的workspace大小,由第一段接口aclnnAtanGetWorkspaceSize获取。 | ||
| 85 | - * @param [in] stream: acl stream流。 | ||
| 86 | - * @param [in] executor: op执行器,包含了算子计算流程。 | ||
| 87 | - * @return aclnnStatus: 返回状态码。 | ||
| 88 | - */ | ||
| 89 | -ACLNN_API aclnnStatus aclnnInplaceAtan(void* workspace, uint64_t workspaceSize, aclOpExecutor* executor, | ||
| 90 | - const aclrtStream stream); | ||
| 91 | - | ||
| 92 | -} | ||
| 93 | - | ||
| 94 | - | ||
| 95 | - | ||
| @@ -1,19 +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 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | -namespace l0op { | ||
| 16 | -const aclTensor* Atan(const aclTensor* input, aclOpExecutor* executor); | ||
| 17 | -} | ||
| 18 | - | ||
| 19 | - | ||
| @@ -0,0 +1,47 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file atan_dag.h | ||
| 13 | + * atan: | ||
| 14 | + * atan(x) = x - x^3/3 + x^5/5 - x^7/7 + x^9/9 - x^11/11 + x^13/13... (|x|<=1) | ||
| 15 | + * = pi/4 + atan((x-1)/(x+1)) (x>1) | ||
| 16 | + * = pi/8 + atan((x-tan(pi/8))/(1+tan(pi/8)*x)) (tan(pi/8)=0.4142135623730950) (x > tan(pi/8) and x < | ||
| 17 | + * tan(pi/4))) | ||
| 18 | + */ | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | +namespace AtanOp { | ||
| 27 | +using namespace Ops::Base; | ||
| 28 | + | ||
| 29 | +template <typename T> | ||
| 30 | +struct AtanDag { | ||
| 31 | + using InputX1T = Bind<Vec::CopyIn<T>, Placeholder::In0<T>>; | ||
| 32 | + | ||
| 33 | + // cast | ||
| 34 | + using InputX1 = Bind<Vec::Cast<float, T, 0>, InputX1T>; | ||
| 35 | + | ||
| 36 | + using AtanRes = Bind<Vec::AtanPolyApprox<float>, InputX1>; | ||
| 37 | + using OpCastRes = Bind<Vec::Cast<T, float, 1>, AtanRes>; | ||
| 38 | + using OpCopyOut = Bind<Vec::CopyOut<T>, Placeholder::Out0<T>, OpCastRes>; | ||
| 39 | + | ||
| 40 | + // 指定输出节点 | ||
| 41 | + using Outputs = Elems<OpCopyOut>; | ||
| 42 | + using MemCfg = MemOptCfg<MemLevel::LEVEL_2>; | ||
| 43 | + using OpDag = DAGSch<Outputs, void, MemCfg>; | ||
| 44 | +}; | ||
| 45 | +} // namespace AtanOp | ||
| 46 | + | ||
| 47 | + | ||
| @@ -0,0 +1,39 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file atan_struct.h | ||
| 13 | + * \brief atan_struct | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +namespace AtanOp { | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | +// placeholder to avoid tilingkey overlap | ||
| 30 | + | ||
| 31 | +ASCENDC_TPL_ARGS_DECL( | ||
| 32 | + Atan, ASCENDC_TPL_UINT_DECL(schMode, 1, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 33 | + ASCENDC_TPL_DTYPE_DECL(dType, TPL_FP16, TPL_BF16, TPL_FP32)); | ||
| 34 | + | ||
| 35 | +ASCENDC_TPL_SEL(ASCENDC_TPL_ARGS_SEL( | ||
| 36 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 37 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_FP16, TPL_BF16, TPL_FP32))); | ||
| 38 | +} // namespace AtanOp | ||
| 39 | + | ||
| @@ -0,0 +1,46 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file atan_apt.cpp | ||
| 13 | + * \brief atan kernel | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +using namespace Ops::Base; | ||
| 22 | +using namespace AscendC; | ||
| 23 | + | ||
| 24 | +template <uint64_t schMode, uint64_t dType> | ||
| 25 | +__global__ __aicore__ void atan(GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) | ||
| 26 | +{ | ||
| 27 | + REGISTER_TILING_DEFAULT(EleBaseTilingDataV2); | ||
| 28 | + GET_TILING_DATA_WITH_STRUCT(EleBaseTilingDataV2, tilingData, tiling); | ||
| 29 | + KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY); | ||
| 30 | + TPipe pipe; | ||
| 31 | + | ||
| 32 | + if constexpr (dType == TPL_FP16) { | ||
| 33 | + ElementwiseSch<schMode, AtanOp::AtanDag<half>::OpDag> sch(&tilingData, &pipe); | ||
| 34 | + sch.Init(x, y); | ||
| 35 | + sch.Process(); | ||
| 36 | + } else if constexpr (dType == TPL_BF16) { | ||
| 37 | + ElementwiseSch<schMode, AtanOp::AtanDag<bfloat16_t>::OpDag> sch(&tilingData, &pipe); | ||
| 38 | + sch.Init(x, y); | ||
| 39 | + sch.Process(); | ||
| 40 | + } else if constexpr (dType == TPL_FP32) { | ||
| 41 | + ElementwiseSch<schMode, AtanOp::AtanDag<float>::OpDag> sch(&tilingData, &pipe); | ||
| 42 | + sch.Init(x, y); | ||
| 43 | + sch.Process(); | ||
| 44 | + } | ||
| 45 | + return; | ||
| 46 | +} | ||
| @@ -0,0 +1,153 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +using namespace std; | ||
| 23 | + | ||
| 24 | +class l2_atan_test : public testing::Test { | ||
| 25 | +protected: | ||
| 26 | + static void SetUpTestCase() | ||
| 27 | + { | ||
| 28 | + cout << "l2_atan_test SetUp" << endl; | ||
| 29 | + } | ||
| 30 | + | ||
| 31 | + static void TearDownTestCase() | ||
| 32 | + { | ||
| 33 | + cout << "l2_atan_test TearDown" << endl; | ||
| 34 | + } | ||
| 35 | +}; | ||
| 36 | + | ||
| 37 | +TEST_F(l2_atan_test, ascend910B2_atan_dtype_all) | ||
| 38 | +{ | ||
| 39 | + vector<aclDataType> input_vaild_dtype_list{ACL_INT8, ACL_INT32, ACL_UINT8, ACL_INT16, ACL_INT64, | ||
| 40 | + ACL_BOOL, ACL_FLOAT, ACL_FLOAT16, ACL_DOUBLE, ACL_BF16}; | ||
| 41 | + vector<aclDataType> output_vaild_dtype_list{ACL_FLOAT, ACL_FLOAT16, ACL_DOUBLE}; | ||
| 42 | + vector<aclDataType> invaild_dtype_list{ACL_COMPLEX64, ACL_COMPLEX128}; | ||
| 43 | + for (auto dtype1 : input_vaild_dtype_list) { | ||
| 44 | + auto self_tensor_desc = TensorDesc({3, 5}, dtype1, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 45 | + for (auto dtype2 : output_vaild_dtype_list) { | ||
| 46 | + auto out_tensor_desc = TensorDesc({3, 5}, dtype2, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 47 | + | ||
| 48 | + auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 49 | + uint64_t workspace_size = 0; | ||
| 50 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 51 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + for (auto dtype : invaild_dtype_list) { | ||
| 55 | + auto self_tensor_desc = TensorDesc({3, 5}, dtype, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 56 | + auto out_tensor_desc = TensorDesc({3, 5}, dtype, ACL_FORMAT_ND); | ||
| 57 | + | ||
| 58 | + auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 59 | + uint64_t workspace_size = 0; | ||
| 60 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 61 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 62 | + } | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +TEST_F(l2_atan_test, atan_nullptr) | ||
| 66 | +{ | ||
| 67 | + auto ut = OP_API_UT(aclnnAtan, INPUT((aclTensor*)nullptr), OUTPUT((aclTensor*)nullptr)); | ||
| 68 | + uint64_t workspace_size = 0; | ||
| 69 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 70 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_NULLPTR); | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +TEST_F(l2_atan_test, atan_precision) | ||
| 74 | +{ | ||
| 75 | + auto self_tensor_desc = TensorDesc({13, 16, 9}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 76 | + auto out_tensor_desc = TensorDesc({13, 16, 9}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 77 | + | ||
| 78 | + auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 79 | + uint64_t workspace_size = 0; | ||
| 80 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 81 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 82 | +} | ||
| 83 | + | ||
| 84 | +TEST_F(l2_atan_test, ascend910B2_atan_bf16_precision) | ||
| 85 | +{ | ||
| 86 | + auto self_tensor_desc = TensorDesc({13, 16, 9}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 87 | + auto out_tensor_desc = TensorDesc({13, 16, 9}, ACL_BF16, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 88 | + | ||
| 89 | + auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 90 | + uint64_t workspace_size = 0; | ||
| 91 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 92 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 93 | +} | ||
| 94 | + | ||
| 95 | +TEST_F(l2_atan_test, atan_empty_tensor) | ||
| 96 | +{ | ||
| 97 | + auto self_tensor_desc = TensorDesc({13, 0, 9}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 98 | + auto out_tensor_desc = TensorDesc({13, 0, 9}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 99 | + | ||
| 100 | + auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 101 | + uint64_t workspace_size = 0; | ||
| 102 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 103 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +TEST_F(l2_atan_test, atan_non_contiguous) | ||
| 107 | +{ | ||
| 108 | + auto self_tensor_desc = TensorDesc({5, 3}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {3, 5}).ValueRange(-20, 20); | ||
| 109 | + auto out_tensor_desc = TensorDesc({5, 3}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {3, 5}).Precision(0.001, 0.001); | ||
| 110 | + | ||
| 111 | + auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 112 | + uint64_t workspace_size = 0; | ||
| 113 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 114 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +TEST_F(l2_atan_test, atan_bigDim) | ||
| 118 | +{ | ||
| 119 | + auto self_tensor_desc = TensorDesc({2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 120 | + auto out_tensor_desc = TensorDesc({2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 121 | + | ||
| 122 | + auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 123 | + uint64_t workspace_size = 0; | ||
| 124 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 125 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +TEST_F(l2_atan_test, atan_bigDim_non_contiguous) | ||
| 129 | +{ | ||
| 130 | + auto self_tensor_desc = TensorDesc( | ||
| 131 | + {2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND, {128, 64, 32, 16, 8, 4, 2, 1, 0}, | ||
| 132 | + 0, {2, 2, 2, 2, 2, 2, 2, 2, 1}) | ||
| 133 | + .ValueRange(-20, 20); | ||
| 134 | + auto out_tensor_desc = TensorDesc( | ||
| 135 | + {2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND, {128, 64, 32, 16, 8, 4, 2, 1, 0}, | ||
| 136 | + 0, {2, 2, 2, 2, 2, 2, 2, 2, 1}) | ||
| 137 | + .Precision(0.001, 0.001); | ||
| 138 | + | ||
| 139 | + auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 140 | + uint64_t workspace_size = 0; | ||
| 141 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 142 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 143 | +} | ||
| 144 | + | ||
| 145 | +TEST_F(l2_atan_test, atan_inplace) | ||
| 146 | +{ | ||
| 147 | + auto self_tensor_desc = TensorDesc({3, 5}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 148 | + auto ut = OP_API_UT(aclnnInplaceAtan, INPUT(self_tensor_desc), OUTPUT()); | ||
| 149 | + | ||
| 150 | + uint64_t workspace_size = 0; | ||
| 151 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 152 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 153 | +} | ||
| @@ -1,139 +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 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - | ||
| 19 | - | ||
| 20 | - | ||
| 21 | -using namespace std; | ||
| 22 | - | ||
| 23 | -class l2_atan_test : public testing::Test { | ||
| 24 | - protected: | ||
| 25 | - static void SetUpTestCase() { | ||
| 26 | - cout << "l2_atan_test SetUp" << endl; | ||
| 27 | - } | ||
| 28 | - | ||
| 29 | - static void TearDownTestCase() { | ||
| 30 | - cout << "l2_atan_test TearDown" << endl; | ||
| 31 | - } | ||
| 32 | -}; | ||
| 33 | - | ||
| 34 | -TEST_F(l2_atan_test, ascend910B2_atan_dtype_all) { | ||
| 35 | - vector<aclDataType> input_vaild_dtype_list{ACL_INT8, ACL_INT32, ACL_UINT8, ACL_INT16, ACL_INT64, | ||
| 36 | - ACL_BOOL, ACL_FLOAT, ACL_FLOAT16, ACL_DOUBLE, ACL_BF16}; | ||
| 37 | - vector<aclDataType> output_vaild_dtype_list{ACL_FLOAT, ACL_FLOAT16, ACL_DOUBLE}; | ||
| 38 | - vector<aclDataType> invaild_dtype_list{ACL_COMPLEX64, ACL_COMPLEX128}; | ||
| 39 | - for (auto dtype1 : input_vaild_dtype_list) { | ||
| 40 | - auto self_tensor_desc = TensorDesc({3, 5}, dtype1, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 41 | - for (auto dtype2 : output_vaild_dtype_list) { | ||
| 42 | - auto out_tensor_desc = TensorDesc({3, 5}, dtype2, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 43 | - | ||
| 44 | - auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 45 | - uint64_t workspace_size = 0; | ||
| 46 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 47 | - EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 48 | - } | ||
| 49 | - } | ||
| 50 | - for (auto dtype : invaild_dtype_list) { | ||
| 51 | - auto self_tensor_desc = TensorDesc({3, 5}, dtype, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 52 | - auto out_tensor_desc = TensorDesc({3, 5}, dtype, ACL_FORMAT_ND); | ||
| 53 | - | ||
| 54 | - auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 55 | - uint64_t workspace_size = 0; | ||
| 56 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 57 | - EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 58 | - } | ||
| 59 | -} | ||
| 60 | - | ||
| 61 | -TEST_F(l2_atan_test, atan_nullptr) { | ||
| 62 | - auto ut = OP_API_UT(aclnnAtan, INPUT((aclTensor*)nullptr), OUTPUT((aclTensor*)nullptr)); | ||
| 63 | - uint64_t workspace_size = 0; | ||
| 64 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 65 | - EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_NULLPTR); | ||
| 66 | -} | ||
| 67 | - | ||
| 68 | -TEST_F(l2_atan_test, atan_precision) { | ||
| 69 | - auto self_tensor_desc = TensorDesc({13, 16, 9}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 70 | - auto out_tensor_desc = TensorDesc({13, 16, 9}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 71 | - | ||
| 72 | - auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 73 | - uint64_t workspace_size = 0; | ||
| 74 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 75 | - EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 76 | -} | ||
| 77 | - | ||
| 78 | -TEST_F(l2_atan_test, ascend910B2_atan_bf16_precision) { | ||
| 79 | - auto self_tensor_desc = TensorDesc({13, 16, 9}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 80 | - auto out_tensor_desc = TensorDesc({13, 16, 9}, ACL_BF16, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 81 | - | ||
| 82 | - auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 83 | - uint64_t workspace_size = 0; | ||
| 84 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 85 | - EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 86 | -} | ||
| 87 | - | ||
| 88 | -TEST_F(l2_atan_test, atan_empty_tensor) { | ||
| 89 | - auto self_tensor_desc = TensorDesc({13, 0, 9}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 90 | - auto out_tensor_desc = TensorDesc({13, 0, 9}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 91 | - | ||
| 92 | - auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 93 | - uint64_t workspace_size = 0; | ||
| 94 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 95 | - EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 96 | -} | ||
| 97 | - | ||
| 98 | -TEST_F(l2_atan_test, atan_non_contiguous) { | ||
| 99 | - auto self_tensor_desc = TensorDesc({5, 3}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {3, 5}).ValueRange(-20, 20); | ||
| 100 | - auto out_tensor_desc = TensorDesc({5, 3}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {3, 5}).Precision(0.001, 0.001); | ||
| 101 | - | ||
| 102 | - auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 103 | - uint64_t workspace_size = 0; | ||
| 104 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 105 | - EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 106 | -} | ||
| 107 | - | ||
| 108 | -TEST_F(l2_atan_test, atan_bigDim) { | ||
| 109 | - auto self_tensor_desc = TensorDesc({2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 110 | - auto out_tensor_desc = TensorDesc({2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 111 | - | ||
| 112 | - auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 113 | - uint64_t workspace_size = 0; | ||
| 114 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 115 | - EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 116 | -} | ||
| 117 | - | ||
| 118 | -TEST_F(l2_atan_test, atan_bigDim_non_contiguous) { | ||
| 119 | - auto self_tensor_desc = TensorDesc({2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND, | ||
| 120 | - {128, 64, 32, 16, 8, 4, 2, 1, 0}, 0, {2, 2, 2, 2, 2, 2, 2, 2, 1}) | ||
| 121 | - .ValueRange(-20, 20); | ||
| 122 | - auto out_tensor_desc = TensorDesc({2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND, | ||
| 123 | - {128, 64, 32, 16, 8, 4, 2, 1, 0}, 0, {2, 2, 2, 2, 2, 2, 2, 2, 1}) | ||
| 124 | - .Precision(0.001, 0.001); | ||
| 125 | - | ||
| 126 | - auto ut = OP_API_UT(aclnnAtan, INPUT(self_tensor_desc), OUTPUT(out_tensor_desc)); | ||
| 127 | - uint64_t workspace_size = 0; | ||
| 128 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 129 | - EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 130 | -} | ||
| 131 | - | ||
| 132 | -TEST_F(l2_atan_test, atan_inplace) { | ||
| 133 | - auto self_tensor_desc = TensorDesc({3, 5}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-20, 20); | ||
| 134 | - auto ut = OP_API_UT(aclnnInplaceAtan, INPUT(self_tensor_desc), OUTPUT()); | ||
| 135 | - | ||
| 136 | - uint64_t workspace_size = 0; | ||
| 137 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 138 | - EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 139 | -} | ||
| @@ -0,0 +1,151 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +using namespace std; | ||
| 19 | + | ||
| 20 | +class AtanTilingTest : public testing::Test { | ||
| 21 | +protected: | ||
| 22 | + static void SetUpTestCase() | ||
| 23 | + { | ||
| 24 | + std::cout << "AtanTilingTest SetUp" << std::endl; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + static void TearDownTestCase() | ||
| 28 | + { | ||
| 29 | + std::cout << "AtanTilingTest TearDown" << std::endl; | ||
| 30 | + } | ||
| 31 | +}; | ||
| 32 | + | ||
| 33 | +TEST_F(AtanTilingTest, atan_test_tiling_fp16_input) | ||
| 34 | +{ | ||
| 35 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 36 | + gert::TilingContextPara tilingContextPara( | ||
| 37 | + "Atan", | ||
| 38 | + { | ||
| 39 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 40 | + }, | ||
| 41 | + { | ||
| 42 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 43 | + }, | ||
| 44 | + {}, &compileInfo); | ||
| 45 | + | ||
| 46 | + uint64_t expectTilingKey = 203; | ||
| 47 | + string expectTilingData = "8192 4 5760 2048 4 1 1 2048 2048 5760 1 "; | ||
| 48 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 49 | + ExecuteTestCaseForEle( | ||
| 50 | + tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +TEST_F(AtanTilingTest, atan_test_tiling_bf16_input) | ||
| 54 | +{ | ||
| 55 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 56 | + gert::TilingContextPara tilingContextPara( | ||
| 57 | + "Atan", | ||
| 58 | + { | ||
| 59 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 60 | + }, | ||
| 61 | + { | ||
| 62 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 63 | + }, | ||
| 64 | + {}, &compileInfo); | ||
| 65 | + | ||
| 66 | + uint64_t expectTilingKey = 205; | ||
| 67 | + string expectTilingData = "8192 4 5760 2048 4 1 1 2048 2048 5760 1 "; | ||
| 68 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 69 | + ExecuteTestCaseForEle( | ||
| 70 | + tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +TEST_F(AtanTilingTest, atan_test_tiling_fp32_input) | ||
| 74 | +{ | ||
| 75 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 76 | + gert::TilingContextPara tilingContextPara( | ||
| 77 | + "Atan", | ||
| 78 | + { | ||
| 79 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 80 | + }, | ||
| 81 | + { | ||
| 82 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 83 | + }, | ||
| 84 | + {}, &compileInfo); | ||
| 85 | + | ||
| 86 | + uint64_t expectTilingKey = 207; | ||
| 87 | + string expectTilingData = "8192 8 8704 1024 8 1 1 1024 1024 8704 1 "; | ||
| 88 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 89 | + ExecuteTestCaseForEle( | ||
| 90 | + tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +TEST_F(AtanTilingTest, atan_test_tiling_invalid_input_dtype) | ||
| 94 | +{ | ||
| 95 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 96 | + gert::TilingContextPara tilingContextPara( | ||
| 97 | + "Atan", | ||
| 98 | + { | ||
| 99 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT32, ge::FORMAT_ND}, | ||
| 100 | + }, | ||
| 101 | + { | ||
| 102 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 103 | + }, | ||
| 104 | + {}, &compileInfo); | ||
| 105 | + | ||
| 106 | + uint64_t expectTilingKey = 7; | ||
| 107 | + string expectTilingData = ""; | ||
| 108 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 109 | + ExecuteTestCaseForEle( | ||
| 110 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +TEST_F(AtanTilingTest, atan_test_tiling_invalid_output_dtype) | ||
| 114 | +{ | ||
| 115 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 116 | + gert::TilingContextPara tilingContextPara( | ||
| 117 | + "Atan", | ||
| 118 | + { | ||
| 119 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 120 | + }, | ||
| 121 | + { | ||
| 122 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 123 | + }, | ||
| 124 | + {}, &compileInfo); | ||
| 125 | + | ||
| 126 | + uint64_t expectTilingKey = 7; | ||
| 127 | + string expectTilingData = ""; | ||
| 128 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 129 | + ExecuteTestCaseForEle( | ||
| 130 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 131 | +} | ||
| 132 | + | ||
| 133 | +TEST_F(AtanTilingTest, atan_test_tiling_invalid_shape) | ||
| 134 | +{ | ||
| 135 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 136 | + gert::TilingContextPara tilingContextPara( | ||
| 137 | + "Atan", | ||
| 138 | + { | ||
| 139 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 140 | + }, | ||
| 141 | + { | ||
| 142 | + {{{1, 64, 2, 6}, {1, 64, 2, 6}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 143 | + }, | ||
| 144 | + {}, &compileInfo); | ||
| 145 | + | ||
| 146 | + uint64_t expectTilingKey = 7; | ||
| 147 | + string expectTilingData = ""; | ||
| 148 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 149 | + ExecuteTestCaseForEle( | ||
| 150 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 151 | +} | ||
| @@ -0,0 +1,69 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +class AtanInferShape : public testing::Test { | ||
| 17 | +protected: | ||
| 18 | + static void SetUpTestCase() | ||
| 19 | + { | ||
| 20 | + std::cout << "Atan InferShape SetUp" << std::endl; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + static void TearDownTestCase() | ||
| 24 | + { | ||
| 25 | + std::cout << "Atan InferShape TearDown" << std::endl; | ||
| 26 | + } | ||
| 27 | +}; | ||
| 28 | + | ||
| 29 | +TEST_F(AtanInferShape, atan_infershape_diff_test) | ||
| 30 | +{ | ||
| 31 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 32 | + "Atan", | ||
| 33 | + { | ||
| 34 | + {{{4, 3, 4}, {4, 3, 4}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 35 | + }, | ||
| 36 | + { | ||
| 37 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 38 | + }); | ||
| 39 | + std::vector<std::vector<int64_t>> expectOutputShape = {{4, 3, 4}}; | ||
| 40 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +TEST_F(AtanInferShape, atan_infershape_same_test) | ||
| 44 | +{ | ||
| 45 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 46 | + "Atan", | ||
| 47 | + { | ||
| 48 | + {{{1, 3, 4}, {1, 3, 4}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 49 | + }, | ||
| 50 | + { | ||
| 51 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 52 | + }); | ||
| 53 | + std::vector<std::vector<int64_t>> expectOutputShape = {{1, 3, 4}}; | ||
| 54 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +TEST_F(AtanInferShape, atan_infershape_dynamic_test) | ||
| 58 | +{ | ||
| 59 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 60 | + "Atan", | ||
| 61 | + { | ||
| 62 | + {{{-1}, {-1}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 63 | + }, | ||
| 64 | + { | ||
| 65 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 66 | + }); | ||
| 67 | + std::vector<std::vector<int64_t>> expectOutputShape = {{-1}}; | ||
| 68 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 69 | +} | ||
| @@ -1,20 +1,15 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | -# 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 | -# This file is a part of the CANN Open Software. | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 5 | -# Licensed under 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. | 5 | # 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, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 7 | +# 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. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | 10 | ||
| 12 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | +# 设置算子定义时支持的芯片类型 |
| 13 | -if(NOT ENABLE_TEST AND NOT BENCHMARK) | 12 | +set(SUPPORT_COMPUTE_UNIT "ascend950" "mc62cm12a") |
| 14 | - list(REMOVE_ITEM CURRENT_DIRS tests) | 13 | +# 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 |
| 15 | -endif() | 14 | +set(SUPPORT_TILING_DIR "arch35" "arch35") |
| 16 | -foreach(SUB_DIR ${CURRENT_DIRS}) | 15 | +add_all_modules_sources(OPTYPE erf ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE) |
| 17 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 18 | - add_subdirectory(${SUB_DIR}) | ||
| 19 | - endif() | ||
| 20 | -endforeach() | ||
| @@ -0,0 +1,43 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file erf_proto.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +namespace ge { | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | +* @brief Computes the Gauss error function of 'x' element-wise. \n | ||
| 25 | + | ||
| 26 | +* @par Inputs: | ||
| 27 | +* x: A Tensor of type bfloat16, float16, float32 or double. the format can be | ||
| 28 | +* [NCHW,NHWC,ND] | ||
| 29 | + | ||
| 30 | +* @par Outputs: | ||
| 31 | +* y: A Tensor. Has the same type, format and shape as 'x'. \n | ||
| 32 | + | ||
| 33 | +* @par Third-party framework compatibility | ||
| 34 | +* Compatible with the TensorFlow operator Erf. | ||
| 35 | +*/ | ||
| 36 | +REG_OP(Erf) | ||
| 37 | + .INPUT(x, TensorType({FloatingDataType, DT_BF16})) | ||
| 38 | + .OUTPUT(y, TensorType({FloatingDataType, DT_BF16})) | ||
| 39 | + .OP_END_FACTORY_REG(Erf) | ||
| 40 | + | ||
| 41 | +} // namespace ge | ||
| 42 | + | ||
| 43 | + | ||
| @@ -1,12 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -add_modules_sources() | ||
| @@ -0,0 +1,145 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file erf_tiling_arch35.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | +using namespace ErfOp; | ||
| 30 | +using namespace Ops::Math::OpTiling; | ||
| 31 | + | ||
| 32 | +namespace optiling { | ||
| 33 | +const size_t ASCEND_WORKSPACE = 16777216; // 16M | ||
| 34 | +const int64_t ASCEND_API_BUFFER = 122880; // 120K | ||
| 35 | + | ||
| 36 | +ge::graphStatus ErfTiling::CalcInputDtype() | ||
| 37 | +{ | ||
| 38 | + OP_LOGD(tilingContext->GetNodeName(), "ErfTiling CalcInputDtype enter."); | ||
| 39 | + auto inputDesc = tilingContext->GetInputDesc(0); | ||
| 40 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputDesc); | ||
| 41 | + this->inputDtype = inputDesc->GetDataType(); | ||
| 42 | + OP_CHECK_IF( | ||
| 43 | + this->inputDtype != ge::DT_FLOAT16 && this->inputDtype != ge::DT_BF16 && this->inputDtype != ge::DT_FLOAT, | ||
| 44 | + OP_LOGE( | ||
| 45 | + tilingContext->GetNodeName(), | ||
| 46 | + "input x dtype [%s] not supported, only support [DT_FLOAT16, DT_BF16, DT_FLOAT]", | ||
| 47 | + ge::TypeUtils::DataTypeToSerialString(this->inputDtype).c_str()), | ||
| 48 | + return ge::GRAPH_FAILED); | ||
| 49 | + return ge::GRAPH_SUCCESS; | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +ge::graphStatus ErfTiling::CalcOutputDtype() | ||
| 53 | +{ | ||
| 54 | + OP_LOGD(tilingContext->GetNodeName(), "ErfTiling CalcOutputDtype enter."); | ||
| 55 | + auto outputDesc = tilingContext->GetOutputDesc(0); | ||
| 56 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputDesc); | ||
| 57 | + this->outputDtype = outputDesc->GetDataType(); | ||
| 58 | + OP_CHECK_IF( | ||
| 59 | + this->outputDtype != this->inputDtype, | ||
| 60 | + OP_LOGE(tilingContext->GetNodeName(), "output y dtype not same as input x"), return ge::GRAPH_FAILED); | ||
| 61 | + return ge::GRAPH_SUCCESS; | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +ge::graphStatus ErfTiling::CheckShape() | ||
| 65 | +{ | ||
| 66 | + OP_LOGD(tilingContext->GetNodeName(), "ErfTiling CheckShape enter."); | ||
| 67 | + auto inputStorageShape = tilingContext->GetInputShape(0); | ||
| 68 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputStorageShape); | ||
| 69 | + const gert::Shape& inputXShape = EnsureNotScalar(inputStorageShape->GetStorageShape()); | ||
| 70 | + | ||
| 71 | + auto outputStorageShape = tilingContext->GetOutputShape(0); | ||
| 72 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputStorageShape); | ||
| 73 | + const gert::Shape& outputYShape = EnsureNotScalar(outputStorageShape->GetStorageShape()); | ||
| 74 | + | ||
| 75 | + OP_CHECK_IF( | ||
| 76 | + inputXShape != outputYShape, OP_LOGE(tilingContext->GetNodeName(), "input x and output y shape not same"), | ||
| 77 | + return ge::GRAPH_FAILED); | ||
| 78 | + return ge::GRAPH_SUCCESS; | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +ge::graphStatus ErfTiling::RunTiling() | ||
| 82 | +{ | ||
| 83 | + OP_LOGD(tilingContext->GetNodeName(), "ErfTiling RunTiling enter."); | ||
| 84 | + ElewiseBaseTiling elewiseBaseTiling(tilingContext); | ||
| 85 | + OP_CHECK_IF( | ||
| 86 | + CalcInputDtype() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "get input dtype failed"), | ||
| 87 | + return ge::GRAPH_FAILED); | ||
| 88 | + OP_CHECK_IF( | ||
| 89 | + CalcOutputDtype() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "get output dtype failed"), | ||
| 90 | + return ge::GRAPH_FAILED); | ||
| 91 | + OP_CHECK_IF( | ||
| 92 | + CheckShape() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "check shape failed"), return ge::GRAPH_FAILED); | ||
| 93 | + | ||
| 94 | + auto tiling = tilingContext->GetTilingData<EleBaseTilingDataV2>(); | ||
| 95 | + OP_CHECK_IF( | ||
| 96 | + (tiling == nullptr), OP_LOGE(tilingContext->GetNodeName(), "Get AssignAddTiling from GE context failed"), | ||
| 97 | + return ge::GRAPH_FAILED); | ||
| 98 | + | ||
| 99 | + ge::graphStatus baseTilingResult = ge::GRAPH_FAILED; | ||
| 100 | + if (this->outputDtype == ge::DT_FLOAT16) { | ||
| 101 | + dType = TPL_FP16; | ||
| 102 | + baseTilingResult = elewiseBaseTiling.DoTiling<ErfOp::ErfDAG<half, half>::OpDag>(*tiling, ASCEND_API_BUFFER); | ||
| 103 | + } else if (this->outputDtype == ge::DT_BF16) { | ||
| 104 | + dType = TPL_BF16; | ||
| 105 | + baseTilingResult = elewiseBaseTiling.DoTiling<ErfOp::ErfDAG<bfloat16_t>::OpDag>(*tiling, ASCEND_API_BUFFER); | ||
| 106 | + } else if (this->outputDtype == ge::DT_FLOAT) { | ||
| 107 | + dType = TPL_FP32; | ||
| 108 | + baseTilingResult = elewiseBaseTiling.DoTiling<ErfOp::ErfDAG<float>::OpDag>(*tiling, ASCEND_API_BUFFER); | ||
| 109 | + } else { | ||
| 110 | + OP_LOGE( | ||
| 111 | + tilingContext->GetNodeName(), | ||
| 112 | + "output y dtype [%s] not supported, only support [DT_FLOAT16, DT_BF16, DT_FLOAT]", | ||
| 113 | + ge::TypeUtils::DataTypeToSerialString(this->outputDtype).c_str()); | ||
| 114 | + return ge::GRAPH_FAILED; | ||
| 115 | + } | ||
| 116 | + OP_CHECK_IF( | ||
| 117 | + baseTilingResult == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "elewiseBaseTiling failed"), | ||
| 118 | + return ge::GRAPH_FAILED); | ||
| 119 | + | ||
| 120 | + size_t* currentWorkspace = tilingContext->GetWorkspaceSizes(1); | ||
| 121 | + currentWorkspace[0] = ASCEND_WORKSPACE; | ||
| 122 | + | ||
| 123 | + const uint64_t tilingKey = GET_TPL_TILING_KEY(static_cast<uint64_t>(tiling->scheMode), dType); | ||
| 124 | + OP_LOGD(tilingContext->GetNodeName(), "[TilingData] : tilingKey=%lu", tilingKey); | ||
| 125 | + tilingContext->SetTilingKey(tilingKey); | ||
| 126 | + tilingContext->SetBlockDim(tiling->blockNum); | ||
| 127 | + return ge::GRAPH_SUCCESS; | ||
| 128 | +} | ||
| 129 | + | ||
| 130 | +static ge::graphStatus Tiling4Erf(gert::TilingContext* tilingContextGen) | ||
| 131 | +{ | ||
| 132 | + OP_LOGD(tilingContextGen->GetNodeName(), "Tiling4Erf rt2.0 is running."); | ||
| 133 | + auto compileInfo = reinterpret_cast<const ElewiseCompileInfo*>(tilingContextGen->GetCompileInfo()); | ||
| 134 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContextGen, compileInfo); | ||
| 135 | + ErfTiling baseOpTiling(tilingContextGen); | ||
| 136 | + return baseOpTiling.RunTiling(); | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +static ge::graphStatus TilingPrepareForErf([[maybe_unused]] gert::TilingParseContext* context) | ||
| 140 | +{ | ||
| 141 | + return ge::GRAPH_SUCCESS; | ||
| 142 | +} | ||
| 143 | + | ||
| 144 | +IMPL_OP_OPTILING(Erf).Tiling(Tiling4Erf).TilingParse<ElewiseCompileInfo>(TilingPrepareForErf); | ||
| 145 | +} // namespace optiling | ||
| @@ -0,0 +1,42 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file erf_tiling_arch35.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace optiling { | ||
| 23 | +using namespace Ops::Base; | ||
| 24 | + | ||
| 25 | +class ErfTiling { | ||
| 26 | +public: | ||
| 27 | + explicit ErfTiling(gert::TilingContext* context) : tilingContext(context) {}; | ||
| 28 | + ge::graphStatus RunTiling(); | ||
| 29 | + | ||
| 30 | +protected: | ||
| 31 | + ge::graphStatus CalcOutputDtype(); | ||
| 32 | + ge::graphStatus CalcInputDtype(); | ||
| 33 | + ge::graphStatus CheckShape(); | ||
| 34 | + | ||
| 35 | +private: | ||
| 36 | + gert::TilingContext* tilingContext; | ||
| 37 | + ge::DataType outputDtype; | ||
| 38 | + ge::DataType inputDtype; | ||
| 39 | + uint64_t dType = 0; | ||
| 40 | +}; | ||
| 41 | +} // namespace optiling | ||
| 42 | + | ||
| @@ -0,0 +1,92 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "Erf", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "Erf_edc28b7a93481966e91becc3c30d25f0", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "x", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "bfloat16", | ||
| 11 | + "format": "ND", | ||
| 12 | + "paramType": "required", | ||
| 13 | + "shape": [ | ||
| 14 | + -2 | ||
| 15 | + ], | ||
| 16 | + "format_match_mode": "FormatAgnostic" | ||
| 17 | + } | ||
| 18 | + ], | ||
| 19 | + "outputs": [ | ||
| 20 | + { | ||
| 21 | + "name": "y", | ||
| 22 | + "index": 0, | ||
| 23 | + "dtype": "bfloat16", | ||
| 24 | + "format": "ND", | ||
| 25 | + "paramType": "required", | ||
| 26 | + "shape": [ | ||
| 27 | + -2 | ||
| 28 | + ], | ||
| 29 | + "format_match_mode": "FormatAgnostic" | ||
| 30 | + } | ||
| 31 | + ] | ||
| 32 | + }, | ||
| 33 | + { | ||
| 34 | + "bin_filename": "Erf_e73d8e0483dd2b837ef71ecbee13cf01", | ||
| 35 | + "inputs": [ | ||
| 36 | + { | ||
| 37 | + "name": "x", | ||
| 38 | + "index": 0, | ||
| 39 | + "dtype": "float16", | ||
| 40 | + "format": "ND", | ||
| 41 | + "paramType": "required", | ||
| 42 | + "shape": [ | ||
| 43 | + -2 | ||
| 44 | + ], | ||
| 45 | + "format_match_mode": "FormatAgnostic" | ||
| 46 | + } | ||
| 47 | + ], | ||
| 48 | + "outputs": [ | ||
| 49 | + { | ||
| 50 | + "name": "y", | ||
| 51 | + "index": 0, | ||
| 52 | + "dtype": "float16", | ||
| 53 | + "format": "ND", | ||
| 54 | + "paramType": "required", | ||
| 55 | + "shape": [ | ||
| 56 | + -2 | ||
| 57 | + ], | ||
| 58 | + "format_match_mode": "FormatAgnostic" | ||
| 59 | + } | ||
| 60 | + ] | ||
| 61 | + }, | ||
| 62 | + { | ||
| 63 | + "bin_filename": "Erf_61f744b9d0e233e3b5200517ad55da6f", | ||
| 64 | + "inputs": [ | ||
| 65 | + { | ||
| 66 | + "name": "x", | ||
| 67 | + "index": 0, | ||
| 68 | + "dtype": "float32", | ||
| 69 | + "format": "ND", | ||
| 70 | + "paramType": "required", | ||
| 71 | + "shape": [ | ||
| 72 | + -2 | ||
| 73 | + ], | ||
| 74 | + "format_match_mode": "FormatAgnostic" | ||
| 75 | + } | ||
| 76 | + ], | ||
| 77 | + "outputs": [ | ||
| 78 | + { | ||
| 79 | + "name": "y", | ||
| 80 | + "index": 0, | ||
| 81 | + "dtype": "float32", | ||
| 82 | + "format": "ND", | ||
| 83 | + "paramType": "required", | ||
| 84 | + "shape": [ | ||
| 85 | + -2 | ||
| 86 | + ], | ||
| 87 | + "format_match_mode": "FormatAgnostic" | ||
| 88 | + } | ||
| 89 | + ] | ||
| 90 | + } | ||
| 91 | + ] | ||
| 92 | +} | ||
| @@ -0,0 +1,2 @@ | |||
| 1 | +[Erf] | ||
| 2 | +default=0 | ||
| @@ -0,0 +1,49 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file erf_def.cpp | ||
| 13 | + * \brief erf def | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +namespace ops { | ||
| 20 | +class Erf : public OpDef { | ||
| 21 | +public: | ||
| 22 | + explicit Erf(const char* name) : OpDef(name) | ||
| 23 | + { | ||
| 24 | + this->Input("x") | ||
| 25 | + .ParamType(REQUIRED) | ||
| 26 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}) | ||
| 27 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 28 | + .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 29 | + this->Output("y") | ||
| 30 | + .ParamType(REQUIRED) | ||
| 31 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}) | ||
| 32 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 33 | + .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 34 | + | ||
| 35 | + OpAICoreConfig aicoreConfig; | ||
| 36 | + aicoreConfig.DynamicCompileStaticFlag(true) | ||
| 37 | + .DynamicFormatFlag(false) | ||
| 38 | + .DynamicRankSupportFlag(true) | ||
| 39 | + .DynamicShapeSupportFlag(true) | ||
| 40 | + .NeedCheckSupportFlag(false) | ||
| 41 | + .PrecisionReduceFlag(true) | ||
| 42 | + .ExtendCfgInfo("opFile.value", "erf_apt"); | ||
| 43 | + this->AICore().AddConfig("ascend950", aicoreConfig); | ||
| 44 | + this->AICore().AddConfig("mc62cm12a", aicoreConfig); | ||
| 45 | + } | ||
| 46 | +}; | ||
| 47 | + | ||
| 48 | +OP_ADD(Erf); | ||
| 49 | +} // namespace ops | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -8,15 +8,14 @@ | |||
| 8 | * See LICENSE in the root of the software repository for the full text of the License. | 8 | * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | - #ifndef OP_API_INC_LEVEL0_RIGHT_SHIFT_H_ | 11 | +/*! |
| 12 | - #define OP_API_INC_LEVEL0_RIGHT_SHIFT_H_ | 12 | + * \file erf_infershape.cpp |
| 13 | - | 13 | + * \brief |
| 14 | - #include "opdev/op_executor.h" | 14 | + */ |
| 15 | - | 15 | +#include "infershape_elewise_util.h" |
| 16 | - namespace l0op { | 16 | +#include "register/op_impl_registry.h" |
| 17 | - bool IsSupported(const aclTensor* x, const aclTensor* y); | 17 | + |
| 18 | - const aclTensor* RightShift(const aclTensor* x, const aclTensor* y, aclOpExecutor* executor); | 18 | +using namespace ge; |
| 19 | - } // namespace l0op | 19 | +namespace ops { |
| 20 | - | 20 | +IMPL_OP_INFERSHAPE(Erf).InferShape(Ops::Base::InferShape4Elewise); |
| 21 | - #endif // OP_API_INC_LEVEL0_RIGHT_SHIFT_H_ | 21 | +} // namespace ops |
| 22 | - | ||
| @@ -0,0 +1,42 @@ | |||
| 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 | +/* ! | ||
| 12 | + * \file erf_dag.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +namespace ErfOp { | ||
| 24 | +using namespace Ops::Base; | ||
| 25 | +const int CAST_MODE_NONE = 0; | ||
| 26 | +const int CAST_MODE_RINT = 1; | ||
| 27 | + | ||
| 28 | +template <typename U, typename T = float> | ||
| 29 | +struct ErfDAG { | ||
| 30 | + using OpCopyIn0 = Bind<Vec::CopyIn<U>, Placeholder::In0<U>>; | ||
| 31 | + using OpCopyIn0Cast = Bind<Vec::Cast<T, U, CAST_MODE_NONE>, OpCopyIn0>; | ||
| 32 | + using OpResult = Bind<Vec::Erf<T>, OpCopyIn0Cast>; | ||
| 33 | + using OpResultCast = Bind<Vec::Cast<U, T, CAST_MODE_RINT>, OpResult>; | ||
| 34 | + using OpCopyOut = Bind<Vec::CopyOut<U>, Placeholder::Out0<U>, OpResultCast>; | ||
| 35 | + | ||
| 36 | + using Outputs = Elems<OpCopyOut>; | ||
| 37 | + using MemCfg = MemOptCfg<MemLevel::LEVEL_2>; | ||
| 38 | + using OpDag = DAGSch<Outputs, void, MemCfg>; | ||
| 39 | +}; | ||
| 40 | +} // namespace ErfOp | ||
| 41 | + | ||
| 42 | + | ||
| @@ -0,0 +1,45 @@ | |||
| 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 | +/* ! | ||
| 12 | + * \file erf_struct.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +namespace ErfOp { | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | +ASCENDC_TPL_ARGS_DECL( | ||
| 30 | + Erf, ASCENDC_TPL_UINT_DECL(schMode, 1, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 31 | + ASCENDC_TPL_DTYPE_DECL(dType, TPL_FP16, TPL_BF16, TPL_FP32)); | ||
| 32 | + | ||
| 33 | +ASCENDC_TPL_SEL( | ||
| 34 | + ASCENDC_TPL_ARGS_SEL( | ||
| 35 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 36 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_FP16)), | ||
| 37 | + ASCENDC_TPL_ARGS_SEL( | ||
| 38 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 39 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_BF16)), | ||
| 40 | + ASCENDC_TPL_ARGS_SEL( | ||
| 41 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 42 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_FP32))); | ||
| 43 | +} // namespace ErfOp | ||
| 44 | + | ||
| 45 | + | ||
| @@ -0,0 +1,48 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file erf_apt.cpp | ||
| 13 | + * \brief z = erf(x) | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +using namespace Ops::Base; | ||
| 23 | +namespace AscendC { | ||
| 24 | + | ||
| 25 | +template <uint64_t schMode, uint64_t dType> | ||
| 26 | +__global__ __aicore__ void erf(GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) | ||
| 27 | +{ | ||
| 28 | + REGISTER_TILING_DEFAULT(EleBaseTilingDataV2); | ||
| 29 | + GET_TILING_DATA_WITH_STRUCT(EleBaseTilingDataV2, tilingData, tiling); | ||
| 30 | + KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY); | ||
| 31 | + TPipe pipe; | ||
| 32 | + if constexpr (dType == TPL_FP16) { | ||
| 33 | + ElementwiseSch<schMode, ErfOp::ErfDAG<half, half>::OpDag> sch(&tilingData, &pipe); | ||
| 34 | + sch.Init(x, y); | ||
| 35 | + sch.Process(); | ||
| 36 | + } else if constexpr (dType == TPL_BF16) { | ||
| 37 | + ElementwiseSch<schMode, ErfOp::ErfDAG<bfloat16_t>::OpDag> sch(&tilingData, &pipe); | ||
| 38 | + sch.Init(x, y); | ||
| 39 | + sch.Process(); | ||
| 40 | + } else if constexpr (dType == TPL_FP32) { | ||
| 41 | + ElementwiseSch<schMode, ErfOp::ErfDAG<float>::OpDag> sch(&tilingData, &pipe); | ||
| 42 | + sch.Init(x, y); | ||
| 43 | + sch.Process(); | ||
| 44 | + } | ||
| 45 | + return; | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +} // namespace AscendC | ||
| @@ -1,17 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
| @@ -1,17 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
| @@ -1,18 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
| 18 | - | ||
| @@ -1,13 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -if(PASS_UT OR (UT_TEST_ALL AND NOT AICPU_ONLY)) | ||
| 13 | -endif() | ||
| @@ -0,0 +1,352 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +class l2ErfTest : public testing::Test { | ||
| 17 | +protected: | ||
| 18 | + static void SetUpTestCase() | ||
| 19 | + { | ||
| 20 | + std::cout << "l2ErfTest SetUp" << std::endl; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + static void TearDownTestCase() | ||
| 24 | + { | ||
| 25 | + std::cout << "l2ErfTest TearDown" << std::endl; | ||
| 26 | + } | ||
| 27 | +}; | ||
| 28 | + | ||
| 29 | +// self的数据类型不在支持范围内 | ||
| 30 | +TEST_F(l2ErfTest, l2_erf_test_001) | ||
| 31 | +{ | ||
| 32 | + auto selfDesc = TensorDesc({2, 3}, ACL_INT8, ACL_FORMAT_ND); | ||
| 33 | + auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 34 | + | ||
| 35 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 36 | + | ||
| 37 | + uint64_t workspaceSize = 0; | ||
| 38 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 39 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +// out的数据类型不在支持范围内 | ||
| 43 | +TEST_F(l2ErfTest, l2_erf_test_002) | ||
| 44 | +{ | ||
| 45 | + auto selfDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 46 | + auto outDesc = TensorDesc({2, 3}, ACL_INT8, ACL_FORMAT_ND); | ||
| 47 | + | ||
| 48 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 49 | + | ||
| 50 | + uint64_t workspaceSize = 0; | ||
| 51 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 52 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +// self和out的shape不一致 | ||
| 56 | +TEST_F(l2ErfTest, l2_erf_test_004) | ||
| 57 | +{ | ||
| 58 | + auto selfDesc = TensorDesc({2, 3, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 59 | + auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 60 | + | ||
| 61 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 62 | + | ||
| 63 | + uint64_t workspaceSize = 0; | ||
| 64 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 65 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +// self和out的shape不一致 | ||
| 69 | +TEST_F(l2ErfTest, l2_erf_test_005) | ||
| 70 | +{ | ||
| 71 | + auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 72 | + auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 73 | + | ||
| 74 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 75 | + | ||
| 76 | + uint64_t workspaceSize = 0; | ||
| 77 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 78 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 79 | +} | ||
| 80 | + | ||
| 81 | +// 空tensor | ||
| 82 | +TEST_F(l2ErfTest, l2_erf_test_006) | ||
| 83 | +{ | ||
| 84 | + auto selfDesc = TensorDesc({2, 0}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 85 | + auto outDesc = TensorDesc({2, 0}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 86 | + | ||
| 87 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 88 | + | ||
| 89 | + uint64_t workspaceSize = 0; | ||
| 90 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 91 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +// 正常路径,float32,万分之一精度不合格,用千分之一精度。 | ||
| 95 | +TEST_F(l2ErfTest, l2_erf_test_007) | ||
| 96 | +{ | ||
| 97 | + auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 98 | + auto outDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.01, 0.01); | ||
| 99 | + | ||
| 100 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 101 | + | ||
| 102 | + uint64_t workspaceSize = 0; | ||
| 103 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 104 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +// 正常路径,float16 由于NUMPY目前不支持ERF函数,无法进行精度测试 | ||
| 108 | +TEST_F(l2ErfTest, l2_erf_test_008) | ||
| 109 | +{ | ||
| 110 | + auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 111 | + auto outDesc = TensorDesc({2, 4}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 112 | + | ||
| 113 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 114 | + | ||
| 115 | + uint64_t workspaceSize = 0; | ||
| 116 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 117 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +// self为空 | ||
| 121 | +TEST_F(l2ErfTest, l2_erf_test_009) | ||
| 122 | +{ | ||
| 123 | + auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 124 | + | ||
| 125 | + auto ut = OP_API_UT(aclnnErf, INPUT((aclTensor*)nullptr), OUTPUT(outDesc)); | ||
| 126 | + | ||
| 127 | + uint64_t workspaceSize = 0; | ||
| 128 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 129 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_NULLPTR); | ||
| 130 | +} | ||
| 131 | + | ||
| 132 | +// out为空 | ||
| 133 | +TEST_F(l2ErfTest, l2_erf_test_010) | ||
| 134 | +{ | ||
| 135 | + auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 136 | + | ||
| 137 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT((aclTensor*)nullptr)); | ||
| 138 | + | ||
| 139 | + uint64_t workspaceSize = 0; | ||
| 140 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 141 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_NULLPTR); | ||
| 142 | +} | ||
| 143 | + | ||
| 144 | +// dtype int32 | ||
| 145 | +TEST_F(l2ErfTest, l2_erf_test_013) | ||
| 146 | +{ | ||
| 147 | + auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_INT32, ACL_FORMAT_NDHWC); | ||
| 148 | + auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_INT32, ACL_FORMAT_NDHWC); | ||
| 149 | + | ||
| 150 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 151 | + | ||
| 152 | + uint64_t workspaceSize = 0; | ||
| 153 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 154 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 155 | +} | ||
| 156 | + | ||
| 157 | +// dtype int64 | ||
| 158 | +TEST_F(l2ErfTest, l2_erf_test_014) | ||
| 159 | +{ | ||
| 160 | + auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_INT64, ACL_FORMAT_NDHWC); | ||
| 161 | + auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_INT64, ACL_FORMAT_NDHWC); | ||
| 162 | + | ||
| 163 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 164 | + | ||
| 165 | + uint64_t workspaceSize = 0; | ||
| 166 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 167 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 168 | +} | ||
| 169 | + | ||
| 170 | +// dtype int16 | ||
| 171 | +TEST_F(l2ErfTest, l2_erf_test_015) | ||
| 172 | +{ | ||
| 173 | + auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_INT16, ACL_FORMAT_NDHWC); | ||
| 174 | + auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_INT16, ACL_FORMAT_NDHWC); | ||
| 175 | + | ||
| 176 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 177 | + | ||
| 178 | + uint64_t workspaceSize = 0; | ||
| 179 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 180 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 181 | +} | ||
| 182 | + | ||
| 183 | +// dtype int8 | ||
| 184 | +TEST_F(l2ErfTest, l2_erf_test_016) | ||
| 185 | +{ | ||
| 186 | + auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_INT8, ACL_FORMAT_NDHWC); | ||
| 187 | + auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_INT8, ACL_FORMAT_NDHWC); | ||
| 188 | + | ||
| 189 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 190 | + | ||
| 191 | + uint64_t workspaceSize = 0; | ||
| 192 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 193 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 194 | +} | ||
| 195 | + | ||
| 196 | +// dtype uint8 | ||
| 197 | +TEST_F(l2ErfTest, l2_erf_test_017) | ||
| 198 | +{ | ||
| 199 | + auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_UINT8, ACL_FORMAT_NDHWC); | ||
| 200 | + auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_UINT8, ACL_FORMAT_NDHWC); | ||
| 201 | + | ||
| 202 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 203 | + | ||
| 204 | + uint64_t workspaceSize = 0; | ||
| 205 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 206 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 207 | +} | ||
| 208 | + | ||
| 209 | +// dtype bool | ||
| 210 | +TEST_F(l2ErfTest, l2_erf_test_018) | ||
| 211 | +{ | ||
| 212 | + auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_BOOL, ACL_FORMAT_NDHWC); | ||
| 213 | + auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_FLOAT, ACL_FORMAT_NDHWC); | ||
| 214 | + | ||
| 215 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 216 | + | ||
| 217 | + uint64_t workspaceSize = 0; | ||
| 218 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 219 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 220 | +} | ||
| 221 | + | ||
| 222 | +// dtype complex64 | ||
| 223 | +TEST_F(l2ErfTest, l2_erf_test_019) | ||
| 224 | +{ | ||
| 225 | + auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_COMPLEX64, ACL_FORMAT_NDHWC); | ||
| 226 | + auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_COMPLEX64, ACL_FORMAT_NDHWC); | ||
| 227 | + | ||
| 228 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 229 | + | ||
| 230 | + uint64_t workspaceSize = 0; | ||
| 231 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 232 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 233 | +} | ||
| 234 | + | ||
| 235 | +// dtype complex128 | ||
| 236 | +TEST_F(l2ErfTest, l2_erf_test_020) | ||
| 237 | +{ | ||
| 238 | + auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_COMPLEX128, ACL_FORMAT_NDHWC); | ||
| 239 | + auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_COMPLEX128, ACL_FORMAT_NDHWC); | ||
| 240 | + | ||
| 241 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 242 | + | ||
| 243 | + uint64_t workspaceSize = 0; | ||
| 244 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 245 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 246 | +} | ||
| 247 | + | ||
| 248 | +// dtype undefine | ||
| 249 | +TEST_F(l2ErfTest, l2_erf_test_021) | ||
| 250 | +{ | ||
| 251 | + auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_DT_UNDEFINED, ACL_FORMAT_NDHWC); | ||
| 252 | + auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_DT_UNDEFINED, ACL_FORMAT_NDHWC); | ||
| 253 | + | ||
| 254 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 255 | + | ||
| 256 | + uint64_t workspaceSize = 0; | ||
| 257 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 258 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 259 | +} | ||
| 260 | + | ||
| 261 | +// format self是私有格式 | ||
| 262 | +TEST_F(l2ErfTest, l2_erf_test_025) | ||
| 263 | +{ | ||
| 264 | + auto selfDesc = TensorDesc({2, 4, 6, 8, 5}, ACL_FLOAT, ACL_FORMAT_NC1HWC0); | ||
| 265 | + auto outDesc = TensorDesc({2, 4, 6, 8}, ACL_FLOAT, ACL_FORMAT_HWCN); | ||
| 266 | + | ||
| 267 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 268 | + | ||
| 269 | + uint64_t workspaceSize = 0; | ||
| 270 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 271 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 272 | +} | ||
| 273 | + | ||
| 274 | +// format out是私有格式 | ||
| 275 | +TEST_F(l2ErfTest, l2_erf_test_026) | ||
| 276 | +{ | ||
| 277 | + auto selfDesc = TensorDesc({2, 4, 6, 8}, ACL_FLOAT, ACL_FORMAT_HWCN); | ||
| 278 | + auto outDesc = TensorDesc({2, 4, 6, 8, 8}, ACL_FLOAT, ACL_FORMAT_NC1HWC0); | ||
| 279 | + | ||
| 280 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 281 | + | ||
| 282 | + uint64_t workspaceSize = 0; | ||
| 283 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 284 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 285 | +} | ||
| 286 | + | ||
| 287 | +// 正常路径,float32,inplace | ||
| 288 | +TEST_F(l2ErfTest, l2_erf_test_027) | ||
| 289 | +{ | ||
| 290 | + auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.01, 0.01); | ||
| 291 | + | ||
| 292 | + auto ut = OP_API_UT(aclnnInplaceErf, INPUT(selfDesc), OUTPUT()); | ||
| 293 | + | ||
| 294 | + uint64_t workspaceSize = 0; | ||
| 295 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 296 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 297 | +} | ||
| 298 | + | ||
| 299 | +// 非连续 | ||
| 300 | +TEST_F(l2ErfTest, l2_erf_test_029) | ||
| 301 | +{ | ||
| 302 | + auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 2}, 0, {4, 2}); | ||
| 303 | + auto outDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 2}, 0, {4, 2}).Precision(0.01, 0.01); | ||
| 304 | + | ||
| 305 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 306 | + | ||
| 307 | + uint64_t workspaceSize = 0; | ||
| 308 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 309 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 310 | +} | ||
| 311 | + | ||
| 312 | +// CheckShape_10D | ||
| 313 | +TEST_F(l2ErfTest, l2_erf_test_030) | ||
| 314 | +{ | ||
| 315 | + auto selfDesc = TensorDesc({2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 316 | + auto outDesc = TensorDesc({2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 317 | + | ||
| 318 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 319 | + | ||
| 320 | + // only test GetWorkspaceSize | ||
| 321 | + uint64_t workspaceSize = 0; | ||
| 322 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 323 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 324 | +} | ||
| 325 | + | ||
| 326 | +// Check dtype | ||
| 327 | +TEST_F(l2ErfTest, l2_erf_test_031) | ||
| 328 | +{ | ||
| 329 | + auto selfDesc = TensorDesc({2, 4}, ACL_BOOL, ACL_FORMAT_ND); | ||
| 330 | + auto outDesc = TensorDesc({2, 4}, ACL_INT32, ACL_FORMAT_ND); | ||
| 331 | + | ||
| 332 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 333 | + | ||
| 334 | + // only test GetWorkspaceSize | ||
| 335 | + uint64_t workspaceSize = 0; | ||
| 336 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 337 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 338 | +} | ||
| 339 | + | ||
| 340 | +// Check dtype | ||
| 341 | +TEST_F(l2ErfTest, l2_erf_test_032) | ||
| 342 | +{ | ||
| 343 | + auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 344 | + auto outDesc = TensorDesc({2, 4}, ACL_INT32, ACL_FORMAT_ND); | ||
| 345 | + | ||
| 346 | + auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 347 | + | ||
| 348 | + // only test GetWorkspaceSize | ||
| 349 | + uint64_t workspaceSize = 0; | ||
| 350 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 351 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 352 | +} | ||
| @@ -1,20 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
| 18 | - | ||
| 19 | -if(OP_API_UT OR (UT_TEST_ALL AND NOT AICPU_ONLY)) | ||
| 20 | -endif() | ||
| @@ -0,0 +1,151 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +using namespace std; | ||
| 19 | + | ||
| 20 | +class ErfTilingTest : public testing::Test { | ||
| 21 | +protected: | ||
| 22 | + static void SetUpTestCase() | ||
| 23 | + { | ||
| 24 | + std::cout << "ErfTilingTest SetUp" << std::endl; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + static void TearDownTestCase() | ||
| 28 | + { | ||
| 29 | + std::cout << "ErfTilingTest TearDown" << std::endl; | ||
| 30 | + } | ||
| 31 | +}; | ||
| 32 | + | ||
| 33 | +TEST_F(ErfTilingTest, erf_test_tiling_fp16_input) | ||
| 34 | +{ | ||
| 35 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 36 | + gert::TilingContextPara tilingContextPara( | ||
| 37 | + "Erf", | ||
| 38 | + { | ||
| 39 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 40 | + }, | ||
| 41 | + { | ||
| 42 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 43 | + }, | ||
| 44 | + {}, &compileInfo); | ||
| 45 | + | ||
| 46 | + uint64_t expectTilingKey = 3; | ||
| 47 | + string expectTilingData = "8192 4 17408 2048 4 1 1 2048 2048 17408 1 "; | ||
| 48 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 49 | + ExecuteTestCaseForEle( | ||
| 50 | + tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +TEST_F(ErfTilingTest, erf_test_tiling_bf16_input) | ||
| 54 | +{ | ||
| 55 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 56 | + gert::TilingContextPara tilingContextPara( | ||
| 57 | + "Erf", | ||
| 58 | + { | ||
| 59 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 60 | + }, | ||
| 61 | + { | ||
| 62 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 63 | + }, | ||
| 64 | + {}, &compileInfo); | ||
| 65 | + | ||
| 66 | + uint64_t expectTilingKey = 5; | ||
| 67 | + string expectTilingData = "8192 4 5760 2048 4 1 1 2048 2048 5760 1 "; | ||
| 68 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 69 | + ExecuteTestCaseForEle( | ||
| 70 | + tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +TEST_F(ErfTilingTest, erf_test_tiling_fp32_input) | ||
| 74 | +{ | ||
| 75 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 76 | + gert::TilingContextPara tilingContextPara( | ||
| 77 | + "Erf", | ||
| 78 | + { | ||
| 79 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 80 | + }, | ||
| 81 | + { | ||
| 82 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 83 | + }, | ||
| 84 | + {}, &compileInfo); | ||
| 85 | + | ||
| 86 | + uint64_t expectTilingKey = 7; | ||
| 87 | + string expectTilingData = "8192 8 8704 1024 8 1 1 1024 1024 8704 1 "; | ||
| 88 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 89 | + ExecuteTestCaseForEle( | ||
| 90 | + tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +TEST_F(ErfTilingTest, erf_test_tiling_invalid_input_dtype) | ||
| 94 | +{ | ||
| 95 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 96 | + gert::TilingContextPara tilingContextPara( | ||
| 97 | + "Erf", | ||
| 98 | + { | ||
| 99 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT32, ge::FORMAT_ND}, | ||
| 100 | + }, | ||
| 101 | + { | ||
| 102 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 103 | + }, | ||
| 104 | + {}, &compileInfo); | ||
| 105 | + | ||
| 106 | + uint64_t expectTilingKey = 7; | ||
| 107 | + string expectTilingData = ""; | ||
| 108 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 109 | + ExecuteTestCaseForEle( | ||
| 110 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +TEST_F(ErfTilingTest, erf_test_tiling_invalid_output_dtype) | ||
| 114 | +{ | ||
| 115 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 116 | + gert::TilingContextPara tilingContextPara( | ||
| 117 | + "Erf", | ||
| 118 | + { | ||
| 119 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 120 | + }, | ||
| 121 | + { | ||
| 122 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 123 | + }, | ||
| 124 | + {}, &compileInfo); | ||
| 125 | + | ||
| 126 | + uint64_t expectTilingKey = 7; | ||
| 127 | + string expectTilingData = ""; | ||
| 128 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 129 | + ExecuteTestCaseForEle( | ||
| 130 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 131 | +} | ||
| 132 | + | ||
| 133 | +TEST_F(ErfTilingTest, erf_test_tiling_invalid_shape) | ||
| 134 | +{ | ||
| 135 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 136 | + gert::TilingContextPara tilingContextPara( | ||
| 137 | + "Erf", | ||
| 138 | + { | ||
| 139 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 140 | + }, | ||
| 141 | + { | ||
| 142 | + {{{1, 64, 2, 6}, {1, 64, 2, 6}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 143 | + }, | ||
| 144 | + {}, &compileInfo); | ||
| 145 | + | ||
| 146 | + uint64_t expectTilingKey = 7; | ||
| 147 | + string expectTilingData = ""; | ||
| 148 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 149 | + ExecuteTestCaseForEle( | ||
| 150 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 151 | +} | ||
| @@ -1,10 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -# ---------------------------------------------------------------------------- | ||
| @@ -1,332 +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 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | -class l2ErfTest : public testing::Test { | ||
| 17 | -protected: | ||
| 18 | - static void SetUpTestCase() { | ||
| 19 | - std::cout << "l2ErfTest SetUp" << std::endl; | ||
| 20 | - } | ||
| 21 | - | ||
| 22 | - static void TearDownTestCase() { std::cout << "l2ErfTest TearDown" << std::endl; } | ||
| 23 | -}; | ||
| 24 | - | ||
| 25 | -// self的数据类型不在支持范围内 | ||
| 26 | -TEST_F(l2ErfTest, l2_erf_test_001) { | ||
| 27 | - auto selfDesc = TensorDesc({2, 3}, ACL_INT8, ACL_FORMAT_ND); | ||
| 28 | - auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 29 | - | ||
| 30 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 31 | - | ||
| 32 | - uint64_t workspaceSize = 0; | ||
| 33 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 34 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 35 | -} | ||
| 36 | - | ||
| 37 | -// out的数据类型不在支持范围内 | ||
| 38 | -TEST_F(l2ErfTest, l2_erf_test_002) { | ||
| 39 | - auto selfDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 40 | - auto outDesc = TensorDesc({2, 3}, ACL_INT8, ACL_FORMAT_ND); | ||
| 41 | - | ||
| 42 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 43 | - | ||
| 44 | - uint64_t workspaceSize = 0; | ||
| 45 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 46 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 47 | -} | ||
| 48 | - | ||
| 49 | -// self和out的shape不一致 | ||
| 50 | -TEST_F(l2ErfTest, l2_erf_test_004) { | ||
| 51 | - auto selfDesc = TensorDesc({2, 3, 5}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 52 | - auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 53 | - | ||
| 54 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 55 | - | ||
| 56 | - uint64_t workspaceSize = 0; | ||
| 57 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 58 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 59 | -} | ||
| 60 | - | ||
| 61 | -// self和out的shape不一致 | ||
| 62 | -TEST_F(l2ErfTest, l2_erf_test_005) { | ||
| 63 | - auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 64 | - auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 65 | - | ||
| 66 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 67 | - | ||
| 68 | - uint64_t workspaceSize = 0; | ||
| 69 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 70 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 71 | -} | ||
| 72 | - | ||
| 73 | -// 空tensor | ||
| 74 | -TEST_F(l2ErfTest, l2_erf_test_006) { | ||
| 75 | - auto selfDesc = TensorDesc({2, 0}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 76 | - auto outDesc = TensorDesc({2, 0}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 77 | - | ||
| 78 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 79 | - | ||
| 80 | - uint64_t workspaceSize = 0; | ||
| 81 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 82 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 83 | - | ||
| 84 | -} | ||
| 85 | - | ||
| 86 | -// 正常路径,float32,万分之一精度不合格,用千分之一精度。 | ||
| 87 | -TEST_F(l2ErfTest, l2_erf_test_007) { | ||
| 88 | - auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 89 | - auto outDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.01, 0.01); | ||
| 90 | - | ||
| 91 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 92 | - | ||
| 93 | - uint64_t workspaceSize = 0; | ||
| 94 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 95 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 96 | - | ||
| 97 | -} | ||
| 98 | - | ||
| 99 | -// 正常路径,float16 由于NUMPY目前不支持ERF函数,无法进行精度测试 | ||
| 100 | -TEST_F(l2ErfTest, l2_erf_test_008) { | ||
| 101 | - auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 102 | - auto outDesc = TensorDesc({2, 4}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 103 | - | ||
| 104 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 105 | - | ||
| 106 | - uint64_t workspaceSize = 0; | ||
| 107 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 108 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 109 | - | ||
| 110 | -} | ||
| 111 | - | ||
| 112 | - | ||
| 113 | -// self为空 | ||
| 114 | -TEST_F(l2ErfTest, l2_erf_test_009) { | ||
| 115 | - auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 116 | - | ||
| 117 | - auto ut = OP_API_UT(aclnnErf, INPUT((aclTensor*)nullptr), OUTPUT(outDesc)); | ||
| 118 | - | ||
| 119 | - uint64_t workspaceSize = 0; | ||
| 120 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 121 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_NULLPTR); | ||
| 122 | -} | ||
| 123 | - | ||
| 124 | -// out为空 | ||
| 125 | -TEST_F(l2ErfTest, l2_erf_test_010) { | ||
| 126 | - auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 127 | - | ||
| 128 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT((aclTensor*)nullptr)); | ||
| 129 | - | ||
| 130 | - uint64_t workspaceSize = 0; | ||
| 131 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 132 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_NULLPTR); | ||
| 133 | -} | ||
| 134 | - | ||
| 135 | -// dtype int32 | ||
| 136 | -TEST_F(l2ErfTest, l2_erf_test_013) { | ||
| 137 | - auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_INT32, ACL_FORMAT_NDHWC); | ||
| 138 | - auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_INT32, ACL_FORMAT_NDHWC); | ||
| 139 | - | ||
| 140 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 141 | - | ||
| 142 | - uint64_t workspaceSize = 0; | ||
| 143 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 144 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 145 | -} | ||
| 146 | - | ||
| 147 | -// dtype int64 | ||
| 148 | -TEST_F(l2ErfTest, l2_erf_test_014) { | ||
| 149 | - auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_INT64, ACL_FORMAT_NDHWC); | ||
| 150 | - auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_INT64, ACL_FORMAT_NDHWC); | ||
| 151 | - | ||
| 152 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 153 | - | ||
| 154 | - uint64_t workspaceSize = 0; | ||
| 155 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 156 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 157 | -} | ||
| 158 | - | ||
| 159 | -// dtype int16 | ||
| 160 | -TEST_F(l2ErfTest, l2_erf_test_015) { | ||
| 161 | - auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_INT16, ACL_FORMAT_NDHWC); | ||
| 162 | - auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_INT16, ACL_FORMAT_NDHWC); | ||
| 163 | - | ||
| 164 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 165 | - | ||
| 166 | - uint64_t workspaceSize = 0; | ||
| 167 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 168 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 169 | -} | ||
| 170 | - | ||
| 171 | -// dtype int8 | ||
| 172 | -TEST_F(l2ErfTest, l2_erf_test_016) { | ||
| 173 | - auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_INT8, ACL_FORMAT_NDHWC); | ||
| 174 | - auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_INT8, ACL_FORMAT_NDHWC); | ||
| 175 | - | ||
| 176 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 177 | - | ||
| 178 | - uint64_t workspaceSize = 0; | ||
| 179 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 180 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 181 | -} | ||
| 182 | - | ||
| 183 | -// dtype uint8 | ||
| 184 | -TEST_F(l2ErfTest, l2_erf_test_017) { | ||
| 185 | - auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_UINT8, ACL_FORMAT_NDHWC); | ||
| 186 | - auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_UINT8, ACL_FORMAT_NDHWC); | ||
| 187 | - | ||
| 188 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 189 | - | ||
| 190 | - uint64_t workspaceSize = 0; | ||
| 191 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 192 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 193 | -} | ||
| 194 | - | ||
| 195 | -// dtype bool | ||
| 196 | -TEST_F(l2ErfTest, l2_erf_test_018) { | ||
| 197 | - auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_BOOL, ACL_FORMAT_NDHWC); | ||
| 198 | - auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_FLOAT, ACL_FORMAT_NDHWC); | ||
| 199 | - | ||
| 200 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 201 | - | ||
| 202 | - uint64_t workspaceSize = 0; | ||
| 203 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 204 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 205 | - | ||
| 206 | -} | ||
| 207 | - | ||
| 208 | -// dtype complex64 | ||
| 209 | -TEST_F(l2ErfTest, l2_erf_test_019) { | ||
| 210 | - auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_COMPLEX64, ACL_FORMAT_NDHWC); | ||
| 211 | - auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_COMPLEX64, ACL_FORMAT_NDHWC); | ||
| 212 | - | ||
| 213 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 214 | - | ||
| 215 | - uint64_t workspaceSize = 0; | ||
| 216 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 217 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 218 | -} | ||
| 219 | - | ||
| 220 | -// dtype complex128 | ||
| 221 | -TEST_F(l2ErfTest, l2_erf_test_020) { | ||
| 222 | - auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_COMPLEX128, ACL_FORMAT_NDHWC); | ||
| 223 | - auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_COMPLEX128, ACL_FORMAT_NDHWC); | ||
| 224 | - | ||
| 225 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 226 | - | ||
| 227 | - uint64_t workspaceSize = 0; | ||
| 228 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 229 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 230 | -} | ||
| 231 | - | ||
| 232 | -// dtype undefine | ||
| 233 | -TEST_F(l2ErfTest, l2_erf_test_021) { | ||
| 234 | - auto selfDesc = TensorDesc({2, 4, 6, 7}, ACL_DT_UNDEFINED, ACL_FORMAT_NDHWC); | ||
| 235 | - auto outDesc = TensorDesc({2, 4, 6, 7}, ACL_DT_UNDEFINED, ACL_FORMAT_NDHWC); | ||
| 236 | - | ||
| 237 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 238 | - | ||
| 239 | - uint64_t workspaceSize = 0; | ||
| 240 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 241 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 242 | -} | ||
| 243 | - | ||
| 244 | -// format self是私有格式 | ||
| 245 | -TEST_F(l2ErfTest, l2_erf_test_025) { | ||
| 246 | - auto selfDesc = TensorDesc({2, 4, 6, 8, 5}, ACL_FLOAT, ACL_FORMAT_NC1HWC0); | ||
| 247 | - auto outDesc = TensorDesc({2, 4, 6, 8}, ACL_FLOAT, ACL_FORMAT_HWCN); | ||
| 248 | - | ||
| 249 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 250 | - | ||
| 251 | - uint64_t workspaceSize = 0; | ||
| 252 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 253 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 254 | -} | ||
| 255 | - | ||
| 256 | -// format out是私有格式 | ||
| 257 | -TEST_F(l2ErfTest, l2_erf_test_026) { | ||
| 258 | - auto selfDesc = TensorDesc({2, 4, 6, 8}, ACL_FLOAT, ACL_FORMAT_HWCN); | ||
| 259 | - auto outDesc = TensorDesc({2, 4, 6, 8, 8}, ACL_FLOAT, ACL_FORMAT_NC1HWC0); | ||
| 260 | - | ||
| 261 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 262 | - | ||
| 263 | - uint64_t workspaceSize = 0; | ||
| 264 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 265 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 266 | -} | ||
| 267 | - | ||
| 268 | -// 正常路径,float32,inplace | ||
| 269 | -TEST_F(l2ErfTest, l2_erf_test_027) { | ||
| 270 | - auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.01, 0.01); | ||
| 271 | - | ||
| 272 | - auto ut = OP_API_UT(aclnnInplaceErf, INPUT(selfDesc), OUTPUT()); | ||
| 273 | - | ||
| 274 | - uint64_t workspaceSize = 0; | ||
| 275 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 276 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 277 | - | ||
| 278 | -} | ||
| 279 | - | ||
| 280 | -// 非连续 | ||
| 281 | -TEST_F(l2ErfTest, l2_erf_test_029) { | ||
| 282 | - auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 2}, 0, {4, 2}); | ||
| 283 | - auto outDesc = TensorDesc({2, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 2}, 0, {4, 2}).Precision(0.01, 0.01); | ||
| 284 | - | ||
| 285 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 286 | - | ||
| 287 | - uint64_t workspaceSize = 0; | ||
| 288 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 289 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 290 | - | ||
| 291 | -} | ||
| 292 | - | ||
| 293 | -// CheckShape_10D | ||
| 294 | -TEST_F(l2ErfTest, l2_erf_test_030) { | ||
| 295 | - auto selfDesc = TensorDesc({2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 296 | - auto outDesc = TensorDesc({2, 2, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 297 | - | ||
| 298 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 299 | - | ||
| 300 | - // only test GetWorkspaceSize | ||
| 301 | - uint64_t workspaceSize = 0; | ||
| 302 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 303 | - EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 304 | -} | ||
| 305 | - | ||
| 306 | -// Check dtype | ||
| 307 | -TEST_F(l2ErfTest, l2_erf_test_031) { | ||
| 308 | - auto selfDesc = TensorDesc({2, 4}, ACL_BOOL, ACL_FORMAT_ND); | ||
| 309 | - auto outDesc = TensorDesc({2, 4}, ACL_INT32, ACL_FORMAT_ND); | ||
| 310 | - | ||
| 311 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 312 | - | ||
| 313 | - // only test GetWorkspaceSize | ||
| 314 | - uint64_t workspaceSize = 0; | ||
| 315 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 316 | - EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 317 | -} | ||
| 318 | - | ||
| 319 | -// Check dtype | ||
| 320 | -TEST_F(l2ErfTest, l2_erf_test_032) { | ||
| 321 | - auto selfDesc = TensorDesc({2, 4}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 322 | - auto outDesc = TensorDesc({2, 4}, ACL_INT32, ACL_FORMAT_ND); | ||
| 323 | - | ||
| 324 | - auto ut = OP_API_UT(aclnnErf, INPUT(selfDesc), OUTPUT(outDesc)); | ||
| 325 | - | ||
| 326 | - // only test GetWorkspaceSize | ||
| 327 | - uint64_t workspaceSize = 0; | ||
| 328 | - aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 329 | - EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 330 | -} | ||
| 331 | - | ||
| 332 | - | ||
| @@ -0,0 +1,69 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +class ErfInferShape : public testing::Test { | ||
| 17 | +protected: | ||
| 18 | + static void SetUpTestCase() | ||
| 19 | + { | ||
| 20 | + std::cout << "Erf InferShape SetUp" << std::endl; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + static void TearDownTestCase() | ||
| 24 | + { | ||
| 25 | + std::cout << "Erf InferShape TearDown" << std::endl; | ||
| 26 | + } | ||
| 27 | +}; | ||
| 28 | + | ||
| 29 | +TEST_F(ErfInferShape, erf_infershape_diff_test) | ||
| 30 | +{ | ||
| 31 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 32 | + "Erf", | ||
| 33 | + { | ||
| 34 | + {{{4, 3, 4}, {4, 3, 4}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 35 | + }, | ||
| 36 | + { | ||
| 37 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 38 | + }); | ||
| 39 | + std::vector<std::vector<int64_t>> expectOutputShape = {{4, 3, 4}}; | ||
| 40 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +TEST_F(ErfInferShape, erf_infershape_same_test) | ||
| 44 | +{ | ||
| 45 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 46 | + "Erf", | ||
| 47 | + { | ||
| 48 | + {{{1, 3, 4}, {1, 3, 4}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 49 | + }, | ||
| 50 | + { | ||
| 51 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 52 | + }); | ||
| 53 | + std::vector<std::vector<int64_t>> expectOutputShape = {{1, 3, 4}}; | ||
| 54 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +TEST_F(ErfInferShape, erf_infershape_dynamic_test) | ||
| 58 | +{ | ||
| 59 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 60 | + "Erf", | ||
| 61 | + { | ||
| 62 | + {{{-1}, {-1}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 63 | + }, | ||
| 64 | + { | ||
| 65 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 66 | + }); | ||
| 67 | + std::vector<std::vector<int64_t>> expectOutputShape = {{-1}}; | ||
| 68 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 69 | +} | ||
| @@ -1,20 +1,15 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | -# 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 | -# This file is a part of the CANN Open Software. | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 5 | -# Licensed under 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. | 5 | # 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, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 7 | +# 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. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | 10 | ||
| 12 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | +# 设置算子定义时支持的芯片类型 |
| 13 | -if(NOT ENABLE_TEST AND NOT BENCHMARK) | 12 | +set(SUPPORT_COMPUTE_UNIT "ascend950") |
| 14 | - list(REMOVE_ITEM CURRENT_DIRS tests) | 13 | +# 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 |
| 15 | -endif() | 14 | +set(SUPPORT_TILING_DIR "arch35") |
| 16 | -foreach(SUB_DIR ${CURRENT_DIRS}) | 15 | +add_all_modules_sources(OPTYPE expm1 ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE) |
| 17 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 18 | - add_subdirectory(${SUB_DIR}) | ||
| 19 | - endif() | ||
| 20 | -endforeach() | ||
| @@ -0,0 +1,43 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file expm1_proto.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +namespace ge { | ||
| 22 | + | ||
| 23 | +/** | ||
| 24 | +* @brief Computes the exp(x) - 1 element-wise, y = e^x - 1. | ||
| 25 | + | ||
| 26 | +* @par Inputs: | ||
| 27 | +* One input: | ||
| 28 | +* x: An ND or 5HD tensor. Support 1D~8D. Must be one of the following types: | ||
| 29 | +* bfloat16, float16, float32, double, complex64, complex128. | ||
| 30 | + | ||
| 31 | +* @par Outputs: | ||
| 32 | +* y: A ND Tensor of the same dtype as "x". | ||
| 33 | + | ||
| 34 | +* @par Third-party framework compatibility | ||
| 35 | +* Compatible with TensorFlow operator Expm1. | ||
| 36 | +*/ | ||
| 37 | +REG_OP(Expm1) | ||
| 38 | + .INPUT(x, TensorType::UnaryDataType()) | ||
| 39 | + .OUTPUT(y, TensorType::UnaryDataType()) | ||
| 40 | + .OP_END_FACTORY_REG(Expm1) | ||
| 41 | +} // namespace ge | ||
| 42 | + | ||
| 43 | + | ||
| @@ -1,12 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -add_modules_sources(OPTYPE expm1 ACLNNTYPE aclnn_exclude) | ||
| @@ -0,0 +1,162 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file expm1_tiling_arch35.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | +using namespace Ops::Math::OpTiling; | ||
| 30 | + | ||
| 31 | +namespace optiling { | ||
| 32 | +const int64_t ASCEND_WORKSPACE = 16777216; // 16M | ||
| 33 | +const int64_t ASCEND_API_BUFFER = 122880; // 120K | ||
| 34 | +const int64_t DCACHE_SIZE = 32768; | ||
| 35 | + | ||
| 36 | +ge::graphStatus Expm1Tiling::SetTilingData() | ||
| 37 | +{ | ||
| 38 | + OP_LOGD(tilingContext->GetNodeName(), "Expm1Tiling SetTilingData enter."); | ||
| 39 | + | ||
| 40 | + size_t* currentWorkspace = tilingContext->GetWorkspaceSizes(1); | ||
| 41 | + currentWorkspace[0] = ASCEND_WORKSPACE; | ||
| 42 | + | ||
| 43 | + const uint64_t tilingKey = GET_TPL_TILING_KEY(static_cast<uint64_t>(tiling_->scheMode), dType); | ||
| 44 | + OP_LOGD(tilingContext->GetNodeName(), "[TilingData] : tilingKey=%lu", tilingKey); | ||
| 45 | + tilingContext->SetTilingKey(tilingKey); | ||
| 46 | + tilingContext->SetBlockDim(tiling_->blockNum); | ||
| 47 | + | ||
| 48 | + uint64_t ubSize = 0; | ||
| 49 | + auto platformInfo = tilingContext->GetPlatformInfo(); | ||
| 50 | + if (platformInfo == nullptr) { | ||
| 51 | + auto compileInfoPtr = reinterpret_cast<const ElewiseCompileInfo*>(tilingContext->GetCompileInfo()); | ||
| 52 | + OP_CHECK_IF(compileInfoPtr == nullptr, OP_LOGE(tilingContext, "compile info is null"), return ge::GRAPH_FAILED); | ||
| 53 | + ubSize = compileInfoPtr->ubSize; | ||
| 54 | + } else { | ||
| 55 | + auto ascendcPlatform = platform_ascendc::PlatformAscendC(platformInfo); | ||
| 56 | + uint64_t ubSizePlatForm = 0; | ||
| 57 | + ascendcPlatform.GetCoreMemSize(platform_ascendc::CoreMemType::UB, ubSizePlatForm); | ||
| 58 | + ubSize = ubSizePlatForm; | ||
| 59 | + } | ||
| 60 | + tilingContext->SetLocalMemorySize(static_cast<uint32_t>(ubSize - DCACHE_SIZE)); | ||
| 61 | + | ||
| 62 | + return ge::GRAPH_SUCCESS; | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +ge::graphStatus Expm1Tiling::CalcInputDtype() | ||
| 66 | +{ | ||
| 67 | + OP_LOGD(tilingContext->GetNodeName(), "Expm1Tiling CalcInputDtype enter."); | ||
| 68 | + auto inputDesc = tilingContext->GetInputDesc(0); | ||
| 69 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputDesc); | ||
| 70 | + this->inputDtype = inputDesc->GetDataType(); | ||
| 71 | + OP_CHECK_IF( | ||
| 72 | + this->inputDtype != ge::DT_FLOAT16 && this->inputDtype != ge::DT_BF16 && this->inputDtype != ge::DT_FLOAT, | ||
| 73 | + OP_LOGE( | ||
| 74 | + tilingContext->GetNodeName(), "input x dtype[%s] dtype not support", | ||
| 75 | + ge::TypeUtils::DataTypeToSerialString(this->inputDtype).c_str()), | ||
| 76 | + return ge::GRAPH_FAILED); | ||
| 77 | + return ge::GRAPH_SUCCESS; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +ge::graphStatus Expm1Tiling::CheckShape() | ||
| 81 | +{ | ||
| 82 | + OP_LOGD(tilingContext->GetNodeName(), "Expm1Tiling CheckShape enter."); | ||
| 83 | + auto inputStorageShape = tilingContext->GetInputShape(0); | ||
| 84 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputStorageShape); | ||
| 85 | + const gert::Shape& inputXShape = EnsureNotScalar(inputStorageShape->GetStorageShape()); | ||
| 86 | + | ||
| 87 | + auto outputStorageShape = tilingContext->GetOutputShape(0); | ||
| 88 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputStorageShape); | ||
| 89 | + const gert::Shape& outputYShape = EnsureNotScalar(outputStorageShape->GetStorageShape()); | ||
| 90 | + | ||
| 91 | + OP_CHECK_IF( | ||
| 92 | + inputXShape != outputYShape, OP_LOGE(tilingContext->GetNodeName(), "input x and output y shape not same"), | ||
| 93 | + return ge::GRAPH_FAILED); | ||
| 94 | + return ge::GRAPH_SUCCESS; | ||
| 95 | +} | ||
| 96 | + | ||
| 97 | +ge::graphStatus Expm1Tiling::CalcOutputDtype() | ||
| 98 | +{ | ||
| 99 | + OP_LOGD(tilingContext->GetNodeName(), "Expm1Tiling CalcOutputDtype enter."); | ||
| 100 | + auto outputDesc = tilingContext->GetOutputDesc(0); | ||
| 101 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputDesc); | ||
| 102 | + this->outputDtype = outputDesc->GetDataType(); | ||
| 103 | + OP_CHECK_IF( | ||
| 104 | + this->outputDtype != this->inputDtype, | ||
| 105 | + OP_LOGE(tilingContext->GetNodeName(), "output y dtype not same as input x"), return ge::GRAPH_FAILED); | ||
| 106 | + return ge::GRAPH_SUCCESS; | ||
| 107 | +} | ||
| 108 | + | ||
| 109 | +ge::graphStatus Expm1Tiling::RunTiling() | ||
| 110 | +{ | ||
| 111 | + OP_LOGD(tilingContext->GetNodeName(), "Expm1Tiling RunTiling enter."); | ||
| 112 | + ElewiseBaseTiling elewiseBaseTiling(tilingContext); | ||
| 113 | + OP_CHECK_IF( | ||
| 114 | + CalcInputDtype() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "get input dtype failed"), | ||
| 115 | + return ge::GRAPH_FAILED); | ||
| 116 | + OP_CHECK_IF( | ||
| 117 | + CalcOutputDtype() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "get output dtype failed"), | ||
| 118 | + return ge::GRAPH_FAILED); | ||
| 119 | + OP_CHECK_IF( | ||
| 120 | + CheckShape() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "check shape failed"), return ge::GRAPH_FAILED); | ||
| 121 | + | ||
| 122 | + tiling_ = tilingContext->GetTilingData<EleBaseTilingDataV2>(); | ||
| 123 | + ge::graphStatus baseTilingResult = ge::GRAPH_FAILED; | ||
| 124 | + if (this->outputDtype == ge::DT_FLOAT16) { | ||
| 125 | + dType = TPL_FP16; | ||
| 126 | + baseTilingResult = | ||
| 127 | + elewiseBaseTiling.DoTiling<Expm1Op::Expm1DAG<half>::OpDag>(*tiling_, ASCEND_API_BUFFER + DCACHE_SIZE); | ||
| 128 | + } else if (this->outputDtype == ge::DT_BF16) { | ||
| 129 | + dType = TPL_BF16; | ||
| 130 | + baseTilingResult = | ||
| 131 | + elewiseBaseTiling.DoTiling<Expm1Op::Expm1DAG<bfloat16_t>::OpDag>(*tiling_, ASCEND_API_BUFFER + DCACHE_SIZE); | ||
| 132 | + } else if (this->outputDtype == ge::DT_FLOAT) { | ||
| 133 | + dType = TPL_FP32; | ||
| 134 | + baseTilingResult = | ||
| 135 | + elewiseBaseTiling.DoTiling<Expm1Op::Expm1DAG<float>::OpDag>(*tiling_, ASCEND_API_BUFFER + DCACHE_SIZE); | ||
| 136 | + } else { | ||
| 137 | + OP_LOGE(tilingContext->GetNodeName(), "output dtype not support"); | ||
| 138 | + return ge::GRAPH_FAILED; | ||
| 139 | + } | ||
| 140 | + OP_CHECK_IF( | ||
| 141 | + baseTilingResult != ge::GRAPH_SUCCESS, OP_LOGE(tilingContext, "elewiseBaseTiling failed"), | ||
| 142 | + return ge::GRAPH_FAILED); | ||
| 143 | + | ||
| 144 | + return SetTilingData(); | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +static ge::graphStatus Tiling4Expm1(gert::TilingContext* tilingContextGen) | ||
| 148 | +{ | ||
| 149 | + OP_LOGD(tilingContextGen->GetNodeName(), "Tiling4Expm1 rt2.0 is running."); | ||
| 150 | + auto compileInfo = reinterpret_cast<const ElewiseCompileInfo*>(tilingContextGen->GetCompileInfo()); | ||
| 151 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContextGen, compileInfo); | ||
| 152 | + Expm1Tiling baseOpTiling(tilingContextGen); | ||
| 153 | + return baseOpTiling.RunTiling(); | ||
| 154 | +} | ||
| 155 | + | ||
| 156 | +static ge::graphStatus TilingPrepareForExpm1([[maybe_unused]] gert::TilingParseContext* context) | ||
| 157 | +{ | ||
| 158 | + return ge::GRAPH_SUCCESS; | ||
| 159 | +} | ||
| 160 | + | ||
| 161 | +IMPL_OP_OPTILING(Expm1).Tiling(Tiling4Expm1).TilingParse<ElewiseCompileInfo>(TilingPrepareForExpm1); | ||
| 162 | +} // namespace optiling | ||
| @@ -0,0 +1,44 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file expm1_tiling_arch35.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace optiling { | ||
| 23 | +using namespace Ops::Base; | ||
| 24 | + | ||
| 25 | +class Expm1Tiling { | ||
| 26 | +public: | ||
| 27 | + explicit Expm1Tiling(gert::TilingContext* context) : tilingContext(context) {}; | ||
| 28 | + ge::graphStatus RunTiling(); | ||
| 29 | + | ||
| 30 | +protected: | ||
| 31 | + ge::graphStatus CalcOutputDtype(); | ||
| 32 | + ge::graphStatus CalcInputDtype(); | ||
| 33 | + ge::graphStatus CheckShape(); | ||
| 34 | + ge::graphStatus SetTilingData(); | ||
| 35 | + | ||
| 36 | +private: | ||
| 37 | + EleBaseTilingDataV2* tiling_ = nullptr; | ||
| 38 | + gert::TilingContext* tilingContext; | ||
| 39 | + ge::DataType outputDtype; | ||
| 40 | + ge::DataType inputDtype; | ||
| 41 | + uint64_t dType = 0; | ||
| 42 | +}; | ||
| 43 | +} // namespace optiling | ||
| 44 | + | ||
| @@ -0,0 +1,92 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "Expm1", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "Expm1_d2db1a80c523e7e59a032c95969880af", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "x", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "float16", | ||
| 11 | + "format": "ND", | ||
| 12 | + "paramType": "required", | ||
| 13 | + "shape": [ | ||
| 14 | + -2 | ||
| 15 | + ], | ||
| 16 | + "format_match_mode": "FormatAgnostic" | ||
| 17 | + } | ||
| 18 | + ], | ||
| 19 | + "outputs": [ | ||
| 20 | + { | ||
| 21 | + "name": "y", | ||
| 22 | + "index": 0, | ||
| 23 | + "dtype": "float16", | ||
| 24 | + "format": "ND", | ||
| 25 | + "paramType": "required", | ||
| 26 | + "shape": [ | ||
| 27 | + -2 | ||
| 28 | + ], | ||
| 29 | + "format_match_mode": "FormatAgnostic" | ||
| 30 | + } | ||
| 31 | + ] | ||
| 32 | + }, | ||
| 33 | + { | ||
| 34 | + "bin_filename": "Expm1_5c5e58e043224cccf51a06108010ae13", | ||
| 35 | + "inputs": [ | ||
| 36 | + { | ||
| 37 | + "name": "x", | ||
| 38 | + "index": 0, | ||
| 39 | + "dtype": "float32", | ||
| 40 | + "format": "ND", | ||
| 41 | + "paramType": "required", | ||
| 42 | + "shape": [ | ||
| 43 | + -2 | ||
| 44 | + ], | ||
| 45 | + "format_match_mode": "FormatAgnostic" | ||
| 46 | + } | ||
| 47 | + ], | ||
| 48 | + "outputs": [ | ||
| 49 | + { | ||
| 50 | + "name": "y", | ||
| 51 | + "index": 0, | ||
| 52 | + "dtype": "float32", | ||
| 53 | + "format": "ND", | ||
| 54 | + "paramType": "required", | ||
| 55 | + "shape": [ | ||
| 56 | + -2 | ||
| 57 | + ], | ||
| 58 | + "format_match_mode": "FormatAgnostic" | ||
| 59 | + } | ||
| 60 | + ] | ||
| 61 | + }, | ||
| 62 | + { | ||
| 63 | + "bin_filename": "Expm1_5c5e58e043224cccf51a06108010ae17", | ||
| 64 | + "inputs": [ | ||
| 65 | + { | ||
| 66 | + "name": "x", | ||
| 67 | + "index": 0, | ||
| 68 | + "dtype": "bfloat16", | ||
| 69 | + "format": "ND", | ||
| 70 | + "paramType": "required", | ||
| 71 | + "shape": [ | ||
| 72 | + -2 | ||
| 73 | + ], | ||
| 74 | + "format_match_mode": "FormatAgnostic" | ||
| 75 | + } | ||
| 76 | + ], | ||
| 77 | + "outputs": [ | ||
| 78 | + { | ||
| 79 | + "name": "y", | ||
| 80 | + "index": 0, | ||
| 81 | + "dtype": "bfloat16", | ||
| 82 | + "format": "ND", | ||
| 83 | + "paramType": "required", | ||
| 84 | + "shape": [ | ||
| 85 | + -2 | ||
| 86 | + ], | ||
| 87 | + "format_match_mode": "FormatAgnostic" | ||
| 88 | + } | ||
| 89 | + ] | ||
| 90 | + } | ||
| 91 | + ] | ||
| 92 | +} | ||
| @@ -0,0 +1,2 @@ | |||
| 1 | +[Expm1] | ||
| 2 | +default=0 | ||
| @@ -0,0 +1,48 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file expm1_def.cpp | ||
| 13 | + * \brief expm1 def | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +namespace ops { | ||
| 20 | +class Expm1 : public OpDef { | ||
| 21 | +public: | ||
| 22 | + explicit Expm1(const char* name) : OpDef(name) | ||
| 23 | + { | ||
| 24 | + this->Input("x") | ||
| 25 | + .ParamType(REQUIRED) | ||
| 26 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}) | ||
| 27 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 28 | + .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 29 | + this->Output("y") | ||
| 30 | + .ParamType(REQUIRED) | ||
| 31 | + .DataType({ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}) | ||
| 32 | + .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 33 | + .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 34 | + | ||
| 35 | + OpAICoreConfig aicoreConfig; | ||
| 36 | + aicoreConfig.DynamicCompileStaticFlag(true) | ||
| 37 | + .DynamicFormatFlag(false) | ||
| 38 | + .DynamicRankSupportFlag(true) | ||
| 39 | + .DynamicShapeSupportFlag(true) | ||
| 40 | + .NeedCheckSupportFlag(false) | ||
| 41 | + .PrecisionReduceFlag(true) | ||
| 42 | + .ExtendCfgInfo("opFile.value", "expm1_apt"); | ||
| 43 | + this->AICore().AddConfig("ascend950", aicoreConfig); | ||
| 44 | + } | ||
| 45 | +}; | ||
| 46 | + | ||
| 47 | +OP_ADD(Expm1); | ||
| 48 | +} // namespace ops | ||
| @@ -0,0 +1,21 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file expm1_infershape.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +using namespace ge; | ||
| 19 | +namespace ops { | ||
| 20 | +IMPL_OP_INFERSHAPE(Expm1).InferShape(Ops::Base::InferShape4Elewise); | ||
| 21 | +} // namespace ops | ||
| @@ -0,0 +1,118 @@ | |||
| 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 | +/* ! | ||
| 12 | + * \file expm1_dag.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +namespace Expm1Op { | ||
| 25 | +using namespace Ops::Base; | ||
| 26 | +const int CAST_MODE_NONE = 0; | ||
| 27 | +const int CAST_MODE_RINT = 1; | ||
| 28 | +constexpr uint32_t THREAD_NUM = 1024; | ||
| 29 | +constexpr float INV_LN2_APPROX = 1.4426950216293335f; | ||
| 30 | +constexpr float LN2_HALF_APPROX = 0.4099999964237213f; | ||
| 31 | +constexpr float LN2_APPROX = 0.693145751953125f; | ||
| 32 | +constexpr float ONE_MINUS_LN2_APPROX = 0.000001428606765330187f; | ||
| 33 | +constexpr float FLOAT_128 = 128.000000f; | ||
| 34 | +constexpr float FLOAT_NEG_ONE = -1.00000000f; | ||
| 35 | +constexpr float C5 = 0.008382412604987621f; | ||
| 36 | +constexpr float C4 = 0.0013879507314413786f; | ||
| 37 | +constexpr float C3 = 0.04166783019900322f; | ||
| 38 | +constexpr float C2 = 0.1666639745235443f; | ||
| 39 | +constexpr float C1 = 0.4999999403953552f; | ||
| 40 | +constexpr float FLOAT_INF = std::numeric_limits<float>::infinity(); | ||
| 41 | +constexpr float FLOAT_NEG_25 = -25.0000000f; | ||
| 42 | +constexpr float FLOAT_2 = 2.0000000f; | ||
| 43 | + | ||
| 44 | + | ||
| 45 | +template <typename T> | ||
| 46 | +__simt_vf__ __aicore__ | ||
| 47 | +LAUNCH_BOUND(THREAD_NUM) inline void Expm1SimtCompute(__ubuf__ T* x, __ubuf__ T* y, const int64_t totalNum) | ||
| 48 | +{ | ||
| 49 | + for (int64_t i = Simt::GetThreadIdx(); i < totalNum; i += Simt::GetThreadNum()) { | ||
| 50 | + float f1 = x[i]; | ||
| 51 | + float f0 = Simt::Expm1(f1); | ||
| 52 | + float f2 = f1 * INV_LN2_APPROX; | ||
| 53 | + float f3 = Simt::Round(f2); | ||
| 54 | + float f4 = Simt::Abs(f1); | ||
| 55 | + bool p1 = f4 < LN2_HALF_APPROX; | ||
| 56 | + float f5 = p1 ? 0.0f : f3; | ||
| 57 | + float f6 = -f5; | ||
| 58 | + float f7 = LN2_APPROX; | ||
| 59 | + float f8 = Simt::Fma(f6, f7, f1); | ||
| 60 | + float f9 = ONE_MINUS_LN2_APPROX; | ||
| 61 | + float f10 = Simt::Fma(f6, f9, f8); | ||
| 62 | + bool p2 = f5 == FLOAT_128; | ||
| 63 | + float f11 = f5 + FLOAT_NEG_ONE; | ||
| 64 | + float f12 = p2 ? f11 : f5; | ||
| 65 | + float f13 = C5; | ||
| 66 | + float f14 = C4; | ||
| 67 | + float f15 = Simt::Fma(f14, f10, f13); | ||
| 68 | + float f16 = C3; | ||
| 69 | + float f17 = Simt::Fma(f15, f10, f16); | ||
| 70 | + float f18 = C2; | ||
| 71 | + float f19 = Simt::Fma(f17, f10, f18); | ||
| 72 | + float f20 = C1; | ||
| 73 | + float f21 = Simt::Fma(f19, f10, f20); | ||
| 74 | + float f22 = f10 * f21; | ||
| 75 | + float f23 = Simt::Fma(f22, f10, f10); | ||
| 76 | + float f24 = Simt::Exp2(f12); | ||
| 77 | + float f25 = f24 + FLOAT_NEG_ONE; | ||
| 78 | + float f26 = Simt::Fma(f23, f24, f25); | ||
| 79 | + float f27 = f26 + f26; | ||
| 80 | + float f28 = p2 ? f27 : f26; | ||
| 81 | + bool p3 = f12 > FLOAT_128; | ||
| 82 | + float f29 = p3 ? FLOAT_INF : f28; | ||
| 83 | + bool p4 = f12 < FLOAT_NEG_25; | ||
| 84 | + float f30 = p4 ? FLOAT_NEG_ONE : f29; | ||
| 85 | + bool p5 = f1 == 0.0f; | ||
| 86 | + float f31 = f1 + f1; | ||
| 87 | + float f32 = p5 ? f31 : f30; | ||
| 88 | + y[i] = Simt::Abs(x[i]) > FLOAT_2 ? f0 : f32; | ||
| 89 | + } | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | + | ||
| 93 | +template <class T> | ||
| 94 | +struct Expm1Custom : public Vec::ElemwiseUnaryOP<T, T> { | ||
| 95 | + __aicore__ inline Expm1Custom(LocalTensor<T>& dst, LocalTensor<T>& src, uint32_t count) | ||
| 96 | + { | ||
| 97 | + | ||
| 98 | + __ubuf__ T* srcAddr = (__ubuf__ T*)src.GetPhyAddr(); | ||
| 99 | + __ubuf__ T* dstAddr = (__ubuf__ T*)dst.GetPhyAddr(); | ||
| 100 | + Simt::VF_CALL<Expm1SimtCompute<T>>(Simt::Dim3(THREAD_NUM), srcAddr, dstAddr, count); | ||
| 101 | + | ||
| 102 | + } | ||
| 103 | +}; | ||
| 104 | + | ||
| 105 | +template <typename U, typename T = float> | ||
| 106 | +struct Expm1DAG { | ||
| 107 | + using OpCopyIn0 = Bind<Vec::CopyIn<U>, Placeholder::In0<U>>; | ||
| 108 | + using OpCopyIn0Cast = Bind<Vec::Cast<T, U, CAST_MODE_NONE>, OpCopyIn0>; | ||
| 109 | + using OpResult1 = Bind<Expm1Custom<T>, OpCopyIn0Cast>; | ||
| 110 | + using OpResultCast = Bind<Vec::Cast<U, T, CAST_MODE_RINT>, OpResult1>; | ||
| 111 | + using OpCopyOut = Bind<Vec::CopyOut<U>, Placeholder::Out0<U>, OpResultCast>; | ||
| 112 | + | ||
| 113 | + using Outputs = Elems<OpCopyOut>; | ||
| 114 | + using MemCfg = MemOptCfg<MemLevel::LEVEL_2>; | ||
| 115 | + using OpDag = DAGSch<Outputs, void, MemCfg>; | ||
| 116 | +}; | ||
| 117 | +} // namespace Expm1Op | ||
| 118 | + | ||
| @@ -0,0 +1,35 @@ | |||
| 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 | +/* ! | ||
| 12 | + * \file expm1_struct.h | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | +ASCENDC_TPL_ARGS_DECL( | ||
| 29 | + Expm1, ASCENDC_TPL_UINT_DECL(schMode, 1, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 30 | + ASCENDC_TPL_DTYPE_DECL(dType, TPL_FP16, TPL_BF16, TPL_FP32)); | ||
| 31 | + | ||
| 32 | +ASCENDC_TPL_SEL(ASCENDC_TPL_ARGS_SEL( | ||
| 33 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 34 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_FP16, TPL_BF16, TPL_FP32))); | ||
| 35 | + | ||
| @@ -0,0 +1,48 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file expm1_apt.cpp | ||
| 13 | + * \brief z = expm1(x) | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +using namespace Ops::Base; | ||
| 23 | +namespace AscendC { | ||
| 24 | + | ||
| 25 | +template <uint64_t schMode, uint64_t dType> | ||
| 26 | +__global__ __aicore__ void expm1(GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) | ||
| 27 | +{ | ||
| 28 | + REGISTER_TILING_DEFAULT(EleBaseTilingDataV2); | ||
| 29 | + GET_TILING_DATA_WITH_STRUCT(EleBaseTilingDataV2, tilingData, tiling); | ||
| 30 | + KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY); | ||
| 31 | + | ||
| 32 | + TPipe pipe; | ||
| 33 | + if constexpr (dType == TPL_FP32) { | ||
| 34 | + ElementwiseSch<schMode, Expm1Op::Expm1DAG<float>::OpDag> sch(&tilingData, &pipe); | ||
| 35 | + sch.Init(x, y); | ||
| 36 | + sch.Process(); | ||
| 37 | + } else if constexpr (dType == TPL_BF16) { | ||
| 38 | + ElementwiseSch<schMode, Expm1Op::Expm1DAG<bfloat16_t>::OpDag> sch(&tilingData, &pipe); | ||
| 39 | + sch.Init(x, y); | ||
| 40 | + sch.Process(); | ||
| 41 | + } else if constexpr (dType == TPL_FP16) { | ||
| 42 | + ElementwiseSch<schMode, Expm1Op::Expm1DAG<half>::OpDag> sch(&tilingData, &pipe); | ||
| 43 | + sch.Init(x, y); | ||
| 44 | + sch.Process(); | ||
| 45 | + } | ||
| 46 | +} | ||
| 47 | + | ||
| 48 | +} // namespace AscendC | ||
| @@ -1,17 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
| @@ -1,17 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
Rmath/expm1/tests/ut/op_host/op_api/test_aclnn_expm1.cpp→math/expm1/tests/ut/op_api/test_aclnn_expm1.cpp+42-41
| @@ -1,18 +1,18 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 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, | 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. | 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. | 8 | + * See LICENSE in the root of the software repository for the full text of the License. |
| 9 | - */ | 9 | + */ |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | -#include "aclnn_expm1.h" | 15 | +#include "math/expm1/op_api/aclnn_expm1.h" |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| @@ -20,17 +20,22 @@ | |||
| 20 | using namespace op; | 20 | using namespace op; |
| 21 | using namespace std; | 21 | using namespace std; |
| 22 | 22 | ||
| 23 | - | ||
| 24 | class l2_expm1_test : public testing::Test { | 23 | class l2_expm1_test : public testing::Test { |
| 25 | protected: | 24 | protected: |
| 26 | - static void SetUpTestCase() { std::cout << "Expm1 Test Setup" << std::endl; } | 25 | + static void SetUpTestCase() |
| 27 | - static void TearDownTestCase() { std::cout << "Expm1 Test TearDown" << std::endl; } | 26 | + { |
| 27 | + std::cout << "Expm1 Test Setup" << std::endl; | ||
| 28 | + } | ||
| 29 | + static void TearDownTestCase() | ||
| 30 | + { | ||
| 31 | + std::cout << "Expm1 Test TearDown" << std::endl; | ||
| 32 | + } | ||
| 28 | }; | 33 | }; |
| 29 | 34 | ||
| 30 | TEST_F(l2_expm1_test, expm1_testcase_001_normal_float32) | 35 | TEST_F(l2_expm1_test, expm1_testcase_001_normal_float32) |
| 31 | { | 36 | { |
| 32 | auto outDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); | 37 | auto outDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); |
| 33 | - auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1,1); | 38 | + auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 34 | 39 | ||
| 35 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 40 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 36 | 41 | ||
| @@ -38,14 +43,13 @@ TEST_F(l2_expm1_test, expm1_testcase_001_normal_float32) | |||
| 38 | uint64_t workspaceSize = 0; | 43 | uint64_t workspaceSize = 0; |
| 39 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | 44 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); |
| 40 | EXPECT_EQ(aclRet, ACL_SUCCESS); | 45 | EXPECT_EQ(aclRet, ACL_SUCCESS); |
| 41 | - | ||
| 42 | } | 46 | } |
| 43 | 47 | ||
| 44 | // float16 | 48 | // float16 |
| 45 | TEST_F(l2_expm1_test, expm1_testcase_002_normal_float16) | 49 | TEST_F(l2_expm1_test, expm1_testcase_002_normal_float16) |
| 46 | { | 50 | { |
| 47 | auto outDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND).Precision(0.001, 0.001); | 51 | auto outDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND).Precision(0.001, 0.001); |
| 48 | - auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-1,1); | 52 | + auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 49 | 53 | ||
| 50 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 54 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 51 | 55 | ||
| @@ -53,14 +57,13 @@ TEST_F(l2_expm1_test, expm1_testcase_002_normal_float16) | |||
| 53 | uint64_t workspaceSize = 0; | 57 | uint64_t workspaceSize = 0; |
| 54 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | 58 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); |
| 55 | EXPECT_EQ(aclRet, ACL_SUCCESS); | 59 | EXPECT_EQ(aclRet, ACL_SUCCESS); |
| 56 | - | ||
| 57 | } | 60 | } |
| 58 | 61 | ||
| 59 | // bfloat16 | 62 | // bfloat16 |
| 60 | TEST_F(l2_expm1_test, ascend910B2_expm1_testcase_002_normal_float16) | 63 | TEST_F(l2_expm1_test, ascend910B2_expm1_testcase_002_normal_float16) |
| 61 | { | 64 | { |
| 62 | auto outDesc = TensorDesc({2, 5}, ACL_BF16, ACL_FORMAT_ND).Precision(0.001, 0.001); | 65 | auto outDesc = TensorDesc({2, 5}, ACL_BF16, ACL_FORMAT_ND).Precision(0.001, 0.001); |
| 63 | - auto selfDesc = TensorDesc({2, 5}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-1,1); | 66 | + auto selfDesc = TensorDesc({2, 5}, ACL_BF16, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 64 | 67 | ||
| 65 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 68 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 66 | 69 | ||
| @@ -68,7 +71,6 @@ TEST_F(l2_expm1_test, ascend910B2_expm1_testcase_002_normal_float16) | |||
| 68 | uint64_t workspaceSize = 0; | 71 | uint64_t workspaceSize = 0; |
| 69 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | 72 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); |
| 70 | EXPECT_EQ(aclRet, ACL_SUCCESS); | 73 | EXPECT_EQ(aclRet, ACL_SUCCESS); |
| 71 | - | ||
| 72 | } | 74 | } |
| 73 | 75 | ||
| 74 | // empty | 76 | // empty |
| @@ -88,7 +90,7 @@ TEST_F(l2_expm1_test, expm1_testcase_003_normal_empty_tensor) | |||
| 88 | // CheckNotNull | 90 | // CheckNotNull |
| 89 | TEST_F(l2_expm1_test, expm1_testcase_004_exception_null_out) | 91 | TEST_F(l2_expm1_test, expm1_testcase_004_exception_null_out) |
| 90 | { | 92 | { |
| 91 | - auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-1,1); | 93 | + auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 92 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT((aclTensor*)nullptr)); | 94 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT((aclTensor*)nullptr)); |
| 93 | 95 | ||
| 94 | // SAMPLE: only test GetWorkspaceSize | 96 | // SAMPLE: only test GetWorkspaceSize |
| @@ -114,7 +116,7 @@ TEST_F(l2_expm1_test, expm1_testcase_005_exception_null_self) | |||
| 114 | TEST_F(l2_expm1_test, expm1_testcase_007_normal_dtype_not_the_same) | 116 | TEST_F(l2_expm1_test, expm1_testcase_007_normal_dtype_not_the_same) |
| 115 | { | 117 | { |
| 116 | auto outDesc = TensorDesc({5, 5}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | 118 | auto outDesc = TensorDesc({5, 5}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); |
| 117 | - auto selfDesc = TensorDesc({5, 5}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-1,1); | 119 | + auto selfDesc = TensorDesc({5, 5}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 118 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 120 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 119 | 121 | ||
| 120 | // SAMPLE: only test GetWorkspaceSize | 122 | // SAMPLE: only test GetWorkspaceSize |
| @@ -122,14 +124,13 @@ TEST_F(l2_expm1_test, expm1_testcase_007_normal_dtype_not_the_same) | |||
| 122 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | 124 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); |
| 123 | 125 | ||
| 124 | EXPECT_EQ(aclRet, ACLNN_SUCCESS); | 126 | EXPECT_EQ(aclRet, ACLNN_SUCCESS); |
| 125 | - | ||
| 126 | } | 127 | } |
| 127 | 128 | ||
| 128 | // CheckDtype different dtype of input | 129 | // CheckDtype different dtype of input |
| 129 | TEST_F(l2_expm1_test, expm1_testcase_008_normal_dtype_not_the_same) | 130 | TEST_F(l2_expm1_test, expm1_testcase_008_normal_dtype_not_the_same) |
| 130 | { | 131 | { |
| 131 | auto outDesc = TensorDesc({1, 16, 1, 1}, ACL_FLOAT16, ACL_FORMAT_ND).Precision(0.001, 0.001); | 132 | auto outDesc = TensorDesc({1, 16, 1, 1}, ACL_FLOAT16, ACL_FORMAT_ND).Precision(0.001, 0.001); |
| 132 | - auto selfDesc = TensorDesc({1, 16, 1, 1}, ACL_BOOL, ACL_FORMAT_ND).ValueRange(-1,1); | 133 | + auto selfDesc = TensorDesc({1, 16, 1, 1}, ACL_BOOL, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 133 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 134 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 134 | 135 | ||
| 135 | // SAMPLE: only test GetWorkspaceSize | 136 | // SAMPLE: only test GetWorkspaceSize |
| @@ -156,7 +157,8 @@ TEST_F(l2_expm1_test, expm1_testcase_009_exception_different_shape) | |||
| 156 | // not contiguous | 157 | // not contiguous |
| 157 | TEST_F(l2_expm1_test, expm1_testcase_010_normal_not_contiguous_float) | 158 | TEST_F(l2_expm1_test, expm1_testcase_010_normal_not_contiguous_float) |
| 158 | { | 159 | { |
| 159 | - auto outDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND, {1, 2}, 0, {5, 2}).Value(vector<float>{1,1,1,1,1,1,1,1,1,1}); | 160 | + auto outDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND, {1, 2}, 0, {5, 2}) |
| 161 | + .Value(vector<float>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); | ||
| 160 | auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND, {1, 2}, 0, {5, 2}).ValueRange(-1, 1); | 162 | auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND, {1, 2}, 0, {5, 2}).ValueRange(-1, 1); |
| 161 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 163 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 162 | 164 | ||
| @@ -168,7 +170,7 @@ TEST_F(l2_expm1_test, expm1_testcase_010_normal_not_contiguous_float) | |||
| 168 | // not contiguous | 170 | // not contiguous |
| 169 | TEST_F(l2_expm1_test, expm1_testcase_011_normal_not_contiguous_float16) | 171 | TEST_F(l2_expm1_test, expm1_testcase_011_normal_not_contiguous_float16) |
| 170 | { | 172 | { |
| 171 | - auto outDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND).Value(vector<float>{1,1,1,1,1,1,1,1,1,1}); | 173 | + auto outDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND).Value(vector<float>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); |
| 172 | auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND, {1, 2}, 0, {5, 2}).ValueRange(-1, 1); | 174 | auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND, {1, 2}, 0, {5, 2}).ValueRange(-1, 1); |
| 173 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 175 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 174 | 176 | ||
| @@ -180,7 +182,8 @@ TEST_F(l2_expm1_test, expm1_testcase_011_normal_not_contiguous_float16) | |||
| 180 | // not contiguous | 182 | // not contiguous |
| 181 | TEST_F(l2_expm1_test, expm1_testcase_012_normal_not_contiguous_float16) | 183 | TEST_F(l2_expm1_test, expm1_testcase_012_normal_not_contiguous_float16) |
| 182 | { | 184 | { |
| 183 | - auto outDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND, {1, 2}, 0, {5, 2}).Value(vector<float>{1,1,1,1,1,1,1,1,1,1}); | 185 | + auto outDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND, {1, 2}, 0, {5, 2}) |
| 186 | + .Value(vector<float>{1, 1, 1, 1, 1, 1, 1, 1, 1, 1}); | ||
| 184 | auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-1, 1); | 187 | auto selfDesc = TensorDesc({2, 5}, ACL_FLOAT16, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 185 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 188 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 186 | 189 | ||
| @@ -218,8 +221,8 @@ TEST_F(l2_expm1_test, expm1_testcase_014_exception_complex128_dtype_not_supporte | |||
| 218 | // largeDim | 221 | // largeDim |
| 219 | TEST_F(l2_expm1_test, expm1_testcase_015_normal_large_dims) | 222 | TEST_F(l2_expm1_test, expm1_testcase_015_normal_large_dims) |
| 220 | { | 223 | { |
| 221 | - auto outDesc = TensorDesc({1,2,2,2,2,2,2,2,2}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); | 224 | + auto outDesc = TensorDesc({1, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); |
| 222 | - auto selfDesc = TensorDesc({1,2,2,2,2,2,2,2,2}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1,1); | 225 | + auto selfDesc = TensorDesc({1, 2, 2, 2, 2, 2, 2, 2, 2}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 223 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 226 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 224 | 227 | ||
| 225 | // SAMPLE: only test GetWorkspaceSize | 228 | // SAMPLE: only test GetWorkspaceSize |
| @@ -231,7 +234,7 @@ TEST_F(l2_expm1_test, expm1_testcase_015_normal_large_dims) | |||
| 231 | // empty | 234 | // empty |
| 232 | TEST_F(l2_expm1_test, expm1_testcase_016_normal_self_empty_tensor) | 235 | TEST_F(l2_expm1_test, expm1_testcase_016_normal_self_empty_tensor) |
| 233 | { | 236 | { |
| 234 | - auto outDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1,1); | 237 | + auto outDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 235 | auto selfDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND); | 238 | auto selfDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND); |
| 236 | 239 | ||
| 237 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 240 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| @@ -246,7 +249,7 @@ TEST_F(l2_expm1_test, expm1_testcase_016_normal_self_empty_tensor) | |||
| 246 | TEST_F(l2_expm1_test, expm1_testcase_017_exception_out_empty_tensor) | 249 | TEST_F(l2_expm1_test, expm1_testcase_017_exception_out_empty_tensor) |
| 247 | { | 250 | { |
| 248 | auto outDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND); | 251 | auto outDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND); |
| 249 | - auto selfDesc = TensorDesc({16, 16}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1,1); | 252 | + auto selfDesc = TensorDesc({16, 16}, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 250 | 253 | ||
| 251 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 254 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 252 | 255 | ||
| @@ -259,8 +262,8 @@ TEST_F(l2_expm1_test, expm1_testcase_017_exception_out_empty_tensor) | |||
| 259 | // dtype can cast to out | 262 | // dtype can cast to out |
| 260 | TEST_F(l2_expm1_test, expm1_testcase_018_can_cast_out) | 263 | TEST_F(l2_expm1_test, expm1_testcase_018_can_cast_out) |
| 261 | { | 264 | { |
| 262 | - auto selfDesc = TensorDesc({5,5}, ACL_INT64, ACL_FORMAT_ND).ValueRange(-1,1); | 265 | + auto selfDesc = TensorDesc({5, 5}, ACL_INT64, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 263 | - auto outDesc = TensorDesc({5,5}, ACL_BOOL, ACL_FORMAT_ND); | 266 | + auto outDesc = TensorDesc({5, 5}, ACL_BOOL, ACL_FORMAT_ND); |
| 264 | 267 | ||
| 265 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 268 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 266 | 269 | ||
| @@ -273,8 +276,8 @@ TEST_F(l2_expm1_test, expm1_testcase_018_can_cast_out) | |||
| 273 | // dtype can cast to out | 276 | // dtype can cast to out |
| 274 | TEST_F(l2_expm1_test, expm1_testcase_019_can_cast_out) | 277 | TEST_F(l2_expm1_test, expm1_testcase_019_can_cast_out) |
| 275 | { | 278 | { |
| 276 | - auto selfDesc = TensorDesc({5,5}, ACL_INT64, ACL_FORMAT_ND).ValueRange(-1,1); | 279 | + auto selfDesc = TensorDesc({5, 5}, ACL_INT64, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 277 | - auto outDesc = TensorDesc({5,5}, ACL_FLOAT, ACL_FORMAT_ND); | 280 | + auto outDesc = TensorDesc({5, 5}, ACL_FLOAT, ACL_FORMAT_ND); |
| 278 | 281 | ||
| 279 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 282 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 280 | 283 | ||
| @@ -287,8 +290,8 @@ TEST_F(l2_expm1_test, expm1_testcase_019_can_cast_out) | |||
| 287 | // dtype can cast to out | 290 | // dtype can cast to out |
| 288 | TEST_F(l2_expm1_test, expm1_testcase_020_can_cast_out) | 291 | TEST_F(l2_expm1_test, expm1_testcase_020_can_cast_out) |
| 289 | { | 292 | { |
| 290 | - auto selfDesc = TensorDesc({5,5}, ACL_BOOL, ACL_FORMAT_ND).ValueRange(-1,1); | 293 | + auto selfDesc = TensorDesc({5, 5}, ACL_BOOL, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 291 | - auto outDesc = TensorDesc({5,5}, ACL_FLOAT, ACL_FORMAT_ND); | 294 | + auto outDesc = TensorDesc({5, 5}, ACL_FLOAT, ACL_FORMAT_ND); |
| 292 | 295 | ||
| 293 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 296 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 294 | 297 | ||
| @@ -301,7 +304,7 @@ TEST_F(l2_expm1_test, expm1_testcase_020_can_cast_out) | |||
| 301 | TEST_F(l2_expm1_test, expm1_testcase_021_normal_int64_float32) | 304 | TEST_F(l2_expm1_test, expm1_testcase_021_normal_int64_float32) |
| 302 | { | 305 | { |
| 303 | auto outDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); | 306 | auto outDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); |
| 304 | - auto selfDesc = TensorDesc({2, 5}, ACL_INT64, ACL_FORMAT_ND).ValueRange(-1,1); | 307 | + auto selfDesc = TensorDesc({2, 5}, ACL_INT64, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 305 | 308 | ||
| 306 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 309 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 307 | 310 | ||
| @@ -309,13 +312,12 @@ TEST_F(l2_expm1_test, expm1_testcase_021_normal_int64_float32) | |||
| 309 | uint64_t workspaceSize = 0; | 312 | uint64_t workspaceSize = 0; |
| 310 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | 313 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); |
| 311 | EXPECT_EQ(aclRet, ACL_SUCCESS); | 314 | EXPECT_EQ(aclRet, ACL_SUCCESS); |
| 312 | - | ||
| 313 | } | 315 | } |
| 314 | 316 | ||
| 315 | TEST_F(l2_expm1_test, expm1_testcase_022_normal_bool_float32) | 317 | TEST_F(l2_expm1_test, expm1_testcase_022_normal_bool_float32) |
| 316 | { | 318 | { |
| 317 | auto outDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); | 319 | auto outDesc = TensorDesc({2, 5}, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.0001, 0.0001); |
| 318 | - auto selfDesc = TensorDesc({2, 5}, ACL_BOOL, ACL_FORMAT_ND).ValueRange(-1,1); | 320 | + auto selfDesc = TensorDesc({2, 5}, ACL_BOOL, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 319 | 321 | ||
| 320 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 322 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 321 | 323 | ||
| @@ -323,14 +325,13 @@ TEST_F(l2_expm1_test, expm1_testcase_022_normal_bool_float32) | |||
| 323 | uint64_t workspaceSize = 0; | 325 | uint64_t workspaceSize = 0; |
| 324 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); | 326 | aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspaceSize); |
| 325 | EXPECT_EQ(aclRet, ACL_SUCCESS); | 327 | EXPECT_EQ(aclRet, ACL_SUCCESS); |
| 326 | - | ||
| 327 | } | 328 | } |
| 328 | 329 | ||
| 329 | // dtype cannot cast to out | 330 | // dtype cannot cast to out |
| 330 | TEST_F(l2_expm1_test, expm1_testcase_023_cannot_cast_out) | 331 | TEST_F(l2_expm1_test, expm1_testcase_023_cannot_cast_out) |
| 331 | { | 332 | { |
| 332 | - auto selfDesc = TensorDesc({5,5}, ACL_BOOL, ACL_FORMAT_ND).ValueRange(-1,1); | 333 | + auto selfDesc = TensorDesc({5, 5}, ACL_BOOL, ACL_FORMAT_ND).ValueRange(-1, 1); |
| 333 | - auto outDesc = TensorDesc({5,5}, ACL_INT64, ACL_FORMAT_ND); | 334 | + auto outDesc = TensorDesc({5, 5}, ACL_INT64, ACL_FORMAT_ND); |
| 334 | 335 | ||
| 335 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); | 336 | auto ut = OP_API_UT(aclnnExpm1, INPUT(selfDesc), OUTPUT(outDesc)); |
| 336 | 337 | ||
| @@ -1,20 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
| 18 | - | ||
| 19 | -if(OP_API_UT OR (UT_TEST_ALL AND NOT AICPU_ONLY)) | ||
| 20 | -endif() | ||
| @@ -0,0 +1,191 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +using namespace std; | ||
| 19 | + | ||
| 20 | +class Expm1TilingTest : public testing::Test { | ||
| 21 | +protected: | ||
| 22 | + static void SetUpTestCase() | ||
| 23 | + { | ||
| 24 | + std::cout << "Expm1TilingTest SetUp" << std::endl; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + static void TearDownTestCase() | ||
| 28 | + { | ||
| 29 | + std::cout << "Expm1TilingTest TearDown" << std::endl; | ||
| 30 | + } | ||
| 31 | +}; | ||
| 32 | + | ||
| 33 | +TEST_F(Expm1TilingTest, expm1_test_tiling_fp16_input) | ||
| 34 | +{ | ||
| 35 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 36 | + gert::TilingContextPara tilingContextPara( | ||
| 37 | + "Expm1", | ||
| 38 | + { | ||
| 39 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 40 | + }, | ||
| 41 | + { | ||
| 42 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 43 | + }, | ||
| 44 | + {}, &compileInfo); | ||
| 45 | + | ||
| 46 | + uint64_t expectTilingKey = 3; | ||
| 47 | + string expectTilingData = "8192 4 4352 2048 4 1 1 2048 2048 4352 1 "; | ||
| 48 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 49 | + ExecuteTestCaseForEle( | ||
| 50 | + tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 51 | +} | ||
| 52 | + | ||
| 53 | +TEST_F(Expm1TilingTest, expm1_test_tiling_bf16_input) | ||
| 54 | +{ | ||
| 55 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 56 | + gert::TilingContextPara tilingContextPara( | ||
| 57 | + "Expm1", | ||
| 58 | + { | ||
| 59 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 60 | + }, | ||
| 61 | + { | ||
| 62 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 63 | + }, | ||
| 64 | + {}, &compileInfo); | ||
| 65 | + | ||
| 66 | + uint64_t expectTilingKey = 5; | ||
| 67 | + string expectTilingData = "8192 4 4352 2048 4 1 1 2048 2048 4352 1 "; | ||
| 68 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 69 | + ExecuteTestCaseForEle( | ||
| 70 | + tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +TEST_F(Expm1TilingTest, expm1_test_tiling_fp32_input) | ||
| 74 | +{ | ||
| 75 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 76 | + gert::TilingContextPara tilingContextPara( | ||
| 77 | + "Expm1", | ||
| 78 | + { | ||
| 79 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 80 | + }, | ||
| 81 | + { | ||
| 82 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 83 | + }, | ||
| 84 | + {}, &compileInfo); | ||
| 85 | + | ||
| 86 | + uint64_t expectTilingKey = 7; | ||
| 87 | + string expectTilingData = "8192 8 6656 1024 8 1 1 1024 1024 6656 1 "; | ||
| 88 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 89 | + ExecuteTestCaseForEle( | ||
| 90 | + tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 91 | +} | ||
| 92 | + | ||
| 93 | +TEST_F(Expm1TilingTest, expm1_test_tiling_invalid_input_dtype) | ||
| 94 | +{ | ||
| 95 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 96 | + gert::TilingContextPara tilingContextPara( | ||
| 97 | + "Expm1", | ||
| 98 | + { | ||
| 99 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_DOUBLE, ge::FORMAT_ND}, | ||
| 100 | + }, | ||
| 101 | + { | ||
| 102 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 103 | + }, | ||
| 104 | + {}, &compileInfo); | ||
| 105 | + | ||
| 106 | + uint64_t expectTilingKey = 7; | ||
| 107 | + string expectTilingData = ""; | ||
| 108 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 109 | + ExecuteTestCaseForEle( | ||
| 110 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +TEST_F(Expm1TilingTest, expm1_test_tiling_invalid_output_dtype) | ||
| 114 | +{ | ||
| 115 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 116 | + gert::TilingContextPara tilingContextPara( | ||
| 117 | + "Expm1", | ||
| 118 | + { | ||
| 119 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 120 | + }, | ||
| 121 | + { | ||
| 122 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_DOUBLE, ge::FORMAT_ND}, | ||
| 123 | + }, | ||
| 124 | + {}, &compileInfo); | ||
| 125 | + | ||
| 126 | + uint64_t expectTilingKey = 7; | ||
| 127 | + string expectTilingData = ""; | ||
| 128 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 129 | + ExecuteTestCaseForEle( | ||
| 130 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 131 | +} | ||
| 132 | + | ||
| 133 | +TEST_F(Expm1TilingTest, expm1_test_tiling_invalid_shape) | ||
| 134 | +{ | ||
| 135 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 136 | + gert::TilingContextPara tilingContextPara( | ||
| 137 | + "Expm1", | ||
| 138 | + { | ||
| 139 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 140 | + }, | ||
| 141 | + { | ||
| 142 | + {{{1, 64, 2, 32}, {1, 64, 2, 32}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 143 | + }, | ||
| 144 | + {}, &compileInfo); | ||
| 145 | + | ||
| 146 | + uint64_t expectTilingKey = 7; | ||
| 147 | + string expectTilingData = ""; | ||
| 148 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 149 | + ExecuteTestCaseForEle( | ||
| 150 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +TEST_F(Expm1TilingTest, expm1_test_tiling_empty_tensor) | ||
| 154 | +{ | ||
| 155 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 156 | + gert::TilingContextPara tilingContextPara( | ||
| 157 | + "Expm1", | ||
| 158 | + { | ||
| 159 | + {{{1, 0, 2, 64}, {1, 0, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 160 | + }, | ||
| 161 | + { | ||
| 162 | + {{{1, 0, 2, 64}, {1, 0, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 163 | + }, | ||
| 164 | + {}, &compileInfo); | ||
| 165 | + | ||
| 166 | + uint64_t expectTilingKey = 7; | ||
| 167 | + string expectTilingData = ""; | ||
| 168 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 169 | + ExecuteTestCaseForEle( | ||
| 170 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | +TEST_F(Expm1TilingTest, expm1_test_tiling_invalid_input_output_dtype) | ||
| 174 | +{ | ||
| 175 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 176 | + gert::TilingContextPara tilingContextPara( | ||
| 177 | + "Expm1", | ||
| 178 | + { | ||
| 179 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 180 | + }, | ||
| 181 | + { | ||
| 182 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 183 | + }, | ||
| 184 | + {}, &compileInfo); | ||
| 185 | + | ||
| 186 | + uint64_t expectTilingKey = 7; | ||
| 187 | + string expectTilingData = ""; | ||
| 188 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 189 | + ExecuteTestCaseForEle( | ||
| 190 | + tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 191 | +} | ||
| @@ -1,10 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -# ---------------------------------------------------------------------------- | ||
| @@ -0,0 +1,55 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +class Expm1InferShape : public testing::Test { | ||
| 17 | +protected: | ||
| 18 | + static void SetUpTestCase() | ||
| 19 | + { | ||
| 20 | + std::cout << "Expm1 InferShape SetUp" << std::endl; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + static void TearDownTestCase() | ||
| 24 | + { | ||
| 25 | + std::cout << "Expm1 InferShape TearDown" << std::endl; | ||
| 26 | + } | ||
| 27 | +}; | ||
| 28 | + | ||
| 29 | +TEST_F(Expm1InferShape, expm1_infershape_diff_test) | ||
| 30 | +{ | ||
| 31 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 32 | + "Expm1", | ||
| 33 | + { | ||
| 34 | + {{{-1}, {-1}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 35 | + }, | ||
| 36 | + { | ||
| 37 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 38 | + }); | ||
| 39 | + std::vector<std::vector<int64_t>> expectOutputShape = {{-1}}; | ||
| 40 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +TEST_F(Expm1InferShape, expm1_infershape_static_test) | ||
| 44 | +{ | ||
| 45 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 46 | + "Expm1", | ||
| 47 | + { | ||
| 48 | + {{{4, 3, 4}, {4, 3, 4}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 49 | + }, | ||
| 50 | + { | ||
| 51 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 52 | + }); | ||
| 53 | + std::vector<std::vector<int64_t>> expectOutputShape = {{4, 3, 4}}; | ||
| 54 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 55 | +} | ||
| @@ -1,20 +1,15 @@ | |||
| 1 | # ---------------------------------------------------------------------------- | 1 | # ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify it. | 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. |
| 3 | -# 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 | -# This file is a part of the CANN Open Software. | 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). |
| 5 | -# Licensed under 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. | 5 | # 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, INCLUDING | 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, |
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | 7 | +# 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. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 10 | # ---------------------------------------------------------------------------- | 9 | # ---------------------------------------------------------------------------- |
| 11 | 10 | ||
| 12 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | +# 设置算子定义时支持的芯片类型 |
| 13 | -if(NOT ENABLE_TEST AND NOT BENCHMARK) | 12 | +set(SUPPORT_COMPUTE_UNIT "ascend950") |
| 14 | - list(REMOVE_ITEM CURRENT_DIRS tests) | 13 | +# 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 |
| 15 | -endif() | 14 | +set(SUPPORT_TILING_DIR "arch35") |
| 16 | -foreach(SUB_DIR ${CURRENT_DIRS}) | 15 | +add_all_modules_sources(OPTYPE nan_to_num ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE) |
| 17 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 18 | - add_subdirectory(${SUB_DIR}) | ||
| 19 | - endif() | ||
| 20 | -endforeach() | ||
Rmath/nan_to_num/op_host/op_api/aclnn_nan_to_num.cpp→math/nan_to_num/op_api/aclnn_nan_to_num.cpp+0-0
文件重命名但无更改。
| @@ -0,0 +1,42 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file nan_to_num_proto.h | ||
| 13 | + * \brief nan_to_num proto | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +namespace ge { | ||
| 21 | +/** | ||
| 22 | + * @brief Replaces NaN, positive infinity, and negative infinity values in x with specified values. | ||
| 23 | + * @par Inputs | ||
| 24 | + * x: An ND tensor of type float16, bfloat16, float32. | ||
| 25 | + * @par Outputs | ||
| 26 | + * y: An ND tensor of the same type as x. | ||
| 27 | + * @par Attributes | ||
| 28 | + * nan: An attr of type float. The value to replace NaN values. | ||
| 29 | + * posinf: An attr of type float. The value to replace positive infinity values. | ||
| 30 | + * neginf: An attr of type float. The value to replace negative infinity values. | ||
| 31 | + * @par Third-party framework compatibility | ||
| 32 | + * Compatible with PyTorch operator nan_to_num. | ||
| 33 | + */ | ||
| 34 | +REG_OP(NanToNum) | ||
| 35 | + .INPUT(x, TensorType({DT_BF16, DT_FLOAT16, DT_FLOAT})) | ||
| 36 | + .OUTPUT(y, TensorType({DT_BF16, DT_FLOAT16, DT_FLOAT})) | ||
| 37 | + .REQUIRED_ATTR(nan, Float) | ||
| 38 | + .REQUIRED_ATTR(posinf, Float) | ||
| 39 | + .REQUIRED_ATTR(neginf, Float) | ||
| 40 | + .OP_END_FACTORY_REG(NanToNum) | ||
| 41 | +} // namespace ge | ||
| 42 | + | ||
| @@ -1,12 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -add_modules_sources() | ||
| @@ -0,0 +1,178 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file nan_to_num_tiling_arch35.cpp | ||
| 13 | + * \brief nan_to_num_tiling source file | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + | ||
| 30 | +using namespace ge; | ||
| 31 | +using namespace NanToNumOp; | ||
| 32 | +using namespace Ops::Math::OpTiling; | ||
| 33 | + | ||
| 34 | +namespace optiling { | ||
| 35 | +constexpr int64_t ASCEND_API_BUFFER = 122880; | ||
| 36 | +const int64_t ASCEND_WORKSPACE = 16 * 1024 * 1024; | ||
| 37 | + | ||
| 38 | +ge::graphStatus NanToNumTiling::CalcInputDtype() | ||
| 39 | +{ | ||
| 40 | + OP_LOGD(tilingContext->GetNodeName(), "NanToNumTiling CalcInputDtype enter."); | ||
| 41 | + auto inputDesc = tilingContext->GetInputDesc(0); | ||
| 42 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputDesc); | ||
| 43 | + this->inputDtype = inputDesc->GetDataType(); | ||
| 44 | + OP_CHECK_IF( | ||
| 45 | + this->inputDtype != ge::DT_FLOAT16 && this->inputDtype != ge::DT_BF16 && this->inputDtype != ge::DT_FLOAT, | ||
| 46 | + OP_LOGE( | ||
| 47 | + tilingContext->GetNodeName(), | ||
| 48 | + "input x dtype [%s] not supported, only support [DT_FLOAT16, DT_BF16, DT_FLOAT]", | ||
| 49 | + ge::TypeUtils::DataTypeToSerialString(this->inputDtype).c_str()), | ||
| 50 | + return ge::GRAPH_FAILED); | ||
| 51 | + return ge::GRAPH_SUCCESS; | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +ge::graphStatus NanToNumTiling::CalcOutputDtype() | ||
| 55 | +{ | ||
| 56 | + OP_LOGD(tilingContext->GetNodeName(), "NanToNumTiling CalcOutputDtype enter."); | ||
| 57 | + auto outputDesc = tilingContext->GetOutputDesc(0); | ||
| 58 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputDesc); | ||
| 59 | + this->outputDtype = outputDesc->GetDataType(); | ||
| 60 | + OP_CHECK_IF( | ||
| 61 | + this->outputDtype != this->inputDtype, | ||
| 62 | + OP_LOGE(tilingContext->GetNodeName(), "output y dtype not same as input x"), return ge::GRAPH_FAILED); | ||
| 63 | + return ge::GRAPH_SUCCESS; | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +ge::graphStatus NanToNumTiling::CheckShape() | ||
| 67 | +{ | ||
| 68 | + OP_LOGD(tilingContext->GetNodeName(), "NanToNumTiling CheckShape enter."); | ||
| 69 | + auto inputStorageShape = tilingContext->GetInputShape(0); | ||
| 70 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, inputStorageShape); | ||
| 71 | + const gert::Shape& inputXShape = EnsureNotScalar(inputStorageShape->GetStorageShape()); | ||
| 72 | + | ||
| 73 | + auto outputStorageShape = tilingContext->GetOutputShape(0); | ||
| 74 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, outputStorageShape); | ||
| 75 | + const gert::Shape& outputYShape = EnsureNotScalar(outputStorageShape->GetStorageShape()); | ||
| 76 | + | ||
| 77 | + OP_CHECK_IF( | ||
| 78 | + inputXShape != outputYShape, OP_LOGE(tilingContext->GetNodeName(), "input x and output y shape not same"), | ||
| 79 | + return ge::GRAPH_FAILED); | ||
| 80 | + return ge::GRAPH_SUCCESS; | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +ge::graphStatus NanToNumTiling::SetAttr() | ||
| 84 | +{ | ||
| 85 | + OP_LOGD(tilingContext->GetNodeName(), "NanToNumTiling SetAttr enter."); | ||
| 86 | + auto attrs = tilingContext->GetAttrs(); | ||
| 87 | + OP_CHECK_NULL_WITH_CONTEXT(tilingContext, attrs); | ||
| 88 | + const float* nanValueAttr = attrs->GetAttrPointer<float>(NanToNumOp::PLACEHOLDER_INDEX_0); | ||
| 89 | + const float* posinfValueAttr = attrs->GetAttrPointer<float>(NanToNumOp::PLACEHOLDER_INDEX_1); | ||
| 90 | + const float* neginfValueAttr = attrs->GetAttrPointer<float>(NanToNumOp::PLACEHOLDER_INDEX_2); | ||
| 91 | + | ||
| 92 | + OP_CHECK_IF( | ||
| 93 | + nanValueAttr == nullptr, OP_LOGE(tilingContext->GetNodeName(), "nan value must exist"), | ||
| 94 | + return ge::GRAPH_FAILED); | ||
| 95 | + OP_CHECK_IF( | ||
| 96 | + posinfValueAttr == nullptr, OP_LOGE(tilingContext->GetNodeName(), "posinf value must exist"), | ||
| 97 | + return ge::GRAPH_FAILED); | ||
| 98 | + OP_CHECK_IF( | ||
| 99 | + neginfValueAttr == nullptr, OP_LOGE(tilingContext->GetNodeName(), "neginf value must exist"), | ||
| 100 | + return ge::GRAPH_FAILED); | ||
| 101 | + | ||
| 102 | + tiling->nan = *nanValueAttr; | ||
| 103 | + tiling->posinf = *posinfValueAttr; | ||
| 104 | + tiling->neginf = *neginfValueAttr; | ||
| 105 | + return ge::GRAPH_SUCCESS; | ||
| 106 | +} | ||
| 107 | + | ||
| 108 | +ge::graphStatus NanToNumTiling::SetTilingData() | ||
| 109 | +{ | ||
| 110 | + OP_LOGD(tilingContext->GetNodeName(), "NanToNumTiling SetTilingData enter."); | ||
| 111 | + | ||
| 112 | + size_t* currentWorkspace = tilingContext->GetWorkspaceSizes(1); | ||
| 113 | + currentWorkspace[0] = ASCEND_WORKSPACE; | ||
| 114 | + | ||
| 115 | + const uint64_t tilingKey = GET_TPL_TILING_KEY(static_cast<uint64_t>(tiling->baseTiling.scheMode), dType); | ||
| 116 | + OP_LOGD(tilingContext->GetNodeName(), "[TilingData] : tilingKey=%lu", tilingKey); | ||
| 117 | + tilingContext->SetTilingKey(tilingKey); | ||
| 118 | + tilingContext->SetBlockDim(tiling->baseTiling.blockNum); | ||
| 119 | + return ge::GRAPH_SUCCESS; | ||
| 120 | +} | ||
| 121 | + | ||
| 122 | +ge::graphStatus NanToNumTiling::RunTiling() | ||
| 123 | +{ | ||
| 124 | + OP_LOGD(tilingContext->GetNodeName(), "NanToNumTiling RunTiling enter."); | ||
| 125 | + ElewiseBaseTiling elewiseBaseTiling(tilingContext); | ||
| 126 | + tiling = tilingContext->GetTilingData<NanToNumTilingData>(); | ||
| 127 | + | ||
| 128 | + OP_CHECK_IF( | ||
| 129 | + CalcInputDtype() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "get input dtype failed"), | ||
| 130 | + return ge::GRAPH_FAILED); | ||
| 131 | + OP_CHECK_IF( | ||
| 132 | + CalcOutputDtype() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "get output dtype failed"), | ||
| 133 | + return ge::GRAPH_FAILED); | ||
| 134 | + OP_CHECK_IF( | ||
| 135 | + CheckShape() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "check shape failed"), return ge::GRAPH_FAILED); | ||
| 136 | + OP_CHECK_IF(SetAttr() == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "set Attr failed"), return ge::GRAPH_FAILED); | ||
| 137 | + | ||
| 138 | + ge::graphStatus baseTilingResult = ge::GRAPH_FAILED; | ||
| 139 | + if (this->outputDtype == ge::DT_FLOAT16) { | ||
| 140 | + dType = TPL_FP16; | ||
| 141 | + baseTilingResult = elewiseBaseTiling.DoTiling<NanToNumOp::NanToNumDAG<half>::OpDag>(tiling->baseTiling); | ||
| 142 | + } else if (this->outputDtype == ge::DT_BF16) { | ||
| 143 | + dType = TPL_BF16; | ||
| 144 | + baseTilingResult = elewiseBaseTiling.DoTiling<NanToNumOp::NanToNumDAG<bfloat16_t>::OpDag>(tiling->baseTiling); | ||
| 145 | + } else if (this->outputDtype == ge::DT_FLOAT) { | ||
| 146 | + dType = TPL_FP32; | ||
| 147 | + baseTilingResult = elewiseBaseTiling.DoTiling<NanToNumOp::NanToNumDAG<float>::OpDag>(tiling->baseTiling); | ||
| 148 | + } else { | ||
| 149 | + OP_LOGE( | ||
| 150 | + tilingContext->GetNodeName(), | ||
| 151 | + "output y dtype [%s] not supported, only support [DT_FLOAT16, DT_BF16, DT_FLOAT]", | ||
| 152 | + ge::TypeUtils::DataTypeToSerialString(this->outputDtype).c_str()); | ||
| 153 | + return ge::GRAPH_FAILED; | ||
| 154 | + } | ||
| 155 | + OP_CHECK_IF( | ||
| 156 | + baseTilingResult == ge::GRAPH_FAILED, OP_LOGE(tilingContext, "elewiseBaseTiling failed"), | ||
| 157 | + return ge::GRAPH_FAILED); | ||
| 158 | + | ||
| 159 | + return SetTilingData(); | ||
| 160 | +} | ||
| 161 | + | ||
| 162 | +static ge::graphStatus Tiling4NanToNum(gert::TilingContext* context) | ||
| 163 | +{ | ||
| 164 | + OP_LOGD(context->GetNodeName(), "Tiling4NanToNum rt2.0 is running."); | ||
| 165 | + auto compileInfo = reinterpret_cast<const ElewiseCompileInfo*>(context->GetCompileInfo()); | ||
| 166 | + OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo); | ||
| 167 | + NanToNumTiling baseOpTiling(context); | ||
| 168 | + return baseOpTiling.RunTiling(); | ||
| 169 | +} | ||
| 170 | + | ||
| 171 | +static ge::graphStatus TilingPrepareForNanToNum([[maybe_unused]] gert::TilingParseContext* context) | ||
| 172 | +{ | ||
| 173 | + return ge::GRAPH_SUCCESS; | ||
| 174 | +} | ||
| 175 | + | ||
| 176 | +IMPL_OP_OPTILING(NanToNum).Tiling(Tiling4NanToNum).TilingParse<ElewiseCompileInfo>(TilingPrepareForNanToNum); | ||
| 177 | + | ||
| 178 | +} // namespace optiling | ||
| @@ -0,0 +1,44 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file nan_to_num_tiling_arch35.h | ||
| 13 | + * \brief nan_to_num_tiling head file | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace optiling { | ||
| 23 | +using namespace NanToNum; | ||
| 24 | +class NanToNumTiling { | ||
| 25 | +public: | ||
| 26 | + explicit NanToNumTiling(gert::TilingContext* context) : tilingContext(context) {}; | ||
| 27 | + ge::graphStatus RunTiling(); | ||
| 28 | + NanToNumTilingData* tiling = nullptr; | ||
| 29 | + | ||
| 30 | +protected: | ||
| 31 | + ge::graphStatus CalcOutputDtype(); | ||
| 32 | + ge::graphStatus CalcInputDtype(); | ||
| 33 | + ge::graphStatus CheckShape(); | ||
| 34 | + ge::graphStatus SetAttr(); | ||
| 35 | + ge::graphStatus SetTilingData(); | ||
| 36 | + | ||
| 37 | +private: | ||
| 38 | + uint64_t dType = 0; | ||
| 39 | + gert::TilingContext* tilingContext; | ||
| 40 | + ge::DataType outputDtype; | ||
| 41 | + ge::DataType inputDtype; | ||
| 42 | +}; | ||
| 43 | +} // namespace optiling | ||
| 44 | + | ||
| @@ -0,0 +1,143 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "NanToNum", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "NanToNum_1380099fab80e737f7e8ae05be4056ee", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "x", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "bfloat16", | ||
| 11 | + "format": "ND", | ||
| 12 | + "paramType": "required", | ||
| 13 | + "shape": [ | ||
| 14 | + -2 | ||
| 15 | + ], | ||
| 16 | + "format_match_mode": "FormatAgnostic" | ||
| 17 | + } | ||
| 18 | + ], | ||
| 19 | + "outputs": [ | ||
| 20 | + { | ||
| 21 | + "name": "y", | ||
| 22 | + "index": 0, | ||
| 23 | + "dtype": "bfloat16", | ||
| 24 | + "format": "ND", | ||
| 25 | + "paramType": "required", | ||
| 26 | + "shape": [ | ||
| 27 | + -2 | ||
| 28 | + ], | ||
| 29 | + "format_match_mode": "FormatAgnostic" | ||
| 30 | + } | ||
| 31 | + ], | ||
| 32 | + "attrs": [ | ||
| 33 | + { | ||
| 34 | + "name": "nan", | ||
| 35 | + "dtype": "float", | ||
| 36 | + "value": null | ||
| 37 | + }, | ||
| 38 | + { | ||
| 39 | + "name": "posinf", | ||
| 40 | + "dtype": "float", | ||
| 41 | + "value": null | ||
| 42 | + }, | ||
| 43 | + { | ||
| 44 | + "name": "neginf", | ||
| 45 | + "dtype": "float", | ||
| 46 | + "value": null | ||
| 47 | + } | ||
| 48 | + ] | ||
| 49 | + }, | ||
| 50 | + { | ||
| 51 | + "bin_filename": "NanToNum_a75a498177a4fc56db6ce7bd9fe08211", | ||
| 52 | + "inputs": [ | ||
| 53 | + { | ||
| 54 | + "name": "x", | ||
| 55 | + "index": 0, | ||
| 56 | + "dtype": "float16", | ||
| 57 | + "format": "ND", | ||
| 58 | + "paramType": "required", | ||
| 59 | + "shape": [ | ||
| 60 | + -2 | ||
| 61 | + ], | ||
| 62 | + "format_match_mode": "FormatAgnostic" | ||
| 63 | + } | ||
| 64 | + ], | ||
| 65 | + "outputs": [ | ||
| 66 | + { | ||
| 67 | + "name": "y", | ||
| 68 | + "index": 0, | ||
| 69 | + "dtype": "float16", | ||
| 70 | + "format": "ND", | ||
| 71 | + "paramType": "required", | ||
| 72 | + "shape": [ | ||
| 73 | + -2 | ||
| 74 | + ], | ||
| 75 | + "format_match_mode": "FormatAgnostic" | ||
| 76 | + } | ||
| 77 | + ], | ||
| 78 | + "attrs": [ | ||
| 79 | + { | ||
| 80 | + "name": "nan", | ||
| 81 | + "dtype": "float", | ||
| 82 | + "value": null | ||
| 83 | + }, | ||
| 84 | + { | ||
| 85 | + "name": "posinf", | ||
| 86 | + "dtype": "float", | ||
| 87 | + "value": null | ||
| 88 | + }, | ||
| 89 | + { | ||
| 90 | + "name": "neginf", | ||
| 91 | + "dtype": "float", | ||
| 92 | + "value": null | ||
| 93 | + } | ||
| 94 | + ] | ||
| 95 | + }, | ||
| 96 | + { | ||
| 97 | + "bin_filename": "NanToNum_1266cdadbc347490c57865a77cde9902", | ||
| 98 | + "inputs": [ | ||
| 99 | + { | ||
| 100 | + "name": "x", | ||
| 101 | + "index": 0, | ||
| 102 | + "dtype": "float32", | ||
| 103 | + "format": "ND", | ||
| 104 | + "paramType": "required", | ||
| 105 | + "shape": [ | ||
| 106 | + -2 | ||
| 107 | + ], | ||
| 108 | + "format_match_mode": "FormatAgnostic" | ||
| 109 | + } | ||
| 110 | + ], | ||
| 111 | + "outputs": [ | ||
| 112 | + { | ||
| 113 | + "name": "y", | ||
| 114 | + "index": 0, | ||
| 115 | + "dtype": "float32", | ||
| 116 | + "format": "ND", | ||
| 117 | + "paramType": "required", | ||
| 118 | + "shape": [ | ||
| 119 | + -2 | ||
| 120 | + ], | ||
| 121 | + "format_match_mode": "FormatAgnostic" | ||
| 122 | + } | ||
| 123 | + ], | ||
| 124 | + "attrs": [ | ||
| 125 | + { | ||
| 126 | + "name": "nan", | ||
| 127 | + "dtype": "float", | ||
| 128 | + "value": null | ||
| 129 | + }, | ||
| 130 | + { | ||
| 131 | + "name": "posinf", | ||
| 132 | + "dtype": "float", | ||
| 133 | + "value": null | ||
| 134 | + }, | ||
| 135 | + { | ||
| 136 | + "name": "neginf", | ||
| 137 | + "dtype": "float", | ||
| 138 | + "value": null | ||
| 139 | + } | ||
| 140 | + ] | ||
| 141 | + } | ||
| 142 | + ] | ||
| 143 | + } | ||
| @@ -0,0 +1,2 @@ | |||
| 1 | +[NanToNum] | ||
| 2 | +default=0 | ||
| @@ -0,0 +1,53 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file nan_to_num_def.cpp | ||
| 13 | + * \brief NanToNum def | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +namespace ops { | ||
| 20 | +static const std::vector<ge::DataType> nanToNumDataType = {ge::DT_BF16, ge::DT_FLOAT16, ge::DT_FLOAT}; | ||
| 21 | +static const std::vector<ge::Format> nanToNumFormat = {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND}; | ||
| 22 | +class NanToNum : public OpDef { | ||
| 23 | +public: | ||
| 24 | + explicit NanToNum(const char* name) : OpDef(name) | ||
| 25 | + { | ||
| 26 | + this->Input("x") | ||
| 27 | + .ParamType(REQUIRED) | ||
| 28 | + .DataType(nanToNumDataType) | ||
| 29 | + .Format(nanToNumFormat) | ||
| 30 | + .UnknownShapeFormat(nanToNumFormat); | ||
| 31 | + this->Output("y") | ||
| 32 | + .ParamType(REQUIRED) | ||
| 33 | + .DataType(nanToNumDataType) | ||
| 34 | + .Format(nanToNumFormat) | ||
| 35 | + .UnknownShapeFormat(nanToNumFormat); | ||
| 36 | + this->Attr("nan").AttrType(REQUIRED).Float(); | ||
| 37 | + this->Attr("posinf").AttrType(REQUIRED).Float(); | ||
| 38 | + this->Attr("neginf").AttrType(REQUIRED).Float(); | ||
| 39 | + | ||
| 40 | + OpAICoreConfig aicoreConfig; | ||
| 41 | + aicoreConfig.DynamicCompileStaticFlag(true) | ||
| 42 | + .DynamicFormatFlag(false) | ||
| 43 | + .DynamicRankSupportFlag(true) | ||
| 44 | + .DynamicShapeSupportFlag(true) | ||
| 45 | + .NeedCheckSupportFlag(false) | ||
| 46 | + .PrecisionReduceFlag(true) | ||
| 47 | + .ExtendCfgInfo("opFile.value", "nan_to_num_apt"); | ||
| 48 | + this->AICore().AddConfig("ascend950", aicoreConfig); | ||
| 49 | + } | ||
| 50 | +}; | ||
| 51 | + | ||
| 52 | +OP_ADD(NanToNum); | ||
| 53 | +} // namespace ops | ||
| @@ -0,0 +1,21 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file nan_to_num_infershape.cpp | ||
| 13 | + * \brief NanToNum infershape | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +using namespace ge; | ||
| 19 | +namespace ops { | ||
| 20 | +IMPL_OP_INFERSHAPE(NanToNum).InferShape(Ops::Base::InferShape4Elewise); | ||
| 21 | +} // namespace ops | ||
| @@ -0,0 +1,133 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file nan_to_num_dag.h | ||
| 13 | + * \brief nan_to_num dag | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | +constexpr static AscendC::MicroAPI::CastTrait castTrait0 = { | ||
| 25 | + AscendC::MicroAPI::RegLayout::ZERO, AscendC::MicroAPI::SatMode::UNKNOWN, AscendC::MicroAPI::MaskMergeMode::ZEROING, | ||
| 26 | + AscendC::RoundMode::UNKNOWN}; | ||
| 27 | +constexpr static AscendC::MicroAPI::CastTrait castTrait1 = { | ||
| 28 | + AscendC::MicroAPI::RegLayout::ZERO, AscendC::MicroAPI::SatMode::NO_SAT, AscendC::MicroAPI::MaskMergeMode::ZEROING, | ||
| 29 | + AscendC::RoundMode::CAST_RINT}; | ||
| 30 | + | ||
| 31 | + | ||
| 32 | +namespace NanToNumOp { | ||
| 33 | +using namespace Ops::Base; | ||
| 34 | +const int PLACEHOLDER_INDEX_0 = 0; | ||
| 35 | +const int PLACEHOLDER_INDEX_1 = 1; | ||
| 36 | +const int PLACEHOLDER_INDEX_2 = 2; | ||
| 37 | + | ||
| 38 | +const uint32_t MAX_VALUE_FP32 = 0x7f800000; | ||
| 39 | +const uint32_t MIN_VALUE_FP32 = 0xff800000; | ||
| 40 | + | ||
| 41 | +template <class T> | ||
| 42 | +struct NanToNumCustom : public Vec::ElemwiseQuaternaryOP<T, T, float, float, float> { | ||
| 43 | + __aicore__ inline NanToNumCustom( | ||
| 44 | + LocalTensor<T>& dst, LocalTensor<T>& src, float nan, float posinf, float neginf, uint32_t count) | ||
| 45 | + { | ||
| 46 | + | ||
| 47 | + uint32_t dtypeSize = sizeof(float); | ||
| 48 | + uint32_t vl = VECTOR_REG_WIDTH / dtypeSize; | ||
| 49 | + uint16_t loopNum = (count + vl - 1) / vl; | ||
| 50 | + uint32_t vlSize = vl; | ||
| 51 | + | ||
| 52 | + T maxValue = 0; | ||
| 53 | + T minValue = 0; | ||
| 54 | + maxValue = *reinterpret_cast<const float*>(&MAX_VALUE_FP32); | ||
| 55 | + minValue = *reinterpret_cast<const float*>(&MIN_VALUE_FP32); | ||
| 56 | + __ubuf__ T* srcAddr = (__ubuf__ T*)src.GetPhyAddr(); | ||
| 57 | + __ubuf__ T* dstAddr = (__ubuf__ T*)dst.GetPhyAddr(); | ||
| 58 | + MicroAPI::RegTensor<float, MicroAPI::RegTraitNumOne> vregInput; | ||
| 59 | + MicroAPI::RegTensor<float, MicroAPI::RegTraitNumOne> vregOutput; | ||
| 60 | + MicroAPI::RegTensor<T, MicroAPI::RegTraitNumOne> vregInput16; | ||
| 61 | + MicroAPI::RegTensor<T, MicroAPI::RegTraitNumOne> vregOutput16; | ||
| 62 | + MicroAPI::RegTensor<float> nanTensor; | ||
| 63 | + MicroAPI::RegTensor<float> posinfTensor; | ||
| 64 | + MicroAPI::RegTensor<float> neginfTensor; | ||
| 65 | + MicroAPI::MaskReg mask, cmpMaskNan, cmpMaskPosinf, cmpMaskNeginf; | ||
| 66 | + if constexpr (std::is_same_v<T, float>) { | ||
| 67 | + __VEC_SCOPE__ | ||
| 68 | + { | ||
| 69 | + MicroAPI::Duplicate(nanTensor, nan); | ||
| 70 | + MicroAPI::Duplicate(posinfTensor, posinf); | ||
| 71 | + MicroAPI::Duplicate(neginfTensor, neginf); | ||
| 72 | + | ||
| 73 | + for (uint16_t loopIdx = 0; loopIdx < loopNum; loopIdx++) { | ||
| 74 | + mask = MicroAPI::UpdateMask<float, MicroAPI::RegTraitNumOne>(count); | ||
| 75 | + // OpCopyIn | ||
| 76 | + MicroAPI::DataCopy<T, MicroAPI::LoadDist::DIST_NORM>( | ||
| 77 | + vregInput, (__ubuf__ T*)(srcAddr + loopIdx * vlSize)); | ||
| 78 | + MicroAPI::Compare<T, CMPMODE::NE>(cmpMaskNan, vregInput, vregInput, mask); | ||
| 79 | + MicroAPI::CompareScalar<T, CMPMODE::EQ>(cmpMaskPosinf, vregInput, maxValue, mask); | ||
| 80 | + MicroAPI::CompareScalar<T, CMPMODE::EQ>(cmpMaskNeginf, vregInput, minValue, mask); | ||
| 81 | + MicroAPI::Select<T>(vregOutput, nanTensor, vregInput, cmpMaskNan); | ||
| 82 | + MicroAPI::Select<T>(vregOutput, posinfTensor, vregOutput, cmpMaskPosinf); | ||
| 83 | + MicroAPI::Select<T>(vregOutput, neginfTensor, vregOutput, cmpMaskNeginf); | ||
| 84 | + // OpCopyOut | ||
| 85 | + MicroAPI::DataCopy<T, MicroAPI::StoreDist::DIST_NORM_B32>( | ||
| 86 | + (__ubuf__ T*)(dstAddr + loopIdx * vlSize), vregOutput, mask); | ||
| 87 | + } | ||
| 88 | + } | ||
| 89 | + } else { | ||
| 90 | + __VEC_SCOPE__ | ||
| 91 | + { | ||
| 92 | + MicroAPI::Duplicate(nanTensor, nan); | ||
| 93 | + MicroAPI::Duplicate(posinfTensor, posinf); | ||
| 94 | + MicroAPI::Duplicate(neginfTensor, neginf); | ||
| 95 | + | ||
| 96 | + for (uint16_t loopIdx = 0; loopIdx < loopNum; loopIdx++) { | ||
| 97 | + mask = MicroAPI::UpdateMask<float, MicroAPI::RegTraitNumOne>(count); | ||
| 98 | + // OpCopyIn | ||
| 99 | + MicroAPI::DataCopy<T, MicroAPI::LoadDist::DIST_UNPACK_B16>( | ||
| 100 | + vregInput16, (__ubuf__ T*)(srcAddr + loopIdx * vlSize)); | ||
| 101 | + MicroAPI::Cast<float, T, castTrait0>(vregInput, vregInput16, mask); | ||
| 102 | + MicroAPI::Compare<float, CMPMODE::NE>(cmpMaskNan, vregInput, vregInput, mask); | ||
| 103 | + MicroAPI::CompareScalar<float, CMPMODE::EQ>(cmpMaskPosinf, vregInput, maxValue, mask); | ||
| 104 | + MicroAPI::CompareScalar<float, CMPMODE::EQ>(cmpMaskNeginf, vregInput, minValue, mask); | ||
| 105 | + MicroAPI::Select<float>(vregOutput, nanTensor, vregInput, cmpMaskNan); | ||
| 106 | + MicroAPI::Select<float>(vregOutput, posinfTensor, vregOutput, cmpMaskPosinf); | ||
| 107 | + MicroAPI::Select<float>(vregOutput, neginfTensor, vregOutput, cmpMaskNeginf); | ||
| 108 | + MicroAPI::Cast<T, float, castTrait1>(vregOutput16, vregOutput, mask); | ||
| 109 | + // OpCopyOut | ||
| 110 | + MicroAPI::DataCopy<T, MicroAPI::StoreDist::DIST_PACK_B32>( | ||
| 111 | + (__ubuf__ T*)(dstAddr + loopIdx * vlSize), vregOutput16, mask); | ||
| 112 | + } | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + | ||
| 116 | + | ||
| 117 | + } | ||
| 118 | +}; | ||
| 119 | + | ||
| 120 | +template <typename U> | ||
| 121 | +struct NanToNumDAG { | ||
| 122 | + using OpCopyIn0 = Bind<Vec::CopyIn<U>, Placeholder::In0<U>>; | ||
| 123 | + using OpResult = Bind< | ||
| 124 | + NanToNumCustom<U>, OpCopyIn0, Placeholder::Var<float, PLACEHOLDER_INDEX_0>, | ||
| 125 | + Placeholder::Var<float, PLACEHOLDER_INDEX_1>, Placeholder::Var<float, PLACEHOLDER_INDEX_2>>; | ||
| 126 | + using OpCopyOut = Bind<Vec::CopyOut<U>, Placeholder::Out0<U>, OpResult>; | ||
| 127 | + using Outputs = Elems<OpCopyOut>; | ||
| 128 | + using MemCfg = MemOptCfg<MemLevel::LEVEL_2>; | ||
| 129 | + using OpDag = DAGSch<Outputs, void, MemCfg>; | ||
| 130 | +}; | ||
| 131 | +} // namespace NanToNumOp | ||
| 132 | + | ||
| 133 | + | ||
| @@ -0,0 +1,44 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file nan_to_num_struct.h | ||
| 13 | + * \brief nan_to_num_struct | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +namespace NanToNumOp { | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | +ASCENDC_TPL_ARGS_DECL( | ||
| 30 | + NanToNum, ASCENDC_TPL_UINT_DECL(schMode, 1, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 31 | + ASCENDC_TPL_DTYPE_DECL(dType, TPL_FP16, TPL_BF16, TPL_FP32)); | ||
| 32 | + | ||
| 33 | +ASCENDC_TPL_SEL( | ||
| 34 | + ASCENDC_TPL_ARGS_SEL( | ||
| 35 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 36 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_FP16)), | ||
| 37 | + ASCENDC_TPL_ARGS_SEL( | ||
| 38 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 39 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_BF16)), | ||
| 40 | + ASCENDC_TPL_ARGS_SEL( | ||
| 41 | + ASCENDC_TPL_UINT_SEL(schMode, ASCENDC_TPL_UI_LIST, TPL_SCH_MODE_0, TPL_SCH_MODE_1), | ||
| 42 | + ASCENDC_TPL_DTYPE_SEL(dType, TPL_FP32))); | ||
| 43 | +} // namespace NanToNumOp | ||
| 44 | + | ||
| @@ -0,0 +1,24 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | +namespace NanToNum { | ||
| 16 | +using namespace Ops::Base; | ||
| 17 | +struct NanToNumTilingData { | ||
| 18 | + EleBaseTilingData baseTiling; | ||
| 19 | + float nan; | ||
| 20 | + float posinf; | ||
| 21 | + float neginf; | ||
| 22 | +}; | ||
| 23 | +} // namespace NanToNum | ||
| 24 | + | ||
| @@ -0,0 +1,57 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file nan_to_num_apt.cpp | ||
| 13 | + * \brief z = nan_to_num(x) | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +using namespace AscendC; | ||
| 23 | +using namespace NanToNumOp; | ||
| 24 | +using namespace NanToNum; | ||
| 25 | + | ||
| 26 | +template <uint64_t schMode, uint64_t dType> | ||
| 27 | +__global__ __aicore__ void nan_to_num(GM_ADDR x, GM_ADDR y, GM_ADDR workspace, GM_ADDR tiling) | ||
| 28 | +{ | ||
| 29 | + REGISTER_TILING_DEFAULT(NanToNumTilingData); | ||
| 30 | + GET_TILING_DATA_WITH_STRUCT(NanToNumTilingData, tilingData, tiling); | ||
| 31 | + KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY); | ||
| 32 | + | ||
| 33 | + TPipe pipe; | ||
| 34 | + if constexpr (dType == TPL_FP16) { | ||
| 35 | + ElementwiseSch<schMode, NanToNumOp::NanToNumDAG<half>::OpDag> sch(&(tilingData.baseTiling), &pipe); | ||
| 36 | + sch.template SetVar<float, NanToNumOp::PLACEHOLDER_INDEX_0>(tilingData.nan); | ||
| 37 | + sch.template SetVar<float, NanToNumOp::PLACEHOLDER_INDEX_1>(tilingData.posinf); | ||
| 38 | + sch.template SetVar<float, NanToNumOp::PLACEHOLDER_INDEX_2>(tilingData.neginf); | ||
| 39 | + sch.Init(x, y); | ||
| 40 | + sch.Process(); | ||
| 41 | + } else if constexpr (dType == TPL_BF16) { | ||
| 42 | + ElementwiseSch<schMode, NanToNumOp::NanToNumDAG<bfloat16_t>::OpDag> sch(&(tilingData.baseTiling), &pipe); | ||
| 43 | + sch.template SetVar<float, NanToNumOp::PLACEHOLDER_INDEX_0>(tilingData.nan); | ||
| 44 | + sch.template SetVar<float, NanToNumOp::PLACEHOLDER_INDEX_1>(tilingData.posinf); | ||
| 45 | + sch.template SetVar<float, NanToNumOp::PLACEHOLDER_INDEX_2>(tilingData.neginf); | ||
| 46 | + sch.Init(x, y); | ||
| 47 | + sch.Process(); | ||
| 48 | + } else if constexpr (dType == TPL_FP32) { | ||
| 49 | + ElementwiseSch<schMode, NanToNumOp::NanToNumDAG<float>::OpDag> sch(&(tilingData.baseTiling), &pipe); | ||
| 50 | + sch.template SetVar<float, NanToNumOp::PLACEHOLDER_INDEX_0>(tilingData.nan); | ||
| 51 | + sch.template SetVar<float, NanToNumOp::PLACEHOLDER_INDEX_1>(tilingData.posinf); | ||
| 52 | + sch.template SetVar<float, NanToNumOp::PLACEHOLDER_INDEX_2>(tilingData.neginf); | ||
| 53 | + sch.Init(x, y); | ||
| 54 | + sch.Process(); | ||
| 55 | + } | ||
| 56 | + return; | ||
| 57 | +} | ||
| @@ -1,17 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
| @@ -1,17 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 13 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 14 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 15 | - add_subdirectory(${SUB_DIR}) | ||
| 16 | - endif() | ||
| 17 | -endforeach() | ||
| @@ -0,0 +1,341 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +class l2InplaceNanToNumTest : public testing::Test { | ||
| 17 | +protected: | ||
| 18 | + static void SetUpTestCase() | ||
| 19 | + { | ||
| 20 | + std::cout << "l2InplaceNanToNumTest SetUp" << std::endl; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + static void TearDownTestCase() | ||
| 24 | + { | ||
| 25 | + std::cout << "l2InplaceNanToNumTest TearDown" << std::endl; | ||
| 26 | + } | ||
| 27 | +}; | ||
| 28 | + | ||
| 29 | +// 异常场景:self为空指针,返回ACLNN_ERR_PARAM_NULLPTR | ||
| 30 | +TEST_F(l2InplaceNanToNumTest, l2_nan_to_num_test_err_self_null) | ||
| 31 | +{ | ||
| 32 | + float nan = 0; | ||
| 33 | + float posinf = 1.0; | ||
| 34 | + float neginf = -1.0; | ||
| 35 | + | ||
| 36 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT((aclTensor*)nullptr, nan, posinf, neginf), OUTPUT()); | ||
| 37 | + | ||
| 38 | + uint64_t workspaceSize = 0; | ||
| 39 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 40 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_NULLPTR); | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +// 异常场景:self的数据类型不在支持范围内,返回ACLNN_ERR_PARAM_INVALID | ||
| 44 | +TEST_F(l2InplaceNanToNumTest, l2_nan_to_num_test_err_self_double) | ||
| 45 | +{ | ||
| 46 | + auto selfDesc = TensorDesc({2, 3}, ACL_DOUBLE, ACL_FORMAT_ND); | ||
| 47 | + float nan = 0; | ||
| 48 | + float posinf = 1.0; | ||
| 49 | + float neginf = -1.0; | ||
| 50 | + | ||
| 51 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 52 | + | ||
| 53 | + uint64_t workspaceSize = 0; | ||
| 54 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 55 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +// 异常场景:self的数据类型不在支持范围内,返回ACLNN_ERR_PARAM_INVALID | ||
| 59 | +TEST_F(l2InplaceNanToNumTest, l2_nan_to_num_test_err_self_complex) | ||
| 60 | +{ | ||
| 61 | + auto selfDesc = TensorDesc({2, 3}, ACL_COMPLEX64, ACL_FORMAT_ND); | ||
| 62 | + float nan = 0; | ||
| 63 | + float posinf = 1.0; | ||
| 64 | + float neginf = -1.0; | ||
| 65 | + | ||
| 66 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 67 | + | ||
| 68 | + uint64_t workspaceSize = 0; | ||
| 69 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 70 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +// 异常场景:Tensor为9维、返回ACLNN_ERR_PARAM_INVALID | ||
| 74 | +TEST_F(l2InplaceNanToNumTest, l2_nan_to_num_test_err_dim_over) | ||
| 75 | +{ | ||
| 76 | + auto selfDesc = TensorDesc({1, 2, 3, 4, 5, 6, 7, 8, 9}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 77 | + float nan = 0; | ||
| 78 | + float posinf = 1.0; | ||
| 79 | + float neginf = -1.0; | ||
| 80 | + | ||
| 81 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 82 | + | ||
| 83 | + uint64_t workspaceSize = 0; | ||
| 84 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 85 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | +// 正常场景:空tensor,返回ACLNN_SUCCESS | ||
| 89 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_err_empty_tensor) | ||
| 90 | +{ | ||
| 91 | + auto selfDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 92 | + float nan = 0; | ||
| 93 | + float posinf = 1.0; | ||
| 94 | + float neginf = -1.0; | ||
| 95 | + | ||
| 96 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 97 | + | ||
| 98 | + uint64_t workspaceSize = 0; | ||
| 99 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 100 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +// 正常场景:float16、6维、nan/posinf/neginf为int,返回ACLNN_SUCCESS,精度校验通过 | ||
| 104 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_fp16_dim6_para_int) | ||
| 105 | +{ | ||
| 106 | + auto selfDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 107 | + int nan = 0; | ||
| 108 | + int posinf = 1; | ||
| 109 | + int neginf = -1; | ||
| 110 | + | ||
| 111 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 112 | + | ||
| 113 | + uint64_t workspaceSize = 0; | ||
| 114 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 115 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +// 正常场景:float16、6维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 119 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_fp16_dim6) | ||
| 120 | +{ | ||
| 121 | + auto selfDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 122 | + float nan = 0; | ||
| 123 | + float posinf = 1.0; | ||
| 124 | + float neginf = -1.0; | ||
| 125 | + | ||
| 126 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 127 | + | ||
| 128 | + uint64_t workspaceSize = 0; | ||
| 129 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 130 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 131 | +} | ||
| 132 | + | ||
| 133 | +// 正常场景:float32、7维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 134 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_fp32_dim7) | ||
| 135 | +{ | ||
| 136 | + auto selfDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 137 | + float nan = 0; | ||
| 138 | + float posinf = 1.0; | ||
| 139 | + float neginf = -1.0; | ||
| 140 | + | ||
| 141 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 142 | + | ||
| 143 | + uint64_t workspaceSize = 0; | ||
| 144 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 145 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +// 正常场景:bfloat16、8维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 149 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_bf16_dim8) | ||
| 150 | +{ | ||
| 151 | + auto selfDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12, 23}, ACL_BF16, ACL_FORMAT_ND); | ||
| 152 | + float nan = 0; | ||
| 153 | + float posinf = 1.0; | ||
| 154 | + float neginf = -1.0; | ||
| 155 | + | ||
| 156 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 157 | + | ||
| 158 | + uint64_t workspaceSize = 0; | ||
| 159 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 160 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 161 | +} | ||
| 162 | + | ||
| 163 | +// 正常场景:ACL_INT8、1维,ACLNN_SUCCESS | ||
| 164 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_int8_dim1) | ||
| 165 | +{ | ||
| 166 | + auto selfDesc = TensorDesc({2}, ACL_INT8, ACL_FORMAT_ND); | ||
| 167 | + float nan = 0; | ||
| 168 | + float posinf = 1.0; | ||
| 169 | + float neginf = -1.0; | ||
| 170 | + | ||
| 171 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 172 | + | ||
| 173 | + uint64_t workspaceSize = 0; | ||
| 174 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 175 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 176 | +} | ||
| 177 | + | ||
| 178 | +// 正常场景:ACL_INT16、2维,ACLNN_SUCCESS | ||
| 179 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_int16_dim2) | ||
| 180 | +{ | ||
| 181 | + auto selfDesc = TensorDesc({2, 4}, ACL_INT16, ACL_FORMAT_ND); | ||
| 182 | + float nan = 0; | ||
| 183 | + float posinf = 1.0; | ||
| 184 | + float neginf = -1.0; | ||
| 185 | + | ||
| 186 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 187 | + | ||
| 188 | + uint64_t workspaceSize = 0; | ||
| 189 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 190 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 191 | +} | ||
| 192 | + | ||
| 193 | +// 正常场景:ACL_INT32、3维,ACLNN_SUCCESS | ||
| 194 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_int32_dim3) | ||
| 195 | +{ | ||
| 196 | + auto selfDesc = TensorDesc({2, 4, 12}, ACL_INT32, ACL_FORMAT_ND); | ||
| 197 | + float nan = 0; | ||
| 198 | + float posinf = 1.0; | ||
| 199 | + float neginf = -1.0; | ||
| 200 | + | ||
| 201 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 202 | + | ||
| 203 | + uint64_t workspaceSize = 0; | ||
| 204 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 205 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 206 | +} | ||
| 207 | + | ||
| 208 | +// 正常场景:ACL_INT64、4维,ACLNN_SUCCESS | ||
| 209 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_int64_dim4) | ||
| 210 | +{ | ||
| 211 | + auto selfDesc = TensorDesc({2, 4, 12, 9}, ACL_INT64, ACL_FORMAT_ND); | ||
| 212 | + float nan = 0; | ||
| 213 | + float posinf = 1.0; | ||
| 214 | + float neginf = -1.0; | ||
| 215 | + | ||
| 216 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 217 | + | ||
| 218 | + uint64_t workspaceSize = 0; | ||
| 219 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 220 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 221 | +} | ||
| 222 | + | ||
| 223 | +// 正常场景:ACL_UINT8、5维,ACLNN_SUCCESS | ||
| 224 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_uint8_dim5) | ||
| 225 | +{ | ||
| 226 | + auto selfDesc = TensorDesc({2, 4, 12, 9, 21}, ACL_UINT8, ACL_FORMAT_ND); | ||
| 227 | + float nan = 0; | ||
| 228 | + float posinf = 1.0; | ||
| 229 | + float neginf = -1.0; | ||
| 230 | + | ||
| 231 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 232 | + | ||
| 233 | + uint64_t workspaceSize = 0; | ||
| 234 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 235 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 236 | +} | ||
| 237 | + | ||
| 238 | +// 正常场景:ACL_BOOL、6维,ACLNN_SUCCESS | ||
| 239 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_bool_dim6) | ||
| 240 | +{ | ||
| 241 | + auto selfDesc = TensorDesc({2, 4, 12, 9, 21, 32}, ACL_BOOL, ACL_FORMAT_ND); | ||
| 242 | + float nan = 0; | ||
| 243 | + float posinf = 1.0; | ||
| 244 | + float neginf = -1.0; | ||
| 245 | + | ||
| 246 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 247 | + | ||
| 248 | + uint64_t workspaceSize = 0; | ||
| 249 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 250 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 251 | +} | ||
| 252 | + | ||
| 253 | +// 正常场景:float32、4维、ACL_FORMAT_NCHW,返回ACLNN_SUCCESS,精度校验通过 | ||
| 254 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nchw) | ||
| 255 | +{ | ||
| 256 | + auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NCHW); | ||
| 257 | + float nan = 0; | ||
| 258 | + float posinf = 1.0; | ||
| 259 | + float neginf = -1.0; | ||
| 260 | + | ||
| 261 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 262 | + | ||
| 263 | + uint64_t workspaceSize = 0; | ||
| 264 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 265 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 266 | +} | ||
| 267 | + | ||
| 268 | +// 正常场景:float32、4维、ACL_FORMAT_NHWC,返回ACLNN_SUCCESS,精度校验通过 | ||
| 269 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nhwc) | ||
| 270 | +{ | ||
| 271 | + auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NHWC); | ||
| 272 | + float nan = 0; | ||
| 273 | + float posinf = 1.0; | ||
| 274 | + float neginf = -1.0; | ||
| 275 | + | ||
| 276 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 277 | + | ||
| 278 | + uint64_t workspaceSize = 0; | ||
| 279 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 280 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 281 | +} | ||
| 282 | + | ||
| 283 | +// 正常场景:float32、4维、ACL_FORMAT_NC1HWC0,返回ACLNN_SUCCESS,精度校验通过 | ||
| 284 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nc1hwc0) | ||
| 285 | +{ | ||
| 286 | + auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NC1HWC0); | ||
| 287 | + float nan = 0; | ||
| 288 | + float posinf = 1.0; | ||
| 289 | + float neginf = -1.0; | ||
| 290 | + | ||
| 291 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 292 | + | ||
| 293 | + uint64_t workspaceSize = 0; | ||
| 294 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 295 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 296 | +} | ||
| 297 | + | ||
| 298 | +// 正常场景:float32、4维、ACL_FORMAT_HWCN,返回ACLNN_SUCCESS,精度校验通过 | ||
| 299 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_float32_hwcn) | ||
| 300 | +{ | ||
| 301 | + auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_HWCN); | ||
| 302 | + float nan = 0; | ||
| 303 | + float posinf = 1.0; | ||
| 304 | + float neginf = -1.0; | ||
| 305 | + | ||
| 306 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 307 | + | ||
| 308 | + uint64_t workspaceSize = 0; | ||
| 309 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 310 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 311 | +} | ||
| 312 | + | ||
| 313 | +// 成功场景:浮点型、non-continuous,返回ACLNN_SUCCESS,精度校验通过 | ||
| 314 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_float32_non_continuous) | ||
| 315 | +{ | ||
| 316 | + auto selfDesc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {4, 5}).ValueRange(-2, 2); | ||
| 317 | + float nan = 0; | ||
| 318 | + float posinf = 1.0; | ||
| 319 | + float neginf = -1.0; | ||
| 320 | + | ||
| 321 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 322 | + | ||
| 323 | + uint64_t workspaceSize = 0; | ||
| 324 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 325 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 326 | +} | ||
| 327 | + | ||
| 328 | +// 成功场景:整型、non-continuous,返回ACLNN_SUCCESS,精度校验通过 | ||
| 329 | +TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_int_non_continuous) | ||
| 330 | +{ | ||
| 331 | + auto selfDesc = TensorDesc({5, 4}, ACL_INT32, ACL_FORMAT_ND, {1, 5}, 0, {4, 5}).ValueRange(-2, 2); | ||
| 332 | + float nan = 0; | ||
| 333 | + float posinf = 1.0; | ||
| 334 | + float neginf = -1.0; | ||
| 335 | + | ||
| 336 | + auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 337 | + | ||
| 338 | + uint64_t workspaceSize = 0; | ||
| 339 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 340 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 341 | +} | ||
| @@ -0,0 +1,329 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +class l2NanToNumTest : public testing::Test { | ||
| 17 | +protected: | ||
| 18 | + static void SetUpTestCase() | ||
| 19 | + { | ||
| 20 | + std::cout << "l2NanToNumTest SetUp" << std::endl; | ||
| 21 | + } | ||
| 22 | + | ||
| 23 | + static void TearDownTestCase() | ||
| 24 | + { | ||
| 25 | + std::cout << "l2NanToNumTest TearDown" << std::endl; | ||
| 26 | + } | ||
| 27 | +}; | ||
| 28 | + | ||
| 29 | +// 异常场景:self为空指针,返回ACLNN_ERR_PARAM_NULLPTR | ||
| 30 | +TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_self_null) | ||
| 31 | +{ | ||
| 32 | + auto outDesc = TensorDesc({2, 3}, ACL_INT32, ACL_FORMAT_ND); | ||
| 33 | + float nan = 0; | ||
| 34 | + float posinf = 1.0; | ||
| 35 | + float neginf = -1.0; | ||
| 36 | + | ||
| 37 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT((aclTensor*)nullptr, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 38 | + | ||
| 39 | + uint64_t workspaceSize = 0; | ||
| 40 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 41 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_NULLPTR); | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +// 异常场景:out为空指针,返回ACLNN_ERR_PARAM_NULLPTR | ||
| 45 | +TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_out_null) | ||
| 46 | +{ | ||
| 47 | + auto selfDesc = TensorDesc({2, 3}, ACL_INT32, ACL_FORMAT_ND); | ||
| 48 | + float nan = 0; | ||
| 49 | + float posinf = 1.0; | ||
| 50 | + float neginf = -1.0; | ||
| 51 | + | ||
| 52 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT((aclTensor*)nullptr)); | ||
| 53 | + | ||
| 54 | + uint64_t workspaceSize = 0; | ||
| 55 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 56 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_NULLPTR); | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +// 异常场景:self和out的数据类型不一致,返回ACLNN_ERR_PARAM_INVALID | ||
| 60 | +TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_self_out_datatype_inconsistent) | ||
| 61 | +{ | ||
| 62 | + auto selfDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 63 | + auto outDesc = TensorDesc({2, 3}, ACL_INT8, ACL_FORMAT_ND); | ||
| 64 | + float nan = 0; | ||
| 65 | + float posinf = 1.0; | ||
| 66 | + float neginf = -1.0; | ||
| 67 | + | ||
| 68 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 69 | + | ||
| 70 | + uint64_t workspaceSize = 0; | ||
| 71 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 72 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 73 | +} | ||
| 74 | + | ||
| 75 | +// 异常场景:self的数据类型不在支持范围内,返回ACLNN_ERR_PARAM_INVALID | ||
| 76 | +TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_self_double) | ||
| 77 | +{ | ||
| 78 | + auto selfDesc = TensorDesc({2, 3}, ACL_DOUBLE, ACL_FORMAT_ND); | ||
| 79 | + auto outDesc = TensorDesc({2, 3}, ACL_DOUBLE, ACL_FORMAT_ND); | ||
| 80 | + float nan = 0; | ||
| 81 | + float posinf = 1.0; | ||
| 82 | + float neginf = -1.0; | ||
| 83 | + | ||
| 84 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 85 | + | ||
| 86 | + uint64_t workspaceSize = 0; | ||
| 87 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 88 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 89 | +} | ||
| 90 | + | ||
| 91 | +// 异常场景:self的数据类型不在支持范围内,返回ACLNN_ERR_PARAM_INVALID | ||
| 92 | +TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_self_complex) | ||
| 93 | +{ | ||
| 94 | + auto selfDesc = TensorDesc({2, 3}, ACL_COMPLEX64, ACL_FORMAT_ND); | ||
| 95 | + auto outDesc = TensorDesc({2, 3}, ACL_COMPLEX64, ACL_FORMAT_ND); | ||
| 96 | + float nan = 0; | ||
| 97 | + float posinf = 1.0; | ||
| 98 | + float neginf = -1.0; | ||
| 99 | + | ||
| 100 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 101 | + | ||
| 102 | + uint64_t workspaceSize = 0; | ||
| 103 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 104 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 105 | +} | ||
| 106 | + | ||
| 107 | +// 异常场景:self和out的shape不一致,返回ACLNN_ERR_PARAM_INVALID | ||
| 108 | +TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_self_fp32_out_fp16) | ||
| 109 | +{ | ||
| 110 | + auto selfDesc = TensorDesc({2, 3, 9}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 111 | + auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 112 | + float nan = 0; | ||
| 113 | + float posinf = 1.0; | ||
| 114 | + float neginf = -1.0; | ||
| 115 | + | ||
| 116 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 117 | + | ||
| 118 | + uint64_t workspaceSize = 0; | ||
| 119 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 120 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 121 | +} | ||
| 122 | + | ||
| 123 | +// 异常场景:Tensor为9维、返回ACLNN_ERR_PARAM_INVALID | ||
| 124 | +TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_dim_over) | ||
| 125 | +{ | ||
| 126 | + auto selfDesc = TensorDesc({1, 2, 3, 4, 5, 6, 7, 8, 9}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 127 | + auto outDesc = TensorDesc({1, 2, 3, 4, 5, 6, 7, 8, 9}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 128 | + float nan = 0; | ||
| 129 | + float posinf = 1.0; | ||
| 130 | + float neginf = -1.0; | ||
| 131 | + | ||
| 132 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 133 | + | ||
| 134 | + uint64_t workspaceSize = 0; | ||
| 135 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 136 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 137 | +} | ||
| 138 | + | ||
| 139 | +// 正常场景:空tensor,返回ACLNN_SUCCESS | ||
| 140 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_err_empty_tensor) | ||
| 141 | +{ | ||
| 142 | + auto selfDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 143 | + auto outDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 144 | + float nan = 0; | ||
| 145 | + float posinf = 1.0; | ||
| 146 | + float neginf = -1.0; | ||
| 147 | + | ||
| 148 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 149 | + | ||
| 150 | + uint64_t workspaceSize = 0; | ||
| 151 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 152 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 153 | +} | ||
| 154 | + | ||
| 155 | +// 正常场景:float16、6维、nan/posinf/neginf为int,返回ACLNN_SUCCESS,精度校验通过 | ||
| 156 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_fp16_dim6_para_int) | ||
| 157 | +{ | ||
| 158 | + auto selfDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 159 | + auto outDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 160 | + int nan = 0; | ||
| 161 | + int posinf = 1; | ||
| 162 | + int neginf = -1; | ||
| 163 | + | ||
| 164 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 165 | + | ||
| 166 | + uint64_t workspaceSize = 0; | ||
| 167 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 168 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 169 | +} | ||
| 170 | + | ||
| 171 | +// 正常场景:float16、6维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 172 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_fp16_dim6) | ||
| 173 | +{ | ||
| 174 | + auto selfDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 175 | + auto outDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 176 | + float nan = 0; | ||
| 177 | + float posinf = 1.0; | ||
| 178 | + float neginf = -1.0; | ||
| 179 | + | ||
| 180 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 181 | + | ||
| 182 | + uint64_t workspaceSize = 0; | ||
| 183 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 184 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 185 | +} | ||
| 186 | + | ||
| 187 | +// 正常场景:float32、7维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 188 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_fp32_dim7) | ||
| 189 | +{ | ||
| 190 | + auto selfDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 191 | + auto outDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 192 | + float nan = 0; | ||
| 193 | + float posinf = 1.0; | ||
| 194 | + float neginf = -1.0; | ||
| 195 | + | ||
| 196 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 197 | + | ||
| 198 | + uint64_t workspaceSize = 0; | ||
| 199 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 200 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +// 正常场景:bfloat16、8维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 204 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_bf16_dim8) | ||
| 205 | +{ | ||
| 206 | + auto selfDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12, 23}, ACL_BF16, ACL_FORMAT_ND); | ||
| 207 | + auto outDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12, 23}, ACL_BF16, ACL_FORMAT_ND); | ||
| 208 | + float nan = 0; | ||
| 209 | + float posinf = 1.0; | ||
| 210 | + float neginf = -1.0; | ||
| 211 | + | ||
| 212 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 213 | + | ||
| 214 | + uint64_t workspaceSize = 0; | ||
| 215 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 216 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 217 | +} | ||
| 218 | + | ||
| 219 | +// 正常场景:ACL_BOOL、6维,ACLNN_SUCCESS | ||
| 220 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_bool_dim6) | ||
| 221 | +{ | ||
| 222 | + auto selfDesc = TensorDesc({2, 4, 12, 9, 21, 32}, ACL_BOOL, ACL_FORMAT_ND); | ||
| 223 | + auto outDesc = TensorDesc({2, 4, 12, 9, 21, 32}, ACL_BOOL, ACL_FORMAT_ND); | ||
| 224 | + float nan = 0; | ||
| 225 | + float posinf = 1.0; | ||
| 226 | + float neginf = -1.0; | ||
| 227 | + | ||
| 228 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 229 | + | ||
| 230 | + uint64_t workspaceSize = 0; | ||
| 231 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 232 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 233 | +} | ||
| 234 | + | ||
| 235 | +// 正常场景:float32、4维、ACL_FORMAT_NCHW,返回ACLNN_SUCCESS,精度校验通过 | ||
| 236 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nchw) | ||
| 237 | +{ | ||
| 238 | + auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NCHW); | ||
| 239 | + auto outDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NCHW); | ||
| 240 | + float nan = 0; | ||
| 241 | + float posinf = 1.0; | ||
| 242 | + float neginf = -1.0; | ||
| 243 | + | ||
| 244 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 245 | + | ||
| 246 | + uint64_t workspaceSize = 0; | ||
| 247 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 248 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 249 | +} | ||
| 250 | + | ||
| 251 | +// 正常场景:float32、4维、ACL_FORMAT_NHWC,返回ACLNN_SUCCESS,精度校验通过 | ||
| 252 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nhwc) | ||
| 253 | +{ | ||
| 254 | + auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NHWC); | ||
| 255 | + auto outDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NHWC); | ||
| 256 | + float nan = 0; | ||
| 257 | + float posinf = 1.0; | ||
| 258 | + float neginf = -1.0; | ||
| 259 | + | ||
| 260 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 261 | + | ||
| 262 | + uint64_t workspaceSize = 0; | ||
| 263 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 264 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 265 | +} | ||
| 266 | + | ||
| 267 | +// 正常场景:float32、4维、ACL_FORMAT_NC1HWC0,返回ACLNN_SUCCESS,精度校验通过 | ||
| 268 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nc1hwc0) | ||
| 269 | +{ | ||
| 270 | + auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NC1HWC0); | ||
| 271 | + auto outDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NC1HWC0); | ||
| 272 | + float nan = 0; | ||
| 273 | + float posinf = 1.0; | ||
| 274 | + float neginf = -1.0; | ||
| 275 | + | ||
| 276 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 277 | + | ||
| 278 | + uint64_t workspaceSize = 0; | ||
| 279 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 280 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 281 | +} | ||
| 282 | + | ||
| 283 | +// 正常场景:float32、4维、ACL_FORMAT_HWCN,返回ACLNN_SUCCESS,精度校验通过 | ||
| 284 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_float32_hwcn) | ||
| 285 | +{ | ||
| 286 | + auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_HWCN); | ||
| 287 | + auto outDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_HWCN); | ||
| 288 | + float nan = 0; | ||
| 289 | + float posinf = 1.0; | ||
| 290 | + float neginf = -1.0; | ||
| 291 | + | ||
| 292 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 293 | + | ||
| 294 | + uint64_t workspaceSize = 0; | ||
| 295 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 296 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 297 | +} | ||
| 298 | + | ||
| 299 | +// 成功场景:浮点型、non-continuous,返回ACLNN_SUCCESS,精度校验通过 | ||
| 300 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_float32_non_continuous) | ||
| 301 | +{ | ||
| 302 | + auto selfDesc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {4, 5}).ValueRange(-2, 2); | ||
| 303 | + auto outDesc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {4, 5}).ValueRange(-2, 2); | ||
| 304 | + float nan = 0; | ||
| 305 | + float posinf = 1.0; | ||
| 306 | + float neginf = -1.0; | ||
| 307 | + | ||
| 308 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 309 | + | ||
| 310 | + uint64_t workspaceSize = 0; | ||
| 311 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 312 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 313 | +} | ||
| 314 | + | ||
| 315 | +// 成功场景:整型、non-continuous,返回ACLNN_SUCCESS,精度校验通过 | ||
| 316 | +TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_int_non_continuous) | ||
| 317 | +{ | ||
| 318 | + auto selfDesc = TensorDesc({5, 4}, ACL_INT32, ACL_FORMAT_ND, {1, 5}, 0, {4, 5}).ValueRange(-2, 2); | ||
| 319 | + auto outDesc = TensorDesc({5, 4}, ACL_INT32, ACL_FORMAT_ND, {1, 5}, 0, {4, 5}).ValueRange(-2, 2); | ||
| 320 | + float nan = 0; | ||
| 321 | + float posinf = 1.0; | ||
| 322 | + float neginf = -1.0; | ||
| 323 | + | ||
| 324 | + auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 325 | + | ||
| 326 | + uint64_t workspaceSize = 0; | ||
| 327 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 328 | + EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 329 | +} | ||
| @@ -1,22 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | -if(UT_TEST_ALL OR OP_HOST_UT) | ||
| 13 | - add_modules_ut_sources(UT_NAME ${OP_TILING_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 14 | - add_modules_ut_sources(UT_NAME ${OP_INFERSHAPE_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 15 | -endif() | ||
| 16 | - | ||
| 17 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 18 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 19 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 20 | - add_subdirectory(${SUB_DIR}) | ||
| 21 | - endif() | ||
| 22 | -endforeach() | ||
| @@ -0,0 +1,173 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +using namespace std; | ||
| 19 | + | ||
| 20 | +class NanToNumTilingTest : public testing::Test { | ||
| 21 | + protected: | ||
| 22 | + static void SetUpTestCase() { | ||
| 23 | + std::cout << "NanToNumTilingTest SetUp" << std::endl; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + static void TearDownTestCase() { | ||
| 27 | + std::cout << "NanToNumTilingTest TearDown" << std::endl; | ||
| 28 | + } | ||
| 29 | +}; | ||
| 30 | + | ||
| 31 | +TEST_F(NanToNumTilingTest, nan_to_num_test_tiling_fp16_input) | ||
| 32 | +{ | ||
| 33 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 34 | + gert::TilingContextPara tilingContextPara( | ||
| 35 | + "NanToNum", | ||
| 36 | + { | ||
| 37 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 41 | + }, | ||
| 42 | + { | ||
| 43 | + gert::TilingContextPara::OpAttr("nan", Ops::Math::AnyValue::CreateFrom<float>(-1.0)), | ||
| 44 | + gert::TilingContextPara::OpAttr("posinf", Ops::Math::AnyValue::CreateFrom<float>(1.0)), | ||
| 45 | + gert::TilingContextPara::OpAttr("neginf", Ops::Math::AnyValue::CreateFrom<float>(0.0)), | ||
| 46 | + }, | ||
| 47 | + &compileInfo); | ||
| 48 | + | ||
| 49 | + uint64_t expectTilingKey = 3; | ||
| 50 | + string expectTilingData = "8192 4 32768 2048 4 1 1 2048 2048 32768 1 "; | ||
| 51 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 52 | + ExecuteTestCaseForEle(tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +TEST_F(NanToNumTilingTest, nan_to_num_test_tiling_bf16_input) | ||
| 56 | +{ | ||
| 57 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 58 | + gert::TilingContextPara tilingContextPara( | ||
| 59 | + "NanToNum", | ||
| 60 | + { | ||
| 61 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 62 | + }, | ||
| 63 | + { | ||
| 64 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 65 | + }, | ||
| 66 | + { | ||
| 67 | + gert::TilingContextPara::OpAttr("nan", Ops::Math::AnyValue::CreateFrom<float>(-1.0)), | ||
| 68 | + gert::TilingContextPara::OpAttr("posinf", Ops::Math::AnyValue::CreateFrom<float>(1.0)), | ||
| 69 | + gert::TilingContextPara::OpAttr("neginf", Ops::Math::AnyValue::CreateFrom<float>(0.0)), | ||
| 70 | + }, | ||
| 71 | + &compileInfo); | ||
| 72 | + | ||
| 73 | + uint64_t expectTilingKey = 5; | ||
| 74 | + string expectTilingData = "8192 4 32768 2048 4 1 1 2048 2048 32768 1 "; | ||
| 75 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 76 | + ExecuteTestCaseForEle(tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +TEST_F(NanToNumTilingTest, nan_to_num_test_tiling_fp32_input) | ||
| 80 | +{ | ||
| 81 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 82 | + gert::TilingContextPara tilingContextPara( | ||
| 83 | + "NanToNum", | ||
| 84 | + { | ||
| 85 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 86 | + }, | ||
| 87 | + { | ||
| 88 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 89 | + }, | ||
| 90 | + { | ||
| 91 | + gert::TilingContextPara::OpAttr("nan", Ops::Math::AnyValue::CreateFrom<float>(-1.0)), | ||
| 92 | + gert::TilingContextPara::OpAttr("posinf", Ops::Math::AnyValue::CreateFrom<float>(1.0)), | ||
| 93 | + gert::TilingContextPara::OpAttr("neginf", Ops::Math::AnyValue::CreateFrom<float>(0.0)), | ||
| 94 | + }, | ||
| 95 | + &compileInfo); | ||
| 96 | + | ||
| 97 | + uint64_t expectTilingKey = 7; | ||
| 98 | + string expectTilingData = "8192 8 16384 1024 8 1 1 1024 1024 16384 1 "; | ||
| 99 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 100 | + ExecuteTestCaseForEle(tilingContextPara, ge::GRAPH_SUCCESS, true, expectTilingKey, true, expectTilingData, expectWorkspaces); | ||
| 101 | +} | ||
| 102 | + | ||
| 103 | +TEST_F(NanToNumTilingTest, nan_to_num_test_tiling_invalid_input_dtype) | ||
| 104 | +{ | ||
| 105 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 106 | + gert::TilingContextPara tilingContextPara( | ||
| 107 | + "NanToNum", | ||
| 108 | + { | ||
| 109 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT32, ge::FORMAT_ND}, | ||
| 110 | + }, | ||
| 111 | + { | ||
| 112 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 113 | + }, | ||
| 114 | + { | ||
| 115 | + gert::TilingContextPara::OpAttr("nan", Ops::Math::AnyValue::CreateFrom<float>(-1.0)), | ||
| 116 | + gert::TilingContextPara::OpAttr("posinf", Ops::Math::AnyValue::CreateFrom<float>(1.0)), | ||
| 117 | + gert::TilingContextPara::OpAttr("neginf", Ops::Math::AnyValue::CreateFrom<float>(0.0)), | ||
| 118 | + }, | ||
| 119 | + &compileInfo); | ||
| 120 | + | ||
| 121 | + uint64_t expectTilingKey = 7; | ||
| 122 | + string expectTilingData = ""; | ||
| 123 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 124 | + ExecuteTestCaseForEle(tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 125 | +} | ||
| 126 | + | ||
| 127 | +TEST_F(NanToNumTilingTest, nan_to_num_test_tiling_invalid_output_dtype) | ||
| 128 | +{ | ||
| 129 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 130 | + gert::TilingContextPara tilingContextPara( | ||
| 131 | + "NanToNum", | ||
| 132 | + { | ||
| 133 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 134 | + }, | ||
| 135 | + { | ||
| 136 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 137 | + }, | ||
| 138 | + { | ||
| 139 | + gert::TilingContextPara::OpAttr("nan", Ops::Math::AnyValue::CreateFrom<float>(-1.0)), | ||
| 140 | + gert::TilingContextPara::OpAttr("posinf", Ops::Math::AnyValue::CreateFrom<float>(1.0)), | ||
| 141 | + gert::TilingContextPara::OpAttr("neginf", Ops::Math::AnyValue::CreateFrom<float>(0.0)), | ||
| 142 | + }, | ||
| 143 | + &compileInfo); | ||
| 144 | + | ||
| 145 | + uint64_t expectTilingKey = 7; | ||
| 146 | + string expectTilingData = ""; | ||
| 147 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 148 | + ExecuteTestCaseForEle(tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 149 | +} | ||
| 150 | + | ||
| 151 | +TEST_F(NanToNumTilingTest, nan_to_num_test_tiling_invalid_shape) | ||
| 152 | +{ | ||
| 153 | + Ops::Base::ElewiseCompileInfo compileInfo = {64, 253952}; | ||
| 154 | + gert::TilingContextPara tilingContextPara( | ||
| 155 | + "NanToNum", | ||
| 156 | + { | ||
| 157 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 158 | + }, | ||
| 159 | + { | ||
| 160 | + {{{1, 64, 2, 6}, {1, 64, 2, 6}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 161 | + }, | ||
| 162 | + { | ||
| 163 | + gert::TilingContextPara::OpAttr("nan", Ops::Math::AnyValue::CreateFrom<float>(-1.0)), | ||
| 164 | + gert::TilingContextPara::OpAttr("posinf", Ops::Math::AnyValue::CreateFrom<float>(1.0)), | ||
| 165 | + gert::TilingContextPara::OpAttr("neginf", Ops::Math::AnyValue::CreateFrom<float>(0.0)), | ||
| 166 | + }, | ||
| 167 | + &compileInfo); | ||
| 168 | + | ||
| 169 | + uint64_t expectTilingKey = 7; | ||
| 170 | + string expectTilingData = ""; | ||
| 171 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 172 | + ExecuteTestCaseForEle(tilingContextPara, ge::GRAPH_FAILED, true, expectTilingKey, false, expectTilingData, expectWorkspaces); | ||
| 173 | +} | ||
| @@ -1,11 +0,0 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | ||
| 2 | -# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | ||
| 4 | -# This file is a part of the CANN Open Software. | ||
| 5 | -# Licensed under 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, INCLUDING | ||
| 8 | -# 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 | - | ||
| @@ -1,347 +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 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | -class l2InplaceNanToNumTest : public testing::Test { | ||
| 17 | - protected: | ||
| 18 | - static void SetUpTestCase() { | ||
| 19 | - std::cout << "l2InplaceNanToNumTest SetUp" << std::endl; | ||
| 20 | - } | ||
| 21 | - | ||
| 22 | - static void TearDownTestCase() { | ||
| 23 | - std::cout << "l2InplaceNanToNumTest TearDown" << std::endl; | ||
| 24 | - } | ||
| 25 | -}; | ||
| 26 | - | ||
| 27 | -// 异常场景:self为空指针,返回ACLNN_ERR_PARAM_NULLPTR | ||
| 28 | -TEST_F(l2InplaceNanToNumTest, l2_nan_to_num_test_err_self_null) { | ||
| 29 | - float nan = 0; | ||
| 30 | - float posinf = 1.0; | ||
| 31 | - float neginf = -1.0; | ||
| 32 | - | ||
| 33 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT((aclTensor *)nullptr, nan, posinf, neginf), OUTPUT()); | ||
| 34 | - | ||
| 35 | - uint64_t workspaceSize = 0; | ||
| 36 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 37 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_NULLPTR); | ||
| 38 | -} | ||
| 39 | - | ||
| 40 | -// 异常场景:self的数据类型不在支持范围内,返回ACLNN_ERR_PARAM_INVALID | ||
| 41 | -TEST_F(l2InplaceNanToNumTest, l2_nan_to_num_test_err_self_double) { | ||
| 42 | - auto selfDesc = TensorDesc({2, 3}, ACL_DOUBLE, ACL_FORMAT_ND); | ||
| 43 | - float nan = 0; | ||
| 44 | - float posinf = 1.0; | ||
| 45 | - float neginf = -1.0; | ||
| 46 | - | ||
| 47 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 48 | - | ||
| 49 | - uint64_t workspaceSize = 0; | ||
| 50 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 51 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 52 | -} | ||
| 53 | - | ||
| 54 | -// 异常场景:self的数据类型不在支持范围内,返回ACLNN_ERR_PARAM_INVALID | ||
| 55 | -TEST_F(l2InplaceNanToNumTest, l2_nan_to_num_test_err_self_complex) { | ||
| 56 | - auto selfDesc = TensorDesc({2, 3}, ACL_COMPLEX64, ACL_FORMAT_ND); | ||
| 57 | - float nan = 0; | ||
| 58 | - float posinf = 1.0; | ||
| 59 | - float neginf = -1.0; | ||
| 60 | - | ||
| 61 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 62 | - | ||
| 63 | - uint64_t workspaceSize = 0; | ||
| 64 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 65 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 66 | -} | ||
| 67 | - | ||
| 68 | -// 异常场景:Tensor为9维、返回ACLNN_ERR_PARAM_INVALID | ||
| 69 | -TEST_F(l2InplaceNanToNumTest, l2_nan_to_num_test_err_dim_over) { | ||
| 70 | - auto selfDesc = TensorDesc({1, 2, 3, 4, 5, 6, 7, 8, 9}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 71 | - float nan = 0; | ||
| 72 | - float posinf = 1.0; | ||
| 73 | - float neginf = -1.0; | ||
| 74 | - | ||
| 75 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 76 | - | ||
| 77 | - uint64_t workspaceSize = 0; | ||
| 78 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 79 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 80 | -} | ||
| 81 | - | ||
| 82 | -// 正常场景:空tensor,返回ACLNN_SUCCESS | ||
| 83 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_err_empty_tensor) { | ||
| 84 | - auto selfDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 85 | - float nan = 0; | ||
| 86 | - float posinf = 1.0; | ||
| 87 | - float neginf = -1.0; | ||
| 88 | - | ||
| 89 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 90 | - | ||
| 91 | - uint64_t workspaceSize = 0; | ||
| 92 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 93 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 94 | - | ||
| 95 | - ut.TestPrecision(); | ||
| 96 | -} | ||
| 97 | - | ||
| 98 | -// 正常场景:float16、6维、nan/posinf/neginf为int,返回ACLNN_SUCCESS,精度校验通过 | ||
| 99 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_fp16_dim6_para_int) { | ||
| 100 | - auto selfDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 101 | - int nan = 0; | ||
| 102 | - int posinf = 1; | ||
| 103 | - int neginf = -1; | ||
| 104 | - | ||
| 105 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 106 | - | ||
| 107 | - uint64_t workspaceSize = 0; | ||
| 108 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 109 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 110 | - | ||
| 111 | - ut.TestPrecision(); | ||
| 112 | -} | ||
| 113 | - | ||
| 114 | -// 正常场景:float16、6维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 115 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_fp16_dim6) { | ||
| 116 | - auto selfDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 117 | - float nan = 0; | ||
| 118 | - float posinf = 1.0; | ||
| 119 | - float neginf = -1.0; | ||
| 120 | - | ||
| 121 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 122 | - | ||
| 123 | - uint64_t workspaceSize = 0; | ||
| 124 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 125 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 126 | - | ||
| 127 | - ut.TestPrecision(); | ||
| 128 | -} | ||
| 129 | - | ||
| 130 | -// 正常场景:float32、7维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 131 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_fp32_dim7) { | ||
| 132 | - auto selfDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 133 | - float nan = 0; | ||
| 134 | - float posinf = 1.0; | ||
| 135 | - float neginf = -1.0; | ||
| 136 | - | ||
| 137 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 138 | - | ||
| 139 | - uint64_t workspaceSize = 0; | ||
| 140 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 141 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 142 | - | ||
| 143 | - ut.TestPrecision(); | ||
| 144 | -} | ||
| 145 | - | ||
| 146 | -// 正常场景:bfloat16、8维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 147 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_bf16_dim8) { | ||
| 148 | - auto selfDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12, 23}, ACL_BF16, ACL_FORMAT_ND); | ||
| 149 | - float nan = 0; | ||
| 150 | - float posinf = 1.0; | ||
| 151 | - float neginf = -1.0; | ||
| 152 | - | ||
| 153 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 154 | - | ||
| 155 | - uint64_t workspaceSize = 0; | ||
| 156 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 157 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 158 | - | ||
| 159 | - // ut.TestPrecision(); | ||
| 160 | -} | ||
| 161 | - | ||
| 162 | -// 正常场景:ACL_INT8、1维,ACLNN_SUCCESS | ||
| 163 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_int8_dim1) { | ||
| 164 | - auto selfDesc = TensorDesc({2}, ACL_INT8, ACL_FORMAT_ND); | ||
| 165 | - float nan = 0; | ||
| 166 | - float posinf = 1.0; | ||
| 167 | - float neginf = -1.0; | ||
| 168 | - | ||
| 169 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 170 | - | ||
| 171 | - uint64_t workspaceSize = 0; | ||
| 172 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 173 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 174 | - | ||
| 175 | - ut.TestPrecision(); | ||
| 176 | -} | ||
| 177 | - | ||
| 178 | -// 正常场景:ACL_INT16、2维,ACLNN_SUCCESS | ||
| 179 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_int16_dim2) { | ||
| 180 | - auto selfDesc = TensorDesc({2, 4}, ACL_INT16, ACL_FORMAT_ND); | ||
| 181 | - float nan = 0; | ||
| 182 | - float posinf = 1.0; | ||
| 183 | - float neginf = -1.0; | ||
| 184 | - | ||
| 185 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 186 | - | ||
| 187 | - uint64_t workspaceSize = 0; | ||
| 188 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 189 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 190 | - | ||
| 191 | - ut.TestPrecision(); | ||
| 192 | -} | ||
| 193 | - | ||
| 194 | -// 正常场景:ACL_INT32、3维,ACLNN_SUCCESS | ||
| 195 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_int32_dim3) { | ||
| 196 | - auto selfDesc = TensorDesc({2, 4, 12}, ACL_INT32, ACL_FORMAT_ND); | ||
| 197 | - float nan = 0; | ||
| 198 | - float posinf = 1.0; | ||
| 199 | - float neginf = -1.0; | ||
| 200 | - | ||
| 201 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 202 | - | ||
| 203 | - uint64_t workspaceSize = 0; | ||
| 204 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 205 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 206 | - | ||
| 207 | - ut.TestPrecision(); | ||
| 208 | -} | ||
| 209 | - | ||
| 210 | -// 正常场景:ACL_INT64、4维,ACLNN_SUCCESS | ||
| 211 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_int64_dim4) { | ||
| 212 | - auto selfDesc = TensorDesc({2, 4, 12, 9}, ACL_INT64, ACL_FORMAT_ND); | ||
| 213 | - float nan = 0; | ||
| 214 | - float posinf = 1.0; | ||
| 215 | - float neginf = -1.0; | ||
| 216 | - | ||
| 217 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 218 | - | ||
| 219 | - uint64_t workspaceSize = 0; | ||
| 220 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 221 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 222 | - | ||
| 223 | - ut.TestPrecision(); | ||
| 224 | -} | ||
| 225 | - | ||
| 226 | -// 正常场景:ACL_UINT8、5维,ACLNN_SUCCESS | ||
| 227 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_uint8_dim5) { | ||
| 228 | - auto selfDesc = TensorDesc({2, 4, 12, 9, 21}, ACL_UINT8, ACL_FORMAT_ND); | ||
| 229 | - float nan = 0; | ||
| 230 | - float posinf = 1.0; | ||
| 231 | - float neginf = -1.0; | ||
| 232 | - | ||
| 233 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 234 | - | ||
| 235 | - uint64_t workspaceSize = 0; | ||
| 236 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 237 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 238 | - | ||
| 239 | - ut.TestPrecision(); | ||
| 240 | -} | ||
| 241 | - | ||
| 242 | -// 正常场景:ACL_BOOL、6维,ACLNN_SUCCESS | ||
| 243 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_bool_dim6) { | ||
| 244 | - auto selfDesc = TensorDesc({2, 4, 12, 9, 21, 32}, ACL_BOOL, ACL_FORMAT_ND); | ||
| 245 | - float nan = 0; | ||
| 246 | - float posinf = 1.0; | ||
| 247 | - float neginf = -1.0; | ||
| 248 | - | ||
| 249 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 250 | - | ||
| 251 | - uint64_t workspaceSize = 0; | ||
| 252 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 253 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 254 | - | ||
| 255 | - ut.TestPrecision(); | ||
| 256 | -} | ||
| 257 | - | ||
| 258 | -// 正常场景:float32、4维、ACL_FORMAT_NCHW,返回ACLNN_SUCCESS,精度校验通过 | ||
| 259 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nchw) { | ||
| 260 | - auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NCHW); | ||
| 261 | - float nan = 0; | ||
| 262 | - float posinf = 1.0; | ||
| 263 | - float neginf = -1.0; | ||
| 264 | - | ||
| 265 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 266 | - | ||
| 267 | - uint64_t workspaceSize = 0; | ||
| 268 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 269 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 270 | - ut.TestPrecision(); | ||
| 271 | -} | ||
| 272 | - | ||
| 273 | -// 正常场景:float32、4维、ACL_FORMAT_NHWC,返回ACLNN_SUCCESS,精度校验通过 | ||
| 274 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nhwc) { | ||
| 275 | - auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NHWC); | ||
| 276 | - float nan = 0; | ||
| 277 | - float posinf = 1.0; | ||
| 278 | - float neginf = -1.0; | ||
| 279 | - | ||
| 280 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 281 | - | ||
| 282 | - uint64_t workspaceSize = 0; | ||
| 283 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 284 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 285 | - ut.TestPrecision(); | ||
| 286 | -} | ||
| 287 | - | ||
| 288 | -// 正常场景:float32、4维、ACL_FORMAT_NC1HWC0,返回ACLNN_SUCCESS,精度校验通过 | ||
| 289 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nc1hwc0) { | ||
| 290 | - auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NC1HWC0); | ||
| 291 | - float nan = 0; | ||
| 292 | - float posinf = 1.0; | ||
| 293 | - float neginf = -1.0; | ||
| 294 | - | ||
| 295 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 296 | - | ||
| 297 | - uint64_t workspaceSize = 0; | ||
| 298 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 299 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 300 | - ut.TestPrecision(); | ||
| 301 | -} | ||
| 302 | - | ||
| 303 | -// 正常场景:float32、4维、ACL_FORMAT_HWCN,返回ACLNN_SUCCESS,精度校验通过 | ||
| 304 | -TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_float32_hwcn) { | ||
| 305 | - auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_HWCN); | ||
| 306 | - float nan = 0; | ||
| 307 | - float posinf = 1.0; | ||
| 308 | - float neginf = -1.0; | ||
| 309 | - | ||
| 310 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 311 | - | ||
| 312 | - uint64_t workspaceSize = 0; | ||
| 313 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 314 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 315 | - ut.TestPrecision(); | ||
| 316 | -} | ||
| 317 | - | ||
| 318 | -// 成功场景:浮点型、non-continuous,返回ACLNN_SUCCESS,精度校验通过 | ||
| 319 | - TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_float32_non_continuous) { | ||
| 320 | - auto selfDesc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {4,5}).ValueRange(-2, 2); | ||
| 321 | - float nan = 0; | ||
| 322 | - float posinf = 1.0; | ||
| 323 | - float neginf = -1.0; | ||
| 324 | - | ||
| 325 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 326 | - | ||
| 327 | - uint64_t workspaceSize = 0; | ||
| 328 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 329 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 330 | - ut.TestPrecision(); | ||
| 331 | -} | ||
| 332 | - | ||
| 333 | -// 成功场景:整型、non-continuous,返回ACLNN_SUCCESS,精度校验通过 | ||
| 334 | - TEST_F(l2InplaceNanToNumTest, ascend910B2_l2_nan_to_num_test_int_non_continuous) { | ||
| 335 | - auto selfDesc = TensorDesc({5, 4}, ACL_INT32, ACL_FORMAT_ND, {1, 5}, 0, {4,5}).ValueRange(-2, 2); | ||
| 336 | - float nan = 0; | ||
| 337 | - float posinf = 1.0; | ||
| 338 | - float neginf = -1.0; | ||
| 339 | - | ||
| 340 | - auto ut = OP_API_UT(aclnnInplaceNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT()); | ||
| 341 | - | ||
| 342 | - uint64_t workspaceSize = 0; | ||
| 343 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 344 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 345 | - ut.TestPrecision(); | ||
| 346 | -} | ||
| 347 | - | ||
| @@ -1,327 +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 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | -class l2NanToNumTest : public testing::Test { | ||
| 17 | - protected: | ||
| 18 | - static void SetUpTestCase() { | ||
| 19 | - std::cout << "l2NanToNumTest SetUp" << std::endl; | ||
| 20 | - } | ||
| 21 | - | ||
| 22 | - static void TearDownTestCase() { | ||
| 23 | - std::cout << "l2NanToNumTest TearDown" << std::endl; | ||
| 24 | - } | ||
| 25 | -}; | ||
| 26 | - | ||
| 27 | -// 异常场景:self为空指针,返回ACLNN_ERR_PARAM_NULLPTR | ||
| 28 | -TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_self_null) { | ||
| 29 | - auto outDesc = TensorDesc({2, 3}, ACL_INT32, ACL_FORMAT_ND); | ||
| 30 | - float nan = 0; | ||
| 31 | - float posinf = 1.0; | ||
| 32 | - float neginf = -1.0; | ||
| 33 | - | ||
| 34 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT((aclTensor *)nullptr, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 35 | - | ||
| 36 | - uint64_t workspaceSize = 0; | ||
| 37 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 38 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_NULLPTR); | ||
| 39 | -} | ||
| 40 | - | ||
| 41 | -// 异常场景:out为空指针,返回ACLNN_ERR_PARAM_NULLPTR | ||
| 42 | -TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_out_null) { | ||
| 43 | - auto selfDesc = TensorDesc({2, 3}, ACL_INT32, ACL_FORMAT_ND); | ||
| 44 | - float nan = 0; | ||
| 45 | - float posinf = 1.0; | ||
| 46 | - float neginf = -1.0; | ||
| 47 | - | ||
| 48 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT((aclTensor *)nullptr)); | ||
| 49 | - | ||
| 50 | - uint64_t workspaceSize = 0; | ||
| 51 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 52 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_NULLPTR); | ||
| 53 | -} | ||
| 54 | - | ||
| 55 | -// 异常场景:self和out的数据类型不一致,返回ACLNN_ERR_PARAM_INVALID | ||
| 56 | -TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_self_out_datatype_inconsistent) { | ||
| 57 | - auto selfDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 58 | - auto outDesc = TensorDesc({2, 3}, ACL_INT8, ACL_FORMAT_ND); | ||
| 59 | - float nan = 0; | ||
| 60 | - float posinf = 1.0; | ||
| 61 | - float neginf = -1.0; | ||
| 62 | - | ||
| 63 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 64 | - | ||
| 65 | - uint64_t workspaceSize = 0; | ||
| 66 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 67 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 68 | -} | ||
| 69 | - | ||
| 70 | -// 异常场景:self的数据类型不在支持范围内,返回ACLNN_ERR_PARAM_INVALID | ||
| 71 | -TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_self_double) { | ||
| 72 | - auto selfDesc = TensorDesc({2, 3}, ACL_DOUBLE, ACL_FORMAT_ND); | ||
| 73 | - auto outDesc = TensorDesc({2, 3}, ACL_DOUBLE, ACL_FORMAT_ND); | ||
| 74 | - float nan = 0; | ||
| 75 | - float posinf = 1.0; | ||
| 76 | - float neginf = -1.0; | ||
| 77 | - | ||
| 78 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 79 | - | ||
| 80 | - uint64_t workspaceSize = 0; | ||
| 81 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 82 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 83 | -} | ||
| 84 | - | ||
| 85 | -// 异常场景:self的数据类型不在支持范围内,返回ACLNN_ERR_PARAM_INVALID | ||
| 86 | -TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_self_complex) { | ||
| 87 | - auto selfDesc = TensorDesc({2, 3}, ACL_COMPLEX64, ACL_FORMAT_ND); | ||
| 88 | - auto outDesc = TensorDesc({2, 3}, ACL_COMPLEX64, ACL_FORMAT_ND); | ||
| 89 | - float nan = 0; | ||
| 90 | - float posinf = 1.0; | ||
| 91 | - float neginf = -1.0; | ||
| 92 | - | ||
| 93 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 94 | - | ||
| 95 | - uint64_t workspaceSize = 0; | ||
| 96 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 97 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 98 | -} | ||
| 99 | - | ||
| 100 | -// 异常场景:self和out的shape不一致,返回ACLNN_ERR_PARAM_INVALID | ||
| 101 | -TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_self_fp32_out_fp16) { | ||
| 102 | - auto selfDesc = TensorDesc({2, 3, 9}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 103 | - auto outDesc = TensorDesc({2, 3}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 104 | - float nan = 0; | ||
| 105 | - float posinf = 1.0; | ||
| 106 | - float neginf = -1.0; | ||
| 107 | - | ||
| 108 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 109 | - | ||
| 110 | - uint64_t workspaceSize = 0; | ||
| 111 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 112 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 113 | -} | ||
| 114 | - | ||
| 115 | -// 异常场景:Tensor为9维、返回ACLNN_ERR_PARAM_INVALID | ||
| 116 | -TEST_F(l2NanToNumTest, l2_nan_to_num_test_err_dim_over) { | ||
| 117 | - auto selfDesc = TensorDesc({1, 2, 3, 4, 5, 6, 7, 8, 9}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 118 | - auto outDesc = TensorDesc({1, 2, 3, 4, 5, 6, 7, 8, 9}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 119 | - float nan = 0; | ||
| 120 | - float posinf = 1.0; | ||
| 121 | - float neginf = -1.0; | ||
| 122 | - | ||
| 123 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 124 | - | ||
| 125 | - uint64_t workspaceSize = 0; | ||
| 126 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 127 | - EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 128 | -} | ||
| 129 | - | ||
| 130 | -// 正常场景:空tensor,返回ACLNN_SUCCESS | ||
| 131 | -TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_err_empty_tensor) { | ||
| 132 | - auto selfDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 133 | - auto outDesc = TensorDesc({0}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 134 | - float nan = 0; | ||
| 135 | - float posinf = 1.0; | ||
| 136 | - float neginf = -1.0; | ||
| 137 | - | ||
| 138 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 139 | - | ||
| 140 | - uint64_t workspaceSize = 0; | ||
| 141 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 142 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 143 | - | ||
| 144 | - ut.TestPrecision(); | ||
| 145 | -} | ||
| 146 | - | ||
| 147 | -// 正常场景:float16、6维、nan/posinf/neginf为int,返回ACLNN_SUCCESS,精度校验通过 | ||
| 148 | -TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_fp16_dim6_para_int) { | ||
| 149 | - auto selfDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 150 | - auto outDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 151 | - int nan = 0; | ||
| 152 | - int posinf = 1; | ||
| 153 | - int neginf = -1; | ||
| 154 | - | ||
| 155 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 156 | - | ||
| 157 | - uint64_t workspaceSize = 0; | ||
| 158 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 159 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 160 | - | ||
| 161 | - ut.TestPrecision(); | ||
| 162 | -} | ||
| 163 | - | ||
| 164 | -// 正常场景:float16、6维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 165 | -TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_fp16_dim6) { | ||
| 166 | - auto selfDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 167 | - auto outDesc = TensorDesc({2, 4, 6, 7, 9, 1}, ACL_FLOAT16, ACL_FORMAT_ND); | ||
| 168 | - float nan = 0; | ||
| 169 | - float posinf = 1.0; | ||
| 170 | - float neginf = -1.0; | ||
| 171 | - | ||
| 172 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 173 | - | ||
| 174 | - uint64_t workspaceSize = 0; | ||
| 175 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 176 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 177 | - | ||
| 178 | - ut.TestPrecision(); | ||
| 179 | -} | ||
| 180 | - | ||
| 181 | -// 正常场景:float32、7维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 182 | -TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_fp32_dim7) { | ||
| 183 | - auto selfDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 184 | - auto outDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12}, ACL_FLOAT, ACL_FORMAT_ND); | ||
| 185 | - float nan = 0; | ||
| 186 | - float posinf = 1.0; | ||
| 187 | - float neginf = -1.0; | ||
| 188 | - | ||
| 189 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 190 | - | ||
| 191 | - uint64_t workspaceSize = 0; | ||
| 192 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 193 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 194 | - | ||
| 195 | - ut.TestPrecision(); | ||
| 196 | -} | ||
| 197 | - | ||
| 198 | -// 正常场景:bfloat16、8维,返回ACLNN_SUCCESS,精度校验通过 | ||
| 199 | -TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_bf16_dim8) { | ||
| 200 | - auto selfDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12, 23}, ACL_BF16, ACL_FORMAT_ND); | ||
| 201 | - auto outDesc = TensorDesc({2, 4, 7, 9, 1, 2, 12, 23}, ACL_BF16, ACL_FORMAT_ND); | ||
| 202 | - float nan = 0; | ||
| 203 | - float posinf = 1.0; | ||
| 204 | - float neginf = -1.0; | ||
| 205 | - | ||
| 206 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 207 | - | ||
| 208 | - uint64_t workspaceSize = 0; | ||
| 209 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 210 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 211 | - | ||
| 212 | - // ut.TestPrecision(); | ||
| 213 | -} | ||
| 214 | - | ||
| 215 | -// 正常场景:ACL_BOOL、6维,ACLNN_SUCCESS | ||
| 216 | -TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_bool_dim6) { | ||
| 217 | - auto selfDesc = TensorDesc({2, 4, 12, 9, 21, 32}, ACL_BOOL, ACL_FORMAT_ND); | ||
| 218 | - auto outDesc = TensorDesc({2, 4, 12, 9, 21, 32}, ACL_BOOL, ACL_FORMAT_ND); | ||
| 219 | - float nan = 0; | ||
| 220 | - float posinf = 1.0; | ||
| 221 | - float neginf = -1.0; | ||
| 222 | - | ||
| 223 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 224 | - | ||
| 225 | - uint64_t workspaceSize = 0; | ||
| 226 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 227 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 228 | - | ||
| 229 | - ut.TestPrecision(); | ||
| 230 | -} | ||
| 231 | - | ||
| 232 | -// 正常场景:float32、4维、ACL_FORMAT_NCHW,返回ACLNN_SUCCESS,精度校验通过 | ||
| 233 | -TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nchw) { | ||
| 234 | - auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NCHW); | ||
| 235 | - auto outDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NCHW); | ||
| 236 | - float nan = 0; | ||
| 237 | - float posinf = 1.0; | ||
| 238 | - float neginf = -1.0; | ||
| 239 | - | ||
| 240 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 241 | - | ||
| 242 | - uint64_t workspaceSize = 0; | ||
| 243 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 244 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 245 | - ut.TestPrecision(); | ||
| 246 | -} | ||
| 247 | - | ||
| 248 | -// 正常场景:float32、4维、ACL_FORMAT_NHWC,返回ACLNN_SUCCESS,精度校验通过 | ||
| 249 | -TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nhwc) { | ||
| 250 | - auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NHWC); | ||
| 251 | - auto outDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NHWC); | ||
| 252 | - float nan = 0; | ||
| 253 | - float posinf = 1.0; | ||
| 254 | - float neginf = -1.0; | ||
| 255 | - | ||
| 256 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 257 | - | ||
| 258 | - uint64_t workspaceSize = 0; | ||
| 259 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 260 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 261 | - ut.TestPrecision(); | ||
| 262 | -} | ||
| 263 | - | ||
| 264 | -// 正常场景:float32、4维、ACL_FORMAT_NC1HWC0,返回ACLNN_SUCCESS,精度校验通过 | ||
| 265 | -TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_float32_nc1hwc0) { | ||
| 266 | - auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NC1HWC0); | ||
| 267 | - auto outDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_NC1HWC0); | ||
| 268 | - float nan = 0; | ||
| 269 | - float posinf = 1.0; | ||
| 270 | - float neginf = -1.0; | ||
| 271 | - | ||
| 272 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 273 | - | ||
| 274 | - uint64_t workspaceSize = 0; | ||
| 275 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 276 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 277 | - ut.TestPrecision(); | ||
| 278 | -} | ||
| 279 | - | ||
| 280 | -// 正常场景:float32、4维、ACL_FORMAT_HWCN,返回ACLNN_SUCCESS,精度校验通过 | ||
| 281 | -TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_float32_hwcn) { | ||
| 282 | - auto selfDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_HWCN); | ||
| 283 | - auto outDesc = TensorDesc({2, 3, 4, 5}, ACL_FLOAT, ACL_FORMAT_HWCN); | ||
| 284 | - float nan = 0; | ||
| 285 | - float posinf = 1.0; | ||
| 286 | - float neginf = -1.0; | ||
| 287 | - | ||
| 288 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 289 | - | ||
| 290 | - uint64_t workspaceSize = 0; | ||
| 291 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 292 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 293 | - ut.TestPrecision(); | ||
| 294 | -} | ||
| 295 | - | ||
| 296 | -// 成功场景:浮点型、non-continuous,返回ACLNN_SUCCESS,精度校验通过 | ||
| 297 | - TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_float32_non_continuous) { | ||
| 298 | - auto selfDesc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {4,5}).ValueRange(-2, 2); | ||
| 299 | - auto outDesc = TensorDesc({5, 4}, ACL_FLOAT, ACL_FORMAT_ND, {1, 5}, 0, {4,5}).ValueRange(-2, 2); | ||
| 300 | - float nan = 0; | ||
| 301 | - float posinf = 1.0; | ||
| 302 | - float neginf = -1.0; | ||
| 303 | - | ||
| 304 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 305 | - | ||
| 306 | - uint64_t workspaceSize = 0; | ||
| 307 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 308 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 309 | - ut.TestPrecision(); | ||
| 310 | -} | ||
| 311 | - | ||
| 312 | -// 成功场景:整型、non-continuous,返回ACLNN_SUCCESS,精度校验通过 | ||
| 313 | - TEST_F(l2NanToNumTest, ascend910B2_l2_nan_to_num_test_int_non_continuous) { | ||
| 314 | - auto selfDesc = TensorDesc({5, 4}, ACL_INT32, ACL_FORMAT_ND, {1, 5}, 0, {4,5}).ValueRange(-2, 2); | ||
| 315 | - auto outDesc = TensorDesc({5, 4}, ACL_INT32, ACL_FORMAT_ND, {1, 5}, 0, {4,5}).ValueRange(-2, 2); | ||
| 316 | - float nan = 0; | ||
| 317 | - float posinf = 1.0; | ||
| 318 | - float neginf = -1.0; | ||
| 319 | - | ||
| 320 | - auto ut = OP_API_UT(aclnnNanToNum, INPUT(selfDesc, nan, posinf, neginf), OUTPUT(outDesc)); | ||
| 321 | - | ||
| 322 | - uint64_t workspaceSize = 0; | ||
| 323 | - aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 324 | - EXPECT_EQ(getWorkspaceResult, ACLNN_SUCCESS); | ||
| 325 | - ut.TestPrecision(); | ||
| 326 | -} | ||
| 327 | - | ||
| @@ -0,0 +1,81 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +class NanToNumInferShape : public testing::Test { | ||
| 17 | + protected: | ||
| 18 | + static void SetUpTestCase() { | ||
| 19 | + std::cout << "NanToNum InferShape SetUp" << std::endl; | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + static void TearDownTestCase() { | ||
| 23 | + std::cout << "NanToNum InferShape TearDown" << std::endl; | ||
| 24 | + } | ||
| 25 | +}; | ||
| 26 | + | ||
| 27 | +TEST_F(NanToNumInferShape, nan_to_num_infershape_diff_test) | ||
| 28 | +{ | ||
| 29 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 30 | + "NanToNum", | ||
| 31 | + { | ||
| 32 | + {{{4, 3, 4}, {4, 3, 4}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 33 | + }, | ||
| 34 | + { | ||
| 35 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 36 | + }); | ||
| 37 | + std::vector<std::vector<int64_t>> expectOutputShape = {{4, 3, 4}}; | ||
| 38 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 39 | +} | ||
| 40 | + | ||
| 41 | +TEST_F(NanToNumInferShape, nan_to_num_infershape_same_test) | ||
| 42 | +{ | ||
| 43 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 44 | + "NanToNum", | ||
| 45 | + { | ||
| 46 | + {{{1, 3, 4}, {1, 3, 4}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 47 | + }, | ||
| 48 | + { | ||
| 49 | + {{{}, {}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 50 | + }); | ||
| 51 | + std::vector<std::vector<int64_t>> expectOutputShape = {{1, 3, 4}}; | ||
| 52 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 53 | +} | ||
| 54 | + | ||
| 55 | +TEST_F(NanToNumInferShape, nan_to_num_infershape_test2) | ||
| 56 | +{ | ||
| 57 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 58 | + "NanToNum", | ||
| 59 | + { | ||
| 60 | + {{{5, -1}, {5, -1}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 61 | + }, | ||
| 62 | + { | ||
| 63 | + {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 64 | + }); | ||
| 65 | + std::vector<std::vector<int64_t>> expectOutputShape = {{5, -1}}; | ||
| 66 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 67 | +} | ||
| 68 | + | ||
| 69 | +TEST_F(NanToNumInferShape, nan_to_num_infershape_test3) | ||
| 70 | +{ | ||
| 71 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 72 | + "NanToNum", | ||
| 73 | + { | ||
| 74 | + {{{-2}, {-2}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 75 | + }, | ||
| 76 | + { | ||
| 77 | + {{{}, {}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 78 | + }); | ||
| 79 | + std::vector<std::vector<int64_t>> expectOutputShape = {{-2}}; | ||
| 80 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 81 | +} | ||
| @@ -1,12 +1,16 @@ | |||
| 1 | -# --------------------------------------------------------------------------------------------------------- | 1 | +# ---------------------------------------------------------------------------- |
| 2 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 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, | 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. | 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. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 9 | -# --------------------------------------------------------------------------------------------------------- | 9 | +# ---------------------------------------------------------------------------- |
| 10 | 10 | ||
| 11 | -add_all_modules_sources(OPTYPE right_shift ACLNNTYPE aclnn_exclude) | 11 | +# 设置算子定义时支持的芯片类型 |
| 12 | -add_subdirectory(framework) | 12 | +set(SUPPORT_COMPUTE_UNIT "ascend950") |
| 13 | +# 设置每种芯片类型对应的tiling文件目录,即采用op_host目录下哪个文件夹下的tiling文件编译 | ||
| 14 | +set(SUPPORT_TILING_DIR "arch35") | ||
| 15 | +add_all_modules_sources(OPTYPE right_shift ACLNNTYPE aclnn_exclude COMPUTE_UNIT ${SUPPORT_COMPUTE_UNIT} TILING_DIR ${SUPPORT_TILING_DIR} DISABLE_IN_OPP TRUE) | ||
| 16 | +add_subdirectory(framework) | ||
| @@ -1,12 +1,12 @@ | |||
| 1 | -# ---------------------------------------------------------------------------- | 1 | +# ---------------------------------------------------------------------------- |
| 2 | -# This program is free software, you can redistribute it and/or modify. | 2 | +# This program is free software, you can redistribute it and/or modify. |
| 3 | -# Copyright (c) 2025 Huawei Technologies Co., Ltd. | 3 | +# Copyright (c) 2025 Huawei Technologies Co., Ltd. |
| 4 | -# This file is a part of the CANN Open Software. | 4 | +# This file is a part of the CANN Open Software. |
| 5 | -# Licensed under CANN Open Software License Agreement Version 2.0 (the "License"). | 5 | +# Licensed under 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. | 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, INCLUDING | 7 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING |
| 8 | -# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. See LICENSE in the root of | 8 | +# BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. See LICENSE in the root of |
| 9 | -# the software repository for the full text of the License. | 9 | +# the software repository for the full text of the License. |
| 10 | -# ---------------------------------------------------------------------------- | 10 | +# ---------------------------------------------------------------------------- |
| 11 | - | 11 | + |
| 12 | add_onnx_plugin_sources() | 12 | add_onnx_plugin_sources() |
| @@ -0,0 +1,31 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file right_shift_graph_infer.cpp | ||
| 13 | + * \brief right_shift graph infer | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +using namespace ge; | ||
| 20 | +namespace ops { | ||
| 21 | +static constexpr size_t kInputIndex0 = 0U; | ||
| 22 | +static constexpr size_t kOutputIndex0 = 0U; | ||
| 23 | +static ge::graphStatus InferDataTypeForRightShift(gert::InferDataTypeContext* context) | ||
| 24 | +{ | ||
| 25 | + OP_LOGI(context->GetNodeName(), "Begin to do InferDtypeForRightShift"); | ||
| 26 | + const auto x_data_type = context->GetInputDataType(kInputIndex0); | ||
| 27 | + return context->SetOutputDataType(kOutputIndex0, x_data_type); | ||
| 28 | +} | ||
| 29 | + | ||
| 30 | +IMPL_OP(RightShift).InferDataType(InferDataTypeForRightShift); | ||
| 31 | +} // namespace ops | ||
| @@ -7,12 +7,12 @@ | |||
| 7 | * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING | 7 | * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING |
| 8 | * BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. See LICENSE in the root of | 8 | * BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. See LICENSE in the root of |
| 9 | * the software repository for the full text of the License. | 9 | * the software repository for the full text of the License. |
| 10 | - | 10 | + |
| 11 | * The code snippet comes from Huawei's open-source Mindspore project. | 11 | * The code snippet comes from Huawei's open-source Mindspore project. |
| 12 | * Copyright 2019-2020 Huawei Technologies Co., Ltd. | 12 | * Copyright 2019-2020 Huawei Technologies Co., Ltd. |
| 13 | * Licensed under the Apache License, Version 2.0 (the "License"); | 13 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 14 | * You may obtain a copy of the License at | 14 | * You may obtain a copy of the License at |
| 15 | - * | 15 | + * |
| 16 | * http://www.apache.org/licenses/LICENSE-2.0 | 16 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | */ | 17 | */ |
| 18 | 18 | ||
| @@ -44,13 +44,10 @@ int64, uint8, uint16, uint32, uint64. | |||
| 44 | */ | 44 | */ |
| 45 | 45 | ||
| 46 | REG_OP(RightShift) | 46 | REG_OP(RightShift) |
| 47 | - .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, \ | 47 | + .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64})) |
| 48 | - DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64})) | 48 | + .INPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64})) |
| 49 | - .INPUT(y, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, \ | 49 | + .OUTPUT(z, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64})) |
| 50 | - DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64})) | ||
| 51 | - .OUTPUT(z, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64, \ | ||
| 52 | - DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64})) | ||
| 53 | .OP_END_FACTORY_REG(RightShift) | 50 | .OP_END_FACTORY_REG(RightShift) |
| 54 | -} | 51 | +} // namespace ge |
| 55 | 52 | ||
| 56 | 53 | ||
| @@ -0,0 +1,175 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file right_shift_tiling_arch35.cpp | ||
| 13 | + * \brief right_shift_tiling source file | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | +using namespace ge; | ||
| 28 | +using namespace RightShiftOp; | ||
| 29 | +using namespace Ops::Base; | ||
| 30 | + | ||
| 31 | +namespace optiling { | ||
| 32 | + | ||
| 33 | +static constexpr uint64_t RIGHT_SHIFT_COMMON_TILING_PRIORITY = 0; | ||
| 34 | + | ||
| 35 | +bool RightShiftTiling::CheckDtype( | ||
| 36 | + const ge::DataType& xDtype, const ge::DataType& yDtype, const ge::DataType& zDtype) const | ||
| 37 | +{ | ||
| 38 | + if (xDtype != yDtype || xDtype != zDtype) { | ||
| 39 | + OP_LOGE( | ||
| 40 | + context_->GetNodeName(), "Dtype of x[%s] should be equal to dtype of y[%s] and z[%s].", | ||
| 41 | + ge::TypeUtils::DataTypeToSerialString(xDtype).c_str(), | ||
| 42 | + ge::TypeUtils::DataTypeToSerialString(yDtype).c_str(), | ||
| 43 | + ge::TypeUtils::DataTypeToSerialString(zDtype).c_str()); | ||
| 44 | + return false; | ||
| 45 | + } | ||
| 46 | + return true; | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +bool RightShiftTiling::IsCapable() | ||
| 50 | +{ | ||
| 51 | + return true; | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +ge::graphStatus RightShiftTiling::GetPlatformInfo() | ||
| 55 | +{ | ||
| 56 | + return ge::GRAPH_SUCCESS; | ||
| 57 | +} | ||
| 58 | + | ||
| 59 | +ge::graphStatus RightShiftTiling::GetShapeAttrsInfo() | ||
| 60 | +{ | ||
| 61 | + return ge::GRAPH_SUCCESS; | ||
| 62 | +} | ||
| 63 | + | ||
| 64 | +ge::graphStatus RightShiftTiling::DoOpTiling() | ||
| 65 | +{ | ||
| 66 | + OP_LOGD(context_->GetNodeName(), "RightShift DoOpTiling start."); | ||
| 67 | + auto xDesc = context_->GetInputDesc(0); | ||
| 68 | + OP_CHECK_NULL_WITH_CONTEXT(context_, xDesc); | ||
| 69 | + ge::DataType xDType = xDesc->GetDataType(); | ||
| 70 | + | ||
| 71 | + auto yDesc = context_->GetInputDesc(1); | ||
| 72 | + OP_CHECK_NULL_WITH_CONTEXT(context_, yDesc); | ||
| 73 | + ge::DataType yDType = yDesc->GetDataType(); | ||
| 74 | + | ||
| 75 | + auto zDesc = context_->GetOutputDesc(0); | ||
| 76 | + OP_CHECK_NULL_WITH_CONTEXT(context_, zDesc); | ||
| 77 | + ge::DataType zDType = zDesc->GetDataType(); | ||
| 78 | + if (!CheckDtype(xDType, yDType, zDType)) { | ||
| 79 | + return ge::GRAPH_FAILED; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + ge::graphStatus baseTilingResult = ge::GRAPH_FAILED; | ||
| 83 | + | ||
| 84 | + OP_LOGD(context_->GetNodeName(), "Current data type is %s.", ge::TypeUtils::DataTypeToSerialString(xDType).c_str()); | ||
| 85 | + if (xDType == ge::DT_INT8) { | ||
| 86 | + BroadcastBaseTiling<RightShiftDag8<int8_t>::OpDag> brcBaseTiling(context_); | ||
| 87 | + baseTilingResult = brcBaseTiling.DoTiling(); | ||
| 88 | + tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode(), TPL_INT8); | ||
| 89 | + } else if (xDType == ge::DT_UINT8) { | ||
| 90 | + BroadcastBaseTiling<RightShiftDag8<uint8_t>::OpDag> brcBaseTiling(context_); | ||
| 91 | + baseTilingResult = brcBaseTiling.DoTiling(); | ||
| 92 | + tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode(), TPL_UINT8); | ||
| 93 | + } else if (xDType == ge::DT_INT16) { | ||
| 94 | + BroadcastBaseTiling<RightShiftDag16<int16_t>::OpDag> brcBaseTiling(context_); | ||
| 95 | + baseTilingResult = brcBaseTiling.DoTiling(); | ||
| 96 | + tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode(), TPL_INT16); | ||
| 97 | + } else if (xDType == ge::DT_UINT16) { | ||
| 98 | + BroadcastBaseTiling<RightShiftDag16<uint16_t>::OpDag> brcBaseTiling(context_); | ||
| 99 | + baseTilingResult = brcBaseTiling.DoTiling(); | ||
| 100 | + tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode(), TPL_UINT16); | ||
| 101 | + } else if (xDType == ge::DT_INT32) { | ||
| 102 | + BroadcastBaseTiling<RightShiftDag32<int32_t>::OpDag> brcBaseTiling(context_); | ||
| 103 | + baseTilingResult = brcBaseTiling.DoTiling(); | ||
| 104 | + tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode(), TPL_INT32); | ||
| 105 | + } else if (xDType == ge::DT_UINT32) { | ||
| 106 | + BroadcastBaseTiling<RightShiftDag32<uint32_t>::OpDag> brcBaseTiling(context_); | ||
| 107 | + baseTilingResult = brcBaseTiling.DoTiling(); | ||
| 108 | + tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode(), TPL_UINT32); | ||
| 109 | + } else if (xDType == ge::DT_INT64) { | ||
| 110 | + BroadcastBaseTiling<RightShiftDag64<int64_t>::OpDag> brcBaseTiling(context_); | ||
| 111 | + baseTilingResult = brcBaseTiling.DoTiling(); | ||
| 112 | + tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode(), TPL_INT64); | ||
| 113 | + } else if (xDType == ge::DT_UINT64) { | ||
| 114 | + BroadcastBaseTiling<RightShiftDag64<uint64_t>::OpDag> brcBaseTiling(context_); | ||
| 115 | + baseTilingResult = brcBaseTiling.DoTiling(); | ||
| 116 | + tilingKey = GET_TPL_TILING_KEY(brcBaseTiling.GetSchMode(), TPL_UINT64); | ||
| 117 | + } else { | ||
| 118 | + OP_LOGE( | ||
| 119 | + context_->GetNodeName(), | ||
| 120 | + "Input dtype is only support int8, int16, int32, int64, uint8, uint16, uint32, uint64, " | ||
| 121 | + "while got %s!", | ||
| 122 | + ge::TypeUtils::DataTypeToSerialString(xDType).c_str()); | ||
| 123 | + return ge::GRAPH_FAILED; | ||
| 124 | + } | ||
| 125 | + OP_CHECK_IF( | ||
| 126 | + baseTilingResult == ge::GRAPH_FAILED, OP_LOGE(context_->GetNodeName(), "broadcastBaseTiling doTiling failed."), | ||
| 127 | + return ge::GRAPH_FAILED); | ||
| 128 | + OP_LOGD(context_->GetNodeName(), "[RightShiftTilingData] : tilingKey=%lu", tilingKey); | ||
| 129 | + return baseTilingResult; | ||
| 130 | +} | ||
| 131 | + | ||
| 132 | +ge::graphStatus RightShiftTiling::DoLibApiTiling() | ||
| 133 | +{ | ||
| 134 | + return ge::GRAPH_SUCCESS; | ||
| 135 | +} | ||
| 136 | + | ||
| 137 | +uint64_t RightShiftTiling::GetTilingKey() const | ||
| 138 | +{ | ||
| 139 | + return tilingKey; | ||
| 140 | +} | ||
| 141 | + | ||
| 142 | +ge::graphStatus RightShiftTiling::GetWorkspaceSize() | ||
| 143 | +{ | ||
| 144 | + return ge::GRAPH_SUCCESS; | ||
| 145 | +} | ||
| 146 | + | ||
| 147 | +ge::graphStatus RightShiftTiling::PostTiling() | ||
| 148 | +{ | ||
| 149 | + return ge::GRAPH_SUCCESS; | ||
| 150 | +} | ||
| 151 | + | ||
| 152 | +ge::graphStatus Tiling4RightShift(gert::TilingContext* context) | ||
| 153 | +{ | ||
| 154 | + OP_LOGD("RightShiftTiling", "Enter Tiling4RightShift"); | ||
| 155 | + if (context == nullptr) { | ||
| 156 | + OP_LOGE("Tiling4RightShift", "Tiling context is nullptr"); | ||
| 157 | + return ge::GRAPH_FAILED; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + auto compileInfo = reinterpret_cast<const BroadcastCompileInfo*>(context->GetCompileInfo()); | ||
| 161 | + OP_CHECK_NULL_WITH_CONTEXT(context, compileInfo); | ||
| 162 | + | ||
| 163 | + OP_LOGD(context, "Enter ascendc Tiling4RightShift"); | ||
| 164 | + RightShiftTiling tiling(context); | ||
| 165 | + return tiling.DoTiling(); | ||
| 166 | +} | ||
| 167 | + | ||
| 168 | +static ge::graphStatus TilingPrepareForRightShift([[maybe_unused]] gert::TilingParseContext* context) | ||
| 169 | +{ | ||
| 170 | + return ge::GRAPH_SUCCESS; | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | +IMPL_OP_OPTILING(RightShift).Tiling(Tiling4RightShift).TilingParse<BroadcastCompileInfo>(TilingPrepareForRightShift); | ||
| 174 | + | ||
| 175 | +} // namespace optiling | ||
| @@ -0,0 +1,46 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file right_shift_tiling_arch35.h | ||
| 13 | + * \brief right_shift_tiling head file | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +namespace optiling { | ||
| 24 | +using namespace Ops::Math::OpTiling; | ||
| 25 | + | ||
| 26 | +class RightShiftTiling : public TilingBaseClass { | ||
| 27 | +public: | ||
| 28 | + explicit RightShiftTiling(gert::TilingContext* context) : TilingBaseClass(context) | ||
| 29 | + {} | ||
| 30 | + | ||
| 31 | +protected: | ||
| 32 | + bool IsCapable() override; | ||
| 33 | + ge::graphStatus GetPlatformInfo() override; | ||
| 34 | + ge::graphStatus GetShapeAttrsInfo() override; | ||
| 35 | + ge::graphStatus DoOpTiling() override; | ||
| 36 | + ge::graphStatus DoLibApiTiling() override; | ||
| 37 | + uint64_t GetTilingKey() const override; | ||
| 38 | + ge::graphStatus GetWorkspaceSize() override; | ||
| 39 | + ge::graphStatus PostTiling() override; | ||
| 40 | + | ||
| 41 | +private: | ||
| 42 | + uint64_t tilingKey = 0; | ||
| 43 | + bool CheckDtype(const ge::DataType& xDtype, const ge::DataType& yDtype, const ge::DataType& zDtype) const; | ||
| 44 | +}; | ||
| 45 | +} // namespace optiling | ||
| 46 | + | ||
| @@ -0,0 +1,325 @@ | |||
| 1 | +{ | ||
| 2 | + "op_type": "RightShift", | ||
| 3 | + "op_list": [ | ||
| 4 | + { | ||
| 5 | + "bin_filename": "RightShift_int8", | ||
| 6 | + "inputs": [ | ||
| 7 | + { | ||
| 8 | + "name": "x", | ||
| 9 | + "index": 0, | ||
| 10 | + "dtype": "int8", | ||
| 11 | + "format": "ND", | ||
| 12 | + "paramType": "required", | ||
| 13 | + "shape": [ | ||
| 14 | + -2 | ||
| 15 | + ], | ||
| 16 | + "format_match_mode": "FormatAgnostic" | ||
| 17 | + }, | ||
| 18 | + { | ||
| 19 | + "name": "y", | ||
| 20 | + "index": 1, | ||
| 21 | + "dtype": "int8", | ||
| 22 | + "format": "ND", | ||
| 23 | + "paramType": "required", | ||
| 24 | + "shape": [ | ||
| 25 | + -2 | ||
| 26 | + ], | ||
| 27 | + "format_match_mode": "FormatAgnostic" | ||
| 28 | + } | ||
| 29 | + ], | ||
| 30 | + "outputs": [ | ||
| 31 | + { | ||
| 32 | + "name": "z", | ||
| 33 | + "index": 0, | ||
| 34 | + "dtype": "int8", | ||
| 35 | + "format": "ND", | ||
| 36 | + "paramType": "required", | ||
| 37 | + "shape": [ | ||
| 38 | + -2 | ||
| 39 | + ], | ||
| 40 | + "format_match_mode": "FormatAgnostic" | ||
| 41 | + } | ||
| 42 | + ] | ||
| 43 | + }, | ||
| 44 | + { | ||
| 45 | + "bin_filename": "RightShift_uint8", | ||
| 46 | + "inputs": [ | ||
| 47 | + { | ||
| 48 | + "name": "x", | ||
| 49 | + "index": 0, | ||
| 50 | + "dtype": "uint8", | ||
| 51 | + "format": "ND", | ||
| 52 | + "paramType": "required", | ||
| 53 | + "shape": [ | ||
| 54 | + -2 | ||
| 55 | + ], | ||
| 56 | + "format_match_mode": "FormatAgnostic" | ||
| 57 | + }, | ||
| 58 | + { | ||
| 59 | + "name": "y", | ||
| 60 | + "index": 1, | ||
| 61 | + "dtype": "uint8", | ||
| 62 | + "format": "ND", | ||
| 63 | + "paramType": "required", | ||
| 64 | + "shape": [ | ||
| 65 | + -2 | ||
| 66 | + ], | ||
| 67 | + "format_match_mode": "FormatAgnostic" | ||
| 68 | + } | ||
| 69 | + ], | ||
| 70 | + "outputs": [ | ||
| 71 | + { | ||
| 72 | + "name": "z", | ||
| 73 | + "index": 0, | ||
| 74 | + "dtype": "uint8", | ||
| 75 | + "format": "ND", | ||
| 76 | + "paramType": "required", | ||
| 77 | + "shape": [ | ||
| 78 | + -2 | ||
| 79 | + ], | ||
| 80 | + "format_match_mode": "FormatAgnostic" | ||
| 81 | + } | ||
| 82 | + ] | ||
| 83 | + }, | ||
| 84 | + { | ||
| 85 | + "bin_filename": "RightShift_int16", | ||
| 86 | + "inputs": [ | ||
| 87 | + { | ||
| 88 | + "name": "x", | ||
| 89 | + "index": 0, | ||
| 90 | + "dtype": "int16", | ||
| 91 | + "format": "ND", | ||
| 92 | + "paramType": "required", | ||
| 93 | + "shape": [ | ||
| 94 | + -2 | ||
| 95 | + ], | ||
| 96 | + "format_match_mode": "FormatAgnostic" | ||
| 97 | + }, | ||
| 98 | + { | ||
| 99 | + "name": "y", | ||
| 100 | + "index": 1, | ||
| 101 | + "dtype": "int16", | ||
| 102 | + "format": "ND", | ||
| 103 | + "paramType": "required", | ||
| 104 | + "shape": [ | ||
| 105 | + -2 | ||
| 106 | + ], | ||
| 107 | + "format_match_mode": "FormatAgnostic" | ||
| 108 | + } | ||
| 109 | + ], | ||
| 110 | + "outputs": [ | ||
| 111 | + { | ||
| 112 | + "name": "z", | ||
| 113 | + "index": 0, | ||
| 114 | + "dtype": "int16", | ||
| 115 | + "format": "ND", | ||
| 116 | + "paramType": "required", | ||
| 117 | + "shape": [ | ||
| 118 | + -2 | ||
| 119 | + ], | ||
| 120 | + "format_match_mode": "FormatAgnostic" | ||
| 121 | + } | ||
| 122 | + ] | ||
| 123 | + }, | ||
| 124 | + { | ||
| 125 | + "bin_filename": "RightShift_uint16", | ||
| 126 | + "inputs": [ | ||
| 127 | + { | ||
| 128 | + "name": "x", | ||
| 129 | + "index": 0, | ||
| 130 | + "dtype": "uint16", | ||
| 131 | + "format": "ND", | ||
| 132 | + "paramType": "required", | ||
| 133 | + "shape": [ | ||
| 134 | + -2 | ||
| 135 | + ], | ||
| 136 | + "format_match_mode": "FormatAgnostic" | ||
| 137 | + }, | ||
| 138 | + { | ||
| 139 | + "name": "y", | ||
| 140 | + "index": 1, | ||
| 141 | + "dtype": "uint16", | ||
| 142 | + "format": "ND", | ||
| 143 | + "paramType": "required", | ||
| 144 | + "shape": [ | ||
| 145 | + -2 | ||
| 146 | + ], | ||
| 147 | + "format_match_mode": "FormatAgnostic" | ||
| 148 | + } | ||
| 149 | + ], | ||
| 150 | + "outputs": [ | ||
| 151 | + { | ||
| 152 | + "name": "z", | ||
| 153 | + "index": 0, | ||
| 154 | + "dtype": "uint16", | ||
| 155 | + "format": "ND", | ||
| 156 | + "paramType": "required", | ||
| 157 | + "shape": [ | ||
| 158 | + -2 | ||
| 159 | + ], | ||
| 160 | + "format_match_mode": "FormatAgnostic" | ||
| 161 | + } | ||
| 162 | + ] | ||
| 163 | + }, | ||
| 164 | + { | ||
| 165 | + "bin_filename": "RightShift_int32", | ||
| 166 | + "inputs": [ | ||
| 167 | + { | ||
| 168 | + "name": "x", | ||
| 169 | + "index": 0, | ||
| 170 | + "dtype": "int32", | ||
| 171 | + "format": "ND", | ||
| 172 | + "paramType": "required", | ||
| 173 | + "shape": [ | ||
| 174 | + -2 | ||
| 175 | + ], | ||
| 176 | + "format_match_mode": "FormatAgnostic" | ||
| 177 | + }, | ||
| 178 | + { | ||
| 179 | + "name": "y", | ||
| 180 | + "index": 1, | ||
| 181 | + "dtype": "int32", | ||
| 182 | + "format": "ND", | ||
| 183 | + "paramType": "required", | ||
| 184 | + "shape": [ | ||
| 185 | + -2 | ||
| 186 | + ], | ||
| 187 | + "format_match_mode": "FormatAgnostic" | ||
| 188 | + } | ||
| 189 | + ], | ||
| 190 | + "outputs": [ | ||
| 191 | + { | ||
| 192 | + "name": "z", | ||
| 193 | + "index": 0, | ||
| 194 | + "dtype": "int32", | ||
| 195 | + "format": "ND", | ||
| 196 | + "paramType": "required", | ||
| 197 | + "shape": [ | ||
| 198 | + -2 | ||
| 199 | + ], | ||
| 200 | + "format_match_mode": "FormatAgnostic" | ||
| 201 | + } | ||
| 202 | + ] | ||
| 203 | + }, | ||
| 204 | + { | ||
| 205 | + "bin_filename": "RightShift_uint32", | ||
| 206 | + "inputs": [ | ||
| 207 | + { | ||
| 208 | + "name": "x", | ||
| 209 | + "index": 0, | ||
| 210 | + "dtype": "uint32", | ||
| 211 | + "format": "ND", | ||
| 212 | + "paramType": "required", | ||
| 213 | + "shape": [ | ||
| 214 | + -2 | ||
| 215 | + ], | ||
| 216 | + "format_match_mode": "FormatAgnostic" | ||
| 217 | + }, | ||
| 218 | + { | ||
| 219 | + "name": "y", | ||
| 220 | + "index": 1, | ||
| 221 | + "dtype": "uint32", | ||
| 222 | + "format": "ND", | ||
| 223 | + "paramType": "required", | ||
| 224 | + "shape": [ | ||
| 225 | + -2 | ||
| 226 | + ], | ||
| 227 | + "format_match_mode": "FormatAgnostic" | ||
| 228 | + } | ||
| 229 | + ], | ||
| 230 | + "outputs": [ | ||
| 231 | + { | ||
| 232 | + "name": "z", | ||
| 233 | + "index": 0, | ||
| 234 | + "dtype": "uint32", | ||
| 235 | + "format": "ND", | ||
| 236 | + "paramType": "required", | ||
| 237 | + "shape": [ | ||
| 238 | + -2 | ||
| 239 | + ], | ||
| 240 | + "format_match_mode": "FormatAgnostic" | ||
| 241 | + } | ||
| 242 | + ] | ||
| 243 | + }, | ||
| 244 | + { | ||
| 245 | + "bin_filename": "RightShift_int64", | ||
| 246 | + "inputs": [ | ||
| 247 | + { | ||
| 248 | + "name": "x", | ||
| 249 | + "index": 0, | ||
| 250 | + "dtype": "int64", | ||
| 251 | + "format": "ND", | ||
| 252 | + "paramType": "required", | ||
| 253 | + "shape": [ | ||
| 254 | + -2 | ||
| 255 | + ], | ||
| 256 | + "format_match_mode": "FormatAgnostic" | ||
| 257 | + }, | ||
| 258 | + { | ||
| 259 | + "name": "y", | ||
| 260 | + "index": 1, | ||
| 261 | + "dtype": "int64", | ||
| 262 | + "format": "ND", | ||
| 263 | + "paramType": "required", | ||
| 264 | + "shape": [ | ||
| 265 | + -2 | ||
| 266 | + ], | ||
| 267 | + "format_match_mode": "FormatAgnostic" | ||
| 268 | + } | ||
| 269 | + ], | ||
| 270 | + "outputs": [ | ||
| 271 | + { | ||
| 272 | + "name": "z", | ||
| 273 | + "index": 0, | ||
| 274 | + "dtype": "int64", | ||
| 275 | + "format": "ND", | ||
| 276 | + "paramType": "required", | ||
| 277 | + "shape": [ | ||
| 278 | + -2 | ||
| 279 | + ], | ||
| 280 | + "format_match_mode": "FormatAgnostic" | ||
| 281 | + } | ||
| 282 | + ] | ||
| 283 | + }, | ||
| 284 | + { | ||
| 285 | + "bin_filename": "RightShift_uint64", | ||
| 286 | + "inputs": [ | ||
| 287 | + { | ||
| 288 | + "name": "x", | ||
| 289 | + "index": 0, | ||
| 290 | + "dtype": "uint64", | ||
| 291 | + "format": "ND", | ||
| 292 | + "paramType": "required", | ||
| 293 | + "shape": [ | ||
| 294 | + -2 | ||
| 295 | + ], | ||
| 296 | + "format_match_mode": "FormatAgnostic" | ||
| 297 | + }, | ||
| 298 | + { | ||
| 299 | + "name": "y", | ||
| 300 | + "index": 1, | ||
| 301 | + "dtype": "uint64", | ||
| 302 | + "format": "ND", | ||
| 303 | + "paramType": "required", | ||
| 304 | + "shape": [ | ||
| 305 | + -2 | ||
| 306 | + ], | ||
| 307 | + "format_match_mode": "FormatAgnostic" | ||
| 308 | + } | ||
| 309 | + ], | ||
| 310 | + "outputs": [ | ||
| 311 | + { | ||
| 312 | + "name": "z", | ||
| 313 | + "index": 0, | ||
| 314 | + "dtype": "uint64", | ||
| 315 | + "format": "ND", | ||
| 316 | + "paramType": "required", | ||
| 317 | + "shape": [ | ||
| 318 | + -2 | ||
| 319 | + ], | ||
| 320 | + "format_match_mode": "FormatAgnostic" | ||
| 321 | + } | ||
| 322 | + ] | ||
| 323 | + } | ||
| 324 | + ] | ||
| 325 | +} | ||
| @@ -0,0 +1,2 @@ | |||
| 1 | +[RightShift] | ||
| 2 | +default=0 | ||
| @@ -1,78 +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 | - | ||
| 13 | - | ||
| 14 | - | ||
| 15 | - | ||
| 16 | - | ||
| 17 | - | ||
| 18 | -extern "C" { | ||
| 19 | - | ||
| 20 | -/** | ||
| 21 | - * @brief aclnnRightShift的第一段接口,根据具体的计算流程,计算workspace大小。 | ||
| 22 | - * 功能描述:输入张量input中每个元素,根据shiftBits对应位置的参数,按位进行右移。 | ||
| 23 | - * 计算公式: | ||
| 24 | - * output_{i} = input_{i}>>shiftBits_{i} | ||
| 25 | - * @domain aclnn_math | ||
| 26 | - * 参数描述: | ||
| 27 | - * @param [in] input | ||
| 28 | - * 输入Tensor,数据类型支持 INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64。 | ||
| 29 | - * 数据类型需要与shiftBits构成互相推导关系,input需要与shiftBits满足broadcast关系。 | ||
| 30 | - * 支持非连续的Tensor,数据格式支持ND。 | ||
| 31 | - * @param [in] shiftBits | ||
| 32 | - * 输入Tensor,数据类型支持 INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64。 | ||
| 33 | - * 数据类型需要与input构成互相推导关系,input需要与shiftBits满足broadcast关系。 | ||
| 34 | - * 支持非连续的Tensor,数据格式支持ND。 | ||
| 35 | - * @param [out] out | ||
| 36 | - * 输出Tensor,数据类型支持 INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64。 | ||
| 37 | - * shape需要与input和shiftBits做broadcast后的shape一致。 | ||
| 38 | - * 支持非连续的Tensor,数据格式支持ND。 | ||
| 39 | - * @param [out] workspaceSize 返回用户需要在npu device侧申请的workspace大小。 | ||
| 40 | - * @param [out] executor 返回op执行器,包含了算子计算流程。 | ||
| 41 | - * @return aclnnStatus: 返回状态码。 | ||
| 42 | - */ | ||
| 43 | -ACLNN_API aclnnStatus aclnnRightShiftGetWorkspaceSize(const aclTensor *input, const aclTensor *shiftBits, | ||
| 44 | - aclTensor *out, uint64_t *workspaceSize, aclOpExecutor **executor); | ||
| 45 | - | ||
| 46 | -/** | ||
| 47 | - * @brief aclnnRightShift的第二段接口,用于执行计算。 | ||
| 48 | - * 功能描述:输入张量input中每个元素,根据shiftBits对应位置的参数,按位进行右移。 | ||
| 49 | - * 计算公式: | ||
| 50 | - * output_{i} = input_{i}>>shiftBits_{i} | ||
| 51 | - * @domain aclnn_math | ||
| 52 | - * 实现说明: | ||
| 53 | - * api计算的基本路径: | ||
| 54 | - * ```mermaid | ||
| 55 | - * flowchart LR | ||
| 56 | - * input[(input)]-->l0op::Contiguous_input([l0op::Contiguous]) | ||
| 57 | - * l0op::Contiguous_input([l0op::Contiguous])-->l0op::Cast_input([l0op::Cast]) | ||
| 58 | - * l0op::Cast_input([l0op::Cast])-->l0op::rightshift([l0op::rightshift]) | ||
| 59 | - * shiftBits[(shiftBits)]-->l0op::Contiguous_shiftBits([l0op::Contiguous]) | ||
| 60 | - * -->l0op::Cast_shiftBits([l0op::Cast])-->l0op::rightshift([l0op::RightShift]) | ||
| 61 | - * l0op::rightshift([l0op::RightShift])-->l0op::Cast_out([l0op::Cast]) | ||
| 62 | - * l0op::Cast_out([l0op::Cast])-->l0op::ViewCopy_out([l0op::ViewCopy])-->out[(out)] | ||
| 63 | - * ``` | ||
| 64 | - * @param [in] workspace: 在npu device侧申请的workspace内存起址。 | ||
| 65 | - * @param [in] workspaceSize: 在npu device侧申请的workspace大小,由第一段接口aclnnRightShiftGetWorkspaceSize获取。 | ||
| 66 | - * @param [in] executor: op执行器,包含了算子计算流程。 | ||
| 67 | - * @param [in] stream: acl stream流。 | ||
| 68 | - * @return aclnnStatus: 返回状态码。 | ||
| 69 | - */ | ||
| 70 | -ACLNN_API aclnnStatus aclnnRightShift(void *workspace, uint64_t workspaceSize, | ||
| 71 | - aclOpExecutor *executor, aclrtStream stream); | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - | ||
| 75 | -} | ||
| 76 | - | ||
| 77 | - | ||
| 78 | - | ||
| @@ -0,0 +1,70 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file right_shift_def.cpp | ||
| 13 | + * \brief RightShift def | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | +namespace ops { | ||
| 20 | +class RightShift : public OpDef { | ||
| 21 | +public: | ||
| 22 | + explicit RightShift(const char* name) : OpDef(name) | ||
| 23 | + { | ||
| 24 | + this->Input("x") | ||
| 25 | + .ParamType(REQUIRED) | ||
| 26 | + .DataType( | ||
| 27 | + {ge::DT_INT8, ge::DT_UINT8, ge::DT_INT16, ge::DT_UINT16, ge::DT_INT32, ge::DT_UINT32, ge::DT_INT64, | ||
| 28 | + ge::DT_UINT64}) | ||
| 29 | + .Format( | ||
| 30 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 31 | + ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 32 | + .UnknownShapeFormat( | ||
| 33 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 34 | + ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 35 | + this->Input("y") | ||
| 36 | + .ParamType(REQUIRED) | ||
| 37 | + .DataType( | ||
| 38 | + {ge::DT_INT8, ge::DT_UINT8, ge::DT_INT16, ge::DT_UINT16, ge::DT_INT32, ge::DT_UINT32, ge::DT_INT64, | ||
| 39 | + ge::DT_UINT64}) | ||
| 40 | + .Format( | ||
| 41 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 42 | + ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 43 | + .UnknownShapeFormat( | ||
| 44 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 45 | + ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 46 | + this->Output("z") | ||
| 47 | + .ParamType(REQUIRED) | ||
| 48 | + .DataType( | ||
| 49 | + {ge::DT_INT8, ge::DT_UINT8, ge::DT_INT16, ge::DT_UINT16, ge::DT_INT32, ge::DT_UINT32, ge::DT_INT64, | ||
| 50 | + ge::DT_UINT64}) | ||
| 51 | + .Format( | ||
| 52 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 53 | + ge::FORMAT_ND, ge::FORMAT_ND}) | ||
| 54 | + .UnknownShapeFormat( | ||
| 55 | + {ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, | ||
| 56 | + ge::FORMAT_ND, ge::FORMAT_ND}); | ||
| 57 | + | ||
| 58 | + OpAICoreConfig aicoreConfig; | ||
| 59 | + aicoreConfig.DynamicCompileStaticFlag(true) | ||
| 60 | + .DynamicFormatFlag(false) | ||
| 61 | + .DynamicRankSupportFlag(true) | ||
| 62 | + .DynamicShapeSupportFlag(true) | ||
| 63 | + .NeedCheckSupportFlag(false) | ||
| 64 | + .PrecisionReduceFlag(true) | ||
| 65 | + .ExtendCfgInfo("opFile.value", "right_shift_apt"); | ||
| 66 | + this->AICore().AddConfig("ascend950", aicoreConfig); | ||
| 67 | + } | ||
| 68 | +}; | ||
| 69 | +OP_ADD(RightShift); | ||
| 70 | +} // namespace ops | ||
| @@ -0,0 +1,43 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file right_shift_infershape.cpp | ||
| 13 | + * \brief RightShift infershape | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | +using namespace ge; | ||
| 21 | +using namespace Ops::Base; | ||
| 22 | + | ||
| 23 | +namespace ops { | ||
| 24 | +static ge::graphStatus InferShapeForRightShift(gert::InferShapeContext* context) | ||
| 25 | +{ | ||
| 26 | + OP_LOGI(context->GetNodeName(), "Begin to do InferShapeForRightShift"); | ||
| 27 | + const gert::Shape* x_shape = context->GetInputShape(0); | ||
| 28 | + OP_CHECK_NULL_WITH_CONTEXT(context, x_shape); | ||
| 29 | + const gert::Shape* y_shape = context->GetInputShape(1); | ||
| 30 | + OP_CHECK_NULL_WITH_CONTEXT(context, y_shape); | ||
| 31 | + gert::Shape* z_shape = context->GetOutputShape(0); | ||
| 32 | + OP_CHECK_NULL_WITH_CONTEXT(context, z_shape); | ||
| 33 | + OP_CHECK_IF( | ||
| 34 | + !BroadcastShape(x_shape, y_shape, z_shape), | ||
| 35 | + OP_LOGE( | ||
| 36 | + context->GetNodeName(), "shape %s and %s cannot broadcast!", ToString(*x_shape).c_str(), | ||
| 37 | + ToString(*y_shape).c_str()), | ||
| 38 | + return ge::GRAPH_FAILED); | ||
| 39 | + return GRAPH_SUCCESS; | ||
| 40 | +} | ||
| 41 | + | ||
| 42 | +IMPL_OP_INFERSHAPE(RightShift).InferShape(InferShapeForRightShift); | ||
| 43 | +} // namespace ops | ||
| @@ -0,0 +1,302 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file right_shift_dag.h | ||
| 13 | + * \brief right_shift dag | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | + | ||
| 23 | +namespace RightShiftOp { | ||
| 24 | +using namespace Ops::Base; | ||
| 25 | + | ||
| 26 | +template <typename T> | ||
| 27 | +struct RightShiftCustom8 : public Vec::ElemwiseBinaryOP<T, T, T> { | ||
| 28 | + __aicore__ inline RightShiftCustom8(LocalTensor<T>& dst, LocalTensor<T>& src1, LocalTensor<T>& src2, uint32_t count) | ||
| 29 | + { | ||
| 30 | + | ||
| 31 | + uint32_t dtypeSize = sizeof(T); | ||
| 32 | + int8_t digitZero = 0; | ||
| 33 | + int8_t rightShifts = 7; | ||
| 34 | + constexpr uint64_t VECTOR_REG_WIDTH = 256UL; | ||
| 35 | + uint32_t vl = VECTOR_REG_WIDTH / dtypeSize; | ||
| 36 | + uint16_t loopNum = (count + vl - 1) / vl; | ||
| 37 | + uint32_t vlSize = vl; | ||
| 38 | + | ||
| 39 | + __ubuf__ T* src1Addr = (__ubuf__ T*)src1.GetPhyAddr(); | ||
| 40 | + __ubuf__ T* src2Addr = (__ubuf__ T*)src2.GetPhyAddr(); | ||
| 41 | + __ubuf__ T* dstAddr = (__ubuf__ T*)dst.GetPhyAddr(); | ||
| 42 | + | ||
| 43 | + MicroAPI::RegTensor<T> xReg; | ||
| 44 | + MicroAPI::RegTensor<T> yReg; | ||
| 45 | + MicroAPI::RegTensor<T> zReg; | ||
| 46 | + MicroAPI::RegTensor<T> zeroReg; | ||
| 47 | + MicroAPI::RegTensor<T> sizeReg; | ||
| 48 | + | ||
| 49 | + MicroAPI::MaskReg mask; | ||
| 50 | + MicroAPI::MaskReg calcMask; | ||
| 51 | + | ||
| 52 | + __VEC_SCOPE__ | ||
| 53 | + { | ||
| 54 | + MicroAPI::MaskReg scalarMaskReg = MicroAPI::CreateMask<T, MicroAPI::MaskPattern::ALL>(); | ||
| 55 | + MicroAPI::Duplicate(zeroReg, digitZero, scalarMaskReg); | ||
| 56 | + MicroAPI::Duplicate(sizeReg, rightShifts, scalarMaskReg); | ||
| 57 | + | ||
| 58 | + for (uint16_t loopIdx = 0; loopIdx < loopNum; loopIdx++) { | ||
| 59 | + mask = MicroAPI::UpdateMask<T, MicroAPI::RegTraitNumOne>(count); | ||
| 60 | + MicroAPI::DataCopy(xReg, (__ubuf__ T*)(src1Addr + loopIdx * vlSize)); | ||
| 61 | + MicroAPI::DataCopy(yReg, (__ubuf__ T*)(src2Addr + loopIdx * vlSize)); | ||
| 62 | + | ||
| 63 | + if constexpr (std::is_same_v<T, int8_t>) { | ||
| 64 | + MicroAPI::Compare<T, CMPMODE::GE>(calcMask, yReg, zeroReg, mask); | ||
| 65 | + MicroAPI::Select(yReg, yReg, zeroReg, calcMask); | ||
| 66 | + MicroAPI::ShiftRight(zReg, xReg, (MicroAPI::RegTensor<T>&)yReg, mask); | ||
| 67 | + } else if constexpr (std::is_same_v<T, uint8_t>) { | ||
| 68 | + MicroAPI::Compare<T, CMPMODE::LE>(calcMask, yReg, sizeReg, mask); | ||
| 69 | + MicroAPI::Select(yReg, yReg, sizeReg, calcMask); | ||
| 70 | + MicroAPI::ShiftRight(zReg, xReg, (MicroAPI::RegTensor<int8_t>&)yReg, mask); | ||
| 71 | + } | ||
| 72 | + MicroAPI::DataCopy((__ubuf__ T*)(dstAddr + loopIdx * vlSize), zReg, mask); | ||
| 73 | + } | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + } | ||
| 77 | +}; | ||
| 78 | + | ||
| 79 | +template <typename T> | ||
| 80 | +struct RightShiftCustom16 : public Vec::ElemwiseBinaryOP<T, T, T> { | ||
| 81 | + __aicore__ inline RightShiftCustom16( | ||
| 82 | + LocalTensor<T>& dst, LocalTensor<T>& src1, LocalTensor<T>& src2, uint32_t count) | ||
| 83 | + { | ||
| 84 | + | ||
| 85 | + uint32_t dtypeSize = sizeof(T); | ||
| 86 | + int8_t digitZero = 0; | ||
| 87 | + int8_t rightShifts = 15; | ||
| 88 | + constexpr uint64_t VECTOR_REG_WIDTH = 256UL; | ||
| 89 | + uint32_t vl = VECTOR_REG_WIDTH / dtypeSize; | ||
| 90 | + uint16_t loopNum = (count + vl - 1) / vl; | ||
| 91 | + uint32_t vlSize = vl; | ||
| 92 | + | ||
| 93 | + __ubuf__ T* src1Addr = (__ubuf__ T*)src1.GetPhyAddr(); | ||
| 94 | + __ubuf__ T* src2Addr = (__ubuf__ T*)src2.GetPhyAddr(); | ||
| 95 | + __ubuf__ T* dstAddr = (__ubuf__ T*)dst.GetPhyAddr(); | ||
| 96 | + | ||
| 97 | + MicroAPI::RegTensor<T> xReg; | ||
| 98 | + MicroAPI::RegTensor<T> yReg; | ||
| 99 | + MicroAPI::RegTensor<T> zReg; | ||
| 100 | + MicroAPI::RegTensor<T> zeroReg; | ||
| 101 | + MicroAPI::RegTensor<T> sizeReg; | ||
| 102 | + | ||
| 103 | + MicroAPI::MaskReg mask; | ||
| 104 | + MicroAPI::MaskReg calcMask; | ||
| 105 | + | ||
| 106 | + __VEC_SCOPE__ | ||
| 107 | + { | ||
| 108 | + MicroAPI::MaskReg scalarMaskReg = MicroAPI::CreateMask<T, MicroAPI::MaskPattern::ALL>(); | ||
| 109 | + MicroAPI::Duplicate(zeroReg, digitZero, scalarMaskReg); | ||
| 110 | + MicroAPI::Duplicate(sizeReg, rightShifts, scalarMaskReg); | ||
| 111 | + | ||
| 112 | + for (uint16_t loopIdx = 0; loopIdx < loopNum; loopIdx++) { | ||
| 113 | + mask = MicroAPI::UpdateMask<T, MicroAPI::RegTraitNumOne>(count); | ||
| 114 | + MicroAPI::DataCopy(xReg, (__ubuf__ T*)(src1Addr + loopIdx * vlSize)); | ||
| 115 | + MicroAPI::DataCopy(yReg, (__ubuf__ T*)(src2Addr + loopIdx * vlSize)); | ||
| 116 | + | ||
| 117 | + if constexpr (std::is_same_v<T, int16_t>) { | ||
| 118 | + MicroAPI::Compare<T, CMPMODE::GE>(calcMask, yReg, zeroReg, mask); | ||
| 119 | + MicroAPI::Select(yReg, yReg, zeroReg, calcMask); | ||
| 120 | + MicroAPI::ShiftRight(zReg, xReg, (MicroAPI::RegTensor<T>&)yReg, mask); | ||
| 121 | + } else if constexpr (std::is_same_v<T, uint16_t>) { | ||
| 122 | + MicroAPI::Compare<T, CMPMODE::LE>(calcMask, yReg, sizeReg, mask); | ||
| 123 | + MicroAPI::Select(yReg, yReg, sizeReg, calcMask); | ||
| 124 | + MicroAPI::ShiftRight(zReg, xReg, (MicroAPI::RegTensor<int16_t>&)yReg, mask); | ||
| 125 | + } | ||
| 126 | + MicroAPI::DataCopy((__ubuf__ T*)(dstAddr + loopIdx * vlSize), zReg, mask); | ||
| 127 | + } | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + } | ||
| 131 | +}; | ||
| 132 | + | ||
| 133 | +template <typename T> | ||
| 134 | +struct RightShiftCustom32 : public Vec::ElemwiseBinaryOP<T, T, T> { | ||
| 135 | + __aicore__ inline RightShiftCustom32( | ||
| 136 | + LocalTensor<T>& dst, LocalTensor<T>& src1, LocalTensor<T>& src2, uint32_t count) | ||
| 137 | + { | ||
| 138 | + | ||
| 139 | + uint32_t dtypeSize = sizeof(T); | ||
| 140 | + int8_t digitZero = 0; | ||
| 141 | + int8_t rightShifts = 31; | ||
| 142 | + constexpr uint64_t VECTOR_REG_WIDTH = 256UL; | ||
| 143 | + uint32_t vl = VECTOR_REG_WIDTH / dtypeSize; | ||
| 144 | + uint16_t loopNum = (count + vl - 1) / vl; | ||
| 145 | + uint32_t vlSize = vl; | ||
| 146 | + | ||
| 147 | + __ubuf__ T* src1Addr = (__ubuf__ T*)src1.GetPhyAddr(); | ||
| 148 | + __ubuf__ T* src2Addr = (__ubuf__ T*)src2.GetPhyAddr(); | ||
| 149 | + __ubuf__ T* dstAddr = (__ubuf__ T*)dst.GetPhyAddr(); | ||
| 150 | + | ||
| 151 | + MicroAPI::RegTensor<T> xReg; | ||
| 152 | + MicroAPI::RegTensor<T> yReg; | ||
| 153 | + MicroAPI::RegTensor<T> zReg; | ||
| 154 | + MicroAPI::RegTensor<T> zeroReg; | ||
| 155 | + MicroAPI::RegTensor<T> sizeReg; | ||
| 156 | + | ||
| 157 | + MicroAPI::MaskReg mask; | ||
| 158 | + MicroAPI::MaskReg calcMask; | ||
| 159 | + | ||
| 160 | + __VEC_SCOPE__ | ||
| 161 | + { | ||
| 162 | + MicroAPI::MaskReg scalarMaskReg = MicroAPI::CreateMask<T, MicroAPI::MaskPattern::ALL>(); | ||
| 163 | + MicroAPI::Duplicate(zeroReg, digitZero, scalarMaskReg); | ||
| 164 | + MicroAPI::Duplicate(sizeReg, rightShifts, scalarMaskReg); | ||
| 165 | + | ||
| 166 | + for (uint16_t loopIdx = 0; loopIdx < loopNum; loopIdx++) { | ||
| 167 | + mask = MicroAPI::UpdateMask<T, MicroAPI::RegTraitNumOne>(count); | ||
| 168 | + MicroAPI::DataCopy(xReg, (__ubuf__ T*)(src1Addr + loopIdx * vlSize)); | ||
| 169 | + MicroAPI::DataCopy(yReg, (__ubuf__ T*)(src2Addr + loopIdx * vlSize)); | ||
| 170 | + | ||
| 171 | + if constexpr (std::is_same_v<T, int32_t>) { | ||
| 172 | + MicroAPI::Compare<T, CMPMODE::GE>(calcMask, yReg, zeroReg, mask); | ||
| 173 | + MicroAPI::Select(yReg, yReg, zeroReg, calcMask); | ||
| 174 | + MicroAPI::ShiftRight(zReg, xReg, (MicroAPI::RegTensor<T>&)yReg, mask); | ||
| 175 | + } else if constexpr (std::is_same_v<T, uint32_t>) { | ||
| 176 | + MicroAPI::Compare<T, CMPMODE::LE>(calcMask, yReg, sizeReg, mask); | ||
| 177 | + MicroAPI::Select(yReg, yReg, sizeReg, calcMask); | ||
| 178 | + MicroAPI::ShiftRight(zReg, xReg, (MicroAPI::RegTensor<int32_t>&)yReg, mask); | ||
| 179 | + } | ||
| 180 | + MicroAPI::DataCopy((__ubuf__ T*)(dstAddr + loopIdx * vlSize), zReg, mask); | ||
| 181 | + } | ||
| 182 | + } | ||
| 183 | + | ||
| 184 | + } | ||
| 185 | +}; | ||
| 186 | + | ||
| 187 | +template <typename T> | ||
| 188 | +struct RightShiftCustom64 : public Vec::ElemwiseBinaryOP<T, T, T> { | ||
| 189 | + __aicore__ inline RightShiftCustom64( | ||
| 190 | + LocalTensor<T>& dst, LocalTensor<T>& src1, LocalTensor<T>& src2, uint32_t count) | ||
| 191 | + { | ||
| 192 | + | ||
| 193 | + uint32_t dtypeSize = sizeof(T); | ||
| 194 | + int8_t digitZero = 0; | ||
| 195 | + int8_t rightShifts = 63; | ||
| 196 | + constexpr uint64_t VECTOR_REG_WIDTH = 256UL; | ||
| 197 | + uint32_t vl = VECTOR_REG_WIDTH / dtypeSize; | ||
| 198 | + uint16_t loopNum = (count + vl - 1) / vl; | ||
| 199 | + uint32_t vlSize = vl; | ||
| 200 | + | ||
| 201 | + __ubuf__ T* src1Addr = (__ubuf__ T*)src1.GetPhyAddr(); | ||
| 202 | + __ubuf__ T* src2Addr = (__ubuf__ T*)src2.GetPhyAddr(); | ||
| 203 | + __ubuf__ T* dstAddr = (__ubuf__ T*)dst.GetPhyAddr(); | ||
| 204 | + | ||
| 205 | + MicroAPI::RegTensor<T> xReg; | ||
| 206 | + MicroAPI::RegTensor<T> yReg; | ||
| 207 | + MicroAPI::RegTensor<T> zReg; | ||
| 208 | + MicroAPI::RegTensor<T> zeroReg; | ||
| 209 | + MicroAPI::RegTensor<T> sizeReg; | ||
| 210 | + | ||
| 211 | + MicroAPI::MaskReg mask; | ||
| 212 | + MicroAPI::MaskReg calcMask; | ||
| 213 | + | ||
| 214 | + __VEC_SCOPE__ | ||
| 215 | + { | ||
| 216 | + MicroAPI::MaskReg scalarMaskReg = MicroAPI::CreateMask<T, MicroAPI::MaskPattern::ALL>(); | ||
| 217 | + MicroAPI::Duplicate(zeroReg, digitZero, scalarMaskReg); | ||
| 218 | + MicroAPI::Duplicate(sizeReg, rightShifts, scalarMaskReg); | ||
| 219 | + | ||
| 220 | + for (uint16_t loopIdx = 0; loopIdx < loopNum; loopIdx++) { | ||
| 221 | + mask = MicroAPI::UpdateMask<T, MicroAPI::RegTraitNumOne>(count); | ||
| 222 | + MicroAPI::DataCopy(xReg, (__ubuf__ T*)(src1Addr + loopIdx * vlSize)); | ||
| 223 | + MicroAPI::DataCopy(yReg, (__ubuf__ T*)(src2Addr + loopIdx * vlSize)); | ||
| 224 | + | ||
| 225 | + if constexpr (std::is_same_v<T, int64_t>) { | ||
| 226 | + MicroAPI::Compare<T, CMPMODE::GE>(calcMask, yReg, zeroReg, mask); | ||
| 227 | + MicroAPI::Select(yReg, yReg, zeroReg, calcMask); | ||
| 228 | + MicroAPI::ShiftRight(zReg, xReg, (MicroAPI::RegTensor<T>&)yReg, mask); | ||
| 229 | + } else if constexpr (std::is_same_v<T, uint64_t>) { | ||
| 230 | + MicroAPI::Compare<T, CMPMODE::LE>(calcMask, yReg, sizeReg, mask); | ||
| 231 | + MicroAPI::Select(yReg, yReg, sizeReg, calcMask); | ||
| 232 | + MicroAPI::ShiftRight(zReg, xReg, (MicroAPI::RegTensor<int64_t>&)yReg, mask); | ||
| 233 | + } | ||
| 234 | + MicroAPI::DataCopy((__ubuf__ T*)(dstAddr + loopIdx * vlSize), zReg, mask); | ||
| 235 | + } | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + } | ||
| 239 | +}; | ||
| 240 | + | ||
| 241 | +template <typename T> | ||
| 242 | +struct RightShiftDag8 { | ||
| 243 | + using InputX = Bind<Vec::CopyInBrc<T>, Placeholder::In0<T>>; | ||
| 244 | + using InputY = Bind<Vec::CopyInBrc<T>, Placeholder::In1<T>>; | ||
| 245 | + | ||
| 246 | + using OpResult = Bind<RightShiftCustom8<T>, InputX, InputY>; | ||
| 247 | + | ||
| 248 | + using OpCopyOut = Bind<Vec::CopyOut<T>, Placeholder::Out0<T>, OpResult>; | ||
| 249 | + | ||
| 250 | + // 指定输出节点 | ||
| 251 | + using Outputs = Elems<OpCopyOut>; | ||
| 252 | + using MemCfg = MemOptCfg<MemLevel::LEVEL_2>; | ||
| 253 | + using OpDag = DAGSch<Outputs, void, MemCfg>; | ||
| 254 | +}; | ||
| 255 | + | ||
| 256 | +template <typename T> | ||
| 257 | +struct RightShiftDag16 { | ||
| 258 | + using InputX = Bind<Vec::CopyInBrc<T>, Placeholder::In0<T>>; | ||
| 259 | + using InputY = Bind<Vec::CopyInBrc<T>, Placeholder::In1<T>>; | ||
| 260 | + | ||
| 261 | + using OpResult = Bind<RightShiftCustom16<T>, InputX, InputY>; | ||
| 262 | + | ||
| 263 | + using OpCopyOut = Bind<Vec::CopyOut<T>, Placeholder::Out0<T>, OpResult>; | ||
| 264 | + | ||
| 265 | + // 指定输出节点 | ||
| 266 | + using Outputs = Elems<OpCopyOut>; | ||
| 267 | + using MemCfg = MemOptCfg<MemLevel::LEVEL_2>; | ||
| 268 | + using OpDag = DAGSch<Outputs, void, MemCfg>; | ||
| 269 | +}; | ||
| 270 | + | ||
| 271 | +template <typename T> | ||
| 272 | +struct RightShiftDag32 { | ||
| 273 | + using InputX = Bind<Vec::CopyInBrc<T>, Placeholder::In0<T>>; | ||
| 274 | + using InputY = Bind<Vec::CopyInBrc<T>, Placeholder::In1<T>>; | ||
| 275 | + | ||
| 276 | + using OpResult = Bind<RightShiftCustom32<T>, InputX, InputY>; | ||
| 277 | + | ||
| 278 | + using OpCopyOut = Bind<Vec::CopyOut<T>, Placeholder::Out0<T>, OpResult>; | ||
| 279 | + | ||
| 280 | + // 指定输出节点 | ||
| 281 | + using Outputs = Elems<OpCopyOut>; | ||
| 282 | + using MemCfg = MemOptCfg<MemLevel::LEVEL_2>; | ||
| 283 | + using OpDag = DAGSch<Outputs, void, MemCfg>; | ||
| 284 | +}; | ||
| 285 | + | ||
| 286 | +template <typename T> | ||
| 287 | +struct RightShiftDag64 { | ||
| 288 | + using InputX = Bind<Vec::CopyInBrc<T>, Placeholder::In0<T>>; | ||
| 289 | + using InputY = Bind<Vec::CopyInBrc<T>, Placeholder::In1<T>>; | ||
| 290 | + | ||
| 291 | + using OpResult = Bind<RightShiftCustom64<T>, InputX, InputY>; | ||
| 292 | + | ||
| 293 | + using OpCopyOut = Bind<Vec::CopyOut<T>, Placeholder::Out0<T>, OpResult>; | ||
| 294 | + | ||
| 295 | + // 指定输出节点 | ||
| 296 | + using Outputs = Elems<OpCopyOut>; | ||
| 297 | + using MemCfg = MemOptCfg<MemLevel::LEVEL_2>; | ||
| 298 | + using OpDag = DAGSch<Outputs, void, MemCfg>; | ||
| 299 | +}; | ||
| 300 | +} // namespace RightShiftOp | ||
| 301 | + | ||
| 302 | + | ||
| @@ -0,0 +1,51 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file right_shift_struct.h | ||
| 13 | + * \brief right_shift_struct | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | + | ||
| 22 | +namespace RightShiftOp { | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + | ||
| 26 | + | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + | ||
| 30 | + | ||
| 31 | + | ||
| 32 | + | ||
| 33 | + | ||
| 34 | + | ||
| 35 | +ASCENDC_TPL_ARGS_DECL( | ||
| 36 | + RightShift, BRC_TEMP_SCH_MODE_KEY_DECL(schMode), | ||
| 37 | + ASCENDC_TPL_DTYPE_DECL( | ||
| 38 | + dType, TPL_INT8, TPL_UINT8, TPL_INT16, TPL_UINT16, TPL_INT32, TPL_UINT32, TPL_INT64, TPL_UINT64)); | ||
| 39 | + | ||
| 40 | +ASCENDC_TPL_SEL( | ||
| 41 | + ASCENDC_TPL_ARGS_SEL(BRC_TEMP_SCH_MODE_KEY_SEL(schMode), ASCENDC_TPL_DTYPE_SEL(dType, TPL_INT8)), | ||
| 42 | + ASCENDC_TPL_ARGS_SEL(BRC_TEMP_SCH_MODE_KEY_SEL(schMode), ASCENDC_TPL_DTYPE_SEL(dType, TPL_UINT8)), | ||
| 43 | + ASCENDC_TPL_ARGS_SEL(BRC_TEMP_SCH_MODE_KEY_SEL(schMode), ASCENDC_TPL_DTYPE_SEL(dType, TPL_INT16)), | ||
| 44 | + ASCENDC_TPL_ARGS_SEL(BRC_TEMP_SCH_MODE_KEY_SEL(schMode), ASCENDC_TPL_DTYPE_SEL(dType, TPL_UINT16)), | ||
| 45 | + ASCENDC_TPL_ARGS_SEL(BRC_TEMP_SCH_MODE_KEY_SEL(schMode), ASCENDC_TPL_DTYPE_SEL(dType, TPL_INT32)), | ||
| 46 | + ASCENDC_TPL_ARGS_SEL(BRC_TEMP_SCH_MODE_KEY_SEL(schMode), ASCENDC_TPL_DTYPE_SEL(dType, TPL_UINT32)), | ||
| 47 | + ASCENDC_TPL_ARGS_SEL(BRC_TEMP_SCH_MODE_KEY_SEL(schMode), ASCENDC_TPL_DTYPE_SEL(dType, TPL_INT64)), | ||
| 48 | + ASCENDC_TPL_ARGS_SEL(BRC_TEMP_SCH_MODE_KEY_SEL(schMode), ASCENDC_TPL_DTYPE_SEL(dType, TPL_UINT64))); | ||
| 49 | +} // namespace RightShiftOp | ||
| 50 | + | ||
| 51 | + | ||
| @@ -0,0 +1,61 @@ | |||
| 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 | +/*! | ||
| 12 | + * \file right_shift_apt.cpp | ||
| 13 | + * \brief right_shift_apt | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +using namespace AscendC; | ||
| 22 | +using namespace RightShiftOp; | ||
| 23 | + | ||
| 24 | +template <uint64_t schMode, uint64_t dType> | ||
| 25 | +__global__ __aicore__ void right_shift(GM_ADDR x, GM_ADDR y, GM_ADDR z, GM_ADDR workspace, GM_ADDR tiling) | ||
| 26 | +{ | ||
| 27 | + KERNEL_TASK_TYPE_DEFAULT(KERNEL_TYPE_AIV_ONLY); | ||
| 28 | + if constexpr (dType == TPL_INT8) { | ||
| 29 | + using OpDag = RightShiftDag8<int8_t>::OpDag; | ||
| 30 | + BroadcastSch<schMode, OpDag> sch(tiling); | ||
| 31 | + sch.Process(x, y, z); | ||
| 32 | + } else if constexpr (dType == TPL_UINT8) { | ||
| 33 | + using OpDag = RightShiftDag8<uint8_t>::OpDag; | ||
| 34 | + BroadcastSch<schMode, OpDag> sch(tiling); | ||
| 35 | + sch.Process(x, y, z); | ||
| 36 | + } else if constexpr (dType == TPL_INT16) { | ||
| 37 | + using OpDag = RightShiftDag16<int16_t>::OpDag; | ||
| 38 | + BroadcastSch<schMode, OpDag> sch(tiling); | ||
| 39 | + sch.Process(x, y, z); | ||
| 40 | + } else if constexpr (dType == TPL_UINT16) { | ||
| 41 | + using OpDag = RightShiftDag16<uint16_t>::OpDag; | ||
| 42 | + BroadcastSch<schMode, OpDag> sch(tiling); | ||
| 43 | + sch.Process(x, y, z); | ||
| 44 | + } else if constexpr (dType == TPL_INT32) { | ||
| 45 | + using OpDag = RightShiftDag32<int32_t>::OpDag; | ||
| 46 | + BroadcastSch<schMode, OpDag> sch(tiling); | ||
| 47 | + sch.Process(x, y, z); | ||
| 48 | + } else if constexpr (dType == TPL_UINT32) { | ||
| 49 | + using OpDag = RightShiftDag32<uint32_t>::OpDag; | ||
| 50 | + BroadcastSch<schMode, OpDag> sch(tiling); | ||
| 51 | + sch.Process(x, y, z); | ||
| 52 | + } else if constexpr (dType == TPL_INT64) { | ||
| 53 | + using OpDag = RightShiftDag64<int64_t>::OpDag; | ||
| 54 | + BroadcastSch<schMode, OpDag> sch(tiling); | ||
| 55 | + sch.Process(x, y, z); | ||
| 56 | + } else if constexpr (dType == TPL_UINT64) { | ||
| 57 | + using OpDag = RightShiftDag64<uint64_t>::OpDag; | ||
| 58 | + BroadcastSch<schMode, OpDag> sch(tiling); | ||
| 59 | + sch.Process(x, y, z); | ||
| 60 | + } | ||
| 61 | +} | ||
Rmath/right_shift/tests/ut/op_host/op_api/test_right_shift.cpp→math/right_shift/tests/ut/op_api/test_aclnn_right_shift_l0.cpp+48-45
| @@ -1,5 +1,5 @@ | |||
| 1 | /** | 1 | /** |
| 2 | - * Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). | 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. | 5 | * Please refer to the License for details. You may not use this file except in compliance with the License. |
| @@ -9,11 +9,8 @@ | |||
| 9 | */ | 9 | */ |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | - | ||
| 13 | - | ||
| 14 | 12 | ||
| 15 | -#include "level0/right_shift.h" | 13 | +#include "math/right_shift/op_api/right_shift.h" |
| 16 | - | ||
| 17 | 14 | ||
| 18 | using namespace op; | 15 | using namespace op; |
| 19 | using namespace std; | 16 | using namespace std; |
| @@ -22,58 +19,64 @@ const int64_t DATA_SIZE = 24; | |||
| 22 | 19 | ||
| 23 | class RightShiftTest : public ::testing::Test { | 20 | class RightShiftTest : public ::testing::Test { |
| 24 | public: | 21 | public: |
| 25 | - RightShiftTest() : exe(nullptr) { | 22 | + RightShiftTest() : exe(nullptr) |
| 26 | - } | 23 | + {} |
| 27 | 24 | ||
| 28 | - aclTensor* CreateAclTensor(std::vector<int64_t> shape, aclDataType dtype) { | 25 | + aclTensor* CreateAclTensor(std::vector<int64_t> shape, aclDataType dtype) |
| 29 | - return aclCreateTensor(shape.data(), shape.size(), dtype, nullptr, 0, ACL_FORMAT_ND, shape.data(), shape.size(), | 26 | + { |
| 30 | - data); | 27 | + return aclCreateTensor( |
| 31 | - } | 28 | + shape.data(), shape.size(), dtype, nullptr, 0, ACL_FORMAT_ND, shape.data(), shape.size(), data); |
| 29 | + } | ||
| 32 | 30 | ||
| 33 | - void Clear() { | 31 | + void Clear() |
| 34 | - exe->kernelLaunchObjList_.clear(); | 32 | + {} |
| 35 | - } | ||
| 36 | 33 | ||
| 37 | - void SetUp() override { | 34 | + void SetUp() override |
| 38 | - auto executor = &exe; | 35 | + { |
| 39 | - auto unique_executor = CREATE_EXECUTOR(); | 36 | + auto executor = &exe; |
| 40 | - unique_executor.ReleaseTo(executor); | 37 | + auto unique_executor = CREATE_EXECUTOR(); |
| 41 | - } | 38 | + unique_executor.ReleaseTo(executor); |
| 39 | + } | ||
| 42 | 40 | ||
| 43 | - void TearDown() override { | 41 | + void TearDown() override |
| 44 | - delete exe; | 42 | + { |
| 45 | - } | 43 | + delete exe; |
| 44 | + } | ||
| 46 | 45 | ||
| 47 | public: | 46 | public: |
| 48 | - aclOpExecutor* exe; | 47 | + aclOpExecutor* exe; |
| 49 | - int64_t data[DATA_SIZE] = {1}; | 48 | + int64_t data[DATA_SIZE] = {1}; |
| 50 | }; | 49 | }; |
| 51 | 50 | ||
| 52 | -TEST_F(RightShiftTest, RightShiftTest_SUCC) { | 51 | +TEST_F(RightShiftTest, RightShiftTest_SUCC) |
| 53 | - auto x = CreateAclTensor({16}, ACL_INT32); | 52 | +{ |
| 54 | - auto y = CreateAclTensor({1}, ACL_INT32); | 53 | + auto x = CreateAclTensor({16}, ACL_INT32); |
| 55 | - auto z = l0op::RightShift(x, y, exe); | 54 | + auto y = CreateAclTensor({1}, ACL_INT32); |
| 56 | - ASSERT_NE(y, nullptr); | 55 | + auto z = l0op::RightShift(x, y, exe); |
| 56 | + ASSERT_NE(y, nullptr); | ||
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | -TEST_F(RightShiftTest, RightShiftTest_FAILED_1) { | 59 | +TEST_F(RightShiftTest, RightShiftTest_FAILED_1) |
| 60 | - auto x = CreateAclTensor({16}, ACL_FLOAT); | 60 | +{ |
| 61 | - auto y = CreateAclTensor({1}, ACL_INT32); | 61 | + auto x = CreateAclTensor({16}, ACL_FLOAT); |
| 62 | - auto z = l0op::RightShift(x, y, exe); | 62 | + auto y = CreateAclTensor({1}, ACL_INT32); |
| 63 | - ASSERT_NE(y, nullptr); | 63 | + auto z = l0op::RightShift(x, y, exe); |
| 64 | + ASSERT_NE(y, nullptr); | ||
| 64 | } | 65 | } |
| 65 | 66 | ||
| 66 | -TEST_F(RightShiftTest, RightShiftTest_FAILED_2) { | 67 | +TEST_F(RightShiftTest, RightShiftTest_FAILED_2) |
| 67 | - auto x = CreateAclTensor({16}, ACL_INT32); | 68 | +{ |
| 68 | - auto y = CreateAclTensor({1}, ACL_FLOAT); | 69 | + auto x = CreateAclTensor({16}, ACL_INT32); |
| 69 | - auto z = l0op::RightShift(x, y, exe); | 70 | + auto y = CreateAclTensor({1}, ACL_FLOAT); |
| 70 | - ASSERT_NE(y, nullptr); | 71 | + auto z = l0op::RightShift(x, y, exe); |
| 72 | + ASSERT_NE(y, nullptr); | ||
| 71 | } | 73 | } |
| 72 | 74 | ||
| 73 | -TEST_F(RightShiftTest, RightShiftTest_SUCC_950) { | 75 | +TEST_F(RightShiftTest, RightShiftTest_SUCC_950) |
| 74 | - UtMock::GetInstance().SetSocVersion("ASCEND950PR_9589"); | 76 | +{ |
| 75 | - auto x = CreateAclTensor({16}, ACL_INT32); | 77 | + SetPlatformSocVersion(SocVersion::ASCEND950); |
| 76 | - auto y = CreateAclTensor({1}, ACL_INT32); | 78 | + auto x = CreateAclTensor({16}, ACL_INT32); |
| 77 | - auto z = l0op::RightShift(x, y, exe); | 79 | + auto y = CreateAclTensor({1}, ACL_INT32); |
| 78 | - ASSERT_NE(y, nullptr); | 80 | + auto z = l0op::RightShift(x, y, exe); |
| 81 | + ASSERT_NE(y, nullptr); | ||
| 79 | } | 82 | } |
| @@ -0,0 +1,212 @@ | |||
| 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 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +using namespace std; | ||
| 17 | +using namespace op; | ||
| 18 | + | ||
| 19 | +class l2_right_shift_test : public testing::Test { | ||
| 20 | +protected: | ||
| 21 | + static void SetUpTestCase() | ||
| 22 | + { | ||
| 23 | + cout << "tensor_right_shift_test SetUp" << endl; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + static void TearDownTestCase() | ||
| 27 | + { | ||
| 28 | + cout << "tensor_right_shift_test TearDown" << endl; | ||
| 29 | + } | ||
| 30 | +}; | ||
| 31 | + | ||
| 32 | +// 正常调用流程 | ||
| 33 | +TEST_F(l2_right_shift_test, normal_success) | ||
| 34 | +{ | ||
| 35 | + auto inputDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40}); | ||
| 36 | + auto shiftBitsDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1, 2, 3, 4}); | ||
| 37 | + auto outDesc = TensorDesc(inputDesc); | ||
| 38 | + uint64_t workspace_size = 0; | ||
| 39 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 40 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 41 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +// 输入input为空指针 | ||
| 45 | +TEST_F(l2_right_shift_test, nullptr_input) | ||
| 46 | +{ | ||
| 47 | + auto inputDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40}); | ||
| 48 | + auto shiftBitsDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1, 2, 3, 4}); | ||
| 49 | + auto outDesc = TensorDesc(inputDesc); | ||
| 50 | + uint64_t workspace_size = 0; | ||
| 51 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(nullptr, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 52 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 53 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_NULLPTR); | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +// 输入shiftBits为空指针 | ||
| 57 | +TEST_F(l2_right_shift_test, nullptr_shiftBits) | ||
| 58 | +{ | ||
| 59 | + auto inputDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40}); | ||
| 60 | + auto shiftBitsDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1, 2, 3, 4}); | ||
| 61 | + auto outDesc = TensorDesc(inputDesc); | ||
| 62 | + uint64_t workspace_size = 0; | ||
| 63 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, nullptr), OUTPUT(outDesc)); | ||
| 64 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 65 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_NULLPTR); | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | +// 输入out为空指针 | ||
| 69 | +TEST_F(l2_right_shift_test, nullptr_out) | ||
| 70 | +{ | ||
| 71 | + auto inputDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40}); | ||
| 72 | + auto shiftBitsDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1, 2, 3, 4}); | ||
| 73 | + auto outDesc = TensorDesc(inputDesc); | ||
| 74 | + uint64_t workspace_size = 0; | ||
| 75 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(nullptr)); | ||
| 76 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 77 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_NULLPTR); | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | +// 输入类型不支持 | ||
| 81 | +TEST_F(l2_right_shift_test, type_unsupport) | ||
| 82 | +{ | ||
| 83 | + auto inputDesc = TensorDesc({1, 4}, ACL_FLOAT, ACL_FORMAT_ND).Value(vector<float>{10, 20, 30, 40}); | ||
| 84 | + auto shiftBitsDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1, 2, 3, 4}); | ||
| 85 | + auto outDesc = TensorDesc(inputDesc); | ||
| 86 | + uint64_t workspace_size = 0; | ||
| 87 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 88 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 89 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +// 输入类型可以正常类型推导 | ||
| 93 | +TEST_F(l2_right_shift_test, type_promote_normal) | ||
| 94 | +{ | ||
| 95 | + auto inputDesc = TensorDesc({1, 4}, ACL_INT64, ACL_FORMAT_ND).Value(vector<int64_t>{10, 20, 30, 40}); | ||
| 96 | + auto shiftBitsDesc = TensorDesc({1, 4}, ACL_INT32, ACL_FORMAT_ND).Value(vector<int32_t>{1, 2, 3, 4}); | ||
| 97 | + auto outDesc = TensorDesc(inputDesc); | ||
| 98 | + uint64_t workspace_size = 0; | ||
| 99 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 100 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 101 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 102 | +} | ||
| 103 | + | ||
| 104 | +// 输入类型不支持类型推导 | ||
| 105 | +TEST_F(l2_right_shift_test, type_promote_unsupport) | ||
| 106 | +{ | ||
| 107 | + auto inputDesc = TensorDesc({1, 4}, ACL_UINT16, ACL_FORMAT_ND).Value(vector<uint16_t>{10, 20, 30, 40}); | ||
| 108 | + auto shiftBitsDesc = TensorDesc({1, 4}, ACL_UINT32, ACL_FORMAT_ND).Value(vector<uint32_t>{1, 2, 3, 4}); | ||
| 109 | + auto outDesc = TensorDesc(inputDesc); | ||
| 110 | + uint64_t workspace_size = 0; | ||
| 111 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 112 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 113 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 114 | +} | ||
| 115 | + | ||
| 116 | +// 输入类型推导结果无法转换为out类型-不存在,整型可以向任何类型转换,结果应该为true | ||
| 117 | +TEST_F(l2_right_shift_test, type_promote_can_not_cast_to_out) | ||
| 118 | +{ | ||
| 119 | + auto inputDesc = TensorDesc({1, 4}, ACL_INT32, ACL_FORMAT_ND).Value(vector<int32_t>{10, 20, 30, 40}); | ||
| 120 | + auto shiftBitsDesc = TensorDesc({1, 4}, ACL_INT64, ACL_FORMAT_ND).Value(vector<int64_t>{1, 2, 3, 4}); | ||
| 121 | + auto outDesc = TensorDesc({1, 4}, ACL_UINT16, ACL_FORMAT_ND).Value(vector<int64_t>{0, 0, 0, 0}); | ||
| 122 | + uint64_t workspace_size = 0; | ||
| 123 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 124 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 125 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +// 输入shape为空 | ||
| 129 | +TEST_F(l2_right_shift_test, shape_empty_input) | ||
| 130 | +{ | ||
| 131 | + auto inputDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40}); | ||
| 132 | + auto shiftBitsDesc = TensorDesc({}, ACL_INT8, ACL_FORMAT_ND); | ||
| 133 | + auto outDesc = TensorDesc(inputDesc); | ||
| 134 | + uint64_t workspace_size = 0; | ||
| 135 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 136 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 137 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 138 | +} | ||
| 139 | + | ||
| 140 | +// 输入input shape维度超过8 | ||
| 141 | +TEST_F(l2_right_shift_test, input_shape_dim_over_8) | ||
| 142 | +{ | ||
| 143 | + auto inputDesc = | ||
| 144 | + TensorDesc({1, 1, 1, 1, 1, 1, 1, 1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40}); | ||
| 145 | + auto shiftBitsDesc = TensorDesc({1}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1}); | ||
| 146 | + auto outDesc = TensorDesc(inputDesc); | ||
| 147 | + uint64_t workspace_size = 0; | ||
| 148 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 149 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 150 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +// 输入shiftbits shape维度超过8 | ||
| 154 | +TEST_F(l2_right_shift_test, shiftBits_shape_dim_over_8) | ||
| 155 | +{ | ||
| 156 | + auto inputDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40}); | ||
| 157 | + auto shiftBitsDesc = | ||
| 158 | + TensorDesc({1, 1, 1, 1, 1, 1, 1, 1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1, 1, 1, 1}); | ||
| 159 | + auto outDesc = TensorDesc(inputDesc); | ||
| 160 | + uint64_t workspace_size = 0; | ||
| 161 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 162 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 163 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 164 | +} | ||
| 165 | + | ||
| 166 | +// 输入shape与输出shape不一致 | ||
| 167 | +TEST_F(l2_right_shift_test, shape_input_noeq_out) | ||
| 168 | +{ | ||
| 169 | + auto inputDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40}); | ||
| 170 | + auto shiftBitsDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1, 1, 1, 1}); | ||
| 171 | + auto outDesc = TensorDesc({4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40}); | ||
| 172 | + uint64_t workspace_size = 0; | ||
| 173 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 174 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 175 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 176 | +} | ||
| 177 | + | ||
| 178 | +// 输入shape支持广播 | ||
| 179 | +TEST_F(l2_right_shift_test, shape_broadcast_normal) | ||
| 180 | +{ | ||
| 181 | + auto inputDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40}); | ||
| 182 | + auto shiftBitsDesc = TensorDesc({1}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1}); | ||
| 183 | + auto outDesc = TensorDesc(inputDesc); | ||
| 184 | + uint64_t workspace_size = 0; | ||
| 185 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 186 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 187 | + EXPECT_EQ(aclRet, ACL_SUCCESS); | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +// 输入shape不支持广播-维度数一致,大小不一致,且没有等于1的维度 | ||
| 191 | +TEST_F(l2_right_shift_test, shape_broadcast_unsupport) | ||
| 192 | +{ | ||
| 193 | + auto inputDesc = TensorDesc({2, 3}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10, 20, 30, 40, 50, 60}); | ||
| 194 | + auto shiftBitsDesc = TensorDesc({3, 2}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1, 2, 3, 4, 1, 2}); | ||
| 195 | + auto outDesc = TensorDesc(inputDesc); | ||
| 196 | + uint64_t workspace_size = 0; | ||
| 197 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 198 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 199 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 200 | +} | ||
| 201 | + | ||
| 202 | +// 输入shape广播后结果与out的shape不一致 | ||
| 203 | +TEST_F(l2_right_shift_test, shape_broadcast_not_equal_with_out) | ||
| 204 | +{ | ||
| 205 | + auto inputDesc = TensorDesc({1}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{10}); | ||
| 206 | + auto shiftBitsDesc = TensorDesc({1, 4}, ACL_INT8, ACL_FORMAT_ND).Value(vector<int8_t>{1, 1, 1, 1}); | ||
| 207 | + auto outDesc = TensorDesc(inputDesc); | ||
| 208 | + uint64_t workspace_size = 0; | ||
| 209 | + auto ut = OP_API_UT(aclnnRightShift, INPUT(inputDesc, shiftBitsDesc), OUTPUT(outDesc)); | ||
| 210 | + aclnnStatus aclRet = ut.TestGetWorkspaceSize(&workspace_size); | ||
| 211 | + EXPECT_EQ(aclRet, ACLNN_ERR_PARAM_INVALID); | ||
| 212 | +} | ||
| @@ -0,0 +1,238 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | +using namespace std; | ||
| 19 | + | ||
| 20 | +class RightShiftTilingTest : public testing::Test { | ||
| 21 | +protected: | ||
| 22 | + static void SetUpTestCase() | ||
| 23 | + { | ||
| 24 | + std::cout << "RightShiftTilingTest SetUp" << std::endl; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + static void TearDownTestCase() | ||
| 28 | + { | ||
| 29 | + std::cout << "RightShiftTilingTest TearDown" << std::endl; | ||
| 30 | + } | ||
| 31 | +}; | ||
| 32 | + | ||
| 33 | +TEST_F(RightShiftTilingTest, right_shift_test_tiling_int8) | ||
| 34 | +{ | ||
| 35 | + Ops::Base::BroadcastCompileInfo compileInfo; | ||
| 36 | + compileInfo.coreNum = 64; | ||
| 37 | + compileInfo.ubSize = 253952; | ||
| 38 | + | ||
| 39 | + gert::TilingContextPara tilingContextPara( | ||
| 40 | + "RightShift", | ||
| 41 | + { | ||
| 42 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 43 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 44 | + }, | ||
| 45 | + { | ||
| 46 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 47 | + }, | ||
| 48 | + {}, &compileInfo); | ||
| 49 | + | ||
| 50 | + uint64_t expectTilingKey = 65544; | ||
| 51 | + string expectTilingData = "8192 34359738880 "; | ||
| 52 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 53 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 54 | +} | ||
| 55 | + | ||
| 56 | +TEST_F(RightShiftTilingTest, right_shift_test_tiling_uint8) | ||
| 57 | +{ | ||
| 58 | + Ops::Base::BroadcastCompileInfo compileInfo; | ||
| 59 | + compileInfo.coreNum = 64; | ||
| 60 | + compileInfo.ubSize = 253952; | ||
| 61 | + | ||
| 62 | + gert::TilingContextPara tilingContextPara( | ||
| 63 | + "RightShift", | ||
| 64 | + { | ||
| 65 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT8, ge::FORMAT_ND}, | ||
| 66 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT8, ge::FORMAT_ND}, | ||
| 67 | + }, | ||
| 68 | + { | ||
| 69 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT8, ge::FORMAT_ND}, | ||
| 70 | + }, | ||
| 71 | + {}, &compileInfo); | ||
| 72 | + | ||
| 73 | + uint64_t expectTilingKey = 131080; | ||
| 74 | + string expectTilingData = "8192 34359738880 "; | ||
| 75 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 76 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 77 | +} | ||
| 78 | + | ||
| 79 | +TEST_F(RightShiftTilingTest, right_shift_test_tiling_int16) | ||
| 80 | +{ | ||
| 81 | + Ops::Base::BroadcastCompileInfo compileInfo; | ||
| 82 | + compileInfo.coreNum = 64; | ||
| 83 | + compileInfo.ubSize = 253952; | ||
| 84 | + | ||
| 85 | + gert::TilingContextPara tilingContextPara( | ||
| 86 | + "RightShift", | ||
| 87 | + { | ||
| 88 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT16, ge::FORMAT_ND}, | ||
| 89 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT16, ge::FORMAT_ND}, | ||
| 90 | + }, | ||
| 91 | + { | ||
| 92 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT16, ge::FORMAT_ND}, | ||
| 93 | + }, | ||
| 94 | + {}, &compileInfo); | ||
| 95 | + | ||
| 96 | + uint64_t expectTilingKey = 196616; | ||
| 97 | + string expectTilingData = "8192 68719476992 "; | ||
| 98 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 99 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 100 | +} | ||
| 101 | + | ||
| 102 | +TEST_F(RightShiftTilingTest, right_shift_test_tiling_uint16) | ||
| 103 | +{ | ||
| 104 | + Ops::Base::BroadcastCompileInfo compileInfo; | ||
| 105 | + compileInfo.coreNum = 64; | ||
| 106 | + compileInfo.ubSize = 253952; | ||
| 107 | + | ||
| 108 | + gert::TilingContextPara tilingContextPara( | ||
| 109 | + "RightShift", | ||
| 110 | + { | ||
| 111 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT16, ge::FORMAT_ND}, | ||
| 112 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT16, ge::FORMAT_ND}, | ||
| 113 | + }, | ||
| 114 | + { | ||
| 115 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT16, ge::FORMAT_ND}, | ||
| 116 | + }, | ||
| 117 | + {}, &compileInfo); | ||
| 118 | + | ||
| 119 | + uint64_t expectTilingKey = 262152; | ||
| 120 | + string expectTilingData = "8192 68719476992 "; | ||
| 121 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 122 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 123 | +} | ||
| 124 | + | ||
| 125 | +TEST_F(RightShiftTilingTest, right_shift_test_tiling_int32) | ||
| 126 | +{ | ||
| 127 | + Ops::Base::BroadcastCompileInfo compileInfo; | ||
| 128 | + compileInfo.coreNum = 64; | ||
| 129 | + compileInfo.ubSize = 253952; | ||
| 130 | + | ||
| 131 | + gert::TilingContextPara tilingContextPara( | ||
| 132 | + "RightShift", | ||
| 133 | + { | ||
| 134 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT32, ge::FORMAT_ND}, | ||
| 135 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT32, ge::FORMAT_ND}, | ||
| 136 | + }, | ||
| 137 | + { | ||
| 138 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT32, ge::FORMAT_ND}, | ||
| 139 | + }, | ||
| 140 | + {}, &compileInfo); | ||
| 141 | + | ||
| 142 | + uint64_t expectTilingKey = 327688; | ||
| 143 | + string expectTilingData = "8192 137438953600 "; | ||
| 144 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 145 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 146 | +} | ||
| 147 | + | ||
| 148 | +TEST_F(RightShiftTilingTest, right_shift_test_tiling_uint32) | ||
| 149 | +{ | ||
| 150 | + Ops::Base::BroadcastCompileInfo compileInfo; | ||
| 151 | + compileInfo.coreNum = 64; | ||
| 152 | + compileInfo.ubSize = 253952; | ||
| 153 | + | ||
| 154 | + gert::TilingContextPara tilingContextPara( | ||
| 155 | + "RightShift", | ||
| 156 | + { | ||
| 157 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT32, ge::FORMAT_ND}, | ||
| 158 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT32, ge::FORMAT_ND}, | ||
| 159 | + }, | ||
| 160 | + { | ||
| 161 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT32, ge::FORMAT_ND}, | ||
| 162 | + }, | ||
| 163 | + {}, &compileInfo); | ||
| 164 | + | ||
| 165 | + uint64_t expectTilingKey = 393224; | ||
| 166 | + string expectTilingData = "8192 137438953600 "; | ||
| 167 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 168 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 169 | +} | ||
| 170 | + | ||
| 171 | +TEST_F(RightShiftTilingTest, right_shift_test_tiling_int64) | ||
| 172 | +{ | ||
| 173 | + Ops::Base::BroadcastCompileInfo compileInfo; | ||
| 174 | + compileInfo.coreNum = 64; | ||
| 175 | + compileInfo.ubSize = 253952; | ||
| 176 | + | ||
| 177 | + gert::TilingContextPara tilingContextPara( | ||
| 178 | + "RightShift", | ||
| 179 | + { | ||
| 180 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 181 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 182 | + }, | ||
| 183 | + { | ||
| 184 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT64, ge::FORMAT_ND}, | ||
| 185 | + }, | ||
| 186 | + {}, &compileInfo); | ||
| 187 | + | ||
| 188 | + uint64_t expectTilingKey = 458760; | ||
| 189 | + string expectTilingData = "8192 137438953600 "; | ||
| 190 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 191 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 192 | +} | ||
| 193 | + | ||
| 194 | +TEST_F(RightShiftTilingTest, right_shift_test_tiling_uint64) | ||
| 195 | +{ | ||
| 196 | + Ops::Base::BroadcastCompileInfo compileInfo; | ||
| 197 | + compileInfo.coreNum = 64; | ||
| 198 | + compileInfo.ubSize = 253952; | ||
| 199 | + | ||
| 200 | + gert::TilingContextPara tilingContextPara( | ||
| 201 | + "RightShift", | ||
| 202 | + { | ||
| 203 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT64, ge::FORMAT_ND}, | ||
| 204 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT64, ge::FORMAT_ND}, | ||
| 205 | + }, | ||
| 206 | + { | ||
| 207 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_UINT64, ge::FORMAT_ND}, | ||
| 208 | + }, | ||
| 209 | + {}, &compileInfo); | ||
| 210 | + | ||
| 211 | + uint64_t expectTilingKey = 524296; | ||
| 212 | + string expectTilingData = "8192 137438953600 "; | ||
| 213 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 214 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_SUCCESS, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 215 | +} | ||
| 216 | + | ||
| 217 | +TEST_F(RightShiftTilingTest, right_shift_test_tiling_invalid_dtype) | ||
| 218 | +{ | ||
| 219 | + Ops::Base::BroadcastCompileInfo compileInfo; | ||
| 220 | + compileInfo.coreNum = 64; | ||
| 221 | + compileInfo.ubSize = 253952; | ||
| 222 | + | ||
| 223 | + gert::TilingContextPara tilingContextPara( | ||
| 224 | + "RightShift", | ||
| 225 | + { | ||
| 226 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 227 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 228 | + }, | ||
| 229 | + { | ||
| 230 | + {{{1, 64, 2, 64}, {1, 64, 2, 64}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 231 | + }, | ||
| 232 | + {}, &compileInfo); | ||
| 233 | + | ||
| 234 | + uint64_t expectTilingKey = 65536; | ||
| 235 | + string expectTilingData = ""; | ||
| 236 | + std::vector<size_t> expectWorkspaces = {16777216}; | ||
| 237 | + ExecuteTestCase(tilingContextPara, ge::GRAPH_FAILED, expectTilingKey, expectTilingData, expectWorkspaces); | ||
| 238 | +} | ||
| @@ -0,0 +1,59 @@ | |||
| 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 | + | ||
| 12 | + | ||
| 13 | + | ||
| 14 | + | ||
| 15 | + | ||
| 16 | +using namespace ge; | ||
| 17 | + | ||
| 18 | +class RightShiftInferShape : public testing::Test { | ||
| 19 | +protected: | ||
| 20 | + static void SetUpTestCase() | ||
| 21 | + { | ||
| 22 | + std::cout << "RightShift InferShape SetUp" << std::endl; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + static void TearDownTestCase() | ||
| 26 | + { | ||
| 27 | + std::cout << "RightShift InferShape TearDown" << std::endl; | ||
| 28 | + } | ||
| 29 | +}; | ||
| 30 | + | ||
| 31 | +TEST_F(RightShiftInferShape, right_shift_infershape_test) | ||
| 32 | +{ | ||
| 33 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 34 | + "RightShift", | ||
| 35 | + { | ||
| 36 | + {{{4, 3, 4}, {4, 3, 4}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 37 | + {{{4, 3, 4}, {4, 3, 4}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 38 | + }, | ||
| 39 | + { | ||
| 40 | + {{{}, {}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 41 | + }); | ||
| 42 | + std::vector<std::vector<int64_t>> expectOutputShape = {{4, 3, 4}}; | ||
| 43 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +TEST_F(RightShiftInferShape, right_shift_infershape_dynamic_test) | ||
| 47 | +{ | ||
| 48 | + gert::InfershapeContextPara infershapeContextPara( | ||
| 49 | + "RightShift", | ||
| 50 | + { | ||
| 51 | + {{{-1}, {-1}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 52 | + {{{-1}, {-1}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 53 | + }, | ||
| 54 | + { | ||
| 55 | + {{{}, {}}, ge::DT_INT8, ge::FORMAT_ND}, | ||
| 56 | + }); | ||
| 57 | + std::vector<std::vector<int64_t>> expectOutputShape = {{-1}}; | ||
| 58 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 59 | +} | ||
| @@ -24,6 +24,7 @@ operator_group_1: | |||
| 24 | - arg_min_with_value | 24 | - arg_min_with_value |
| 25 | - assign_add | 25 | - assign_add |
| 26 | - assign_sub | 26 | - assign_sub |
| 27 | + - atan | ||
| 27 | - axpy | 28 | - axpy |
| 28 | - axpy_v2 | 29 | - axpy_v2 |
| 29 | - bias_add | 30 | - bias_add |
| @@ -48,8 +49,10 @@ operator_group_1: | |||
| 48 | - dynamic_partition | 49 | - dynamic_partition |
| 49 | - dynamic_stitch | 50 | - dynamic_stitch |
| 50 | - equal | 51 | - equal |
| 52 | + - erf | ||
| 51 | - exp | 53 | - exp |
| 52 | - expand | 54 | - expand |
| 55 | + - expm1 | ||
| 53 | - exp_segsum_grad | 56 | - exp_segsum_grad |
| 54 | - eye | 57 | - eye |
| 55 | - floor | 58 | - floor |
| @@ -89,6 +92,7 @@ operator_group_2: | |||
| 89 | - mul | 92 | - mul |
| 90 | - muls | 93 | - muls |
| 91 | - mul_addn | 94 | - mul_addn |
| 95 | + - nan_to_num | ||
| 92 | - neg | 96 | - neg |
| 93 | - non_finite_check | 97 | - non_finite_check |
| 94 | - not_equal | 98 | - not_equal |
| @@ -113,6 +117,7 @@ operator_group_3: | |||
| 113 | - reduce_log_sum_exp | 117 | - reduce_log_sum_exp |
| 114 | operator_group_4: | 118 | operator_group_4: |
| 115 | - rfft1_d | 119 | - rfft1_d |
| 120 | + - right_shift | ||
| 116 | - round | 121 | - round |
| 117 | - rsqrt | 122 | - rsqrt |
| 118 | - rsqrt_grad | 123 | - rsqrt_grad |