已合并
add_example_aicpu修改 #2237
Ding_Jing创建于 4月15日
add_example_aicpu修改 #2237
已合并
共 7 个文件变更+19-23
| @@ -543,8 +543,8 @@ Software:samples 0.6.0 | |||
| 543 | Official Repository: https://github.com/Ascend/samples | 543 | Official Repository: https://github.com/Ascend/samples |
| 544 | 544 | ||
| 545 | Usage: " | 545 | Usage: " |
| 546 | -examples/add_example_aicpu/op_kernel_aicpu/add_example_aicpu.cpp | 546 | +examples/add_example_aicpu/op_kernel_aicpu/add_example_aicpu_aicpu.cpp |
| 547 | -examples/add_example_aicpu/op_kernel_aicpu/add_example_aicpu.h" | 547 | +examples/add_example_aicpu/op_kernel_aicpu/add_example_aicpu_aicpu.h" |
| 548 | 548 | ||
| 549 | Copyright Notice: | 549 | Copyright Notice: |
| 550 | Copyright 2019-2020 Huawei Technologies Co., Ltd | 550 | Copyright 2019-2020 Huawei Technologies Co., Ltd |
| @@ -267,17 +267,17 @@ pip3 install -r requirements.txt | |||
| 267 | # 安装根目录下test相关requirements.txt依赖 | 267 | # 安装根目录下test相关requirements.txt依赖 |
| 268 | pip3 install -r tests/requirements.txt | 268 | pip3 install -r tests/requirements.txt |
| 269 | # 方式1: 编译并执行指定算子和对应功能的UT测试用例(选其一) | 269 | # 方式1: 编译并执行指定算子和对应功能的UT测试用例(选其一) |
| 270 | -bash build.sh -u --[opapi|ophost|opkernel] --ops=abs | 270 | +bash build.sh -u --[opapi|ophost|opkernel|opkernel_aicpu] --ops=abs |
| 271 | # 方式2: 编译并执行所有的UT测试用例 | 271 | # 方式2: 编译并执行所有的UT测试用例 |
| 272 | # bash build.sh -u | 272 | # bash build.sh -u |
| 273 | # 方式3: 编译所有的UT测试用例但不执行 | 273 | # 方式3: 编译所有的UT测试用例但不执行 |
| 274 | # bash build.sh -u --noexec | 274 | # bash build.sh -u --noexec |
| 275 | # 方式4: 编译并执行对应功能的UT测试用例(选其一) | 275 | # 方式4: 编译并执行对应功能的UT测试用例(选其一) |
| 276 | -# bash build.sh -u --[opapi|ophost|opkernel] | 276 | +# bash build.sh -u --[opapi|ophost|opkernel|opkernel_aicpu] |
| 277 | # 方式5: 编译对应功能的UT测试用例但不执行(选其一) | 277 | # 方式5: 编译对应功能的UT测试用例但不执行(选其一) |
| 278 | -# bash build.sh -u --noexec --[opapi|ophost|opkernel] | 278 | +# bash build.sh -u --noexec --[opapi|ophost|opkernel|opkernel_aicpu] |
| 279 | # 方式6: 执行UT测试用例时可指定soc编译 | 279 | # 方式6: 执行UT测试用例时可指定soc编译 |
| 280 | -# bash build.sh -u --[opapi|ophost|opkernel] [--soc=${soc_version}] | 280 | +# bash build.sh -u --[opapi|ophost|opkernel|opkernel_aicpu] [--soc=${soc_version}] |
| 281 | ``` | 281 | ``` |
| 282 | 282 | ||
| 283 | 以验证ophost功能是否正常为例,执行如下命令: | 283 | 以验证ophost功能是否正常为例,执行如下命令: |
| @@ -1,4 +1,4 @@ | |||
| 1 | -# --------------------------------------------------------------------------------------------------------- | 1 | +# ---------------------------------------------------------------------------- |
| 2 | # Copyright (c) 2025 Huawei Technologies Co., Ltd. | 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 | 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"). |
| @@ -6,14 +6,6 @@ | |||
| 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 | -file(GLOB CURRENT_DIRS RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*) | 11 | +add_all_modules_sources(OPTYPE add_example_aicpu ACLNNTYPE aclnn) |
| 12 | -if(NOT ENABLE_TEST) | ||
| 13 | - list(REMOVE_ITEM CURRENT_DIRS tests) | ||
| 14 | -endif() | ||
| 15 | -foreach(SUB_DIR ${CURRENT_DIRS}) | ||
| 16 | - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${SUB_DIR}/CMakeLists.txt") | ||
| 17 | - add_subdirectory(${SUB_DIR}) | ||
| 18 | - endif() | ||
| 19 | -endforeach() | ||
Rexamples/add_example_aicpu/op_kernel_aicpu/add_example_aicpu.cpp→examples/add_example_aicpu/op_kernel_aicpu/add_example_aicpu_aicpu.cpp+1-1
| @@ -15,7 +15,7 @@ | |||
| 15 | * | 15 | * |
| 16 | */ | 16 | */ |
| 17 | 17 | ||
| 18 | -#include "add_example_aicpu.h" | 18 | +#include "add_example_aicpu_aicpu.h" |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | 21 | ||
Rexamples/add_example_aicpu/op_kernel_aicpu/add_example_aicpu.h→examples/add_example_aicpu/op_kernel_aicpu/add_example_aicpu_aicpu.h+0-0
文件重命名但无更改。
Rexamples/add_example_aicpu/tests/ut/op_kernel_aicpu/test_add_example.cpp→examples/add_example_aicpu/tests/ut/op_kernel_aicpu/test_add_example_aicpu.cpp+5-4
| @@ -34,12 +34,12 @@ class TEST_AddExample_UT : public testing::Test {}; | |||
| 34 | .Input({"x2", data_types[1], shapes[1], datas[1]}) \ | 34 | .Input({"x2", data_types[1], shapes[1], datas[1]}) \ |
| 35 | .Output({"y", data_types[2], shapes[2], datas[2]}); | 35 | .Output({"y", data_types[2], shapes[2], datas[2]}); |
已过期 🔴 严重: 测试类名不一致。EXPECT_EQ 使用 TEST_AddExample_UT,但实际定义的测试类是 TEST_AddExample_UT(第37行)。这里应改为 TEST_AddExample_UT ![]() ![]() | |||
| 36 | 36 | ||
| 37 | -TEST_F(TEST_ADD_UT, INT32_VECTOR_ADD_SCALAR_SUCC) { | 37 | +TEST_F(TEST_AddExample_UT, INT32_VECTOR_ADD_SUCC) { |
| 38 | vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32}; | 38 | vector<DataType> data_types = {DT_INT32, DT_INT32, DT_INT32}; |
已过期 🔴 严重: input2数组越界。原代码 input2[1]={3},但shapes={2,1,2},input2应有2个元素,否则GenOnesData访问input2[1]时越界读。未定义行为。 ![]() ![]() | |||
| 39 | - vector<vector<int64_t>> shapes = {{2}, {1}, {2}}; | 39 | + vector<vector<int64_t>> shapes = {{2}, {2}, {2}}; |
| 40 | 40 | ||
| 41 | int32_t input1[2] = {2, 5}; | 41 | int32_t input1[2] = {2, 5}; |
| 42 | - int32_t input2[1] = {3}; | 42 | + int32_t input2[2] = {3, 3}; |
| 43 | int32_t output[2] = {0}; | 43 | int32_t output[2] = {0}; |
| 44 | vector<void *> datas = {(void *)input1, | 44 | vector<void *> datas = {(void *)input1, |
| 45 | (void *)input2, | 45 | (void *)input2, |
| @@ -51,4 +51,5 @@ TEST_F(TEST_ADD_UT, INT32_VECTOR_ADD_SCALAR_SUCC) { | |||
| 51 | int32_t output_exp[2] = {5, 8}; | 51 | int32_t output_exp[2] = {5, 8}; |
| 52 | bool compare = CompareResult(output, output_exp, 2); | 52 | bool compare = CompareResult(output, output_exp, 2); |
| 53 | EXPECT_EQ(compare, true); | 53 | EXPECT_EQ(compare, true); |
| 54 | -} | 54 | +} |
已过期 🟢 小建议: 文件末尾添加换行符,符合POSIX标准,避免某些工具警告。 ![]() ![]() | |||
| 55 | + | ||
| @@ -19,5 +19,8 @@ foreach(SUB_DIR ${CURRENT_DIRS}) | |||
| 19 | endforeach() | 19 | endforeach() |
| 20 | 20 | ||
| 21 | if(ENABLE_TEST AND (UT_TEST_ALL OR OP_KERNEL_AICPU_UT)) | 21 | if(ENABLE_TEST AND (UT_TEST_ALL OR OP_KERNEL_AICPU_UT)) |
| 22 | - add_aicpu_op_test_case(tan) | 22 | + list(FIND ASCEND_OP_NAME tan TAN_INDEX) |
🟡 一般: 条件判断逻辑有误。list(FIND ... tan TAN_INDEX),若tan不在列表中则TAN_INDEX=-1,NOT TAN_INDEX EQUAL -1 为false,不注册测试;但若tan存在,TAN_INDEX>=0,条件为true,反而注册了重复测试。建议改为: if("${TAN_INDEX}" STREQUAL "-1")。 ![]() ![]() | |||
| 23 | + if("${ASCEND_OP_NAME}" STREQUAL "" OR NOT TAN_INDEX EQUAL -1) | ||
| 24 | + add_aicpu_op_test_case(tan) | ||
| 25 | + endif() | ||
| 23 | endif() | 26 | endif() |


🟢 风格: 版权头第2行的分隔符从 79个- 改为了 78个-(去掉首行#后凑成80字符),与同仓库其他文件风格不一致,建议保持原样或统一用80字符版。