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

            Line data    Source code
       1              : /*
       2              :  * Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
       3              :  * Description: ccu context header file
       4              :  * Create: 2025-02-18
       5              :  */
       6              : 
       7              : #ifndef CCU_REP_CTX_H
       8              : #define CCU_REP_CTX_H
       9              : 
      10              : #include <set>
      11              : #include <string>
      12              : #include <unordered_map>
      13              : 
      14              : #include "hcomm_primitives.h"
      15              : #include "ccu_rep_base_v1.h"
      16              : #include "ccu_rep_block_v1.h"
      17              : 
      18              : #include "ccu_common.h"
      19              : #include "task_param.h"
      20              : 
      21              : namespace hcomm {
      22              : constexpr uint16_t  CCU_MAX_CHANNEL_NUM     = 16;     // 最多16条link
      23              : constexpr uint16_t  INVALID_CKE_ID          = 0xFFFF; // CKE ID非法值
      24              : constexpr uint16_t  INVALID_VALUE_CHANNELID = 0xFFFF; // channel id非法值
      25              : constexpr uint64_t  INVALID_VALUE_NOTIFYID  = 0xFFFFFFFFFFFFFFFF; // NOTIFY id非法值
      26              : 
      27              : enum class CcuProfilinType { CCU_TASK_PROFILING, CCU_WAITCKE_PROFILING, CCU_LOOPGROUP_PROFILING, CCU_MAP_PROFILING };
      28              : 
      29              : using CcuProfilingInfo = Hccl::CcuProfilingInfo;
      30              : namespace CcuRep {
      31              : 
      32              : struct LoopGroupProfilingInfo {
      33              :              std::vector<CcuProfilingInfo> ccuProfilingInfos;
      34              :              std::unordered_map<std::shared_ptr<CcuRep::CcuRepBase>, uint32_t> loadRep2ArgIdxMap; // loadArg rep -> argIdx
      35              :              std::vector<std::shared_ptr<CcuRepBase>> assignProfilingReps;  // assign rep
      36              :              std::vector<std::shared_ptr<CcuRepBase>> lgProfilingReps;  // loopgroup rep
      37              :          };
      38              : 
      39              : class CcuRepContext {
      40              : public:
      41              :     explicit CcuRepContext();
      42              :     virtual ~CcuRepContext();
      43              : 
      44              :     // 平台层内部使用
      45              :     std::shared_ptr<CcuRep::CcuRepBlock> CurrentBlock();
      46              :     void                                 SetCurrentBlock(std::shared_ptr<CcuRep::CcuRepBlock> repBlock);
      47              :     virtual void                         Append(std::shared_ptr<CcuRep::CcuRepBase> rep);
      48              :     const std::vector<std::shared_ptr<CcuRep::CcuRepBase>> &GetRepSequence();
      49              :     std::shared_ptr<CcuRep::CcuRepBase> GetRepByInstrId(uint16_t instrId);
      50              :     void DumpReprestation();
      51              : 
      52              :     void     SetDieId(uint32_t dieId);
      53              :     uint32_t GetDieId() const;
      54              :     void     SetMissionId(uint32_t missionId);
      55              :     uint32_t GetMissionId() const;
      56              :     void     SetMissionKey(uint32_t missionKey);
      57              :     uint32_t GetMissionKey() const;
      58              : 
      59              :     // ccu profiling相关接口
      60              :     std::vector<CcuProfilingInfo> &GetProfilingInfo();
      61              :     CcuRep::LoopGroupProfilingInfo &GetLGProfilingInfo();
      62              :     const std::vector<std::shared_ptr<CcuRep::CcuRepBase>> &GetWaiteCkeProfilingReps() const;
      63              :     void CollectProfilingReps(std::shared_ptr<CcuRep::CcuRepBase> rep);
      64              : 
      65              :     void AddSqeProfiling(const std::string &kernelName);
      66              :     int32_t AddProfiling(const std::string &name, uint32_t mask);
      67              :     int32_t AddProfiling(const ChannelHandle channel, const std::string &name, uint32_t signalIndex, uint32_t mask);
      68              :     int32_t AddProfiling(const ChannelHandle *channels, uint32_t channelNum);
      69              :     int32_t AddProfiling(const ChannelHandle *channels, uint32_t channelNum, HcommDataType hcommDataType,
      70              :         HcommDataType hcommOutputDataType, HcommReduceOp hcommOpType);
      71              : 
      72              :     void SetDependencyInfo(uint32_t id, uint32_t mask, const std::shared_ptr<CcuRepBase> &rep);
      73              :     std::unordered_map<uint32_t, std::vector<std::shared_ptr<CcuRepBase>>> GetDependencyInfo(uint32_t id);
      74              :     void EraseDependencyInfo(uint32_t id);
      75              :     void ClearDependencyInfo();
      76              : public:
      77              :     // CCU Profiling相关数据
      78              :     CcuProfilingInfo ccuProfilingInfoCache;
      79              :     std::vector<std::shared_ptr<CcuRepBase>> allLgProfilingReps;  // 当前所有的loopGroup Rep
      80              :     LoopGroupProfilingInfo lgProfilingInfo; // LoopGroup相关profiling缓存信息
      81              :     std::vector<std::shared_ptr<CcuRepBase>> waitCkeProfilingReps; // waitCKE相关REP缓存
      82              :     std::vector<CcuProfilingInfo> profilingInfo; // context全部profiling缓存信息
      83              :     // 需要校验返回值是否为nullptr
      84          283 :     CcuInsGeneraterBase* GetInsGenerator()
      85              :     {
      86          283 :         return insGenerator;
      87              :     }
      88              : 
      89            3 :     void SetInsGenerater(CcuInsGeneraterBase* insGeneraterBase)
      90              :     {
      91            3 :         insGenerator = insGeneraterBase;
      92            3 :     }
      93              : 
      94              : protected:
      95              :     std::set<std::string> registeredLoop;
      96              :     CcuInsGeneraterBase* insGenerator{nullptr};
      97              :     std::unordered_map<uint32_t, std::unordered_map<uint32_t, std::vector<std::shared_ptr<CcuRepBase>>>> depInfo;
      98              : 
      99              : private:
     100              :     std::shared_ptr<CcuRep::CcuRepBlock> activeBlock{nullptr};
     101              :     std::shared_ptr<CcuRep::CcuRepBlock> mainBlock{nullptr};
     102              : 
     103              :     uint32_t             dieId{UINT32_MAX};
     104              :     uint32_t             missionId{UINT32_MAX};
     105              :     uint32_t             missionKey{0};
     106              : };
     107              : 
     108              : }; // namespace CcuRep
     109              : }; // namespace hcomm
     110              : 
     111              : #endif // _CCU_REP_CTX_H
        

Generated by: LCOV version 2.0-1