已合并
新增 TF plugin 编译机制 #1209
zhaowenrui创建于 20 天前
新增 TF plugin 编译机制 #1209
已合并
zhaowenrui创建于 20 天前
11 个文件变更+210-38
M.pre-commit-config.yaml+1-0
@@ -73,5 +73,6 @@ repos:
73 language: system73 language: system
74 pass_filenames: true74 pass_filenames: true
75 types: [file]75 types: [file]
76+ exclude: ^scripts/package/.*\.xml$
76 stages: [pre-commit]77 stages: [pre-commit]
77 verbose: true78 verbose: true
MCMakeLists.txt+1-0
@@ -128,6 +128,7 @@ endif()
128include(cmake/func.cmake)128include(cmake/func.cmake)
129include(cmake/intf_pub_linux.cmake)129include(cmake/intf_pub_linux.cmake)
130include(${PROJECT_SOURCE_DIR}/cmake/ut.cmake)130include(${PROJECT_SOURCE_DIR}/cmake/ut.cmake)
131+init_tf_plugin_modules()
131 132 
132include(version.cmake)133include(version.cmake)
133check_cann_pkg_build_deps("ops_cv")134check_cann_pkg_build_deps("ops_cv")
Mcmake/func.cmake+83-16
@@ -1,10 +1,10 @@
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").
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 
@@ -299,7 +299,7 @@ function(add_op_graph_modules)
299 else()299 else()
300 add_library(${OP_GRAPH_NAME}_obj OBJECT)300 add_library(${OP_GRAPH_NAME}_obj OBJECT)
301 endif()301 endif()
302- target_include_directories(${OP_GRAPH_NAME}_obj PRIVATE 302+ target_include_directories(${OP_GRAPH_NAME}_obj PRIVATE
303 ${OP_PROTO_INCLUDE}303 ${OP_PROTO_INCLUDE}
304 ${PROJECT_SOURCE_DIR}/common/inc304 ${PROJECT_SOURCE_DIR}/common/inc
305 ${ASCEND_DIR}/include305 ${ASCEND_DIR}/include
@@ -374,13 +374,13 @@ macro(add_modules_sources)
374 # ASCEND_OP_NAME 为空表示全部编译374 # ASCEND_OP_NAME 为空表示全部编译
375 return()375 return()
376 endif()376 endif()
377- 377+ 
378 if(OP_NAME IN_LIST COMPILED_OPS)378 if(OP_NAME IN_LIST COMPILED_OPS)
379 # 已经编译过,忽略379 # 已经编译过,忽略
380 message(STATUS "already compiled ${OP_NAME}, skip")380 message(STATUS "already compiled ${OP_NAME}, skip")
381 return()381 return()
382 endif()382 endif()
383- 383+ 
384 # 记录全局的COMPILED_OPS和COMPILED_OP_DIRS,其中COMPILED_OP_DIRS只记录到算子名,例如image/crop_and_resize384 # 记录全局的COMPILED_OPS和COMPILED_OP_DIRS,其中COMPILED_OP_DIRS只记录到算子名,例如image/crop_and_resize
385 set(COMPILED_OPS385 set(COMPILED_OPS
386 ${COMPILED_OPS} ${OP_NAME}386 ${COMPILED_OPS} ${OP_NAME}
@@ -542,14 +542,14 @@ macro(add_all_modules_sources)
542 set(multiValueArgs OPTYPE ACLNNTYPE DEPENDENCIES COMPUTE_UNIT TILING_DIR)542 set(multiValueArgs OPTYPE ACLNNTYPE DEPENDENCIES COMPUTE_UNIT TILING_DIR)
543 543 
544 cmake_parse_arguments(MODULE "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})544 cmake_parse_arguments(MODULE "" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
545- set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 545+ set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
546 546 
547 add_opbase_modules()547 add_opbase_modules()
548 # opapi l0 默认全部编译548 # opapi l0 默认全部编译
549 file(GLOB OPAPI_L0_SRCS ${SOURCE_DIR}/op_api/*.cpp)549 file(GLOB OPAPI_L0_SRCS ${SOURCE_DIR}/op_api/*.cpp)
550 list(FILTER OPAPI_L0_SRCS EXCLUDE REGEX "aclnn_")550 list(FILTER OPAPI_L0_SRCS EXCLUDE REGEX "aclnn_")
551 if(OPAPI_L0_SRCS)551 if(OPAPI_L0_SRCS)
552- add_opapi_modules() 552+ add_opapi_modules()
553 target_sources(${OPHOST_NAME}_opapi_obj PRIVATE ${OPAPI_L0_SRCS})553 target_sources(${OPHOST_NAME}_opapi_obj PRIVATE ${OPAPI_L0_SRCS})
554 endif()554 endif()
555 555 
@@ -591,7 +591,7 @@ macro(add_all_modules_sources)
591 591 
592 file(GLOB OPINFER_SRCS ${SOURCE_DIR}/op_host/*_infershape*.cpp)592 file(GLOB OPINFER_SRCS ${SOURCE_DIR}/op_host/*_infershape*.cpp)
593 if(OPINFER_SRCS)593 if(OPINFER_SRCS)
594- add_infer_modules() 594+ add_infer_modules()
595 target_sources(${OPHOST_NAME}_infer_obj PRIVATE ${OPINFER_SRCS})595 target_sources(${OPHOST_NAME}_infer_obj PRIVATE ${OPINFER_SRCS})
596 endif()596 endif()
597 597 
@@ -599,6 +599,17 @@ macro(add_all_modules_sources)
599 find_value_by_key("${MODULE_COMPUTE_UNIT}" "${MODULE_TILING_DIR}" "${ASCEND_COMPUTE_UNIT}" tiling_dir)599 find_value_by_key("${MODULE_COMPUTE_UNIT}" "${MODULE_TILING_DIR}" "${ASCEND_COMPUTE_UNIT}" tiling_dir)
600 add_tiling_sources("${tiling_dir}" "${MODULE_DISABLE_IN_OPP}")600 add_tiling_sources("${tiling_dir}" "${MODULE_DISABLE_IN_OPP}")
601 601 
602+ # Some existing TF plugin sources in ops-cv still depend on non-public GE headers
603+ # and cannot be built with the installed CANN package yet. Keep automatic
604+ # collection disabled by default and use add_tf_plugin_sources() for explicit
605+ # verification until those files are adapted.
606+ if(ENABLE_AUTO_TF_PLUGIN_SOURCES AND BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG AND NOT ENABLE_TEST)
607+ file(GLOB TF_PLUGIN_SRCS ${SOURCE_DIR}/framework/*_tf_plugin.cpp)
608+ if(TF_PLUGIN_SRCS)
609+ target_sources(${TF_PLUGIN_NAME}_obj PRIVATE ${TF_PLUGIN_SRCS})
610+ endif()
611+ endif()
612+ 
602 if(NOT BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG)613 if(NOT BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG)
603 file(GLOB AICPU_SRCS ${SOURCE_DIR}/op_kernel_aicpu/*_aicpu*.cpp)614 file(GLOB AICPU_SRCS ${SOURCE_DIR}/op_kernel_aicpu/*_aicpu*.cpp)
604 if(AICPU_SRCS)615 if(AICPU_SRCS)
@@ -613,7 +624,7 @@ macro(add_all_modules_sources)
613 if(NOT ${OpTypeLen} EQUAL ${AclnnTypeLen})624 if(NOT ${OpTypeLen} EQUAL ${AclnnTypeLen})
614 message(FATAL_ERROR "OPTYPE AND ACLNNTYPE Should be One-to-One (cv op: ${OP_NAME})")625 message(FATAL_ERROR "OPTYPE AND ACLNNTYPE Should be One-to-One (cv op: ${OP_NAME})")
615 endif()626 endif()
616- 627+ 
617 math(EXPR index "${OpTypeLen} - 1")628 math(EXPR index "${OpTypeLen} - 1")
618 foreach(i RANGE ${index})629 foreach(i RANGE ${index})
619 list(GET MODULE_OPTYPE ${i} OpType)630 list(GET MODULE_OPTYPE ${i} OpType)
@@ -645,7 +656,7 @@ macro(add_all_modules_sources)
645 656 
646 file(GLOB OP_GRAPH_SRCS ${SOURCE_DIR}/op_graph/*_graph_*.cpp ${SOURCE_DIR}/op_graph/*_fallback.cpp ${SOURCE_DIR}/op_graph/fusion_pass/*_pass.cpp)657 file(GLOB OP_GRAPH_SRCS ${SOURCE_DIR}/op_graph/*_graph_*.cpp ${SOURCE_DIR}/op_graph/*_fallback.cpp ${SOURCE_DIR}/op_graph/fusion_pass/*_pass.cpp)
647 if(OP_GRAPH_SRCS)658 if(OP_GRAPH_SRCS)
648- add_op_graph_modules() 659+ add_op_graph_modules()
649 target_sources(${OP_GRAPH_NAME}_obj PRIVATE ${OP_GRAPH_SRCS})660 target_sources(${OP_GRAPH_NAME}_obj PRIVATE ${OP_GRAPH_SRCS})
650 endif()661 endif()
651 662 
@@ -735,7 +746,7 @@ endfunction()
735function(check_compiled_ops)746function(check_compiled_ops)
736 message(STATUS "Ops for this compilation contains: ${COMPILED_OPS}")747 message(STATUS "Ops for this compilation contains: ${COMPILED_OPS}")
737 if(COMPILED_OPS STREQUAL "")748 if(COMPILED_OPS STREQUAL "")
738- message(FATAL_ERROR "Specified ops not found in this depository, please check --ops paramater")749+ message(FATAL_ERROR "Specified ops not found in this depository, please check --ops parameter")
739 endif()750 endif()
740 751 
741 # 未指定算子,全部编译752 # 未指定算子,全部编译
@@ -758,11 +769,11 @@ function(check_compiled_ops)
758 list(JOIN not_compiled_ops "," not_compiled_ops_str)769 list(JOIN not_compiled_ops "," not_compiled_ops_str)
759 if(ENABLE_EXPERIMENTAL)770 if(ENABLE_EXPERIMENTAL)
760 message(FATAL_ERROR771 message(FATAL_ERROR
761- "Specified ops(${not_compiled_ops_str}) not found in experimental, please check --ops paramater"772+ "Specified ops(${not_compiled_ops_str}) not found in experimental, please check --ops parameter"
762 )773 )
763 else()774 else()
764 message(FATAL_ERROR775 message(FATAL_ERROR
765- "Specified ops(${not_compiled_ops_str}) not found in this depository, please check --ops paramater"776+ "Specified ops(${not_compiled_ops_str}) not found in this depository, please check --ops parameter"
766 )777 )
767 endif()778 endif()
768endfunction()779endfunction()
@@ -819,7 +830,7 @@ function(protobuf_generate_external comp c_var h_var)
819 830 
820 if (_add_target)831 if (_add_target)
821 add_custom_target(832 add_custom_target(
822- ${comp} DEPENDS ${${c_var}} ${${h_var}}) 833+ ${comp} DEPENDS ${${c_var}} ${${h_var}})
823 endif()834 endif()
824 835 
825 set_source_files_properties(${${c_var}} ${${h_var}} PROPERTIES GENERATED TRUE)836 set_source_files_properties(${${c_var}} ${${h_var}} PROPERTIES GENERATED TRUE)
@@ -832,7 +843,7 @@ function(add_onnx_plugin_modules)
832 if (NOT TARGET ${ONNX_PLUGIN_NAME}_obj)843 if (NOT TARGET ${ONNX_PLUGIN_NAME}_obj)
833 set(ge_onnx_proto_srcs844 set(ge_onnx_proto_srcs
834 ${ASCEND_DIR}/include/proto/ge_onnx.proto)845 ${ASCEND_DIR}/include/proto/ge_onnx.proto)
835- 846+ 
836 protobuf_generate_external(onnx ge_onnx_proto_cc ge_onnx_proto_h ${ge_onnx_proto_srcs})847 protobuf_generate_external(onnx ge_onnx_proto_cc ge_onnx_proto_h ${ge_onnx_proto_srcs})
837 848 
838 if(BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG)849 if(BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG)
@@ -888,6 +899,62 @@ macro(add_onnx_plugin_sources)
888 target_sources(${ONNX_PLUGIN_NAME}_obj PRIVATE ${ONNX_PLUGIN_SRCS})899 target_sources(${ONNX_PLUGIN_NAME}_obj PRIVATE ${ONNX_PLUGIN_SRCS})
889endmacro()900endmacro()
890 901 
902+function(add_tf_plugin_modules)
903+ if(NOT BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG OR ENABLE_TEST)
904+ return()
905+ endif()
906+ 
907+ if(NOT TARGET ${TF_PLUGIN_NAME}_obj)
908+ set(tf_proto_srcs
909+ ${ASCEND_DIR}/include/proto/ge_ir.proto
910+ )
911+ protobuf_generate_external(tf tf_proto_cc tf_proto_h ${tf_proto_srcs})
912+ npu_op_library(${TF_PLUGIN_NAME}_obj GRAPH ${tf_proto_h})
913+ set_target_properties(${TF_PLUGIN_NAME}_obj PROPERTIES
914+ CXX_STANDARD 14
915+ CXX_STANDARD_REQUIRED ON
916+ CXX_EXTENSIONS OFF
917+ )
918+ target_include_directories(${TF_PLUGIN_NAME}_obj
919+ PRIVATE
920+ ${OP_PROTO_INCLUDE}
921+ ${HOST_PROTOC_SRC}
922+ ${HOST_PROTOC_PATH}
923+ ${PROTOBUF_INCLUDE_DIRS}
924+ ${CMAKE_BINARY_DIR}/proto
925+ ${TF_PLUGIN_COMMON_INCLUDE}
926+ )
927+ target_compile_definitions(${TF_PLUGIN_NAME}_obj PRIVATE OPS_UTILS_LOG_SUB_MOD_NAME="TF_PLUGIN" LOG_CPP)
928+ target_compile_options(
929+ ${TF_PLUGIN_NAME}_obj PRIVATE -Dgoogle=ascend_private -fvisibility=hidden -Wno-shadow -Wno-unused-parameter
930+ )
931+ target_link_libraries(
932+ ${TF_PLUGIN_NAME}_obj
933+ PRIVATE $<BUILD_INTERFACE:intf_pub_cxx14>
934+ $<BUILD_INTERFACE:dlog_headers>
935+ $<$<TARGET_EXISTS:opbase_util_objs>:$<TARGET_OBJECTS:opbase_util_objs>>
936+ $<$<TARGET_EXISTS:opbase_infer_objs>:$<TARGET_OBJECTS:opbase_infer_objs>>
937+ ascend_protobuf_static
938+ )
939+ endif()
940+endfunction()
941+ 
942+function(init_tf_plugin_modules)
943+ add_tf_plugin_modules()
944+endfunction()
945+ 
946+function(add_tf_plugin_sources)
947+ if(NOT BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG OR ENABLE_TEST)
948+ return()
949+ endif()
950+ 
951+ set(SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
952+ file(GLOB TF_PLUGIN_SRCS ${SOURCE_DIR}/*_tf_plugin.cpp)
953+ if(TF_PLUGIN_SRCS)
954+ target_sources(${TF_PLUGIN_NAME}_obj PRIVATE ${TF_PLUGIN_SRCS})
955+ endif()
956+endfunction()
957+ 
891 958 
892# 删除以下重复函数,使用 cmake 仓版本:959# 删除以下重复函数,使用 cmake 仓版本:
893# - replace_cur_major_minor_ver960# - replace_cur_major_minor_ver
Mcmake/symbol.cmake+62-13
@@ -1,10 +1,10 @@
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").
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 
@@ -62,7 +62,7 @@ endfunction()
62 62 
63# gen es_cv63# gen es_cv
64function(gen_es_cv_lib_ready)64function(gen_es_cv_lib_ready)
65- # 合并proto.h生成ops_proto_cv.h和ops_proto_cv.cpp 65+ # 合并proto.h生成ops_proto_cv.h和ops_proto_cv.cpp
66 merge_graph_headers(TARGET merge_ops_proto_${PKG_NAME} OUT_DIR ${ASCEND_GRAPH_CONF_DST})66 merge_graph_headers(TARGET merge_ops_proto_${PKG_NAME} OUT_DIR ${ASCEND_GRAPH_CONF_DST})
67 add_library(67 add_library(
68 proto_${PKG_NAME} SHARED68 proto_${PKG_NAME} SHARED
@@ -78,8 +78,8 @@ function(gen_es_cv_lib_ready)
78 -Wl,--as-needed78 -Wl,--as-needed
79 )79 )
80 target_link_directories(proto_${PKG_NAME} PRIVATE ${ASCEND_DIR}/${SYSTEM_PREFIX}/lib64)80 target_link_directories(proto_${PKG_NAME} PRIVATE ${ASCEND_DIR}/${SYSTEM_PREFIX}/lib64)
81- 81+ 
82- # 生成 es_cv 82+ # 生成 es_cv
83 add_es_library_and_whl(83 add_es_library_and_whl(
84 ES_LINKABLE_AND_ALL_TARGET es_${PKG_NAME}84 ES_LINKABLE_AND_ALL_TARGET es_${PKG_NAME}
85 OPP_PROTO_TARGET proto_${PKG_NAME}85 OPP_PROTO_TARGET proto_${PKG_NAME}
@@ -104,7 +104,7 @@ endfunction()
104 104 
105# gen es_cv for custom105# gen es_cv for custom
106function(gen_es_cv_lib_ready_cust)106function(gen_es_cv_lib_ready_cust)
107- # 合并proto.h生成ops_proto_cv.h和ops_proto_cv.cpp 107+ # 合并proto.h生成ops_proto_cv.h和ops_proto_cv.cpp
108 merge_graph_headers(TARGET merge_ops_proto_${PKG_NAME}_cust OUT_DIR ${ASCEND_GRAPH_CONF_DST})108 merge_graph_headers(TARGET merge_ops_proto_${PKG_NAME}_cust OUT_DIR ${ASCEND_GRAPH_CONF_DST})
109 add_library(109 add_library(
110 proto_${PKG_NAME}_cust SHARED110 proto_${PKG_NAME}_cust SHARED
@@ -120,8 +120,8 @@ function(gen_es_cv_lib_ready_cust)
120 -Wl,--as-needed120 -Wl,--as-needed
121 )121 )
122 target_link_directories(proto_${PKG_NAME}_cust PRIVATE ${ASCEND_DIR}/${SYSTEM_PREFIX}/lib64)122 target_link_directories(proto_${PKG_NAME}_cust PRIVATE ${ASCEND_DIR}/${SYSTEM_PREFIX}/lib64)
123- 123+ 
124- # 生成 es_cv 124+ # 生成 es_cv
125 add_es_library(125 add_es_library(
126 ES_LINKABLE_AND_ALL_TARGET es_${PKG_NAME}126 ES_LINKABLE_AND_ALL_TARGET es_${PKG_NAME}
127 OPP_PROTO_TARGET proto_${PKG_NAME}_cust127 OPP_PROTO_TARGET proto_${PKG_NAME}_cust
@@ -163,7 +163,7 @@ function(gen_opgraph_symbol)
163 $<$<TARGET_EXISTS:opbase_util_objs>:$<TARGET_OBJECTS:opbase_util_objs>>163 $<$<TARGET_EXISTS:opbase_util_objs>:$<TARGET_OBJECTS:opbase_util_objs>>
164 $<$<TARGET_EXISTS:opbase_infer_objs>:$<TARGET_OBJECTS:opbase_infer_objs>>164 $<$<TARGET_EXISTS:opbase_infer_objs>:$<TARGET_OBJECTS:opbase_infer_objs>>
165 )165 )
166- 166+ 
167 target_link_libraries(167 target_link_libraries(
168 ${OPGRAPH_NAME}168 ${OPGRAPH_NAME}
169 PRIVATE $<BUILD_INTERFACE:intf_pub_cxx17>169 PRIVATE $<BUILD_INTERFACE:intf_pub_cxx17>
@@ -182,11 +182,11 @@ function(gen_opgraph_symbol)
182 ascendalog182 ascendalog
183 )183 )
184 184 
185- target_link_directories(${OPGRAPH_NAME} PRIVATE 185+ target_link_directories(${OPGRAPH_NAME} PRIVATE
186 ${ASCEND_DIR}/${SYSTEM_PREFIX}/lib64186 ${ASCEND_DIR}/${SYSTEM_PREFIX}/lib64
187 ${CMAKE_BINARY_DIR}/es_packages/lib64187 ${CMAKE_BINARY_DIR}/es_packages/lib64
188 )188 )
189- set_target_properties(${OPGRAPH_NAME} PROPERTIES 189+ set_target_properties(${OPGRAPH_NAME} PROPERTIES
190 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/opp/built-in/op_proto190 LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/opp/built-in/op_proto
191 )191 )
192 install(192 install(
@@ -331,7 +331,7 @@ function(gen_cust_proto_symbol)
331 -Wl,--as-needed331 -Wl,--as-needed
332 )332 )
333 endif()333 endif()
334- 334+ 
335 file(GLOB_RECURSE proto_headers ${ASCEND_AUTOGEN_PATH}/*_proto.h)335 file(GLOB_RECURSE proto_headers ${ASCEND_AUTOGEN_PATH}/*_proto.h)
336 install(336 install(
337 FILES ${proto_headers}337 FILES ${proto_headers}
@@ -517,6 +517,53 @@ function(gen_onnx_plugin_symbol)
517 517 
518endfunction()518endfunction()
519 519 
520+function(gen_tf_plugin_symbol)
521+ if(NOT BUILD_WITH_INSTALLED_DEPENDENCY_CANN_PKG OR ENABLE_TEST)
522+ return()
523+ endif()
524+ 
525+ if(TARGET ${TF_PLUGIN_NAME}_obj)
526+ unset(TF_PLUGIN_SOURCE)
527+ get_target_property(TF_PLUGIN_SOURCE ${TF_PLUGIN_NAME}_obj SOURCES)
528+ if(TF_PLUGIN_SOURCE)
529+ list(FILTER TF_PLUGIN_SOURCE INCLUDE REGEX "_tf_plugin\\.(cpp|cc|cxx)$")
530+ endif()
531+ endif()
532+ 
533+ if(NOT TF_PLUGIN_SOURCE)
534+ message(STATUS "No tf_plugin sources found for ${TF_PLUGIN_NAME}_obj, skipping tf_plugin library creation")
535+ return()
536+ endif()
537+ 
538+ add_library(
539+ ${TF_PLUGIN_NAME} SHARED
540+ $<TARGET_OBJECTS:${TF_PLUGIN_NAME}_obj>
541+ )
542+ 
543+ target_link_libraries(
544+ ${TF_PLUGIN_NAME}
545+ PRIVATE $<BUILD_INTERFACE:intf_pub_cxx14>
546+ c_sec
547+ -Wl,--no-as-needed
548+ register
549+ -Wl,--as-needed
550+ -Wl,--whole-archive
551+ rt2_registry_static
552+ -Wl,--no-whole-archive
553+ unified_dlog
554+ ascendalog
555+ $<$<CONFIG:Release>:-s>
556+ )
557+ 
558+ target_link_directories(${TF_PLUGIN_NAME} PRIVATE ${ASCEND_DIR}/${SYSTEM_PREFIX}/lib64)
559+ 
560+ install(
561+ TARGETS ${TF_PLUGIN_NAME}
562+ LIBRARY DESTINATION ${TF_PLUGIN_LIB_INSTALL_DIR}
563+ OPTIONAL
564+ )
565+endfunction()
566+ 
520function(gen_norm_symbol)567function(gen_norm_symbol)
521 gen_ophost_symbol()568 gen_ophost_symbol()
522 569 
@@ -527,6 +574,8 @@ function(gen_norm_symbol)
527 gen_aicpu_const_symbol()574 gen_aicpu_const_symbol()
528 575 
529 gen_onnx_plugin_symbol()576 gen_onnx_plugin_symbol()
577+ 
578+ gen_tf_plugin_symbol()
530endfunction()579endfunction()
531 580 
532function(gen_cust_symbol)581function(gen_cust_symbol)
Mcmake/variables.cmake+14-4
@@ -1,10 +1,10 @@
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").
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 
@@ -17,6 +17,7 @@ set(OPGRAPH_NAME opgraph_${PKG_NAME})
17set(OP_GRAPH_NAME op_graph_${PKG_NAME})17set(OP_GRAPH_NAME op_graph_${PKG_NAME})
18set(GRAPH_PLUGIN_NAME graph_plugin_${PKG_NAME})18set(GRAPH_PLUGIN_NAME graph_plugin_${PKG_NAME})
19set(ONNX_PLUGIN_NAME oponnx_plugin_${PKG_NAME})19set(ONNX_PLUGIN_NAME oponnx_plugin_${PKG_NAME})
20+set(TF_PLUGIN_NAME optf_plugin_${PKG_NAME})
20 21 
21set(OP_CATEGORY_LIST "image" "objdetect" "examples")22set(OP_CATEGORY_LIST "image" "objdetect" "examples")
22 23 
@@ -36,6 +37,7 @@ set(NEED_COMPILE_OPS "${ASCEND_OP_NAME}" CACHE STRING "Need to be compiled Ops"
36# 已编译的算子37# 已编译的算子
37set(COMPILED_OPS CACHE STRING "Compiled Ops" FORCE)38set(COMPILED_OPS CACHE STRING "Compiled Ops" FORCE)
38set(COMPILED_OP_DIRS CACHE STRING "Compiled Ops Dirs" FORCE)39set(COMPILED_OP_DIRS CACHE STRING "Compiled Ops Dirs" FORCE)
40+set(ENABLE_AUTO_TF_PLUGIN_SOURCES OFF CACHE BOOL "Enable automatic collection of framework/*_tf_plugin.cpp")
39 41 
40# src path42# src path
41get_filename_component(OPS_CV_CMAKE_DIR "${OPS_CV_DIR}/cmake" REALPATH)43get_filename_component(OPS_CV_CMAKE_DIR "${OPS_CV_DIR}/cmake" REALPATH)
@@ -97,6 +99,7 @@ else()
97 set(OPGRAPH_INC_INSTALL_DIR ${OPP_PREFIX}/built-in/op_graph/inc)99 set(OPGRAPH_INC_INSTALL_DIR ${OPP_PREFIX}/built-in/op_graph/inc)
98 set(OPGRAPH_LIB_INSTALL_DIR ${OPP_PREFIX}/built-in/op_graph/lib/linux/${CMAKE_SYSTEM_PROCESSOR})100 set(OPGRAPH_LIB_INSTALL_DIR ${OPP_PREFIX}/built-in/op_graph/lib/linux/${CMAKE_SYSTEM_PROCESSOR})
99 set(ONNX_PLUGIN_LIB_INSTALL_DIR ${OPP_PREFIX}/built-in/framework/onnx)101 set(ONNX_PLUGIN_LIB_INSTALL_DIR ${OPP_PREFIX}/built-in/framework/onnx)
102+ set(TF_PLUGIN_LIB_INSTALL_DIR ${OPP_PREFIX}/built-in/framework/tensorflow)
100 set(COMMON_INC_INSTALL_DIR ${CMAKE_SYSTEM_PROCESSOR}-linux/include)103 set(COMMON_INC_INSTALL_DIR ${CMAKE_SYSTEM_PROCESSOR}-linux/include)
101 set(COMMON_LIB_INSTALL_DIR ops_cv/lib)104 set(COMMON_LIB_INSTALL_DIR ops_cv/lib)
102 set(VERSION_INFO_INSTALL_DIR ${CMAKE_SYSTEM_PROCESSOR}-linux)105 set(VERSION_INFO_INSTALL_DIR ${CMAKE_SYSTEM_PROCESSOR}-linux)
@@ -199,6 +202,13 @@ set(ONNX_PLUGIN_COMMON_INCLUDE
199 ${OP_PROTO_PATH_LIST}202 ${OP_PROTO_PATH_LIST}
200)203)
201 204 
205+set(TF_PLUGIN_COMMON_INCLUDE
206+ ${OPS_CV_DIR}/common/inc/framework
207+ ${OPS_CV_DIR}/common/inc/op_graph
208+ ${OPS_CV_DIR}/common/stub/inc/framework
209+ ${OP_PROTO_PATH_LIST}
210+)
211+ 
202set(AICPU_INCLUDE212set(AICPU_INCLUDE
203 ${OPBASE_INC_DIRS}213 ${OPBASE_INC_DIRS}
204 ${AICPU_INC_DIRS}214 ${AICPU_INC_DIRS}
@@ -234,4 +244,4 @@ set(OPS_CATEGORY_LIST
234 244 
235# mapping of soc full name and short name245# mapping of soc full name and short name
236set(SHORT_NAME_LIST "ascend910_93" "ascend950" "ascend910b" "ascend910" "ascend310p")246set(SHORT_NAME_LIST "ascend910_93" "ascend950" "ascend910b" "ascend910" "ascend310p")
237-set(FULL_NAME_LIST "ascend910_9391" "ascend950PR_9599" "ascend910B1" "ascend910A" "ascend310P1")247+set(FULL_NAME_LIST "ascend910_9391" "ascend950PR_9599" "ascend910B1" "ascend910A" "ascend310P1")
Mcommon/src/framework/CMakeLists.txt+2-1
@@ -8,4 +8,5 @@
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_onnx_plugin_sources()11+add_onnx_plugin_sources()
12+add_tf_plugin_sources()
Acommon/src/framework/cv_stub_tf_plugin.cpp+16-0
@@ -0,0 +1,16 @@
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+// This source keeps the CV TensorFlow plugin target buildable before real
12+// operator adapters are enabled. Do not register concrete ops here; add real
13+// adapters through *_tf_plugin.cpp files.
14+namespace {
15+void TfPluginStub() {}
16+} // namespace
Mscripts/build_conf.sh+2-2
@@ -11,7 +11,7 @@
11#11#
12# Global config: variables, paths, utility functions shared across all build scripts.12# Global config: variables, paths, utility functions shared across all build scripts.
13 13 
14-RELEASE_TARGETS=("ophost" "opapi" "opgraph" "opkernel" "opkernel_aicpu" "onnxplugin")14+RELEASE_TARGETS=("ophost" "opapi" "opgraph" "opkernel" "opkernel_aicpu" "onnxplugin" "tfplugin")
15SUPPORTED_UT_TARGETS=("ophost_test" "opapi_test" "opgraph_test" "opkernel_test" "opkernel_aicpu_test")15SUPPORTED_UT_TARGETS=("ophost_test" "opapi_test" "opgraph_test" "opkernel_test" "opkernel_aicpu_test")
16SUPPORT_COMPUTE_UNIT_SHORT=("ascend031" "ascend035" "ascend310b" "ascend310p" "ascend610lite" "ascend630"16SUPPORT_COMPUTE_UNIT_SHORT=("ascend031" "ascend035" "ascend310b" "ascend310p" "ascend610lite" "ascend630"
17 "ascend910_93" "ascend950" "ascend910b" "ascend910" "mc62" "kirinx90" "kirin9030")17 "ascend910_93" "ascend950" "ascend910b" "ascend910" "mc62" "kirinx90" "kirin9030")
@@ -24,7 +24,7 @@ SUPPORTED_LONG_OPTS=(
24 "help" "ops=" "soc=" "vendor_name=" "build-type=" "cov" "noexec" "aicpu" "noaicpu" "opkernel" "opkernel_aicpu" "jit"24 "help" "ops=" "soc=" "vendor_name=" "build-type=" "cov" "noexec" "aicpu" "noaicpu" "opkernel" "opkernel_aicpu" "jit"
25 "pkg" "asan" "valgrind" "make_clean" "static" "simulator"25 "pkg" "asan" "valgrind" "make_clean" "static" "simulator"
26 "ophost" "opapi" "opgraph" "ophost_test" "opapi_test" "opgraph_test" "opkernel_test" "opkernel_aicpu_test"26 "ophost" "opapi" "opgraph" "ophost_test" "opapi_test" "opgraph_test" "opkernel_test" "opkernel_aicpu_test"
27- "run_example" "genop=" "genop_aicpu=" "cann_3rd_lib_path" "experimental" "mssanitizer" "oom" "onnxplugin" "dump_cce"27+ "run_example" "genop=" "genop_aicpu=" "cann_3rd_lib_path" "experimental" "mssanitizer" "oom" "onnxplugin" "tfplugin" "dump_cce"
28 "bisheng_flags=" "kernel_template_input=" "rule_launch=" "ccache=" "pkg-type="28 "bisheng_flags=" "kernel_template_input=" "rule_launch=" "ccache=" "pkg-type="
29)29)
30 30 
Mscripts/build_options.sh+25-2
@@ -205,6 +205,20 @@ usage() {
205 echo " bash build.sh --onnxplugin --build-type=Debug"205 echo " bash build.sh --onnxplugin --build-type=Debug"
206 return206 return
207 ;;207 ;;
208+ tfplugin)
209+ echo "TFPlugin Build Options:"
210+ echo $dotted_line
211+ echo " --tfplugin Build tfplugin library"
212+ echo " -j[n] Compile thread nums, default is 8, eg: -j8"
213+ echo " -O[n] Compile optimization options, support [O0 O1 O2 O3], eg:-O3"
214+ echo " --build-type=<TYPE> Specify build type(TYPE options: Release/Debug), Default:Release"
215+ echo " --ccache=<VALUE> Enable or disable ccache (VALUE: on/off/true/false/disable), Default: on"
216+ echo $dotted_line
217+ echo "Examples:"
218+ echo " bash build.sh --tfplugin -j16 -O3"
219+ echo " bash build.sh --tfplugin --build-type=Debug"
220+ return
221+ ;;
208 ophost_test)222 ophost_test)
209 echo "Ophost Test Options:"223 echo "Ophost Test Options:"
210 echo $dotted_line224 echo $dotted_line
@@ -309,6 +323,7 @@ usage() {
309 echo " --aicpu build aicpu task"323 echo " --aicpu build aicpu task"
310 echo " --opgraph build op_graph_cv.so"324 echo " --opgraph build op_graph_cv.so"
311 echo " --onnxplugin build oponnx_plugin_cv.so"325 echo " --onnxplugin build oponnx_plugin_cv.so"
326+ echo " --tfplugin build optf_plugin_cv.so"
312 echo " --opapi build opapi_cv.so"327 echo " --opapi build opapi_cv.so"
313 echo " --ophost build ophost_cv.so"328 echo " --ophost build ophost_cv.so"
314 echo " --opkernel build binary kernel"329 echo " --opkernel build binary kernel"
@@ -347,7 +362,7 @@ check_help_combinations() {
347 for arg in "${args[@]}"; do362 for arg in "${args[@]}"; do
348 case "$arg" in363 case "$arg" in
349 -u) has_u=true ;;364 -u) has_u=true ;;
350- --ophost_test | --opapi_test | --opgraph_test | --ophost | --opapi | --opgraph | --onnxplugin)365+ --ophost_test | --opapi_test | --opgraph_test | --ophost | --opapi | --opgraph | --onnxplugin | --tfplugin)
351 has_test_command=true366 has_test_command=true
352 has_build_command=true367 has_build_command=true
353 ;;368 ;;
@@ -498,7 +513,7 @@ set_create_libs() {
498 return513 return
499 fi514 fi
500 if [[ "$ENABLE_PACKAGE" == "TRUE" && "$ENABLE_CUSTOM" != "TRUE" ]]; then515 if [[ "$ENABLE_PACKAGE" == "TRUE" && "$ENABLE_CUSTOM" != "TRUE" ]]; then
501- BUILD_LIBS=("ophost_${REPOSITORY_NAME}" "opapi_${REPOSITORY_NAME}" "opgraph_${REPOSITORY_NAME}" "oponnx_plugin_${REPOSITORY_NAME}")516+ BUILD_LIBS=("ophost_${REPOSITORY_NAME}" "opapi_${REPOSITORY_NAME}" "opgraph_${REPOSITORY_NAME}" "oponnx_plugin_${REPOSITORY_NAME}" "optf_plugin_${REPOSITORY_NAME}")
502 ENABLE_CREATE_LIB=TRUE517 ENABLE_CREATE_LIB=TRUE
503 else518 else
504 if [[ "$OP_HOST" == "TRUE" ]]; then519 if [[ "$OP_HOST" == "TRUE" ]]; then
@@ -517,6 +532,10 @@ set_create_libs() {
517 BUILD_LIBS+=("oponnx_plugin_${REPOSITORY_NAME}")532 BUILD_LIBS+=("oponnx_plugin_${REPOSITORY_NAME}")
518 ENABLE_CREATE_LIB=TRUE533 ENABLE_CREATE_LIB=TRUE
519 fi534 fi
535+ if [[ "$TF_PLUGIN" == "TRUE" ]]; then
536+ BUILD_LIBS+=("optf_plugin_${REPOSITORY_NAME}")
537+ ENABLE_CREATE_LIB=TRUE
538+ fi
520 if [[ "$OP_KERNEL" == "TRUE" ]]; then539 if [[ "$OP_KERNEL" == "TRUE" ]]; then
521 ENABLE_BINARY=TRUE540 ENABLE_BINARY=TRUE
522 fi541 fi
@@ -671,6 +690,7 @@ checkopts() {
671 OP_HOST=FALSE690 OP_HOST=FALSE
672 OP_GRAPH=FALSE691 OP_GRAPH=FALSE
673 ONNX_PLUGIN=FALSE692 ONNX_PLUGIN=FALSE
693+ TF_PLUGIN=FALSE
674 OP_KERNEL=FALSE694 OP_KERNEL=FALSE
675 OP_KERNEL_AICPU=FALSE695 OP_KERNEL_AICPU=FALSE
676 ENABLE_CREATE_LIB=FALSE696 ENABLE_CREATE_LIB=FALSE
@@ -727,6 +747,7 @@ checkopts() {
727 --opapi) SHOW_HELP="opapi" ;;747 --opapi) SHOW_HELP="opapi" ;;
728 --opgraph) SHOW_HELP="opgraph" ;;748 --opgraph) SHOW_HELP="opgraph" ;;
729 --onnxplugin) SHOW_HELP="onnxplugin" ;;749 --onnxplugin) SHOW_HELP="onnxplugin" ;;
750+ --tfplugin) SHOW_HELP="tfplugin" ;;
730 --ophost_test) SHOW_HELP="ophost_test" ;;751 --ophost_test) SHOW_HELP="ophost_test" ;;
731 --opapi_test) SHOW_HELP="opapi_test" ;;752 --opapi_test) SHOW_HELP="opapi_test" ;;
732 --opgraph_test) SHOW_HELP="opgraph_test" ;;753 --opgraph_test) SHOW_HELP="opgraph_test" ;;
@@ -863,6 +884,8 @@ checkopts() {
863 OP_GRAPH=TRUE884 OP_GRAPH=TRUE
864 elif [[ "$OPTARG" == "onnxplugin" ]]; then885 elif [[ "$OPTARG" == "onnxplugin" ]]; then
865 ONNX_PLUGIN=TRUE886 ONNX_PLUGIN=TRUE
887+ elif [[ "$OPTARG" == "tfplugin" ]]; then
888+ TF_PLUGIN=TRUE
866 elif [[ "$OPTARG" == "opkernel" ]]; then889 elif [[ "$OPTARG" == "opkernel" ]]; then
867 OP_KERNEL=TRUE890 OP_KERNEL=TRUE
868 elif [[ "$OPTARG" == "opkernel_aicpu" ]]; then891 elif [[ "$OPTARG" == "opkernel_aicpu" ]]; then
Mscripts/package/module/ascend/OpsCvInc.xml+3-0
@@ -14,6 +14,9 @@
14 <file_info value="oponnx_plugin_cv_lib" copy_type="delivery" src_path="" dst_path="opp/built-in/framework/onnx/" install_path="opp/built-in/framework/onnx">14 <file_info value="oponnx_plugin_cv_lib" copy_type="delivery" src_path="" dst_path="opp/built-in/framework/onnx/" install_path="opp/built-in/framework/onnx">
15 <file value="liboponnx_plugin_cv.so" install_mod="550"/>15 <file value="liboponnx_plugin_cv.so" install_mod="550"/>
16 </file_info>16 </file_info>
17+ <file_info value="optf_plugin_cv_lib" copy_type="delivery" src_path="" dst_path="opp/built-in/framework/tensorflow/" install_path="opp/built-in/framework/tensorflow" optional="true">
18+ <file value="liboptf_plugin_cv.so" install_mod="550"/>
19+ </file_info>
17 <file_info copy_type="delivery" src_path="" dst_path="opp/built-in/op_impl/ai_core/tbe" install_path="opp/built-in/op_impl/ai_core/tbe" install_type="all">20 <file_info copy_type="delivery" src_path="" dst_path="opp/built-in/op_impl/ai_core/tbe" install_path="opp/built-in/op_impl/ai_core/tbe" install_type="all">
18 <file value="config" install_mod="550"/>21 <file value="config" install_mod="550"/>
19 </file_info>22 </file_info>
Mscripts/package/ops_cv/ops_cv.xml+1-0
@@ -60,6 +60,7 @@
60 <path value="opp/built-in/op_graph/lib/linux/$(ARCH)" install_mod="550"/>60 <path value="opp/built-in/op_graph/lib/linux/$(ARCH)" install_mod="550"/>
61 <path value="opp/built-in/framework" install_mod="550"/>61 <path value="opp/built-in/framework" install_mod="550"/>
62 <path value="opp/built-in/framework/onnx" install_mod="550"/>62 <path value="opp/built-in/framework/onnx" install_mod="550"/>
63+ <path value="opp/built-in/framework/tensorflow" install_mod="550"/>
63 <path value="$(TARGET_ENV)/include/es" install_mod="550"/>64 <path value="$(TARGET_ENV)/include/es" install_mod="550"/>
64 <path value="$(TARGET_ENV)/include/es/es_cv" install_mod="550"/>65 <path value="$(TARGET_ENV)/include/es/es_cv" install_mod="550"/>
65 </dir_info>66 </dir_info>