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 : #ifndef CCU_DEVICE_PUB_H
12 : #define CCU_DEVICE_PUB_H
13 :
14 : #include <memory>
15 : #include <vector>
16 : #include <cstdint>
17 :
18 : #include "ccu_common.h"
19 : #include "ccu_device_res.h"
20 : #include "ccu_res_repo.h"
21 : #include "ccu_drv_handle.h"
22 :
23 : #include "hccl_types.h"
24 : #include "enum_factory.h"
25 : #include "hccl_rank_graph.h"
26 :
27 : // 支持新老通信域混跑,引入legacy数据结构
28 : #include "unified_platform/pub_inc/ccu/ccu_dev_mgr.h"
29 : #include "dev_type.h"
30 :
31 : namespace hcomm {
32 :
33 : // CcuAllocResHandleByResDescs 仅以 const CcuResDesc* 形式使用,前向声明即可,
34 : // 避免此处包含 ccu_res_desc.h(其会引入 ccu_dev_mgr_imp.h,造成循环包含)。
35 : class CcuResDesc;
36 :
37 : using CcuResHandle = void*;
38 :
39 : // 不复用legacy数据结构,对上层支持CommAddr,不使用Hccl::IpAddress
40 : struct CcuChannelPara {
41 : CommAddr commAddr{};
42 : uint32_t channelNum{0};
43 : uint32_t jettyNum{0};
44 : uint32_t sqSize{0};
45 :
46 : CcuChannelPara() = default;
47 15 : CcuChannelPara(const CommAddr& address, const uint32_t channelNum, const uint32_t jettyNum, const uint32_t sqSize)
48 15 : : commAddr(address),
49 15 : channelNum(channelNum),
50 15 : jettyNum(jettyNum),
51 15 : sqSize(sqSize)
52 15 : {}
53 : };
54 :
55 : using CcuJettyType = Hccl::CcuJettyType;
56 : /* 开源自定义算子CCU设备管理实现,当前支持新老通信域混跑,
57 : * 暂时改用legacy数据结构,避免反向依赖
58 : * MAKE_ENUM(CcuJettyType, CCUM_CACHED_JETTY, TA_CACHED_JETTY, INVALID_JETTY);
59 : */
60 :
61 : using CcuJettyInfo = Hccl::CcuJettyInfo;
62 : /* 开源自定义算子CCU设备管理实现,当前支持新老通信域混跑,
63 : * 暂时改用legacy数据结构,避免反向依赖
64 : * struct CcuJettyInfo {
65 : * CcuJettyType jettyType{CcuJettyType::INVALID_JETTY};
66 : * uint16_t jettyCtxId{0};
67 : * uint16_t taJettyId{0};
68 :
69 : * uint32_t sqDepth{0};
70 : * uint32_t wqeBBStartId{0};
71 :
72 : * uint64_t sqBufVa{0};
73 : * uint32_t sqBufSize{0};
74 : * };
75 : */
76 :
77 : using CcuChannelInfo = Hccl::CcuChannelInfo;
78 : /* 开源自定义算子CCU设备管理实现,当前支持新老通信域混跑,
79 : * 暂时改用legacy数据结构,避免反向依赖
80 : * struct CcuChannelInfo {
81 : * uint32_t channelId{0};
82 : * uint8_t dieId{0};
83 : * std::vector<CcuJettyInfo> jettyInfos;
84 : * };
85 : */
86 :
87 : /**
88 : * @brief 启用CCU特性,初始化CCU平台层
89 : *
90 : * @param deviceLogicId 设备逻辑ID
91 : * @param ccuDrvHandle CCU驱动句柄
92 : * @return HcclResult 返回HcclResult类型的结果
93 : * @note 资源不足时返回HCCL_E_UNAVIL,其余非HCCL_SUCCESS结果属于错误
94 : */
95 : CcuResult CcuInitFeature(const int32_t devLogicId, std::shared_ptr<CcuDrvHandle>& ccuDrvHandle);
96 :
97 : /**
98 : * @brief 关闭CCU特性,解初始化CCU平台层
99 : *
100 : * @param deviceLogicId 设备逻辑ID
101 : * @return HcclResult 返回HcclResult类型的结果
102 : * @note 资源不足时返回HCCL_E_UNAVIL,其余非HCCL_SUCCESS结果属于错误
103 : */
104 : CcuResult CcuDeinitFeature(const int32_t devLogicId);
105 :
106 : /**
107 : * @brief 获取指定die是否启用
108 : *
109 : * @param deviceLogicId device逻辑ID
110 : * @param dieId ccu channel 所属的 IO Die 编号
111 : * @param enableFlag 出参,表示该die是否启用
112 : * @return HcclResult 返回HcclResult类型的结果
113 : * @note dieId越界时返回HCCL_E_PARA
114 : */
115 : CcuResult CcuGetDieEnableInfo(int32_t deviceLogicId, uint8_t dieId, bool& enableFlag);
116 :
117 : /**
118 : * @brief 查询指定 ioDie
119 : * 上各类资源总量,按block分的资源类型(LoopEngine、Ms、Cke)查询的是可以分配的总量(块大小*块总数)
120 : *
121 : * @param deviceLogicId 设备逻辑ID
122 : * @param dieId ioDie ID
123 : * @param num 出参,返回该 die 上对应资源类型的总量
124 : * @return CcuResult
125 : * @note dieId 越界或 die 未启用时返回错误
126 : */
127 : CcuResult CcuGetLoopEngineNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num);
128 : CcuResult CcuGetMsNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num);
129 : CcuResult CcuGetCkeNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num);
130 : CcuResult CcuGetXnNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num);
131 : CcuResult CcuGetGsaNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num);
132 : CcuResult CcuGetInstructionNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num);
133 : CcuResult CcuGetMissionNum(int32_t deviceLogicId, uint8_t dieId, uint32_t& num);
134 :
135 : /**
136 : * @brief 获取指定device的主板类型
137 : *
138 : * @param deviceLogicId device逻辑ID
139 : * @param hcclMainboardId 出参,返回该device的主板类型
140 : * @return HcclResult 返回HcclResult类型的结果
141 : */
142 : HcclResult CcuGetMainboardType(uint32_t deviceLogicId, Hccl::HcclMainboardId& hcclMainboardId);
143 :
144 : /**
145 : * @brief 基于资源描述符数组申请批量资源
146 : *
147 : * @param deviceLogicId 设备逻辑ID
148 : * @param descs 资源描述符指针数组(每个描述符携带 dieId 及各资源数量)
149 : * @param descNum 资源描述符数量
150 : * @param resHandle 返回的CCU批量资源句柄
151 : * @return HcclResult 返回HcclResult类型的结果
152 : * @note 资源不足时返回HCCL_E_UNAVIL,其余非HCCL_SUCCESS结果属于错误
153 : */
154 : CcuResult CcuAllocResHandleByResDescs(
155 : int32_t deviceLogicId, const CcuResDesc* descs[], uint32_t descNum, CcuResHandle& resHandle);
156 :
157 : /**
158 : * @brief 按加速引擎模式申请批量资源
159 : *
160 : * @param deviceLogicId 设备逻辑ID
161 : * @param ccuEngine CCU通信引擎类型
162 : * @param resHandle 返回的CCU批量资源句柄
163 : * @return HcclResult 返回HcclResult类型的结果
164 : * @note 资源不足时返回HCCL_E_UNAVIL,其余非HCCL_SUCCESS结果属于错误
165 : */
166 : CcuResult CcuAllocResHandleByInsType(int32_t deviceLogicId, CcuInstanceType ccuInsType, CcuResHandle& resHandle);
167 :
168 : /**
169 : * @brief 根据资源句柄查看对应资源信息
170 : *
171 : * @param deviceLogicId 设备逻辑ID
172 : * @param resHandle 查询的CCU批量资源句柄
173 : * @param resRepo 返回的CCU批量资源信息
174 : * @return HcclResult 返回HcclResult类型的结果
175 : * @note 资源句柄无法查找到时返回HCCL_E_NOT_FOUND,其余非HCCL_SUCCESS结果属于错误
176 : */
177 : CcuResult CcuCheckResource(const int32_t deviceLogicId, const CcuResHandle resHandle, CcuResRepository& resRepo);
178 :
179 : /**
180 : * @brief 根据资源句柄释放对应资源信息
181 : *
182 : * @param deviceLogicId 设备逻辑ID
183 : * @param resHandle 查询的CCU批量资源句柄
184 : * @note 资源句柄无法查找到时返回HCCL_E_NOT_FOUND,其余非HCCL_SUCCESS结果属于错误
185 : * @note 返回批量的channel资源总数可能超过申请数量,jettyNum为0时由平台层决定分配数量
186 : */
187 : HcclResult CcuReleaseResHandle(const int32_t deviceLogicId, const CcuResHandle handle);
188 :
189 : /**
190 : * @brief 申请批量ccu channel资源
191 : *
192 : * @param deviceLogicId device逻辑ID
193 : * @param ccuChannelPara ccu channel 申请参数
194 : * @param ccuChannelInfos 返回的channel资源信息
195 : * @return HcclResult 返回HcclResult类型的结果
196 : * @note 返回批量的channel资源总数可能超过申请数量,jettyNum为0时由平台层决定分配数量
197 : */
198 : HcclResult CcuAllocChannels(
199 : const int32_t deviceLogicId, const CcuChannelPara& ccuChannelPara, std::vector<CcuChannelInfo>& ccuChannelInfos);
200 :
201 : /**
202 : * @brief 释放ccu channel资源
203 : *
204 : * @param deviceLogicId device逻辑ID
205 : * @param dieId ccu channel 所属的 IO Die 编号
206 : * @param ccuChannelId ccu channel 编号
207 : * @return HcclResult 返回HcclResult类型的结果
208 : * @note 无
209 : */
210 : HcclResult CcuReleaseChannel(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t ccuChannelId);
211 :
212 : /**
213 : * @brief 查询CCU设备是否已完成初始化
214 : *
215 : * @param deviceLogicId 设备逻辑ID
216 : * @return bool true表示已初始化,false表示未初始化或入参非法
217 : * @note 无
218 : */
219 : bool CcuIsInited(const int32_t deviceLogicId);
220 :
221 : /**
222 : * @brief 触发CCU Task Kill
223 : *
224 : * @param deviceLogicId device逻辑ID
225 : * @return HcclResult 返回HcclResult类型的结果
226 : * @note 该接口会处理全部die,未启用die将跳过
227 : */
228 : HcclResult CcuSetTaskKill(const int32_t deviceLogicId);
229 :
230 : /**
231 : * @brief 配置CCU Task Kill完成状态
232 : *
233 : * @param deviceLogicId device逻辑ID
234 : * @return HcclResult 返回HcclResult类型的结果
235 : * @note 该接口会处理全部die,未启用die将跳过
236 : */
237 : HcclResult CcuSetTaskKillDone(const int32_t deviceLogicId);
238 :
239 : /**
240 : * @brief 清空CCU Task Kill状态
241 : *
242 : * @param deviceLogicId device逻辑ID
243 : * @return HcclResult 返回HcclResult类型的结果
244 : * @note 该接口会处理全部die,未启用die将跳过
245 : */
246 : HcclResult CcuCleanTaskKillState(const int32_t deviceLogicId);
247 :
248 : /**
249 : * @brief 清理指定ioDie CCU的全部CKE资源,重置为0
250 : *
251 : * @param deviceLogicId device逻辑ID
252 : * @return HcclResult 返回HcclResult类型的结果
253 : * @note 未启用die无需清理将视为成功
254 : */
255 : HcclResult CcuCleanDieCkes(const int32_t deviceLogicId, const uint8_t dieId);
256 :
257 : }; // namespace hcomm
258 : #endif // CCU_DEVICE_PUB_H
|