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_respack_mgr.h"
12 : #include "internal_exception.h"
13 :
14 : namespace Hccl {
15 :
16 : // 新增空的CcuResPack,同时内部做标记,用于回退
17 8 : void CcuResPackMgr::PrepareAlloc(u32 size)
18 : {
19 8 : if (resPacks.size() < size) {
20 8 : unConfirmedNum = size - resPacks.size();
21 8 : resPacks.resize(size);
22 : }
23 :
24 24 : HCCL_INFO("[CcuResPackMgr][PrepareAlloc] CcuResPack need size[%u], current resPacks size[%zu], unConfirmedNum[%u]",
25 : size, resPacks.size(), unConfirmedNum);
26 8 : }
27 :
28 : // 确认新增的资源,未来不可回退(对之前调用PrepareXxx()新增的资源,取消标记)
29 3 : void CcuResPackMgr::Confirm()
30 : {
31 3 : unConfirmedNum = 0;
32 3 : }
33 :
34 : // 对新增的资源进行回退
35 4 : void CcuResPackMgr::Fallback()
36 : {
37 9 : for (u32 idx = 0; idx < unConfirmedNum; ++idx) {
38 5 : if (resPacks[idx].handles.size() != 0) {
39 0 : HCCL_WARNING("[CcuResPackMgr][Fallback]resPacks idx[%u] has handles size[%u], not empty", idx,
40 : resPacks[idx].handles.size());
41 : }
42 5 : resPacks.pop_back();
43 : }
44 4 : unConfirmedNum = 0;
45 4 : }
46 :
47 : // 获取idx对应的CcuResPack
48 1 : CcuResPack &CcuResPackMgr::GetCcuResPack(u32 idx)
49 : {
50 1 : u32 size = resPacks.size();
51 1 : if (size <= idx) {
52 0 : THROW<InternalException>(
53 0 : StringFormat("[CcuResPackMgr][GetCcuResPack] idx[%u] is bigger than resPacks size[%u]", idx, size));
54 : }
55 1 : return resPacks[idx];
56 : }
57 :
58 : } // namespace Hccl
|