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 HCCL_CCU_DEV_MGR_H
12 : #define HCCL_CCU_DEV_MGR_H
13 :
14 : #include "ip_address.h"
15 :
16 : namespace Hccl {
17 :
18 : constexpr uint8_t MAX_CCU_IODIE_NUM = 2; // 设计支持的最大IOdie数量
19 :
20 : struct CcuChannelPara {
21 : IpAddress ipAddr{};
22 : uint32_t channelNum{0};
23 : uint32_t jettyNum{0};
24 : uint32_t sqSize{0};
25 :
26 : CcuChannelPara() = default;
27 49 : CcuChannelPara(const IpAddress& ip, const uint32_t channelNum, const uint32_t jettyNum, const uint32_t sqSize)
28 49 : : ipAddr(ip),
29 49 : channelNum(channelNum),
30 49 : jettyNum(jettyNum),
31 49 : sqSize(sqSize)
32 49 : {}
33 : };
34 :
35 1363 : MAKE_ENUM(CcuJettyType, CCUM_CACHED_JETTY, TA_CACHED_JETTY, INVALID_JETTY);
36 :
37 : struct CcuJettyInfo {
38 : CcuJettyType jettyType{CcuJettyType::INVALID_JETTY};
39 : uint16_t jettyCtxId{0};
40 : uint16_t taJettyId{0};
41 :
42 : uint32_t sqDepth{0};
43 : uint32_t wqeBBStartId{0};
44 :
45 : uint64_t sqBufVa{0};
46 : uint32_t sqBufSize{0};
47 :
48 : std::string ToString() const
49 : {
50 : return StringFormat(
51 : "jettyType=%d, jettyCtxId=%u, taJettyId=%u, sqDepth=%u, "
52 : "wqeBBStartId=%u, sqBufVa=%llu, sqBufSize=%u.",
53 : jettyType, jettyCtxId, taJettyId, sqDepth, wqeBBStartId, sqBufVa, sqBufSize);
54 : }
55 : };
56 :
57 : struct CcuChannelInfo {
58 : uint32_t channelId{0};
59 : uint8_t dieId{0};
60 : vector<CcuJettyInfo> jettyInfos;
61 : };
62 :
63 : /**
64 : * @brief 申请批量ccu channel资源
65 : *
66 : * @param deviceLogicId device逻辑ID
67 : * @param ccuChannelPara ccu channel 申请参数
68 : * @param ccuChannelInfos 返回的channel资源信息
69 : * @return HcclResult 返回HcclResult类型的结果
70 : * @note 返回批量的channel资源总数可能超过申请数量,jettyNum为0时由平台层决定分配数量
71 : */
72 : HcclResult CcuAllocChannels(
73 : const int32_t deviceLogicId, const CcuChannelPara& ccuChannelPara, std::vector<CcuChannelInfo>& ccuChannelInfos);
74 :
75 : /**
76 : * @brief 释放ccu channel资源
77 : *
78 : * @param deviceLogicId device逻辑ID
79 : * @param dieId ccu channel 所属的 IO Die 编号
80 : * @param ccuChannelId ccu channel 编号
81 : * @return HcclResult 返回HcclResult类型的结果
82 : * @note 无
83 : */
84 : HcclResult CcuReleaseChannel(const int32_t deviceLogicId, const uint8_t dieId, const uint32_t ccuChannelId);
85 :
86 : /**
87 : * @brief 获取设备Channel资源的规格数量
88 : *
89 : * @param deviceLogicId device逻辑ID
90 : * @param dieId ccu 设备所属 IO Die Id
91 : * @param channelNum ccu channel 资源的规格数量
92 : * @return HcclResult 返回HcclResult类型的结果
93 : * @note 无
94 : */
95 : HcclResult CcuGetChannelSpecNum(const int32_t deviceLogicId, const uint8_t dieId, uint32_t& channelNum);
96 :
97 : /**
98 : * @brief 查询CCU设备是否已完成初始化
99 : *
100 : * @param deviceLogicId device逻辑ID
101 : * @return bool true表示已初始化,false表示未初始化或入参非法
102 : * @note 无
103 : */
104 : bool CcuIsInited(const int32_t deviceLogicId);
105 :
106 : /**
107 : * @brief 触发CCU Task Kill
108 : *
109 : * @param deviceLogicId device逻辑ID
110 : * @return HcclResult 返回HcclResult类型的结果
111 : * @note 该接口会处理全部die,未启用die将跳过
112 : */
113 : HcclResult CcuSetTaskKill(const int32_t deviceLogicId);
114 :
115 : /**
116 : * @brief 配置CCU Task Kill完成状态
117 : *
118 : * @param deviceLogicId device逻辑ID
119 : * @return HcclResult 返回HcclResult类型的结果
120 : * @note 该接口会处理全部die,未启用die将跳过
121 : */
122 : HcclResult CcuSetTaskKillDone(const int32_t deviceLogicId);
123 :
124 : /**
125 : * @brief 清空CCU Task Kill状态
126 : *
127 : * @param deviceLogicId device逻辑ID
128 : * @return HcclResult 返回HcclResult类型的结果
129 : * @note 该接口会处理全部die,未启用die将跳过
130 : */
131 : HcclResult CcuCleanTaskKillState(const int32_t deviceLogicId);
132 :
133 : /**
134 : * @brief 清理指定ioDie CCU的全部CKE资源,重置为0
135 : *
136 : * @param deviceLogicId device逻辑ID
137 : * @return HcclResult 返回HcclResult类型的结果
138 : * @note 未启用die无需清理将视为成功
139 : */
140 : HcclResult CcuCleanDieCkes(const int32_t deviceLogicId, const uint8_t dieId);
141 :
142 : }; // namespace Hccl
143 : #endif
|