已合并
feat: 补充is_close算子op_host infershape UT #4065
wangqi_ai创建于 7月14日
feat: 补充is_close算子op_host infershape UT #4065
已合并
共 4 个文件变更+212-0
| @@ -0,0 +1,17 @@ | |||
| 1 | +# ---------------------------------------------------------------------------- | ||
| 2 | +# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | +# Copyright (c) 2026 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, 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,17 @@ | |||
| 1 | +# ---------------------------------------------------------------------------- | ||
| 2 | +# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | +# Copyright (c) 2026 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, 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,20 @@ | |||
| 1 | +# ---------------------------------------------------------------------------- | ||
| 2 | +# This program is free software, you can redistribute it and/or modify it. | ||
| 3 | +# Copyright (c) 2026 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, 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,158 @@ | |||
| 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 test_is_close_infershape.cpp | ||
| 13 | + * \brief | ||
| 14 | + */ | ||
| 15 | + | ||
| 16 | + | ||
| 17 | + | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + | ||
| 21 | +class IsCloseInfershape : public testing::Test { | ||
| 22 | +protected: | ||
| 23 | + static void SetUpTestCase() { std::cout << "IsCloseInfershape SetUp" << std::endl; } | ||
| 24 | + | ||
| 25 | + static void TearDownTestCase() { std::cout << "IsCloseInfershape TearDown" << std::endl; } | ||
| 26 | +}; | ||
| 27 | + | ||
| 28 | +// IsClose has 2 inputs and 1 output. Output is the broadcast of the two inputs. | ||
| 29 | +// With same shapes, output shape equals input shape. | ||
| 30 | +TEST_F(IsCloseInfershape, is_close_infershape_float_test) | ||
| 31 | +{ | ||
| 32 | + gert::InfershapeContextPara infershapeContextPara("IsClose", | ||
| 33 | + { | ||
| 34 | + {{{2, 3, 4}, {2, 3, 4}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 35 | + {{{2, 3, 4}, {2, 3, 4}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 36 | + }, | ||
| 37 | + { | ||
| 38 | + {{{}, {}}, ge::DT_BOOL, ge::FORMAT_ND}, | ||
| 39 | + }); | ||
| 40 | + std::vector<std::vector<int64_t>> expectOutputShape = { | ||
| 41 | + {2, 3, 4}, | ||
| 42 | + }; | ||
| 43 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 44 | +} | ||
| 45 | + | ||
| 46 | +TEST_F(IsCloseInfershape, is_close_infershape_float16_test) | ||
| 47 | +{ | ||
| 48 | + gert::InfershapeContextPara infershapeContextPara("IsClose", | ||
| 49 | + { | ||
| 50 | + {{{4, 3, 4}, {4, 3, 4}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 51 | + {{{4, 3, 4}, {4, 3, 4}}, ge::DT_FLOAT16, ge::FORMAT_ND}, | ||
| 52 | + }, | ||
| 53 | + { | ||
| 54 | + {{{}, {}}, ge::DT_BOOL, ge::FORMAT_ND}, | ||
| 55 | + }); | ||
| 56 | + std::vector<std::vector<int64_t>> expectOutputShape = { | ||
| 57 | + {4, 3, 4}, | ||
| 58 | + }; | ||
| 59 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 60 | +} | ||
| 61 | + | ||
| 62 | +TEST_F(IsCloseInfershape, is_close_infershape_int32_test) | ||
| 63 | +{ | ||
| 64 | + gert::InfershapeContextPara infershapeContextPara("IsClose", | ||
| 65 | + { | ||
| 66 | + {{{2, 3, 4}, {2, 3, 4}}, ge::DT_INT32, ge::FORMAT_ND}, | ||
| 67 | + {{{2, 3, 4}, {2, 3, 4}}, ge::DT_INT32, ge::FORMAT_ND}, | ||
| 68 | + }, | ||
| 69 | + { | ||
| 70 | + {{{}, {}}, ge::DT_BOOL, ge::FORMAT_ND}, | ||
| 71 | + }); | ||
| 72 | + std::vector<std::vector<int64_t>> expectOutputShape = { | ||
| 73 | + {2, 3, 4}, | ||
| 74 | + }; | ||
| 75 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 76 | +} | ||
| 77 | + | ||
| 78 | +TEST_F(IsCloseInfershape, is_close_infershape_bf16_test) | ||
| 79 | +{ | ||
| 80 | + gert::InfershapeContextPara infershapeContextPara("IsClose", | ||
| 81 | + { | ||
| 82 | + {{{2, 3, 4}, {2, 3, 4}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 83 | + {{{2, 3, 4}, {2, 3, 4}}, ge::DT_BF16, ge::FORMAT_ND}, | ||
| 84 | + }, | ||
| 85 | + { | ||
| 86 | + {{{}, {}}, ge::DT_BOOL, ge::FORMAT_ND}, | ||
| 87 | + }); | ||
| 88 | + std::vector<std::vector<int64_t>> expectOutputShape = { | ||
| 89 | + {2, 3, 4}, | ||
| 90 | + }; | ||
| 91 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 92 | +} | ||
| 93 | + | ||
| 94 | +// Broadcast case: {2, 3, 4} and {3, 4} -> output {2, 3, 4} | ||
| 95 | +TEST_F(IsCloseInfershape, is_close_infershape_broadcast_test) | ||
| 96 | +{ | ||
| 97 | + gert::InfershapeContextPara infershapeContextPara("IsClose", | ||
| 98 | + { | ||
| 99 | + {{{2, 3, 4}, {2, 3, 4}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 100 | + {{{3, 4}, {3, 4}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 101 | + }, | ||
| 102 | + { | ||
| 103 | + {{{}, {}}, ge::DT_BOOL, ge::FORMAT_ND}, | ||
| 104 | + }); | ||
| 105 | + std::vector<std::vector<int64_t>> expectOutputShape = { | ||
| 106 | + {2, 3, 4}, | ||
| 107 | + }; | ||
| 108 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +// Broadcast case with scalar: {2, 3, 4} and {1} -> output {2, 3, 4} | ||
| 112 | +TEST_F(IsCloseInfershape, is_close_infershape_broadcast_scalar_test) | ||
| 113 | +{ | ||
| 114 | + gert::InfershapeContextPara infershapeContextPara("IsClose", | ||
| 115 | + { | ||
| 116 | + {{{2, 3, 4}, {2, 3, 4}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 117 | + {{{1}, {1}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 118 | + }, | ||
| 119 | + { | ||
| 120 | + {{{}, {}}, ge::DT_BOOL, ge::FORMAT_ND}, | ||
| 121 | + }); | ||
| 122 | + std::vector<std::vector<int64_t>> expectOutputShape = { | ||
| 123 | + {2, 3, 4}, | ||
| 124 | + }; | ||
| 125 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 126 | +} | ||
| 127 | + | ||
| 128 | +TEST_F(IsCloseInfershape, is_close_infershape_1d_tensor_test) | ||
| 129 | +{ | ||
| 130 | + gert::InfershapeContextPara infershapeContextPara("IsClose", | ||
| 131 | + { | ||
| 132 | + {{{10}, {10}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 133 | + {{{10}, {10}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 134 | + }, | ||
| 135 | + { | ||
| 136 | + {{{}, {}}, ge::DT_BOOL, ge::FORMAT_ND}, | ||
| 137 | + }); | ||
| 138 | + std::vector<std::vector<int64_t>> expectOutputShape = { | ||
| 139 | + {10}, | ||
| 140 | + }; | ||
| 141 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 142 | +} | ||
| 143 | + | ||
| 144 | +TEST_F(IsCloseInfershape, is_close_infershape_empty_tensor_test) | ||
| 145 | +{ | ||
| 146 | + gert::InfershapeContextPara infershapeContextPara("IsClose", | ||
| 147 | + { | ||
| 148 | + {{{0, 3, 4}, {0, 3, 4}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 149 | + {{{0, 3, 4}, {0, 3, 4}}, ge::DT_FLOAT, ge::FORMAT_ND}, | ||
| 150 | + }, | ||
| 151 | + { | ||
| 152 | + {{{}, {}}, ge::DT_BOOL, ge::FORMAT_ND}, | ||
| 153 | + }); | ||
| 154 | + std::vector<std::vector<int64_t>> expectOutputShape = { | ||
| 155 | + {0, 3, 4}, | ||
| 156 | + }; | ||
| 157 | + ExecuteTestCase(infershapeContextPara, ge::GRAPH_SUCCESS, expectOutputShape); | ||
| 158 | +} | ||