Merged
[Fix] 长尾算子加固:ForeachDivList 契约对齐社区 issue(out shape size≥x1) #13515
wenqi_wuAdd on 19 days ago
[Fix] 长尾算子加固:ForeachDivList 契约对齐社区 issue(out shape size≥x1) #13515
Merged
Total: 8 files changed+317-7
| @@ -63,7 +63,7 @@ | |||
| 63 | <tr> | 63 | <tr> |
| 64 | <td>y</td> | 64 | <td>y</td> |
| 65 | <td>输出</td> | 65 | <td>输出</td> |
| 66 | - <td>表示除法运算的输出张量列表,对应公式中的`y`。数据类型和数据格式与入参`x1`的数据类型和数据格式一致,shape与入参`x1`的shape一致。该参数中所有Tensor的数据类型保持一致。</td> | 66 | + <td>表示除法运算的输出张量列表,对应公式中的`y`。数据类型和数据格式与入参`x1`的数据类型和数据格式一致,shape size大于等于入参`x1`的shape size。该参数中所有Tensor的数据类型保持一致。</td> |
| 67 | <td>FLOAT32、FLOAT16、BFLOAT16</td> | 67 | <td>FLOAT32、FLOAT16、BFLOAT16</td> |
| 68 | <td>ND</td> | 68 | <td>ND</td> |
| 69 | </tr> | 69 | </tr> |
| @@ -107,7 +107,7 @@ aclnnStatus aclnnForeachDivList( | |||
| 107 | <td>out(aclTensorList*)</td> | 107 | <td>out(aclTensorList*)</td> |
| 108 | <td>输出</td> | 108 | <td>输出</td> |
| 109 | <td>表示除法运算的输出张量列表,对应公式中的`y`。</td> | 109 | <td>表示除法运算的输出张量列表,对应公式中的`y`。</td> |
| 110 | - <td><ul><li>支持空Tensor。</li><li>该参数中所有Tensor的数据类型保持一致。</li><li>数据类型和数据格式与入参`x1`的数据类型和数据格式一致,shape与入参`x1`的shape一致。</li></ul></td> | 110 | + <td><ul><li>支持空Tensor。</li><li>该参数中所有Tensor的数据类型保持一致。</li><li>数据类型和数据格式与入参`x1`的数据类型和数据格式一致,shape size大于等于入参`x1`的shape size。</li></ul></td> |
| 111 | <td>BFLOAT16、FLOAT16、FLOAT32</td> | 111 | <td>BFLOAT16、FLOAT16、FLOAT32</td> |
| 112 | <td>ND</td> | 112 | <td>ND</td> |
| 113 | <td>0-8</td> | 113 | <td>0-8</td> |
| @@ -172,7 +172,7 @@ aclnnStatus aclnnForeachDivList( | |||
| 172 | <td>x1、x2、out的数据格式不在支持的范围之内。</td> | 172 | <td>x1、x2、out的数据格式不在支持的范围之内。</td> |
| 173 | </tr> | 173 | </tr> |
| 174 | <tr> | 174 | <tr> |
| 175 | - <td>x1、x2、out的shape不满足约束。</td> | 175 | + <td>x1、x2、out的shape不满足约束(含out的shape size小于x1的shape size)。</td> |
| 176 | </tr> | 176 | </tr> |
| 177 | <tr> | 177 | <tr> |
| 178 | <td>x1、x2或out中的Tensor的数据类型不一致。</td> | 178 | <td>x1、x2或out中的Tensor的数据类型不一致。</td> |
| @@ -151,8 +151,11 @@ static ge::graphStatus CheckTensorListInfo(gert::TilingContext* context, uint64_ | |||
| 151 | OP_LOGE(context, "The dim num of y[%lu] must be less than or equal to 8, but got %zu.", i, | 151 | OP_LOGE(context, "The dim num of y[%lu] must be less than or equal to 8, but got %zu.", i, |
| 152 | outShape.GetDimNum()), | 152 | outShape.GetDimNum()), |
| 153 | return ge::GRAPH_FAILED); | 153 | return ge::GRAPH_FAILED); |
| 154 | - OP_CHECK_IF(outShape.GetShapeSize() != x1Shape.GetShapeSize(), | 154 | + OP_CHECK_IF(outShape.GetShapeSize() < x1Shape.GetShapeSize(), |
| 155 | - OP_LOGE(context, "The shape size of y[%lu] must be the same as that of x1[%lu].", i, i), | 155 | + OP_LOGE(context, |
| 156 | + "The shape size of y[%lu] must be greater than or equal to that of x1[%lu], but got " | ||
| 157 | + "%ld and %ld.", | ||
| 158 | + i, i, outShape.GetShapeSize(), x1Shape.GetShapeSize()), | ||
| 156 | return ge::GRAPH_FAILED); | 159 | return ge::GRAPH_FAILED); |
| 157 | auto outDescPtr = context->GetOutputDesc(i); | 160 | auto outDescPtr = context->GetOutputDesc(i); |
| 158 | OP_CHECK_NULL_WITH_CONTEXT(context, outDescPtr); | 161 | OP_CHECK_NULL_WITH_CONTEXT(context, outDescPtr); |
| @@ -143,11 +143,24 @@ static inline bool CheckShape(const aclTensorList* x1, const aclTensorList* x2, | |||
| 143 | // tensor 维度检查 | 143 | // tensor 维度检查 |
| 144 | for (uint64_t i = 0; i < x1->Size(); i++) { | 144 | for (uint64_t i = 0; i < x1->Size(); i++) { |
| 145 | OP_CHECK_MAX_DIM((*x1)[i], MAX_SUPPORT_DIMS_NUMS, return false); | 145 | OP_CHECK_MAX_DIM((*x1)[i], MAX_SUPPORT_DIMS_NUMS, return false); |
| 146 | + OP_CHECK_MAX_DIM((*out)[i], MAX_SUPPORT_DIMS_NUMS, return false); | ||
| 146 | } | 147 | } |
| 147 | 148 | ||
| 148 | - // self和out的shape必须一致 | 149 | + // out的元素数必须大于等于x1(文档:out的shape size大于等于入参x1的shape size) |
| 149 | for (uint64_t i = 0; i < x1->Size(); i++) { | 150 | for (uint64_t i = 0; i < x1->Size(); i++) { |
| 150 | - OP_CHECK_SHAPE_NOT_EQUAL((*x1)[i], (*out)[i], return false); | 151 | + const int64_t x1Size = (*x1)[i]->GetViewShape().GetShapeSize(); |
| 152 | + const int64_t outSize = (*out)[i]->GetViewShape().GetShapeSize(); | ||
| 153 | + if (outSize < x1Size) { | ||
| 154 | + const std::string reason = ("The shape size of the " + std::to_string(i) + | ||
| 155 | + "th tensor in out must be greater than or equal to that of x1, but got " + | ||
| 156 | + std::to_string(outSize) + " and " + std::to_string(x1Size) + "."); | ||
| 157 | + OP_LOGE_WITHOUT_REPORT(ACLNN_ERR_PARAM_INVALID, "%s", reason.c_str()); | ||
| 158 | + REPORT_PREDEFINED_ERR_MSG("EZ0015", | ||
| 159 | + (std::vector<const char*>{"param_name", "op_name", "incorrect_size", "reason"}), | ||
| 160 | + (std::vector<const char*>{"out", "aclnnForeachDivList", | ||
| 161 | + (std::to_string(outSize)).c_str(), reason.c_str()})); | ||
| 162 | + return false; | ||
| 163 | + } | ||
| 151 | } | 164 | } |
| 152 | return true; | 165 | return true; |
| 153 | } | 166 | } |
| @@ -11,7 +11,16 @@ | |||
| 11 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) |
| 12 | message(STATUS "=== Debug: CURRENT_DIRS =${CURRENT_DIRS} ") | 12 | message(STATUS "=== Debug: CURRENT_DIRS =${CURRENT_DIRS} ") |
| 13 | 13 | ||
| 14 | +foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 15 | + if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 16 | + add_subdirectory(${SUB_DIR}) | ||
| 17 | + endif() | ||
| 18 | +endforeach() | ||
| 19 | + | ||
| 14 | if(UT_TEST_ALL OR OP_HOST_UT) | 20 | if(UT_TEST_ALL OR OP_HOST_UT) |
| 15 | add_modules_ut_sources(HOSTNAME ${OP_TILING_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | 21 | add_modules_ut_sources(HOSTNAME ${OP_TILING_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 16 | add_modules_ut_sources(HOSTNAME ${OP_INFERSHAPE_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | 22 | add_modules_ut_sources(HOSTNAME ${OP_INFERSHAPE_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) |
| 17 | endif() | 23 | endif() |
| 24 | +if(UT_TEST_ALL OR OP_API_UT) | ||
| 25 | + add_modules_ut_sources(HOSTNAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 26 | +endif() | ||
| @@ -120,8 +120,111 @@ static void RunTilingCase(ge::DataType dtype, uint64_t expectedTilingKey) | |||
| 120 | ASSERT_EQ(tiling_key, expectedTilingKey); | 120 | ASSERT_EQ(tiling_key, expectedTilingKey); |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | +static void RunTilingOutShapeCase(bool outLarger, ge::graphStatus expectedStatus) | ||
| 124 | +{ | ||
| 125 | + std::string op_type("ForeachDivList"); | ||
| 126 | + ASSERT_NE(gert::OpImplRegistry::GetInstance().GetOpImpl(op_type.c_str()), nullptr); | ||
| 127 | + auto tiling_func = gert::OpImplRegistry::GetInstance().GetOpImpl(op_type.c_str())->tiling; | ||
| 128 | + auto tiling_parse_func = gert::OpImplRegistry::GetInstance().GetOpImpl(op_type.c_str())->tiling_parse; | ||
| 129 | + | ||
| 130 | + std::string compile_info_string = R"({ | ||
| 131 | + "hardware_info": { | ||
| 132 | + "BT_SIZE": 0, | ||
| 133 | + "load3d_constraints": "1", | ||
| 134 | + "Intrinsic_fix_pipe_l0c2out": false, | ||
| 135 | + "Intrinsic_data_move_l12ub": true, | ||
| 136 | + "Intrinsic_data_move_l0c2ub": true, | ||
| 137 | + "Intrinsic_data_move_out2l1_nd2nz": false, | ||
| 138 | + "UB_SIZE": 1048576, | ||
| 139 | + "L2_SIZE": 33554432, | ||
| 140 | + "L1_SIZE": 524288, | ||
| 141 | + "L0A_SIZE": 65536, | ||
| 142 | + "L0B_SIZE": 65536, | ||
| 143 | + "L0C_SIZE": 131072, | ||
| 144 | + "CORE_NUM": 24 | ||
| 145 | + } | ||
| 146 | + })"; | ||
| 147 | + std::map<std::string, std::string> soc_infos; | ||
| 148 | + std::map<std::string, std::string> aicore_spec; | ||
| 149 | + std::map<std::string, std::string> intrinsics; | ||
| 150 | + GetPlatFormInfos(compile_info_string.c_str(), soc_infos, aicore_spec, intrinsics); | ||
| 151 | + for (auto& kv : soc_version_infos) { | ||
| 152 | + soc_infos[kv.first] = kv.second; | ||
| 153 | + } | ||
| 154 | + | ||
| 155 | + fe::PlatFormInfos platform_info; | ||
| 156 | + platform_info.Init(); | ||
| 157 | + struct ForeachDivListCompileInfo { | ||
| 158 | + int64_t coreNum = 24; | ||
| 159 | + int64_t ubSize = 1024 * 1024; | ||
| 160 | + } compile_info; | ||
| 161 | + | ||
| 162 | + auto kernel_holder = gert::KernelRunContextFaker() | ||
| 163 | + .KernelIONum(2, 1) | ||
| 164 | + .Inputs({const_cast<char*>(compile_info_string.c_str()), | ||
| 165 | + reinterpret_cast<void*>(&platform_info)}) | ||
| 166 | + .Outputs({&compile_info}) | ||
| 167 | + .Build(); | ||
| 168 | + | ||
| 169 | + ASSERT_TRUE(kernel_holder.GetContext<gert::TilingParseContext>()->GetPlatformInfo()->Init()); | ||
| 170 | + kernel_holder.GetContext<gert::TilingParseContext>()->GetPlatformInfo()->SetPlatformRes("SoCInfo", soc_infos); | ||
| 171 | + kernel_holder.GetContext<gert::TilingParseContext>()->GetPlatformInfo()->SetPlatformRes("AICoreSpec", aicore_spec); | ||
| 172 | + kernel_holder.GetContext<gert::TilingParseContext>()->GetPlatformInfo()->SetCoreNumByCoreType("AICore"); | ||
| 173 | + kernel_holder.GetContext<gert::TilingParseContext>()->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", | ||
| 174 | + intrinsics); | ||
| 175 | + | ||
| 176 | + ASSERT_EQ(tiling_parse_func(kernel_holder.GetContext<gert::KernelContext>()), ge::GRAPH_SUCCESS); | ||
| 177 | + | ||
| 178 | + auto param = gert::TilingData::CreateCap(4096); | ||
| 179 | + ASSERT_NE(param, nullptr); | ||
| 180 | + auto workspace_size_holer = gert::ContinuousVector::Create<size_t>(4096); | ||
| 181 | + auto ws_size = reinterpret_cast<gert::ContinuousVector*>(workspace_size_holer.get()); | ||
| 182 | + gert::StorageShape inputs1 = {{32, 4, 4, 4}, {32, 4, 4, 4}}; | ||
| 183 | + gert::StorageShape inputs2 = {{32, 4, 4, 4}, {32, 4, 4, 4}}; | ||
| 184 | + gert::StorageShape outputs = {{32, 4, 4, 4}, {32, 4, 4, 4}}; | ||
| 185 | + if (outLarger) { | ||
| 186 | + outputs = gert::StorageShape{{32, 4, 4, 8}, {32, 4, 4, 8}}; | ||
| 187 | + } else { | ||
| 188 | + outputs = gert::StorageShape{{32, 4, 4, 2}, {32, 4, 4, 2}}; | ||
| 189 | + } | ||
| 190 | + auto holder = gert::TilingContextFaker() | ||
| 191 | + .NodeIoNum(2, 1) | ||
| 192 | + .IrInstanceNum({1, 1}) | ||
| 193 | + .InputShapes({&inputs1, &inputs2}) | ||
| 194 | + .OutputShapes({&outputs}) | ||
| 195 | + .CompileInfo(&compile_info) | ||
| 196 | + .PlatformInfo(reinterpret_cast<char*>(&platform_info)) | ||
| 197 | + .NodeInputTd(0, ge::DT_FLOAT, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 198 | + .NodeInputTd(1, ge::DT_FLOAT, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 199 | + .NodeOutputTd(0, ge::DT_FLOAT, ge::FORMAT_ND, ge::FORMAT_ND) | ||
| 200 | + .TilingData(param.get()) | ||
| 201 | + .Workspace(ws_size) | ||
| 202 | + .Build(); | ||
| 203 | + | ||
| 204 | + gert::TilingContext* tiling_context = holder.GetContext<gert::TilingContext>(); | ||
| 205 | + ASSERT_NE(tiling_context->GetPlatformInfo(), nullptr); | ||
| 206 | + holder.GetContext<gert::TilingContext>()->GetPlatformInfo()->SetPlatformRes("SoCInfo", soc_infos); | ||
| 207 | + holder.GetContext<gert::TilingContext>()->GetPlatformInfo()->SetPlatformRes("AICoreSpec", aicore_spec); | ||
| 208 | + holder.GetContext<gert::TilingContext>()->GetPlatformInfo()->SetCoreNumByCoreType("AICore"); | ||
| 209 | + holder.GetContext<gert::TilingContext>()->GetPlatformInfo()->SetPlatformRes("AICoreintrinsicDtypeMap", intrinsics); | ||
| 210 | + | ||
| 211 | + EXPECT_EQ(tiling_func(tiling_context), expectedStatus); | ||
| 212 | +} | ||
| 213 | + | ||
| 123 | TEST_F(foreach_div_list_arch35_tiling_test, foreach_div_list_arch35_fp32) { RunTilingCase(ge::DT_FLOAT, 0); } | 214 | TEST_F(foreach_div_list_arch35_tiling_test, foreach_div_list_arch35_fp32) { RunTilingCase(ge::DT_FLOAT, 0); } |
| 124 | 215 | ||
| 216 | +// out 元素数大于 x1(4096 >= 2048,异 shape)应放行:社区 issue #37 的 y>=x 口径守护 | ||
| 217 | +TEST_F(foreach_div_list_arch35_tiling_test, foreach_div_list_arch35_out_shape_larger_accepted) | ||
| 218 | +{ | ||
| 219 | + RunTilingOutShapeCase(true, ge::GRAPH_SUCCESS); | ||
| 220 | +} | ||
| 221 | + | ||
| 222 | +// out 元素数小于 x1(1024 < 2048)应拒绝 | ||
| 223 | +TEST_F(foreach_div_list_arch35_tiling_test, foreach_div_list_arch35_out_shape_smaller_rejected) | ||
| 224 | +{ | ||
| 225 | + RunTilingOutShapeCase(false, ge::GRAPH_FAILED); | ||
| 226 | +} | ||
| 227 | + | ||
| 125 | TEST_F(foreach_div_list_arch35_tiling_test, foreach_div_list_arch35_fp16) { RunTilingCase(ge::DT_FLOAT16, 1); } | 228 | TEST_F(foreach_div_list_arch35_tiling_test, foreach_div_list_arch35_fp16) { RunTilingCase(ge::DT_FLOAT16, 1); } |
| 126 | 229 | ||
| 127 | TEST_F(foreach_div_list_arch35_tiling_test, foreach_div_list_arch35_bf16) { RunTilingCase(ge::DT_BF16, 2); } | 230 | TEST_F(foreach_div_list_arch35_tiling_test, foreach_div_list_arch35_bf16) { RunTilingCase(ge::DT_BF16, 2); } |
| @@ -0,0 +1,14 @@ | |||
| 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 | +file(GLOB CURRENT_DIR RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | ||
| 12 | +if(UT_TEST_ALL OR OP_API_UT) | ||
| 13 | + add_modules_ut_sources(HOSTNAME ${OP_API_MODULE_NAME} MODE PRIVATE DIR ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| 14 | +endif() | ||
| @@ -0,0 +1,168 @@ | |||
| 1 | +/** | ||
| 2 | + * Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | + * This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | + * CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | + * Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | + * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | + * See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | + */ | ||
| 10 | + | ||
| 11 | +#include <vector> | ||
| 12 | +#include "gtest/gtest.h" | ||
| 13 | + | ||
| 14 | +#include "../../../../op_host/op_api/aclnn_foreach_div_list.h" | ||
| 15 | + | ||
| 16 | +#include "op_api_ut_common/tensor_desc.h" | ||
| 17 | +#include "op_api_ut_common/scalar_desc.h" | ||
| 18 | +#include "op_api_ut_common/op_api_ut.h" | ||
| 19 | +#include <iostream> | ||
| 20 | + | ||
| 21 | +using namespace std; | ||
| 22 | + | ||
| 23 | +class l2_foreach_div_list_test : public testing::Test { | ||
| 24 | +protected: | ||
| 25 | + static void SetUpTestCase() { cout << "foreach_div_list_test SetUp" << endl; } | ||
| 26 | + | ||
| 27 | + static void TearDownTestCase() { cout << "foreach_div_list_test TearDown" << endl; } | ||
| 28 | +}; | ||
| 29 | + | ||
| 30 | +// 基线正例:x1/x2/out 同 shape、ND、fp32 | ||
| 31 | +TEST_F(l2_foreach_div_list_test, ascend910B2_foreach_div_list_test_fp32_nd) | ||
| 32 | +{ | ||
| 33 | + vector<vector<int64_t>> selfDims = {{2, 3}}; | ||
| 34 | + auto x1 = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0); | ||
| 35 | + auto x2 = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0); | ||
| 36 | + auto out = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 37 | + auto x1List = TensorListDesc({x1}); | ||
| 38 | + auto x2List = TensorListDesc({x2}); | ||
| 39 | + auto outList = TensorListDesc({out}); | ||
| 40 | + | ||
| 41 | + auto ut = OP_API_UT(aclnnForeachDivList, INPUT(x1List, x2List), OUTPUT(outList)); | ||
| 42 | + uint64_t workspaceSize = 0; | ||
| 43 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 44 | + EXPECT_EQ(getWorkspaceResult, ACL_SUCCESS); | ||
| 45 | +} | ||
| 46 | + | ||
| 47 | +// out 元素数大于 x1:文档要求 shape size >=,应放行(社区 issue #37) | ||
| 48 | +TEST_F(l2_foreach_div_list_test, ascend910B2_foreach_div_list_test_out_shape_larger_numel) | ||
| 49 | +{ | ||
| 50 | + vector<vector<int64_t>> selfDims = {{2, 3}}; | ||
| 51 | + vector<vector<int64_t>> outDims = {{2, 4}}; | ||
| 52 | + auto x1 = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0); | ||
| 53 | + auto x2 = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0); | ||
| 54 | + auto out = TensorDesc(outDims[0], ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 55 | + auto x1List = TensorListDesc({x1}); | ||
| 56 | + auto x2List = TensorListDesc({x2}); | ||
| 57 | + auto outList = TensorListDesc({out}); | ||
| 58 | + | ||
| 59 | + auto ut = OP_API_UT(aclnnForeachDivList, INPUT(x1List, x2List), OUTPUT(outList)); | ||
| 60 | + uint64_t workspaceSize = 0; | ||
| 61 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 62 | + EXPECT_EQ(getWorkspaceResult, ACL_SUCCESS); | ||
| 63 | +} | ||
| 64 | + | ||
| 65 | +// out 与 x1 元素数相同但 shape 不同:应放行(社区 issue #37) | ||
| 66 | +TEST_F(l2_foreach_div_list_test, ascend910B2_foreach_div_list_test_out_shape_same_numel) | ||
| 67 | +{ | ||
| 68 | + vector<vector<int64_t>> selfDims = {{2, 3}}; | ||
| 69 | + vector<vector<int64_t>> outDims = {{3, 2}}; | ||
| 70 | + auto x1 = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0); | ||
| 71 | + auto x2 = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0); | ||
| 72 | + auto out = TensorDesc(outDims[0], ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 73 | + auto x1List = TensorListDesc({x1}); | ||
| 74 | + auto x2List = TensorListDesc({x2}); | ||
| 75 | + auto outList = TensorListDesc({out}); | ||
| 76 | + | ||
| 77 | + auto ut = OP_API_UT(aclnnForeachDivList, INPUT(x1List, x2List), OUTPUT(outList)); | ||
| 78 | + uint64_t workspaceSize = 0; | ||
| 79 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 80 | + EXPECT_EQ(getWorkspaceResult, ACL_SUCCESS); | ||
| 81 | +} | ||
| 82 | + | ||
| 83 | +// out 元素数小于 x1:应拒绝(161002) | ||
| 84 | +TEST_F(l2_foreach_div_list_test, ascend910B2_foreach_div_list_test_out_shape_smaller_numel) | ||
| 85 | +{ | ||
| 86 | + vector<vector<int64_t>> selfDims = {{2, 4}}; | ||
| 87 | + vector<vector<int64_t>> outDims = {{2, 2}}; | ||
| 88 | + auto x1 = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0); | ||
| 89 | + auto x2 = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0); | ||
| 90 | + auto out = TensorDesc(outDims[0], ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 91 | + auto x1List = TensorListDesc({x1}); | ||
| 92 | + auto x2List = TensorListDesc({x2}); | ||
| 93 | + auto outList = TensorListDesc({out}); | ||
| 94 | + | ||
| 95 | + auto ut = OP_API_UT(aclnnForeachDivList, INPUT(x1List, x2List), OUTPUT(outList)); | ||
| 96 | + uint64_t workspaceSize = 0; | ||
| 97 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 98 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 99 | +} | ||
| 100 | + | ||
| 101 | +// out 列表比 x1 短:161002 且不越界(社区 issue #35 场景,错误码守护) | ||
| 102 | +TEST_F(l2_foreach_div_list_test, ascend910B2_foreach_div_list_test_out_list_shorter) | ||
| 103 | +{ | ||
| 104 | + vector<int64_t> dims = {2, 3}; | ||
| 105 | + auto x1 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0); | ||
| 106 | + auto x2 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0); | ||
| 107 | + auto out = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 108 | + auto x1List = TensorListDesc({x1, x1}); | ||
| 109 | + auto x2List = TensorListDesc({x2, x2}); | ||
| 110 | + auto outList = TensorListDesc({out}); | ||
| 111 | + | ||
| 112 | + auto ut = OP_API_UT(aclnnForeachDivList, INPUT(x1List, x2List), OUTPUT(outList)); | ||
| 113 | + uint64_t workspaceSize = 0; | ||
| 114 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 115 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 116 | +} | ||
| 117 | + | ||
| 118 | +// out 列表比 x1 长:161002(社区 issue #35 场景,错误码守护) | ||
| 119 | +TEST_F(l2_foreach_div_list_test, ascend910B2_foreach_div_list_test_out_list_longer) | ||
| 120 | +{ | ||
| 121 | + vector<int64_t> dims = {2, 3}; | ||
| 122 | + auto x1 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0); | ||
| 123 | + auto x2 = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0); | ||
| 124 | + auto out = TensorDesc(dims, ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 125 | + auto x1List = TensorListDesc({x1}); | ||
| 126 | + auto x2List = TensorListDesc({x2}); | ||
| 127 | + auto outList = TensorListDesc({out, out}); | ||
| 128 | + | ||
| 129 | + auto ut = OP_API_UT(aclnnForeachDivList, INPUT(x1List, x2List), OUTPUT(outList)); | ||
| 130 | + uint64_t workspaceSize = 0; | ||
| 131 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 132 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 133 | +} | ||
| 134 | + | ||
| 135 | +// x2 与 x1 shape 不一致:161002 | ||
| 136 | +TEST_F(l2_foreach_div_list_test, ascend910B2_foreach_div_list_test_input_shape_different) | ||
| 137 | +{ | ||
| 138 | + vector<vector<int64_t>> selfDims = {{2, 3}}; | ||
| 139 | + vector<vector<int64_t>> x2Dims = {{2, 4}}; | ||
| 140 | + auto x1 = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).ValueRange(-1.0, 1.0); | ||
| 141 | + auto x2 = TensorDesc(x2Dims[0], ACL_FLOAT, ACL_FORMAT_ND).ValueRange(0.1, 1.0); | ||
| 142 | + auto out = TensorDesc(selfDims[0], ACL_FLOAT, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 143 | + auto x1List = TensorListDesc({x1}); | ||
| 144 | + auto x2List = TensorListDesc({x2}); | ||
| 145 | + auto outList = TensorListDesc({out}); | ||
| 146 | + | ||
| 147 | + auto ut = OP_API_UT(aclnnForeachDivList, INPUT(x1List, x2List), OUTPUT(outList)); | ||
| 148 | + uint64_t workspaceSize = 0; | ||
| 149 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 150 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 151 | +} | ||
| 152 | + | ||
| 153 | +// 不支持的 dtype:161002(社区 issue #36 场景——host 侧参数校验为 ACLNN_ERR_PARAM_INVALID 而非 561002) | ||
| 154 | +TEST_F(l2_foreach_div_list_test, ascend910B2_foreach_div_list_test_not_supported_dtype) | ||
| 155 | +{ | ||
| 156 | + vector<vector<int64_t>> selfDims = {{2, 3}}; | ||
| 157 | + auto x1 = TensorDesc(selfDims[0], ACL_DOUBLE, ACL_FORMAT_ND).ValueRange(-1.0, 1.0); | ||
| 158 | + auto x2 = TensorDesc(selfDims[0], ACL_DOUBLE, ACL_FORMAT_ND).ValueRange(0.1, 1.0); | ||
| 159 | + auto out = TensorDesc(selfDims[0], ACL_DOUBLE, ACL_FORMAT_ND).Precision(0.001, 0.001); | ||
| 160 | + auto x1List = TensorListDesc({x1}); | ||
| 161 | + auto x2List = TensorListDesc({x2}); | ||
| 162 | + auto outList = TensorListDesc({out}); | ||
| 163 | + | ||
| 164 | + auto ut = OP_API_UT(aclnnForeachDivList, INPUT(x1List, x2List), OUTPUT(outList)); | ||
| 165 | + uint64_t workspaceSize = 0; | ||
| 166 | + aclnnStatus getWorkspaceResult = ut.TestGetWorkspaceSize(&workspaceSize); | ||
| 167 | + EXPECT_EQ(getWorkspaceResult, ACLNN_ERR_PARAM_INVALID); | ||
| 168 | +} | ||
out 的校验从 shape 一致放宽成只比 shape size 之后,shape 本身就不再受约束了。