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_aicpu_interface.h"
12 :
13 : #include <sstream>
14 : #include <dlfcn.h>
15 : #include "common/aicpu_hccl_common.h"
16 : #include "common/aicpu_hccl_def.h"
17 : #include "common/aicpu_sqe_context.h"
18 : #include "profiling_manager_device.h"
19 : #include "framework/aicpu_hccl_process.h"
20 : #include "utils/hccl_aicpu_utils.h"
21 : #include "framework/aicpu_communicator.h"
22 : #include "utils/aicpu_hdc_utils.h"
23 : #include "hccl_group_utils.h"
24 : #include "hccl_dl.h"
25 :
26 : extern "C" {
27 0 : __attribute__((visibility("default"))) uint32_t RunAicpuKfcResInitV2(void *args)
28 : {
29 0 : if (args == nullptr) {
30 0 : HCCL_ERROR("args is null.");
31 0 : return HCCL_E_PARA;
32 : }
33 :
34 0 : KFCResInitTask *ctxArgs = reinterpret_cast<KFCResInitTask *>(args);
35 0 : HCCL_INFO("RunAicpuKfcResInitV2 isCustom %u, context %#llx", ctxArgs->isCustom, ctxArgs->context);
36 0 : if (ctxArgs->context == 0) { // for OneSideComm
37 0 : CHK_RET(hrtSetWorkModeAicpu(true));
38 0 : HCCL_INFO("RunAicpuKfcResInitV2 done as context is null, set aicpu work mode");
39 0 : return HCCL_SUCCESS;
40 : }
41 0 : return AicpuHcclProcess::AicpuRpcResInitV2(reinterpret_cast<HcclOpResParam *>(ctxArgs->context),
42 0 : ctxArgs->isCustom);
43 : }
44 :
45 1 : __attribute__((visibility("default"))) uint32_t RunAicpuRpcSrvLaunchV2(void *args)
46 : {
47 1 : if (args == nullptr) {
48 0 : HCCL_ERROR("RunAicpuRpcSrvLaunchV2 args is null.");
49 0 : return HCCL_E_PARA;
50 : }
51 :
52 1 : KFCTaskComm *task = reinterpret_cast<KFCTaskComm *>(args);
53 1 : OpTilingData *tilingData = reinterpret_cast<OpTilingData *>(reinterpret_cast<std::uintptr_t>(task) + sizeof(u64));
54 1 : if (tilingData == nullptr) {
55 0 : HCCL_ERROR("RunAicpuRpcSrvLaunchV2 tilingData args is null.");
56 0 : return HCCL_E_PARA;
57 : }
58 :
59 1 : const HcclCMDType opType = static_cast<HcclCMDType>(tilingData->opType);
60 1 : if ((opType == HcclCMDType::HCCL_CMD_BATCH_GET) || (opType == HcclCMDType::HCCL_CMD_BATCH_PUT)) {
61 0 : return AicpuHcclProcess::HandleOneSideService(tilingData);
62 : }
63 :
64 1 : HcclOpResParam *commParam = reinterpret_cast<HcclOpResParam *>(task->context);
65 1 : if (commParam == nullptr) {
66 0 : HCCL_ERROR("RunAicpuRpcSrvLaunchV2 context args is null.");
67 0 : return HCCL_E_PARA;
68 : }
69 1 : HCCL_INFO("RunAicpuRpcSrvLaunchV2 KFCTask task %p, context %p, tilingData %p", task, commParam, tilingData);
70 :
71 1 : std::string group = commParam->hcomId;
72 1 : hccl::HcclCommAicpu *hcclCommAicpu = AicpuHcclProcess::AicpuGetCommbyGroup(group);
73 1 : if (hcclCommAicpu == nullptr) {
74 0 : HCCL_ERROR("RunAicpuRpcSrvLaunchV2 get Hcclcomm error group[%s], tag[%s]", commParam->hcomId, tilingData->tag);
75 0 : return HCCL_E_INTERNAL;
76 : }
77 1 : HCCL_INFO("[RunAicpuRpcSrvLaunchV2] isZeroCopy [%d], isSymmetricMemory [%d], workflowMode[%d]",
78 : tilingData->isZeroCopy, tilingData->isSymmetricMemory, tilingData->workflowMode);
79 1 : hcclCommAicpu->SetZeroCopyEnable(tilingData->isZeroCopy);
80 1 : hcclCommAicpu->SetSymmetricMemoryEnable(tilingData->isSymmetricMemory);
81 1 : DfxExtendInfo* dfxInfo = hcclCommAicpu->GetDfxExtendInfo();
82 1 : if ((dfxInfo->cqeStatus != dfx::CqeStatus::kDefault) ||
83 1 : (dfxInfo->pollStatus == PollStatus::kStopAsException)) {
84 0 : AicpuHcclProcess::AicpuReleaseCommbyGroup(group);
85 0 : HCCL_ERROR("RunAicpuRpcSrvLaunchV2 exist errors before, cqeStatus:%d, pollStatus:%d, group[%s], sqeType[%u]",
86 : dfxInfo->cqeStatus, dfxInfo->pollStatus, commParam->hcomId, dfxInfo->cqeException.sqeType);
87 0 : if (dfxInfo->cqeException.sqeType == RT_STARS_SQE_TYPE_SDMA) {
88 0 : return TS_ERROR_AICPU_SDMA;
89 : }
90 0 : return HCCL_E_INTERNAL;
91 : }
92 1 : SetWorkflowMode(static_cast<HcclWorkflowMode>(tilingData->workflowMode));
93 1 : HCCL_DEBUG("[NsRecovery]check the suspending status in hcclCommAicpu");
94 1 : HcclComSuspendingFlag kfcFlag = HcclComSuspendingFlag ::isResume;
95 1 : CHK_RET(hcclCommAicpu->GetSuspendingFlag(kfcFlag));
96 1 : if (kfcFlag == HcclComSuspendingFlag::isSuspending) {
97 1 : HCCL_RUN_WARNING("[NsRecovery] the op should not be launched in hcclCommAicpu on the suspending status");
98 1 : HCCL_RUN_WARNING("[NsRecovery] Possible reason: flag not refresh, not enough time between resume and launch");
99 1 : AicpuHcclProcess::AicpuReleaseCommbyGroup(group);
100 1 : return 0;
101 : }
102 0 : hcclCommAicpu->SetNsStopLaunchStatus(false);
103 0 : HcclResult res = AicpuHcclProcess::AicpuRunRpcServerV2(hcclCommAicpu, tilingData, commParam);
104 0 : AicpuHcclProcess::AicpuReleaseCommbyGroup(group);
105 0 : if (res != HCCL_SUCCESS) {
106 0 : if (res == HCCL_E_OPRETRY_FAIL) {
107 0 : HCCL_RUN_INFO("Retry failed, support step retry");
108 0 : return TS_ERROR_RETRY_CONSTRAINT;
109 0 : } else if (res != HCCL_E_SUSPENDING) {
110 0 : if (dfxInfo->cqeException.sqeType == RT_STARS_SQE_TYPE_SDMA) {
111 0 : HCCL_ERROR("run AicpuRunRpcServerV2 failed. ret[%u]", TS_ERROR_AICPU_SDMA);
112 0 : return TS_ERROR_AICPU_SDMA;
113 : }
114 0 : HCCL_ERROR("run AicpuRunRpcServerV2 failed. ret[%d]", res);
115 0 : return res;
116 : } else {
117 0 : HCCL_INFO("aicpu is suspended");
118 0 : return AICPUSUSPENDING_ERROR;
119 : }
120 : }
121 0 : HCCL_INFO("end RunAicpuRpcSrvLaunchV2");
122 0 : return 0;
123 1 : }
124 :
125 0 : __attribute__((visibility("default"))) uint32_t RunAicpuNotifyRecord(void *args)
126 : {
127 0 : if (args == nullptr) {
128 0 : HCCL_ERROR("RunAicpuNotifyRecord args is null.");
129 0 : return HCCL_E_PARA;
130 : }
131 0 : ThreadNotifyRecordParam *param = reinterpret_cast<ThreadNotifyRecordParam *>(args);
132 0 : HCCL_INFO("[RunAicpuNotifyRecord] thread[0x%llx], dstThread[0x%llx], dstNotifyIdx[%u]",
133 : param->thread, param->dstThread, param->dstNotifyIdx);
134 0 : int32_t ret = HcommThreadNotifyRecordOnThread(param->thread, param->dstThread, param->dstNotifyIdx);
135 0 : if (ret != HCCL_SUCCESS) {
136 0 : HCCL_ERROR("RunAicpuNotifyRecord failed. ret[%d]", ret);
137 0 : return ret;
138 : }
139 0 : HCCL_INFO("RunAicpuNotifyRecord success.");
140 0 : return HCCL_SUCCESS;
141 : }
142 :
143 0 : __attribute__((visibility("default"))) uint32_t RunAicpuNotifyWait(void *args)
144 : {
145 0 : if (args == nullptr) {
146 0 : HCCL_ERROR("RunAicpuNotifyWait args is null.");
147 0 : return HCCL_E_PARA;
148 : }
149 0 : ThreadNotifyWaitParam *param = reinterpret_cast<ThreadNotifyWaitParam *>(args);
150 0 : HCCL_INFO("[RunAicpuNotifyWait] thread[0x%llx], notifyIdx[%u]", param->thread, param->notifyIdx);
151 0 : int32_t ret = HcommThreadNotifyWaitOnThreadWithDefaultTimeout(param->thread, param->notifyIdx);
152 0 : if (ret != HCCL_SUCCESS) {
153 0 : HCCL_ERROR("RunAicpuNotifyWait failed. ret[%d]", ret);
154 0 : return ret;
155 : }
156 0 : HCCL_INFO("RunAicpuNotifyWait success.");
157 0 : return HCCL_SUCCESS;
158 : }
159 :
160 : } // extern "C"
|