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