LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_device/ccu_component - ccu_component.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-08-29 17:38:31 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 HCCL_CCU_COMPONENT_H
      12              : #define HCCL_CCU_COMPONENT_H
      13              : 
      14              : #include <memory>
      15              : #include <vector>
      16              : #include <unordered_map>
      17              : #include <shared_mutex>
      18              : 
      19              : #include "hccl/hccl_types.h"
      20              : #include "types.h"
      21              : 
      22              : #include "ccu_channel_mgr.h"
      23              : #include "ccu_res_allocator_legacy.h"
      24              : #include "ccu_device_manager.h"
      25              : #include "tp_manager.h"
      26              : #include "ccu_error_handler.h"
      27              : 
      28              : namespace Hccl {
      29              : 
      30              : class CcuComponent {
      31              : public:
      32              :     CcuComponent(const CcuComponent& that) = delete;
      33              :     CcuComponent& operator=(const CcuComponent& that) = delete;
      34              : 
      35              :     static CcuComponent& GetInstance(const int32_t deviceLogicId);
      36              :     void Init();
      37              :     void Deinit();
      38              : 
      39              :     HcclResult GetCcuResourceSpaceBufInfo(const uint8_t dieId, uint64_t& addr, uint64_t& size) const;
      40              :     HcclResult GetCcuResourceSpaceTokenInfo(const uint8_t dieId, uint64_t& tokenId, uint64_t& tokenValue) const;
      41              :     HcclResult GetCcuResourceSpaceTokenInfoForLocal(const uint8_t dieId, uint64_t& tokenId, uint64_t& tokenValue) const;
      42              : 
      43              :     HcclResult
      44              :     AllocChannels(const uint8_t dieId, const ChannelPara& channelPara, std::vector<ChannelInfo>& channelInfos);
      45              :     HcclResult ConfigChannel(const uint8_t dieId, const ChannelCfg& cfg);
      46              :     HcclResult ReleaseChannel(const uint8_t dieId, const uint32_t channelId);
      47              : 
      48              :     HcclResult GetLoopChannelId(const uint8_t srcDieId, const uint8_t dstDieId, uint32_t& channelId) const;
      49              : 
      50              :     HcclResult AllocRes(
      51              :         const uint8_t dieId, const ResType resType, const uint32_t num, const bool consecutive,
      52              :         vector<ResInfo>& resInfos);
      53              :     HcclResult ReleaseRes(const uint8_t dieId, const ResType resType, const uint32_t startId, const uint32_t num);
      54              : 
      55              :     HcclResult AllocIns(const uint8_t dieId, const uint32_t num, ResInfo& insInfo);
      56              :     HcclResult ReleaseIns(const uint8_t dieId, const ResInfo& insInfo);
      57              :     uint32_t GetInsConsecutiveRemainSize(const uint8_t dieId) const;
      58              :     HcclResult AllocCke(const uint8_t dieId, const uint32_t num, vector<ResInfo>& ckeInfos);
      59              :     HcclResult ReleaseCke(const uint8_t dieId, const vector<ResInfo>& ckeInfos);
      60              :     HcclResult AllocXn(const uint8_t dieId, const uint32_t num, vector<ResInfo>& xnInfos);
      61              :     HcclResult ReleaseXn(const uint8_t dieId, const vector<ResInfo>& xnInfos);
      62              : 
      63              :     HcclResult CleanDieCkes(const uint8_t dieId) const;
      64              :     HcclResult SetTaskKill();
      65              :     HcclResult SetTaskKillDone();
      66              :     HcclResult CleanTaskKillState() const;
      67              : 
      68              :     const std::array<bool, MAX_CCU_IODIE_NUM>& GetDieEnableFlags() const;
      69            6 :     bool IsInited() const { return ifInit; }
      70              : 
      71              : private:
      72              :     static constexpr uint32_t INVALID_DEV_ID = 0xFFFFFFFF;
      73              :     bool ifInit{false};
      74              :     int32_t devLogicId{static_cast<int32_t>(INVALID_DEV_ID)};
      75              :     uint32_t devPhyId{INVALID_DEV_ID};
      76              :     CcuVersion ccuVersion{CcuVersion::CCU_INVALID};
      77              :     std::array<bool, MAX_CCU_IODIE_NUM> dieEnableFlags{}; // 根据资源规格的记录可用的die
      78              : 
      79              :     // 记录环回设备信息,dieId, (feId, ipAddr)
      80              :     std::unordered_map<uint8_t, std::pair<uint32_t, IpAddress>> loopFeIpAddrMap{};
      81              :     // 记录CCU资源空间Buffer,避免重复内存注册
      82              :     std::unordered_map<uint8_t, std::unique_ptr<LocalUbRmaBuffer>> ccuRmaBufferMap{};
      83              :     std::unordered_map<uint8_t, std::unique_ptr<LocalUbRmaBuffer>> localCcuRmaBufferMap{};
      84              :     std::vector<std::unique_ptr<LocalUbRmaBuffer>> additionalCcuRmaBufferMap{};
      85              :     // 资源管理器
      86              :     std::array<std::unique_ptr<CcuChannelMgr>, MAX_CCU_IODIE_NUM> channelMgrs{};
      87              :     std::array<std::unique_ptr<CcuResAllocator>, MAX_CCU_IODIE_NUM> resAllocators{};
      88              :     // 环回channel编号
      89              :     std::array<uint32_t, MAX_CCU_IODIE_NUM> loopChannelIds{};
      90              :     // 环回jetty资源信息
      91              :     std::unordered_map<uint8_t, std::vector<HrtRaUbJettyCreatedOutParam>> createdOutParamMap{};
      92              :     using ImportOutParamPair = std::pair<RdmaHandle, HrtRaUbJettyImportedOutParam>;
      93              :     std::unordered_map<uint8_t, std::vector<ImportOutParamPair>> importedOutParamMap{};
      94              :     std::unordered_map<IpAddress, TpInfo> tpInfoMap{};
      95              :     std::unordered_map<IpAddress, TpAttrInfo> tpAttrInfoMap{};
      96              :     std::unordered_map<IpAddress, uint32_t> psnMap{};
      97              : 
      98              :     // CCU Task Kill相关状态
      99              :     enum class CcuTaskKillStatus : uint8_t { INIT = 0, TASK_KILL = 1, KILL_DONE = 2, CLEAN_TIF = 3, INVALID = 4 };
     100              :     CcuTaskKillStatus status{CcuTaskKillStatus::INVALID};
     101              :     mutable std::shared_mutex innerMutex;
     102              :     std::mutex taskKillMutex_;
     103              : 
     104           83 :     explicit CcuComponent() = default;
     105              :     ~CcuComponent();
     106              : 
     107              :     void CheckDiesEnable();
     108              :     void ChooseLoopEid(bool& dieDrvEnableFlag, uint8_t dieId);
     109              :     HcclResult GetLoopFeIpByDieId(const uint8_t dieId, uint32_t& feId, IpAddress& ipAddr);
     110              :     void CreateCcuRmaBuffer();
     111              :     void CreateResourceManagers();
     112              :     void CreateLoopChannels();
     113              :     HcclResult CreateLoopChannel(const uint8_t dieId, uint32_t& channelId);
     114              :     HcclResult
     115              :     CreateAndImportLoopJettys(const uint8_t dieId, const IpAddress& ipAddr, const vector<JettyInfo>& jettyInfos);
     116              :     TpInfo RequestNewTpInfo(const IpAddress& srcIpAddr, const IpAddress& dstIpAddr) const;
     117              :     TpInfo GetTpInfo(const IpAddress& ipAddr);
     118              :     TpAttrInfo GetLoopTpAttr(const IpAddress& ipAddr, const TpHandle tpHandle);
     119              :     HcclResult GetLoopJettyTimeout(const IpAddress& ipAddr, const TpHandle tpHandle, uint8_t& errTimeout);
     120              :     uint32_t GetPsn(const IpAddress& ipAddr);
     121              :     HcclResult ConfigLoopChannel(const uint8_t dieId, const IpAddress& ipAddr, const ChannelInfo& channelInfo);
     122              :     void ConfigMsIdToken();
     123              : 
     124              :     void ReleaseJettyRes();
     125              :     void UnimportAllJetty();
     126              :     void DestroyAllJetty();
     127              : 
     128              :     void SetProcess(CcuOpcodeType opCode) const;
     129              :     void PrintCcuMissionStatus(int32_t devLogicId) const;
     130              : };
     131              : 
     132              : }; // namespace Hccl
     133              : 
     134              : #endif
        

Generated by: LCOV version 2.0-1