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 : #include "ccu_ctx_mgr.h"
11 : #include "ins_exe_que.h"
12 : #include "ccu_context_mgr_imp.h"
13 : #include "hccl_common_v2.h"
14 : #include "exception_util.h"
15 :
16 : namespace Hccl {
17 : /**
18 : * @brief 分配资源
19 : *
20 : * @param deviceLogicId device逻辑ID
21 : * @param ctxGroup CCU上下文组
22 : * @param resPack 资源包
23 : *
24 : * @return 返回HcclResult,表示分配资源是否成功
25 : * @note 此函数用于分配资源
26 : */
27 3 : HcclResult CcuCtxMgr::AllocRes(s32 deviceLogicId, CcuCtxGroup& ctxGroup, CcuResPack& resPack)
28 : {
29 12 : TRY_CATCH_RETURN(
30 : HCCL_INFO("[AllocRes] Input params: deviceLogicId[%d], ctxGroup size[%u]", deviceLogicId, ctxGroup.ctxs.size());
31 : // 入参校验拦截
32 : CHK_PRT_RET(
33 : (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
34 : HCCL_ERROR(
35 : "[CcuCtxMgr][AllocRes]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
36 : MAX_MODULE_DEVICE_NUM),
37 : HcclResult::HCCL_E_PARA);
38 :
39 : CHK_PRT_RET(
40 : ctxGroup.ctxs.size() == 0, HCCL_ERROR("[CcuCtxMgr][AllocRes]ctxs size is zero"), HcclResult::HCCL_E_PARA);
41 :
42 : CHK_RET_UNAVAIL(CtxMgrImp::GetInstance(deviceLogicId).AllocRes(ctxGroup, resPack)););
43 :
44 3 : return HcclResult::HCCL_SUCCESS;
45 : }
46 :
47 : /**
48 : * @brief 释放资源
49 : *
50 : * @param deviceLogicId device逻辑ID
51 : * @param ctxGroup CCU上下文组
52 : *
53 : * @return 返回HcclResult,表示释放资源是否成功
54 : *
55 : * @note 此函数用于释放指定device设备ID的CCU上下文组的资源
56 : */
57 0 : HcclResult CcuCtxMgr::ReleaseRes(s32 deviceLogicId, CcuCtxGroup& ctxGroup)
58 : {
59 0 : TRY_CATCH_RETURN(
60 : HCCL_RUN_INFO(
61 : "[CcuCtxMgr]ReleaseRes: deviceLogicId[%d], ctxGroup size[%u]", deviceLogicId, ctxGroup.ctxs.size());
62 :
63 : // 入参校验拦截
64 : CHK_PRT_RET(
65 : (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
66 : HCCL_ERROR("[CcuCtxMgr][ReleaseRes]deviceLogicId[%d] error", deviceLogicId), HcclResult::HCCL_E_PARA);
67 :
68 : CHK_PRT_RET(
69 : ctxGroup.ctxs.size() == 0, HCCL_ERROR("[CcuCtxMgr][ReleaseRes]ctxs size is zero"), HcclResult::HCCL_E_PARA);
70 :
71 : CHK_RET(CtxMgrImp::GetInstance(deviceLogicId).ReleaseRes(ctxGroup));
72 :
73 : HCCL_RUN_INFO(
74 : "[CcuCtxMgr]ReleaseRes:success deviceLogicId[%d], ctxGroup size[%u]", deviceLogicId,
75 : ctxGroup.ctxs.size()););
76 :
77 0 : return HcclResult::HCCL_SUCCESS;
78 : }
79 :
80 : /**
81 : * @brief 获取任务参数
82 : *
83 : * @param deviceLogicId device逻辑ID
84 : * @param ccuTaskArg CCU 任务参数
85 : * @param executorId 执行器ID
86 : * @param taskParam 任务参数
87 : *
88 : * @return HcclResult 获取参数结果
89 : * @note 无
90 : */
91 8 : HcclResult CcuCtxMgr::GetTaskParam(
92 : s32 deviceLogicId, CcuTaskArg& ccuTaskArg, const uint64_t executorId,
93 : std::vector<std::vector<CcuTaskParam>>& taskParam)
94 : {
95 410 : TRY_CATCH_RETURN(
96 : HCCL_INFO("[GetTaskParam] Input params: deviceLogicId[%d], executorId[%llu]", deviceLogicId, executorId);
97 : // 入参校验拦截
98 : CHK_PRT_RET(
99 : (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
100 : HCCL_ERROR(
101 : "[CcuCtxMgr][GetTaskParam]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
102 : MAX_MODULE_DEVICE_NUM),
103 : HcclResult::HCCL_E_PARA);
104 :
105 : taskParam = CtxMgrImp::GetInstance(deviceLogicId).GetTaskParam(ccuTaskArg, executorId);
106 :
107 : // 校验taskParam是否为空
108 : CHK_PRT_RET(
109 : (taskParam.size() == 0), HCCL_ERROR("[CcuCtxMgr][GetTaskParam]GetTaskParam fail"),
110 : HcclResult::HCCL_E_PARA););
111 :
112 2 : return HcclResult::HCCL_SUCCESS;
113 : }
114 :
115 : /**
116 : * @brief 注册扩展指令
117 : *
118 : * @param deviceLogicId device逻辑ID
119 : * @param entity 扩展指令执行实体
120 : * @param entityId 扩展指令执行实体ID
121 : * @return HcclResult 返回HcclResult类型的结果
122 : * @note 无
123 : */
124 3 : HcclResult InsExeQue::RegisterExtendInstruction(s32 deviceLogicId, ExtInsExeEntity& entity, ExtInsExeEntityId& entityId)
125 : {
126 3 : TRY_CATCH_RETURN(
127 : // 入参校验拦截
128 : CHK_PRT_RET(
129 : (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
130 : HCCL_ERROR("[CcuCtxMgr][RegisterExtendInstruction]deviceLogicId[%d] error", deviceLogicId),
131 : HcclResult::HCCL_E_PARA);
132 :
133 : CHK_PRT_RET(
134 : entity.ctxGroup.ctxs.size() == 0, HCCL_ERROR("[InsExeQue][RegisterExtendInstruction]ctxs size is zero"),
135 : HcclResult::HCCL_E_PARA);
136 :
137 : entityId = CtxMgrImp::GetInstance(deviceLogicId).Register(entity.ctxGroup, entity.isFuncBlock););
138 3 : return HcclResult::HCCL_SUCCESS;
139 : }
140 :
141 : /**
142 : * @brief 注销扩展指令
143 : *
144 : * @param deviceLogicId device逻辑ID
145 : * @param entityId 扩展指令执行实体ID
146 : * @return HcclResult 返回HcclResult类型的结果
147 : * @note 此函数用于注销扩展指令
148 : */
149 9 : HcclResult InsExeQue::DeregisterExtendInstruction(s32 deviceLogicId, const ExtInsExeEntityId& entityId)
150 : {
151 61 : TRY_CATCH_RETURN(
152 : HCCL_RUN_INFO(
153 : "[InsExeQue]DeregisterExtendInstruction: deviceLogicId[%d], executorId[%llu]", deviceLogicId, entityId);
154 : // 入参校验拦截
155 : CHK_PRT_RET(
156 : (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
157 : HCCL_ERROR("[CcuCtxMgr][DeregisterExtendInstruction]deviceLogicId[%d] error", deviceLogicId),
158 : HcclResult::HCCL_E_PARA);
159 :
160 : CHK_RET(CtxMgrImp::GetInstance(deviceLogicId).UnRegister(entityId));
161 :
162 : HCCL_RUN_INFO(
163 : "[InsExeQue]DeregisterExtendInstruction:success deviceLogicId[%d], executorId[%llu]", deviceLogicId,
164 : entityId););
165 2 : return HcclResult::HCCL_SUCCESS;
166 : }
167 :
168 : /**
169 : * @brief 获取任务Profiling信息
170 : *
171 : * @param deviceLogicId device逻辑ID
172 : * @param ccuTaskArg CCU 任务参数
173 : * @param entityId 执行器ID
174 : * @param profilingInfo 任务profiling信息
175 : *
176 : * @return HcclResult 获取profiling结果
177 : * @note 无
178 : */
179 0 : HcclResult CcuCtxMgr::GetProfilingInfo(
180 : s32 deviceLogicId, CcuTaskArg& ccuTaskArg, uint64_t entityId,
181 : std::vector<std::vector<CcuProfilingInfo>>& profilingInfo)
182 : {
183 0 : TRY_CATCH_RETURN(
184 : HCCL_INFO("[GetProfilingInfo] Input params: deviceLogicId[%d], entityId[%llu]", deviceLogicId, entityId);
185 : // 入参校验拦截
186 : CHK_PRT_RET(
187 : (deviceLogicId < 0 || static_cast<u32>(deviceLogicId) >= MAX_MODULE_DEVICE_NUM),
188 : HCCL_ERROR(
189 : "[CcuCtxMgr][GetProfilingInfo]deviceLogicId[%d] error, MAX_MODULE_DEVICE_NUM[%u]", deviceLogicId,
190 : MAX_MODULE_DEVICE_NUM),
191 : HcclResult::HCCL_E_PARA);
192 :
193 : profilingInfo = CtxMgrImp::GetInstance(deviceLogicId).GetProfilingInfo(ccuTaskArg, entityId);
194 :
195 : // 校验profilingInfo是否为空
196 : CHK_PRT_RET(
197 : (profilingInfo.size() == 0), HCCL_ERROR("[CcuCtxMgr][GetProfilingInfo]GetProfilingInfo fail"),
198 : HcclResult::HCCL_E_PARA););
199 :
200 0 : return HcclResult::HCCL_SUCCESS;
201 : }
202 :
203 : }; // namespace Hccl
|