已开启
【代码侦探Challenge 04】完成 DivCustomTemplate 工程化算子实现(msopgen 工程 + 核函数 + Tiling + ACLNN 验证) #2143
【代码侦探Challenge 04】完成 DivCustomTemplate 工程化算子实现(msopgen 工程 + 核函数 + Tiling + ACLNN 验证) #2143
已开启
村雨雨雨创建于 4 天前
16 个文件变更+902-0
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/.gitignore+3-0文件内容审核中,请稍后刷新重试
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/CMakeLists.txt+31-0
@@ -0,0 +1,31 @@
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+cmake_minimum_required(VERSION 3.16.0)
13+project(opp)
14+find_package(ASC REQUIRED)
15+set(package_name ${vendor_name})
16+ 
17+npu_op_package(${package_name}
18+ TYPE RUN
19+ CONFIG
20+ INSTALL_PATH ${CMAKE_BINARY_DIR}/
21+)
22+ 
23+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/framework)
24+ add_subdirectory(framework)
25+endif()
26+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/op_host)
27+ add_subdirectory(op_host)
28+endif()
29+if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/op_kernel)
30+ add_subdirectory(op_kernel)
31+endif()
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/CMakePresets.json+63-0
@@ -0,0 +1,63 @@
1+{
2+ "version": 1,
3+ "cmakeMinimumRequired": {
4+ "major": 3,
5+ "minor": 16,
6+ "patch": 0
7+ },
8+ "configurePresets": [
9+ {
10+ "name": "default",
11+ "displayName": "Default Config",
12+ "description": "Default build using Unix Makefiles generator",
13+ "generator": "Unix Makefiles",
14+ "binaryDir": "${sourceDir}/build_out",
15+ "cacheVariables": {
16+ "CMAKE_BUILD_TYPE": {
17+ "type": "STRING",
18+ "value": "Release"
19+ },
20+ "ENABLE_SOURCE_PACKAGE": {
21+ "type": "BOOL",
22+ "value": "True"
23+ },
24+ "ENABLE_BINARY_PACKAGE": {
25+ "type": "BOOL",
26+ "value": "True"
27+ },
28+ "ASCEND_COMPUTE_UNIT": {
29+ "type": "STRING",
30+ "value": "ascend910b"
31+ },
32+ "ENABLE_TEST": {
33+ "type": "BOOL",
34+ "value": "True"
35+ },
36+ "vendor_name": {
37+ "type": "STRING",
38+ "value": "customize"
39+ },
40+ "ASCEND_PYTHON_EXECUTABLE": {
41+ "type": "STRING",
42+ "value": "python3"
43+ },
44+ "CMAKE_INSTALL_PREFIX": {
45+ "type": "PATH",
46+ "value": "${sourceDir}/build_out"
47+ },
48+ "ENABLE_CROSS_COMPILE": {
49+ "type": "BOOL",
50+ "value": "False"
51+ },
52+ "CMAKE_CROSS_PLATFORM_COMPILER": {
53+ "type": "PATH",
54+ "value": "/usr/bin/aarch64-linux-gnu-g++"
55+ },
56+ "ASCEND_PACK_SHARED_LIBRARY": {
57+ "type": "BOOL",
58+ "value": "False"
59+ }
60+ }
61+ }
62+ ]
63+}
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/build.sh+40-0
@@ -0,0 +1,40 @@
1+#!/bin/bash
2+# ----------------------------------------------------------------------------------------------------------
3+# Copyright (c) 2025 Huawei Technologies Co., Ltd.
4+# This program is free software, you can redistribute it and/or modify it under the terms and conditions of
5+# 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,
8+# 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.
10+# ----------------------------------------------------------------------------------------------------------
11+ 
12+if [ -z "$BASE_LIBS_PATH" ]; then
13+ if [ -z "$ASCEND_HOME_PATH" ]; then
14+ if [ -z "$ASCEND_AICPU_PATH" ]; then
15+ echo "please set env."
16+ exit 1
17+ else
18+ export ASCEND_HOME_PATH=$ASCEND_AICPU_PATH
19+ fi
20+ else
21+ export ASCEND_HOME_PATH=$ASCEND_HOME_PATH
22+ fi
23+else
24+ export ASCEND_HOME_PATH=$BASE_LIBS_PATH
25+fi
26+echo "using ASCEND_HOME_PATH: $ASCEND_HOME_PATH"
27+script_path=$(realpath $(dirname $0))
28+ 
29+BUILD_DIR="build_out"
30+mkdir -p build_out
31+rm -rf build_out/*
32+opts=$(python3 $ASCEND_HOME_PATH/tools/tikcpp/ascendc_kernel_cmake/fwk_modules/util/preset_parse.py $script_path/CMakePresets.json)
33+cmake_version=$(cmake --version | grep "cmake version" | awk '{print $3}')
34+ 
35+if [ "$cmake_version" \< "3.19.0" ] ; then
36+ cmake -S . -B "$BUILD_DIR" $opts
37+else
38+ cmake -S . -B "$BUILD_DIR" --preset=default
39+fi
40+cmake --build "$BUILD_DIR" --target binary package -j$(nproc)
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/framework/CMakeLists.txt+18-0
@@ -0,0 +1,18 @@
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+if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tf_plugin")
13+ add_subdirectory(tf_plugin)
14+endif()
15+ 
16+if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/onnx_plugin")
17+ add_subdirectory(onnx_plugin)
18+endif()
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/framework/tf_plugin/CMakeLists.txt+24-0
@@ -0,0 +1,24 @@
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+aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} plugin_srcs)
13+if(NOT plugin_srcs)
14+ return()
15+endif()
16+ 
17+npu_op_library(cust_tf_parsers TF_PLUGIN
18+ ${plugin_srcs}
19+)
20+ 
21+npu_op_package_add(${package_name}
22+ LIBRARY
23+ cust_tf_parsers
24+)
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/framework/tf_plugin/tensorflow_div_custom_template_plugin.cc+25-0
@@ -0,0 +1,25 @@
1+/* -------------------------------------------------------------------------
2+ * This file is part of the MindStudio project.
3+ * Copyright (c) 2025 Huawei Technologies Co.,Ltd.
4+ *
5+ * MindStudio is licensed under Mulan PSL v2.
6+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
7+ * You may obtain a copy of Mulan PSL v2 at:
8+ *
9+ * http://license.coscl.org.cn/MulanPSL2
10+ *
11+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
12+ * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
13+ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
14+ * See the Mulan PSL v2 for more details.
15+ * ------------------------------------------------------------------------- */
16+ 
17+#include "register/register.h"
18+ 
19+namespace domi {
20+// register op info to GE
21+REGISTER_CUSTOM_OP("DivCustomTemplate")
22+ .FrameworkType(TENSORFLOW) // type: CAFFE, TENSORFLOW
23+ .OriginOpType("DivCustomTemplate") // name in tf module
24+ .ParseParamsByOperatorFn(AutoMappingByOpFn);
25+} // namespace domi
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/op_host/CMakeLists.txt+58-0
@@ -0,0 +1,58 @@
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+aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} ops_srcs)
13+npu_op_code_gen(
14+ SRC ${ops_srcs}
15+ PACKAGE ${package_name}
16+ OUT_DIR ${ASCEND_AUTOGEN_PATH}
17+ JOIN_OP_DEF True
18+)
19+ 
20+file(GLOB autogen_aclnn_src ${ASCEND_AUTOGEN_PATH}/aclnn_*.cpp)
21+set_source_files_properties(${autogen_aclnn_src} PROPERTIES GENERATED TRUE)
22+npu_op_library(cust_opapi ACLNN
23+ ${autogen_aclnn_src}
24+)
25+ 
26+target_compile_options(cust_opapi PRIVATE
27+ -fvisibility=hidden
28+)
29+ 
30+file(GLOB group_proto_src ${ASCEND_AUTOGEN_PATH}/group_op_proto/*.cc)
31+file(GLOB proto_src ${ASCEND_AUTOGEN_PATH}/op_proto.cc)
32+set_source_files_properties(${group_proto_src} PROPERTIES GENERATED TRUE)
33+set_source_files_properties(${proto_src} PROPERTIES GENERATED TRUE)
34+npu_op_library(cust_op_proto GRAPH
35+ ${ops_srcs}
36+ ${group_proto_src}
37+ ${proto_src}
38+)
39+target_compile_options(cust_op_proto PRIVATE
40+ -fvisibility=hidden
41+)
42+ 
43+file(GLOB fallback_src ${ASCEND_AUTOGEN_PATH}/fallback_*.cpp)
44+set_source_files_properties(${fallback_src} PROPERTIES GENERATED TRUE)
45+npu_op_library(cust_optiling TILING
46+ ${ops_srcs}
47+ ${fallback_src}
48+)
49+target_compile_options(cust_optiling PRIVATE
50+ -fvisibility=hidden
51+)
52+ 
53+npu_op_package_add(${package_name}
54+ LIBRARY
55+ cust_optiling
56+ cust_opapi
57+ cust_op_proto
58+)
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/op_host/div_custom_template.cpp+90-0文件内容审核中,请稍后刷新重试
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/op_kernel/CMakeLists.txt+26-0
@@ -0,0 +1,26 @@
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+if ("${CMAKE_BUILD_TYPE}x" STREQUAL "Debugx")
12+ npu_op_kernel_options(ascendc_kernels ALL OPTIONS -g -O0)
13+endif()
14+ 
15+npu_op_kernel_sources(ascendc_kernels
16+ KERNEL_DIR ./
17+)
18+ 
19+npu_op_kernel_library(ascendc_kernels
20+ SRC_BASE ${CMAKE_CURRENT_SOURCE_DIR}/
21+ TILING_LIBRARY cust_optiling
22+)
23+ 
24+npu_op_package_add(${package_name}
25+ LIBRARY ascendc_kernels
26+)
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/op_kernel/div_custom_template.cpp+108-0文件内容审核中,请稍后刷新重试
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/custom_op/op_kernel/div_custom_template_tiling.h+28-0文件内容审核中,请稍后刷新重试
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/div_custom_template.json+22-0
@@ -0,0 +1,22 @@
1+[{
2+ "op": "DivCustomTemplate",
3+ "input_desc": [{
4+ "name": "x",
5+ "param_type": "required",
6+ "format": ["ND", "ND"],
7+ "type": ["float16", "float"]
8+ },
9+ {
10+ "name": "y",
11+ "param_type": "required",
12+ "format": ["ND", "ND"],
13+ "type": ["float16", "float"]
14+ }
15+ ],
16+ "output_desc": [{
17+ "name": "z",
18+ "param_type": "required",
19+ "format": ["ND", "ND"],
20+ "type": ["float16", "float"]
21+ }]
22+}]
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/run.sh+93-0文件内容审核中,请稍后刷新重试
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/test/CMakeLists.txt+60-0
@@ -0,0 +1,60 @@
1+# Copyright (c) Huawei Technologies Co., Ltd. 2020. All rights reserved.
2+ 
3+# CMake lowest version requirement
4+cmake_minimum_required(VERSION 3.5.1)
5+ 
6+# project information
7+project(acl_execute_div)
8+ 
9+# Compile options
10+add_compile_options(-std=c++11)
11+ 
12+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "./")
13+ 
14+set(INC_PATH $ENV{DDK_PATH})
15+ 
16+if (NOT DEFINED ENV{DDK_PATH})
17+ set(INC_PATH "/usr/local/Ascend/ascend-toolkit/latest")
18+ message(STATUS "set default INC_PATH: ${INC_PATH}")
19+else ()
20+ message(STATUS "env INC_PATH: ${INC_PATH}")
21+endif()
22+ 
23+set(CUST_PKG_PATH "${INC_PATH}/opp/vendors/customize/op_api")
24+ 
25+set(LIB_PATH $ENV{NPU_HOST_LIB})
26+ 
27+# Dynamic libraries in the stub directory can only be used for compilation
28+if (NOT DEFINED ENV{NPU_HOST_LIB})
29+ string(TOLOWER "${CMAKE_SYSTEM_NAME}" SYSTEM_NAME_LOWER)
30+ set(LIB_PATH "/usr/local/Ascend/ascend-toolkit/latest/${CMAKE_SYSTEM_PROCESSOR}-${SYSTEM_NAME_LOWER}/devlib")
31+ message(STATUS "set default LIB_PATH: ${LIB_PATH}")
32+else ()
33+ message(STATUS "env LIB_PATH: ${LIB_PATH}")
34+endif()
35+ 
36+# Header path
37+include_directories(
38+ ${INC_PATH}/include
39+ ${CUST_PKG_PATH}/include
40+)
41+ 
42+# add host lib path
43+link_directories(
44+ ${LIB_PATH}
45+ ${CUST_PKG_PATH}/lib
46+)
47+ 
48+add_executable(execute_div_op
49+ main.cpp
50+)
51+ 
52+target_link_libraries(execute_div_op
53+ ascendcl
54+ cust_opapi
55+ acl_op_compiler
56+ nnopbase
57+ stdc++
58+)
59+ 
60+install(TARGETS execute_div_op DESTINATION ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
A2026/CANN-Code-Detective/Challenge04-DivCustomTemplate/murasame/DivCustomTemplate/test/main.cpp+213-0文件内容审核中,请稍后刷新重试