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