Line data Source code
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 : #include "hccl/hccl_res.h"
12 : #include "log.h"
13 : #include "hccl_comm_pub.h"
14 : #include "independent_op.h"
15 : #include "channel_manager.h"
16 : #include "hcomm_c_adpt.h"
17 : #include "param_check_pub.h"
18 :
19 : using namespace hccl;
20 :
21 0 : HcclResult HcclChannelGetNotifyNum(HcclComm comm, ChannelHandle channel, uint32_t *notifyNum)
22 : {
23 0 : CHK_PTR_NULL(notifyNum);
24 0 : CHK_PTR_NULL(comm);
25 :
26 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
27 0 : HcclResult ret = HCCL_SUCCESS;
28 0 : if (hcclComm->IsCommunicatorV2()) {
29 0 : ret = static_cast<HcclResult>(HcommChannelGetNotifyNum(channel, notifyNum));
30 : }
31 : else {
32 0 : auto& channelMgr = hcclComm->GetIndependentOp().GetChannelManager();
33 0 : ret = channelMgr.ChannelCommGetNotifyNum(channel, notifyNum);
34 : }
35 :
36 0 : if (ret != HCCL_SUCCESS) {
37 0 : HCCL_ERROR("[%s] Failed to get channel notifyNum, group[%s], channel[%llu], ret[%d]",
38 : __func__, hcclComm->GetIdentifier().c_str(), channel, ret);
39 0 : return ret;
40 : }
41 :
42 0 : HCCL_RUN_INFO("[%s] get channel notifyNum success, group[%s], channel[%llu], notifyNum[%lu], ret[%d]",
43 : __func__, hcclComm->GetIdentifier().c_str(), channel, *notifyNum, ret);
44 0 : return HCCL_SUCCESS;
45 : }
46 :
47 0 : HcclResult CommChannelDestroy(HcclComm comm, ChannelHandle *channelList, uint32_t channelNum)
48 : {
49 0 : CHK_PTR_NULL(comm);
50 0 : CHK_PTR_NULL(channelList);
51 0 : CHK_PRT_RET(channelNum == 0, HCCL_ERROR("[%s]Invalid channelNum, channelNum[%u]",
52 : __func__, channelNum), HCCL_E_PARA);
53 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
54 0 : HcclResult ret = HCCL_SUCCESS;
55 0 : if (hcclComm->IsCommunicatorV2()) {
56 0 : CollComm* collComm = hcclComm->GetCollComm();
57 0 : CHK_PTR_NULL(collComm);
58 0 : ChannelManager* channelMgr = collComm->GetChannelManager();
59 0 : CHK_PTR_NULL(channelMgr);
60 0 : ret = channelMgr->ChannelCommDestroy(channelList, channelNum);
61 : }
62 : else {
63 0 : auto& channelMgr = hcclComm->GetIndependentOp().GetChannelManager();
64 0 : ret = channelMgr.ChannelCommDestroy(channelList, channelNum);
65 : }
66 :
67 0 : if (ret != HCCL_SUCCESS) {
68 0 : HCCL_ERROR("[%s] Failed to destroy channel, group[%s], channelList[%p], channelNum[%lu], ret[%d]",
69 : __func__, hcclComm->GetIdentifier().c_str(), channelList, channelNum, ret);
70 0 : return ret;
71 : }
72 :
73 0 : HCCL_RUN_INFO("[%s] destroy channel success, group[%s], channelList[%p], channelNum[%lu], ret[%d]",
74 : __func__, hcclComm->GetIdentifier().c_str(), channelList, channelNum, ret);
75 0 : return HCCL_SUCCESS;
76 : }
77 :
78 3 : HcclResult HcclChannelGetHcclBuffer(HcclComm comm, ChannelHandle channel, void **buffer, uint64_t *size)
79 : {
80 3 : CHK_PTR_NULL(comm);
81 2 : CHK_PTR_NULL(buffer);
82 1 : CHK_PTR_NULL(size);
83 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
84 0 : HCCLV2_FUNC_RUN(
85 : [&]() -> HcclResult {
86 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
87 : CollComm* collComm = hcclComm->GetCollComm();
88 : CHK_PTR_NULL(collComm);
89 : auto myRank = collComm->GetMyRank();
90 : CHK_PTR_NULL(myRank);
91 : CHK_RET(myRank->ChannelGetHcclBuffer(channel, buffer, size));
92 : return HCCL_SUCCESS;
93 : }());
94 : #endif
95 0 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
96 0 : CollComm* collComm = hcclComm->GetCollComm();
97 0 : hccl::MyRank *myRank = nullptr;
98 0 : if (collComm != nullptr) {
99 0 : myRank = collComm->GetMyRank();
100 : }
101 0 : if (collComm != nullptr && hcclComm->GetConnectMode() != 0 && myRank != nullptr) {
102 0 : CHK_RET(myRank->ChannelGetHcclBuffer(channel, buffer, size));
103 0 : return HCCL_SUCCESS;
104 : }
105 :
106 : CommBuffer commBuffer;
107 0 : auto& channelMgr = hcclComm->GetIndependentOp().GetChannelManager();
108 0 : HcclResult ret = channelMgr.ChannelCommGetHcclBuffer(channel, &commBuffer);
109 0 : if (ret != HCCL_SUCCESS) {
110 0 : HCCL_ERROR("[%s] Failed to get channel hccl buffer, group[%s], channel[%llu], ret[%d]",
111 : __func__, hcclComm->GetIdentifier().c_str(), channel, ret);
112 0 : return ret;
113 : }
114 0 : *buffer = commBuffer.addr;
115 0 : *size = commBuffer.size;
116 :
117 0 : HCCL_RUN_INFO("[%s] get channel hccl buffer success, group[%s], channel[%llu], "
118 : "buffer[type:%d, addr:%p, size:%llu], ret[%d]", __func__, hcclComm->GetIdentifier().c_str(),
119 : channel, commBuffer.type, commBuffer.addr, commBuffer.size, ret);
120 0 : return HCCL_SUCCESS;
121 : }
122 :
123 0 : HcclResult HcclChannelGetRemoteMems(HcclComm comm, ChannelHandle channel, uint32_t *memNum, CommMem **remoteMems,
124 : char ***memTags)
125 : {
126 0 : CHK_PTR_NULL(comm);
127 0 : CHK_PTR_NULL(remoteMems);
128 0 : CHK_PTR_NULL(memTags);
129 0 : CHK_PTR_NULL(memNum);
130 :
131 : #if (!defined (HCCD)) && (!defined (CCL_KERNEL_AICPU))
132 0 : HCCLV2_FUNC_RUN(
133 : [&]() -> HcclResult {
134 : hccl::hcclComm *hcclComm = static_cast<hccl::hcclComm *>(comm);
135 : CollComm* collComm = hcclComm->GetCollComm();
136 : CHK_PTR_NULL(collComm);
137 : auto myRank = collComm->GetMyRank();
138 : CHK_PTR_NULL(myRank);
139 : CHK_RET(myRank->ChannelGetRemoteMems(channel, memNum, remoteMems, memTags));
140 : return HCCL_SUCCESS;
141 : }());
142 : #endif
143 0 : HCCL_RUN_INFO("HcclChannelGetRemoteMems is not supported.");
144 0 : return HCCL_SUCCESS;
145 : }
|