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