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 : #include "ccu_channel_mgr.h"
12 :
13 : #include "ccu_res_specs.h"
14 :
15 : namespace Hccl {
16 :
17 34 : static void DumpJettyCtxInfo(const JettyInfo &info)
18 : {
19 102 : HCCL_RUN_INFO("[CcuChannelMgr][%s] local jetty context id[%u], ta jetty id[%u], "
20 : "ta jetty type[%s], sq depth[%u], wqe basic block start id[%u].",
21 : __func__, info.jettyCtxId, info.taJettyId, info.jettyType.Describe().c_str(),
22 : info.sqDepth, info.wqeBBStartId);
23 :
24 34 : if (info.jettyType == CcuJettyType::CCUM_CACHED_JETTY) {
25 102 : HCCL_RUN_INFO("[CcuChannelMgr][%s] sq buffer va[%llu], sq buffer size[%u].",
26 : __func__, info.sqBufVa, info.sqBufSize);
27 : }
28 34 : }
29 :
30 28 : void DumpChannelResInfo(const uint32_t feId, const ChannelInfo &info)
31 : {
32 28 : const auto &jettyInfos = info.jettyInfos;
33 84 : HCCL_RUN_INFO("[CcuChannelMgr][%s]: fe id[%u], channel id[%u], die id[%u], "
34 : "used jetty num[%zu].", __func__, feId, info.channelId, info.dieId,
35 : jettyInfos.size());
36 :
37 62 : for (const auto &jettyInfo: jettyInfos) {
38 34 : DumpJettyCtxInfo(jettyInfo);
39 : }
40 28 : }
41 :
42 28 : bool IsEidEmpty(const uint8_t (&eidRaw)[URMA_EID_LEN])
43 : {
44 444 : for (uint32_t i = 0; i < URMA_EID_LEN; i++) {
45 418 : if (eidRaw[i] != 0) {
46 2 : return false;
47 : }
48 : }
49 :
50 26 : return true;
51 : }
52 :
53 24 : CcuChannelMgr::CcuChannelMgr(const int32_t devLogicId, const uint8_t dieId, const uint32_t devPhyId)
54 24 : : devLogicId(devLogicId), dieId(dieId), devPhyId(devPhyId)
55 : {
56 24 : uint32_t strategy = 0; // 获取失败或为0场景,分配将按资源不足操作
57 24 : (void)CcuResSpecifications::GetInstance(devLogicId).GetChannelNum(dieId, strategy);
58 24 : channelResInfos.resize(strategy);
59 24 : }
60 :
61 32 : bool CcuChannelMgr::CheckIfChannelAllocated(const uint32_t channelId) const
62 : {
63 32 : const uint32_t strategy = channelResInfos.size();
64 32 : if (channelId >= strategy) {
65 3 : HCCL_ERROR("[CcuChannelMgrV1][%s] failed, channelId[%u] is invalid, "
66 : "should be less than the channel strategy[%u], devLogicId[%d], dieId[%u].",
67 : __func__, channelId, strategy, devLogicId, dieId);
68 1 : return false;
69 : }
70 :
71 31 : if (channelResInfos[channelId].allocated == false) {
72 3 : HCCL_ERROR("[CcuChannelMgrV1][%s] failed, channelId[%u] has not been "
73 : "allocated yet, devLogicId[%d], dieId[%u].", __func__, channelId,
74 : devLogicId, dieId);
75 1 : return false;
76 : }
77 :
78 30 : return true;
79 : }
80 :
81 : }; // namespace Hccl
|