Line data Source code
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 : #include "root_info_detect_bridge.h"
12 :
13 : #include "log.h"
14 :
15 : namespace Hccl {
16 : namespace {
17 : // 槽位位于 hccl_v2,hcomm 的 registrar 在装载期回调这里。
18 : // 函数内静态可确保跨 SO 注册发生时槽位已经完成构造。
19 57 : RootInfoDetectBridge& BridgeSlot()
20 : {
21 : static RootInfoDetectBridge bridge{};
22 57 : return bridge;
23 : }
24 : } // namespace
25 :
26 48 : HcclResult RegisterRootInfoDetectBridge(const RootInfoDetectBridge& bridge)
27 : {
28 : // 只发布完整回调表,避免兼容入口读取到部分可用的 bridge。
29 48 : if (bridge.getRootInfo == nullptr || bridge.detectRankTable == nullptr) {
30 0 : return HCCL_E_PTR;
31 : }
32 48 : auto& registeredBridge = BridgeSlot();
33 : // bridge 在装载期固定,禁止运行过程中替换 provider 回调。
34 48 : if (registeredBridge.getRootInfo != nullptr || registeredBridge.detectRankTable != nullptr) {
35 0 : HCCL_ERROR("[%s] RootInfoDetect bridge has already been registered.", __func__);
36 0 : return HCCL_E_INTERNAL;
37 : }
38 48 : registeredBridge = bridge;
39 48 : return HCCL_SUCCESS;
40 : }
41 :
42 9 : const RootInfoDetectBridge* GetRootInfoDetectBridge()
43 : {
44 9 : const auto& bridge = BridgeSlot();
45 : // 未完成注册时统一返回 nullptr,由 hccl_v2 兼容入口转换为明确错误。
46 9 : if (bridge.getRootInfo == nullptr || bridge.detectRankTable == nullptr) {
47 0 : return nullptr;
48 : }
49 9 : return &bridge;
50 : }
51 : } // namespace Hccl
|