Line data Source code
1 : /**
2 : * Copyright (c) 2026 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_wqebb_mgr_v2.h"
12 :
13 : #include "ccu_res_specs.h"
14 :
15 : namespace hcomm {
16 :
17 35 : HcclResult CcuWqeBBMgrV2::Init()
18 : {
19 35 : uint32_t wqeBBNum = 0; // 获取失败或为0场景,分配将按资源不足操作
20 35 : uint32_t jettyNum = 0;
21 35 : uint32_t blockNum = 0;
22 35 : (void)CcuResSpecifications::GetInstance(devLogicId_).GetWqeBBNum(dieId_, wqeBBNum);
23 35 : (void)CcuResSpecifications::GetInstance(devLogicId_).GetJettyNum(dieId_, jettyNum);
24 35 : if (jettyNum == 0) {
25 1 : HCCL_WARNING("[CcuWqeBBMgrV2][%s] failed, jettyNum is [%u].", __func__, jettyNum);
26 1 : return HcclResult::HCCL_E_UNAVAIL;
27 : }
28 :
29 34 : blockNum = wqeBBNum / CCU_V2_FIXED_SQ_SIZE;
30 34 : allocatedWqeBBBlocks_.resize(blockNum, false);
31 34 : return HcclResult::HCCL_SUCCESS;
32 : }
33 :
34 21 : HcclResult CcuWqeBBMgrV2::Alloc(const WqeBBReq& wqeBBReq, ResInfo &wqeBBInfo)
35 : {
36 21 : wqeBBInfo.startId = wqeBBReq.jettyCtxStartId * CCU_V2_FIXED_SQ_SIZE;
37 21 : wqeBBInfo.num = CCU_V2_FIXED_SQ_SIZE;
38 : // 检查是否可用,防止重新分配
39 21 : if (wqeBBReq.jettyCtxStartId >= allocatedWqeBBBlocks_.size()) {
40 1 : HCCL_ERROR("[CcuWqeBBMgrV2][%s] failed, jetty ctx start id[%u] is not expected, "
41 : "more than specNum[%zu].", __func__, wqeBBReq.jettyCtxStartId, allocatedWqeBBBlocks_.size());
42 1 : return HcclResult::HCCL_E_INTERNAL;
43 : }
44 :
45 20 : if (allocatedWqeBBBlocks_[wqeBBReq.jettyCtxStartId]) {
46 1 : HCCL_ERROR("[CcuWqeBBMgrV2][%s] failed, the jetty ctx id[%u] has been allocated.",
47 : __func__, wqeBBReq.jettyCtxStartId);
48 1 : return HcclResult::HCCL_E_INTERNAL;
49 : }
50 :
51 19 : allocatedWqeBBBlocks_[wqeBBReq.jettyCtxStartId] = true;
52 19 : HCCL_INFO("[CcuWqeBBMgrV2][%s] jettyCtxStartId[%u], wqeBBInfo.startId[%u], wqeBBInfo.num[%u]",
53 : __func__, wqeBBReq.jettyCtxStartId, wqeBBInfo.startId, wqeBBInfo.num);
54 19 : return HcclResult::HCCL_SUCCESS;
55 : }
56 :
57 4 : HcclResult CcuWqeBBMgrV2::Release(const ResInfo &wqeBBInfo)
58 : {
59 4 : auto startId = wqeBBInfo.startId / CCU_V2_FIXED_SQ_SIZE;
60 4 : if (startId >= allocatedWqeBBBlocks_.size()) {
61 1 : HCCL_ERROR("[CcuWqeBBMgrV2][%s] failed, jetty ctx start id[%u] is not expected, "
62 : "more than specNum[%zu].", __func__, startId, allocatedWqeBBBlocks_.size());
63 1 : return HcclResult::HCCL_E_INTERNAL;
64 : }
65 :
66 3 : if (!allocatedWqeBBBlocks_[startId]) {
67 1 : HCCL_ERROR("[CcuWqeBBMgrV2][%s] failed, jetty ctx start id[%u] is not allocated.",
68 : __func__, startId, allocatedWqeBBBlocks_.size());
69 1 : return HcclResult::HCCL_E_PARA;
70 : }
71 :
72 2 : allocatedWqeBBBlocks_[startId] = false;
73 2 : return HcclResult::HCCL_SUCCESS;
74 : }
75 :
76 : }; // namespace hcomm
|