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 : #ifndef HCOMM_CCU_RES_DESC_MGR_H
12 : #define HCOMM_CCU_RES_DESC_MGR_H
13 :
14 : #include <memory>
15 : #include <shared_mutex>
16 : #include <unordered_map>
17 :
18 : #include "ccu_res_defs.h"
19 : #include "ccu_res_desc.h"
20 :
21 : namespace hcomm {
22 :
23 : class CcuResDescMgr {
24 : public:
25 132 : CcuResDescMgr() = default;
26 132 : ~CcuResDescMgr() = default;
27 : CcuResDescMgr(const CcuResDescMgr&) = delete;
28 : CcuResDescMgr& operator=(const CcuResDescMgr&) = delete;
29 :
30 : CcuResult Create(uint32_t dieId, HcommCcuResDescHandle& handle);
31 : const CcuResDesc* Get(HcommCcuResDescHandle handle) const;
32 : CcuResult Destroy(HcommCcuResDescHandle handle);
33 : CcuResult SetResNum(HcommCcuResDescHandle handle, ResType resType, uint32_t resNum);
34 : CcuResult QueryResNum(HcommCcuResDescHandle handle, ResType resType, uint32_t& resNum) const;
35 : CcuResult QueryDieId(HcommCcuResDescHandle handle, uint32_t& dieId) const;
36 : CcuResult Deinit();
37 :
38 : // 在锁内遍历资源类型 → 查询容量 → 收集区间 → 扫描最大连续 → 写入 desc
39 : CcuResult QueryRemainRes(HcommCcuResDescHandle handle, int32_t devLogicId) const;
40 :
41 : private:
42 : using DescMap = std::unordered_map<HcommCcuResDescHandle, std::unique_ptr<CcuResDesc>>;
43 : using ConstDescIterator = DescMap::const_iterator;
44 :
45 : CcuResult FindDesc(HcommCcuResDescHandle handle, const char* funcName, ConstDescIterator& it) const;
46 :
47 : mutable std::shared_timed_mutex descMapMutex_;
48 : HcommCcuResDescHandle nextHandle_{0};
49 : DescMap descMap_{};
50 : };
51 :
52 : } // namespace hcomm
53 :
54 : #endif // HCOMM_CCU_RES_DESC_MGR_H
|