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 "hcomm_team_c_adpt.h"
12 : #include "hcomm_team.h"
13 : #include "hcomm_team_mgr.h"
14 : #include "hcomm_result_defs.h"
15 : #include "hcomm_team_entity_defs.h"
16 : #include "log.h"
17 :
18 : using namespace hcomm;
19 :
20 64 : HcommResult HcommTeamCreate(
21 : HcommTeamHandle worldTeam, const HcommTeamCreateDesc* desc, HcommTeamHandle* team, uint64_t* syncMemSize)
22 : {
23 64 : CHK_PRT_RET(
24 : (desc == nullptr || team == nullptr || syncMemSize == nullptr), HCCL_ERROR("[%s] nullptr parameter", __func__),
25 : HCOMM_E_PTR);
26 61 : CHK_PRT_RET(
27 : (desc->memberNum == 0 || desc->memberNum == 1), HCCL_ERROR("[%s] memberNum cannot be 0 or 1", __func__),
28 : HCOMM_E_PARA);
29 59 : CHK_PRT_RET(
30 : desc->selfMemberId >= desc->memberNum,
31 : HCCL_ERROR("[%s] selfMemberId[%u] >= memberNum[%u]", __func__, desc->selfMemberId, desc->memberNum),
32 : HCOMM_E_PARA);
33 58 : CHK_PRT_RET(
34 : (desc->requirement.signalCount != 0 || desc->requirement.counterCount != 0),
35 : HCCL_ERROR(
36 : "[%s] signalCount[%u] and counterCount[%u] must be 0", __func__, desc->requirement.signalCount,
37 : desc->requirement.counterCount),
38 : HCOMM_E_PARA);
39 58 : CHK_PRT_RET(
40 : desc->requirement.barrierCount == 0, HCCL_ERROR("[%s] barrierCount must be >= 1", __func__), HCOMM_E_PARA);
41 56 : CHK_PRT_RET(
42 : worldTeam != nullptr && desc->worldMemberIds == nullptr,
43 : HCCL_ERROR("[%s] sub team worldMemberIds is null", __func__), HCOMM_E_PTR);
44 55 : return HcommTeamMgr::GetInstance().TeamCreate(worldTeam, desc, team, syncMemSize);
45 : }
46 :
47 15 : HcommResult HcommTeamDestroy(HcommTeamHandle team)
48 : {
49 15 : CHK_PRT_RET(team == nullptr, HCCL_ERROR("[%s] team is nullptr", __func__), HCOMM_E_PTR);
50 14 : return HcommTeamMgr::GetInstance().TeamDestroy(team);
51 : }
52 :
53 12 : HcommResult HcommTeamBindChannels(HcommTeamHandle team, const HcommTeamBindChannelsDesc* desc)
54 : {
55 12 : if (team == nullptr || desc == nullptr || desc->channelNumPerMember == nullptr
56 9 : || desc->channelsByMemberId == nullptr) {
57 4 : HCCL_ERROR("[%s] nullptr parameter", __func__);
58 4 : return HCOMM_E_PTR;
59 : }
60 8 : return HcommTeamMgr::GetInstance().BindChannels(team, desc);
61 : }
62 :
63 15 : HcommResult HcommTeamBindRemoteSyncMem(HcommTeamHandle team, const HcommTeamBindSyncMemDesc* remoteDesc)
64 : {
65 15 : CHK_PRT_RET(
66 : (team == nullptr || remoteDesc == nullptr), HCCL_ERROR("[%s] nullptr parameter", __func__), HCOMM_E_PTR);
67 13 : CHK_PRT_RET(remoteDesc->remoteMems == nullptr, HCCL_ERROR("[%s] remoteMems is nullptr", __func__), HCOMM_E_PTR);
68 12 : CHK_PRT_RET(remoteDesc->remoteMemNum == 0, HCCL_ERROR("[%s] remoteMemNum is zero", __func__), HCOMM_E_PARA);
69 12 : return HcommTeamMgr::GetInstance().BindSyncMem(team, remoteDesc);
70 : }
71 :
72 22 : HcommResult HcommTeamWindowRegister(
73 : HcommTeamHandle worldTeam, const HcommTeamWindowDesc* desc, HcommWindowHandle* handle, HcommTeamWindowFlag flag)
74 : {
75 22 : CHK_PRT_RET(
76 : (worldTeam == nullptr || handle == nullptr), HCCL_ERROR("[%s] nullptr parameter", __func__), HCOMM_E_PTR);
77 20 : CHK_PRT_RET(
78 : flag != HCOMM_TEAM_WINDOW_FLAG_SYMMETRIC,
79 : HCCL_ERROR("[%s] flag[%d] is not supported, only support 0", __func__, flag), HCOMM_E_PARA);
80 : /* desc 当前由后续 HcommTeamWindowBindRemoteMems 单独绑定 window 的 mems,注册阶段不消费,允许为 nullptr。 */
81 : (void)desc;
82 20 : return HcommTeamMgr::GetInstance().WindowRegister(worldTeam, handle);
83 : }
84 :
85 : HcommResult
86 17 : HcommTeamWindowBindRemoteMems(HcommTeamHandle team, HcommWindowHandle handle, const HcommTeamWindowDesc* remoteDesc)
87 : {
88 17 : if (team == nullptr || handle == nullptr || remoteDesc == nullptr || remoteDesc->mems == nullptr) {
89 4 : HCCL_ERROR("[%s] nullptr parameter", __func__);
90 4 : return HCOMM_E_PTR;
91 : }
92 13 : return HcommTeamMgr::GetInstance().BindWindow(team, handle, remoteDesc);
93 : }
94 :
95 7 : HcommResult HcommTeamWindowDeregister(HcommTeamHandle worldTeam, HcommWindowHandle handle)
96 : {
97 7 : CHK_PRT_RET(
98 : (worldTeam == nullptr || handle == nullptr), HCCL_ERROR("[%s] nullptr parameter", __func__), HCOMM_E_PTR);
99 6 : return HcommTeamMgr::GetInstance().WindowDeregister(worldTeam, handle);
100 : }
101 :
102 4 : HcommResult HcommTeamGetNetLayer(HcommTeamHandle team, uint32_t* netLayer)
103 : {
104 4 : CHK_PRT_RET((team == nullptr || netLayer == nullptr), HCCL_ERROR("[%s] nullptr parameter", __func__), HCOMM_E_PTR);
105 2 : return HcommTeamMgr::GetInstance().GetNetLayer(team, netLayer);
106 : }
107 :
108 0 : HcommResult HcommTeamIsSubBelongToWorld(HcommTeamHandle worldTeam, HcommTeamHandle subTeam, bool* isBelong)
109 : {
110 0 : CHK_PTR_NULL(worldTeam);
111 0 : CHK_PTR_NULL(subTeam);
112 0 : CHK_PTR_NULL(isBelong);
113 0 : HCCL_ERROR("[%s] not support", __func__);
114 0 : return HCOMM_E_NOT_SUPPORT;
115 : }
|