已合并
fix: 更新CMake配置将libcustom_op_registry_static.a,stub/libgraph.so添加新符号支持特定芯片环境 #3528
Chang-an-HW创建于 6月13日
fix: 更新CMake配置将libcustom_op_registry_static.a,stub/libgraph.so添加新符号支持特定芯片环境 #3528
已合并
共 7 个文件变更+45-23
| @@ -16,6 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | 18 | ||
| 19 | + | ||
| 19 | 20 | ||
| 20 | 21 | ||
| 21 | 22 | ||
| @@ -250,7 +250,7 @@ if("ge-executor" IN_LIST BUILD_COMPONENT) | |||
| 250 | ) | 250 | ) |
| 251 | else() | 251 | else() |
| 252 | # MDC 运行态编译 | 252 | # MDC 运行态编译 |
| 253 | - install(TARGETS ge_common ge_common_base davinci_executor hybrid_executor gert register graph graph_base acl_cblas hcom_executor | 253 | + install(TARGETS ge_common ge_common_base davinci_executor hybrid_executor gert register graph graph_base custom_op_registry_static acl_cblas hcom_executor |
| 254 | acl_mdl acl_mdl_impl acl_mdl_impl_om2 acl_op_executor acl_op_executor_impl om2_executor ge_executor_shared lowering | 254 | acl_mdl acl_mdl_impl acl_mdl_impl_om2 acl_op_executor acl_op_executor_impl om2_executor ge_executor_shared lowering |
| 255 | LIBRARY DESTINATION ${ARCH_LINUX_PATH}/lib64 COMPONENT ge-executor | 255 | LIBRARY DESTINATION ${ARCH_LINUX_PATH}/lib64 COMPONENT ge-executor |
| 256 | ARCHIVE DESTINATION ${ARCH_LINUX_PATH}/lib64 COMPONENT ge-executor | 256 | ARCHIVE DESTINATION ${ARCH_LINUX_PATH}/lib64 COMPONENT ge-executor |
| @@ -90,6 +90,7 @@ set(GRAPH_BASE_SOURCE_LIST | |||
| 90 | "${GE_METADEF_DIR}/base/utils/file_utils.cc" | 90 | "${GE_METADEF_DIR}/base/utils/file_utils.cc" |
| 91 | "${GE_METADEF_DIR}/base/utils/aligned_ptr.cc" | 91 | "${GE_METADEF_DIR}/base/utils/aligned_ptr.cc" |
| 92 | "${GE_METADEF_DIR}/base/common/plugin/plugin_manager.cc" | 92 | "${GE_METADEF_DIR}/base/common/plugin/plugin_manager.cc" |
| 93 | + "normal_graph/custom_op_load_context.cc" | ||
| 93 | ) | 94 | ) |
| 94 | 95 | ||
| 95 | SET(GRAPH_SOURCE_LIST | 96 | SET(GRAPH_SOURCE_LIST |
| @@ -387,6 +388,8 @@ set(STUB_HEADER_LIST | |||
| 387 | ${GE_METADEF_INC_DIR}/graph/ir_definitions_recover.h | 388 | ${GE_METADEF_INC_DIR}/graph/ir_definitions_recover.h |
| 388 | ${CMAKE_CURRENT_LIST_DIR}/../third_party/transformer/src/axis_constants.h | 389 | ${CMAKE_CURRENT_LIST_DIR}/../third_party/transformer/src/axis_constants.h |
| 389 | ${GE_METADEF_INC_DIR}/common/screen_printer.h | 390 | ${GE_METADEF_INC_DIR}/common/screen_printer.h |
| 391 | + ${GE_METADEF_INC_DIR}/graph/custom_op_pull_registry.h | ||
| 392 | + ${GE_METADEF_INC_DIR}/graph/custom_op_registry.h | ||
| 390 | ) | 393 | ) |
| 391 | 394 | ||
| 392 | if (BUILD_OPEN_PROJECT OR ENABLE_OPEN_SRC) | 395 | if (BUILD_OPEN_PROJECT OR ENABLE_OPEN_SRC) |
| @@ -407,8 +410,6 @@ endif () | |||
| 407 | if (NOT "${PRODUCT}" STREQUAL "ascend031") | 410 | if (NOT "${PRODUCT}" STREQUAL "ascend031") |
| 408 | list(APPEND STUB_HEADER_LIST | 411 | list(APPEND STUB_HEADER_LIST |
| 409 | ${GE_METADEF_INC_DIR}/external/graph/operator.h | 412 | ${GE_METADEF_INC_DIR}/external/graph/operator.h |
| 410 | - ${GE_METADEF_INC_DIR}/graph/custom_op_pull_registry.h | ||
| 411 | - ${GE_METADEF_INC_DIR}/graph/custom_op_registry.h | ||
| 412 | ${GE_METADEF_INC_DIR}/graph/ge_tensor.h | 413 | ${GE_METADEF_INC_DIR}/graph/ge_tensor.h |
| 413 | ) | 414 | ) |
| 414 | if (BUILD_OPEN_PROJECT OR ENABLE_OPEN_SRC) | 415 | if (BUILD_OPEN_PROJECT OR ENABLE_OPEN_SRC) |
| @@ -18,9 +18,6 @@ | |||
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | namespace ge { | 20 | namespace ge { |
| 21 | -namespace { | ||
| 22 | -thread_local uint32_t g_offline_custom_op_so_loading_depth = 0U; | ||
| 23 | -} // namespace | ||
| 24 | 21 | ||
| 25 | CustomOpRegistry &CustomOpFactory::GetGlobalRegistry() { | 22 | CustomOpRegistry &CustomOpFactory::GetGlobalRegistry() { |
| 26 | return *GetGlobalRegistryPtr(); | 23 | return *GetGlobalRegistryPtr(); |
| @@ -60,18 +57,4 @@ CustomOpCreatorRegister::CustomOpCreatorRegister(const AscendString &operator_ty | |||
| 60 | } | 57 | } |
| 61 | CustomOpFactory::RegisterCustomOpCreator(operator_type, op_creator); | 58 | CustomOpFactory::RegisterCustomOpCreator(operator_type, op_creator); |
| 62 | } | 59 | } |
| 63 | - | ||
| 64 | -ScopedOfflineCustomOpSoLoadGuard::ScopedOfflineCustomOpSoLoadGuard() { | ||
| 65 | - ++g_offline_custom_op_so_loading_depth; | ||
| 66 | -} | ||
| 67 | - | ||
| 68 | -ScopedOfflineCustomOpSoLoadGuard::~ScopedOfflineCustomOpSoLoadGuard() { | ||
| 69 | - if (g_offline_custom_op_so_loading_depth > 0U) { | ||
| 70 | - --g_offline_custom_op_so_loading_depth; | ||
| 71 | - } | ||
| 72 | -} | ||
| 73 | - | ||
| 74 | -bool IsOfflineCustomOpSoLoading() { | ||
| 75 | - return g_offline_custom_op_so_loading_depth > 0U; | ||
| 76 | -} | ||
| 77 | } // namespace ge | 60 | } // namespace ge |
| @@ -0,0 +1,32 @@ | |||
| 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 | + | ||
| 13 | + | ||
| 14 | +namespace ge { | ||
| 15 | +namespace { | ||
| 16 | +thread_local uint32_t g_offline_custom_op_so_loading_depth = 0U; | ||
| 17 | +} | ||
| 18 | + | ||
| 19 | +ScopedOfflineCustomOpSoLoadGuard::ScopedOfflineCustomOpSoLoadGuard() { | ||
| 20 | + ++g_offline_custom_op_so_loading_depth; | ||
| 21 | +} | ||
| 22 | + | ||
| 23 | +ScopedOfflineCustomOpSoLoadGuard::~ScopedOfflineCustomOpSoLoadGuard() { | ||
| 24 | + if (g_offline_custom_op_so_loading_depth > 0U) { | ||
| 25 | + --g_offline_custom_op_so_loading_depth; | ||
| 26 | + } | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +bool IsOfflineCustomOpSoLoading() { | ||
| 30 | + return g_offline_custom_op_so_loading_depth > 0U; | ||
| 31 | +} | ||
| 32 | +} // namespace ge | ||
| @@ -8,6 +8,7 @@ | |||
| 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 | + | ||
| 11 | 12 | ||
| 12 | 13 | ||
| 13 | 14 | ||
| @@ -146,7 +147,7 @@ BaseCustomOp *CustomOpRegistry::CreateOrGetCustomOp(const AscendString &op_type) | |||
| 146 | return nullptr; | 147 | return nullptr; |
| 147 | } | 148 | } |
| 148 | auto base_custom_op = op_creator_it->second(); | 149 | auto base_custom_op = op_creator_it->second(); |
| 149 | - auto [ops_it, success] = custom_ops_.emplace(op_type, std::move(base_custom_op)); | 150 | + auto [ops_it, success] = custom_ops_.emplace(op_type, std::shared_ptr<BaseCustomOp>(std::move(base_custom_op))); |
| 150 | if (success) { | 151 | if (success) { |
| 151 | return ops_it->second.get(); | 152 | return ops_it->second.get(); |
| 152 | } | 153 | } |
| @@ -13,15 +13,19 @@ | |||
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | + | ||
| 16 | 17 | ||
| 17 | 18 | ||
| 18 | 19 | ||
| 19 | 20 | ||
| 20 | 21 | ||
| 21 | 22 | ||
| 22 | -#include "graph/custom_op.h" | 23 | +#include "graph/ge_error_codes.h" |
| 23 | 24 | ||
| 24 | namespace ge { | 25 | namespace ge { |
| 26 | +class BaseCustomOp; | ||
| 27 | +using BaseOpCreator = std::function<std::unique_ptr<BaseCustomOp>()>; | ||
| 28 | + | ||
| 25 | class CustomOpSoHandle; | 29 | class CustomOpSoHandle; |
| 26 | using CustomOpSoHandlePtr = std::shared_ptr<CustomOpSoHandle>; | 30 | using CustomOpSoHandlePtr = std::shared_ptr<CustomOpSoHandle>; |
| 27 | 31 | ||
| @@ -44,7 +48,7 @@ class CustomOpRegistry { | |||
| 44 | mutable std::mutex mu_; | 48 | mutable std::mutex mu_; |
| 45 | std::vector<CustomOpSoHandlePtr> so_handles_; | 49 | std::vector<CustomOpSoHandlePtr> so_handles_; |
| 46 | std::map<AscendString, BaseOpCreator> creators_; | 50 | std::map<AscendString, BaseOpCreator> creators_; |
| 47 | - std::map<AscendString, std::unique_ptr<BaseCustomOp>> custom_ops_; | 51 | + std::map<AscendString, std::shared_ptr<BaseCustomOp>> custom_ops_; |
| 48 | }; | 52 | }; |
| 49 | 53 | ||
| 50 | using CustomOpRegistryPtr = std::shared_ptr<CustomOpRegistry>; | 54 | using CustomOpRegistryPtr = std::shared_ptr<CustomOpRegistry>; |