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 "coll_comm_aicpu_kernel_adpt.h"
12 : #include "coll_comm_aicpu_mgr.h"
13 : #include "log.h"
14 :
15 : using namespace hccl;
16 :
17 : namespace {
18 : // Acquire → 操作 → Release 的公共骨架:获取 CommEngineResMgr
19 : inline HcclResult
20 1 : AcquireCommEngineRes(const char* groupName, CollCommAicpu*& outComm, CommEngineResAicpuMgr*& outResMgr)
21 : {
22 2 : outComm = CollCommAicpuMgr::GetInstance().AcquireCommForUse(groupName);
23 1 : CHK_PRT_RET(outComm == nullptr, HCCL_ERROR("%s aicpuComm is null, group[%s]", __func__, groupName), HCCL_E_PTR);
24 :
25 1 : outResMgr = outComm->GetCommEngineResMgr();
26 1 : if (outResMgr == nullptr) {
27 0 : HCCL_ERROR("[%s] commEngineResMgr is null, group[%s]", __func__, groupName);
28 0 : CollCommAicpuMgr::GetInstance().ReleaseComm(groupName);
29 0 : return HCCL_E_PTR;
30 : }
31 1 : return HCCL_SUCCESS;
32 : }
33 : } // namespace
34 :
35 2 : HcclResult CollCommAicpuKernelAdptInitThreads(ThreadMgrAicpuParam* param)
36 : {
37 2 : CHK_PTR_NULL(param);
38 1 : std::string group = param->hcomId;
39 1 : HCCL_INFO("[%s]group[%s]", __func__, group.c_str());
40 :
41 1 : CollCommAicpu* aicpuComm = nullptr;
42 1 : CommEngineResAicpuMgr* commEngineResMgr = nullptr;
43 1 : CHK_RET(AcquireCommEngineRes(group.c_str(), aicpuComm, commEngineResMgr));
44 :
45 1 : HcclResult ret = commEngineResMgr->InitThreads(param);
46 1 : CHK_PRT_CONT(
47 : ret != HCCL_SUCCESS,
48 : HCCL_ERROR(
49 : "[%s]errNo[0x%016llx] Failed to init threads group[%s]", __func__, HCCL_ERROR_CODE(ret), group.c_str()));
50 1 : CollCommAicpuMgr::GetInstance().ReleaseComm(group);
51 1 : return ret;
52 1 : }
53 :
54 1 : HcclResult CollCommAicpuKernelAdptInitChannel(HcclChannelUrmaRes* commParam)
55 : {
56 1 : CHK_PTR_NULL(commParam);
57 0 : std::string group = commParam->hcomId;
58 0 : HCCL_INFO("[%s]group[%s]", __func__, group.c_str());
59 :
60 0 : CollCommAicpu* aicpuComm = CollCommAicpuMgr::GetInstance().AcquireCommForUse(group);
61 0 : CHK_PRT_RET(
62 : aicpuComm == nullptr, HCCL_ERROR("%s aicpuComm is null, group[%s]", __func__, group.c_str()), HCCL_E_PTR);
63 :
64 0 : ChannelAicpuMgr* channelMgr = aicpuComm->GetChannelMgr();
65 0 : if (channelMgr == nullptr) {
66 0 : HCCL_ERROR("[%s] channelMgr is null, group[%s]", __func__, group.c_str());
67 0 : CollCommAicpuMgr::GetInstance().ReleaseComm(group);
68 0 : return HCCL_E_PTR;
69 : }
70 0 : HcclResult ret = channelMgr->AllocChannelResource(commParam);
71 0 : CHK_PRT_CONT(
72 : ret != HCCL_SUCCESS,
73 : HCCL_ERROR(
74 : "[%s]errNo[0x%016llx] Failed to init channels group[%s]", __func__, HCCL_ERROR_CODE(ret), group.c_str()));
75 0 : CollCommAicpuMgr::GetInstance().ReleaseComm(group);
76 0 : return ret;
77 0 : }
78 :
79 1 : HcclResult CollCommAicpuKernelAdptUpdateChannel(HcclChannelUrmaRes* commParam)
80 : {
81 1 : CHK_PTR_NULL(commParam);
82 0 : std::string group = commParam->hcomId;
83 0 : HCCL_INFO("[%s]group[%s]", __func__, group.c_str());
84 :
85 0 : CollCommAicpu* aicpuComm = CollCommAicpuMgr::GetInstance().AcquireCommForUse(group);
86 0 : CHK_PRT_RET(
87 : aicpuComm == nullptr, HCCL_ERROR("%s aicpuComm is null, group[%s]", __func__, group.c_str()), HCCL_E_PTR);
88 :
89 : // 通过 CollCommAicpu::Resume 统一处理:通道恢复 + commStatus/isErrorReported/nsRecovery 状态重置
90 0 : HcclResult ret = aicpuComm->Resume(commParam);
91 0 : CHK_PRT_CONT(
92 : ret != HCCL_SUCCESS,
93 : HCCL_ERROR(
94 : "[%s]errNo[0x%016llx] Failed to update channels group[%s]", __func__, HCCL_ERROR_CODE(ret), group.c_str()));
95 0 : CollCommAicpuMgr::GetInstance().ReleaseComm(group);
96 0 : return ret;
97 0 : }
98 :
99 1 : HcclResult CollCommAicpuKernelAdptInitNotify(NotifyMgrAicpuParam* param)
100 : {
101 1 : CHK_PTR_NULL(param);
102 0 : std::string group = param->hcomId;
103 0 : HCCL_INFO("[%s]group[%s]", __func__, group.c_str());
104 :
105 0 : CollCommAicpu* aicpuComm = nullptr;
106 0 : CommEngineResAicpuMgr* commEngineResMgr = nullptr;
107 0 : CHK_RET(AcquireCommEngineRes(group.c_str(), aicpuComm, commEngineResMgr));
108 0 : HcclResult ret = HCCL_E_INTERNAL;
109 0 : const char* opName = nullptr;
110 0 : if (param->freeFlag) {
111 0 : ret = commEngineResMgr->NotifyFree(param);
112 0 : opName = "free";
113 : } else {
114 0 : ret = commEngineResMgr->NotifyAlloc(param);
115 0 : opName = "alloc";
116 : }
117 0 : CHK_PRT_CONT(
118 : ret != HCCL_SUCCESS, HCCL_ERROR(
119 : "[%s]errNo[0x%016llx] Failed to %s notifys group[%s]", __func__, HCCL_ERROR_CODE(ret),
120 : opName, group.c_str()));
121 0 : HCCL_INFO(
122 : "[%s] comm identifier[%s], notify op[%u] end, num[%u]", __func__, group.c_str(), param->freeFlag,
123 : param->notifyNum);
124 0 : CollCommAicpuMgr::GetInstance().ReleaseComm(group);
125 0 : return ret;
126 0 : }
|