LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_device/ccu_comp - ccu_res_allocator.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 3 3
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 2 2

            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 CCU_RES_ALLOCATOR_H
      12              : #define CCU_RES_ALLOCATOR_H
      13              : 
      14              : #include <mutex>
      15              : #include <vector>
      16              : #include <string>
      17              : #include <memory>
      18              : #include <unordered_map>
      19              : 
      20              : #include "ccu_dev_mgr_imp.h"
      21              : 
      22              : namespace hcomm {
      23              : 
      24              : class CcuResIdAllocator {
      25              : public:
      26          730 :     explicit CcuResIdAllocator(const uint32_t capacity) : capacity_(capacity) {};
      27              :     CcuResIdAllocator() = default;
      28              : 
      29              :     HcclResult Alloc(const uint32_t num, const bool consecutive,
      30              :         std::vector<ResInfo> &allocatedResInfos, const std::string &dfxInfo = "");
      31              :     HcclResult Release(const uint32_t startId, const uint32_t num);
      32              : 
      33              :     std::string Describe() const;
      34              : 
      35              : private:
      36              :     uint32_t capacity_{0};
      37              :     uint32_t allocatedSize_{0};
      38              :     std::vector<ResInfo> resInfos_{};
      39              :     std::mutex innerMutex_;
      40              : 
      41              :     size_t FindReleaseResIndex(const uint32_t startId) const;
      42              :     void AllocResInfo(std::vector<ResInfo> newResInfos);
      43              :     void ReleaseResInfo(const size_t resIndex, const uint32_t startId, const uint32_t num);
      44              : };
      45              : 
      46              : class CcuResAllocator {
      47              : public:
      48           74 :     CcuResAllocator(const int32_t devLogicId, const uint8_t dieId)
      49           74 :         : devLogicId_(devLogicId), dieId_(dieId) {};
      50              :     CcuResAllocator() = default;
      51              : 
      52              :     HcclResult Init();
      53              :     HcclResult Alloc(const ResType resType, const uint32_t num, const bool consecutive,
      54              :         std::vector<ResInfo>& resInfos);
      55              :     HcclResult Release(const ResType resType, const uint32_t startId, const uint32_t num);
      56              : 
      57              :     // 0.5rtt专用
      58              :     HcclResult AllocCountXn(const uint32_t num, ResInfo &resInfo);
      59              :     HcclResult ReleaseCountXn(const uint32_t startId, const uint32_t num);
      60              : 
      61              :     std::string Describe() const;
      62              : 
      63              : private:
      64              :     int32_t devLogicId_{0};
      65              :     uint8_t dieId_{0};
      66              : 
      67              :     // ccu v2新增countXn管理
      68              :     uint32_t xnSpecNum_{0};
      69              :     uint32_t countXnSpecNum_{0};
      70              :     std::unordered_map<uint8_t, std::unique_ptr<CcuResIdAllocator>> idAllocatorMap_;
      71              : };
      72              : 
      73              : } // namespace hcomm
      74              : 
      75              : #endif // CCU_RES_ALLOCATOR_H
        

Generated by: LCOV version 2.0-1