LCOV - code coverage report
Current view: top level - base_comm - hcomm_res_mgr.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-08-25 19:18:03 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 HCOMM_RES_MGR_H
      12              : #define HCOMM_RES_MGR_H
      13              : 
      14              : #include <array>
      15              : #include <cstdint>
      16              : #include <mutex>
      17              : #include "acl/acl_rt.h"
      18              : #include "hcomm_res_defs.h"
      19              : #include "config_mgr/config_mgr.h"
      20              : #include "hccl_common.h"
      21              : 
      22              : namespace hcomm {
      23              : 
      24              : /**
      25              :  * @brief 单设备资源管理基类。
      26              :  *
      27              :  * 每个设备对应一个实例,持有 devPhyId,负责触发该设备下各子模块单例创建。
      28              :  */
      29              : class HcommBaseResMgr {
      30              : public:
      31              :     HcommBaseResMgr() = default;
      32              :     explicit HcommBaseResMgr(uint32_t devPhyId) : devPhyId_(devPhyId) {}
      33              :     ~HcommBaseResMgr() = default;
      34              : 
      35              :     void Init();
      36            1 :     void SetDevPhyId(uint32_t devPhyId) { devPhyId_ = devPhyId; }
      37              :     uint32_t GetDevPhyId() const { return devPhyId_; }
      38              : 
      39              : private:
      40              :     uint32_t devPhyId_{0};
      41              : };
      42              : 
      43              : /**
      44              :  * @brief 全局资源管理类,聚合各设备实例和环境变量配置。
      45              :  *
      46              :  * 持有 HcommBaseResMgr[MAX_MODULE_DEVICE_NUM + 1] 和 ConfigMgr,
      47              :  * 通过 GetInstance() 获取单例,GetDeviceResMgr() 访问指定设备,GetConfigMgr() 访问环境变量配置。
      48              :  */
      49              : class HcommResMgr {
      50              : public:
      51              :     static HcommResMgr& GetInstance();
      52              :     static void RegisterDeviceResetCallback();
      53              : 
      54              :     HcommBaseResMgr& GetDeviceResMgr(uint32_t devicePhyId);
      55              :     ConfigMgr& GetConfigMgr();
      56              : 
      57              :     // 进程级 kernel bin 句柄管理(不分 device,与 per-device 实例隔离)
      58              :     static HcclResult EnsureKernelBinLoaded(CommEngine engine);
      59              :     static aclrtBinHandle GetBinHandle();
      60              : 
      61              : private:
      62              :     HcommResMgr();
      63            2 :     ~HcommResMgr() = default;
      64              :     HcommResMgr(const HcommResMgr& that) = delete;
      65              :     HcommResMgr& operator=(const HcommResMgr& that) = delete;
      66              : 
      67              :     void InitDevice(uint32_t devPhyId);
      68              : 
      69              :     std::array<bool, MAX_MODULE_DEVICE_NUM + 1> isInitialized_{false};
      70              :     HcommBaseResMgr deviceResMgrs_[MAX_MODULE_DEVICE_NUM + 1];
      71              :     ConfigMgr configMgr_;
      72              : 
      73              :     static aclrtBinHandle binHandle_;
      74              :     static std::mutex binHandleMtx_;
      75              : };
      76              : 
      77              : } // namespace hcomm
      78              : 
      79              : #endif // HCOMM_RES_MGR_H
        

Generated by: LCOV version 2.0-1