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 % 2 2
Test Date: 2026-08-17 10:19:35 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(
      70              :             const ChannelHandle* channels, uint32_t channelNum, HcommDataType hcommDataType,
      71              :             HcommDataType hcommOutputDataType, HcommReduceOp hcommOpType);
      72              : 
      73              :         void SetDependencyInfo(uint32_t id, uint32_t mask, const std::shared_ptr<CcuRepBase>& rep);
      74              :         std::unordered_map<uint32_t, std::vector<std::shared_ptr<CcuRepBase>>> GetDependencyInfo(uint32_t id);
      75              :         void EraseDependencyInfo(uint32_t id);
      76              :         void ClearDependencyInfo();
      77              : 
      78              :     public:
      79              :         // CCU Profiling相关数据
      80              :         CcuProfilingInfo ccuProfilingInfoCache;
      81              :         std::vector<std::shared_ptr<CcuRepBase>> allLgProfilingReps;   // 当前所有的loopGroup Rep
      82              :         LoopGroupProfilingInfo lgProfilingInfo;                        // LoopGroup相关profiling缓存信息
      83              :         std::vector<std::shared_ptr<CcuRepBase>> waitCkeProfilingReps; // waitCKE相关REP缓存
      84              :         std::vector<CcuProfilingInfo> profilingInfo;                   // context全部profiling缓存信息
      85              :         // 需要校验返回值是否为nullptr
      86          679 :         CcuInsGeneratorBase* GetInsGenerator() { return insGenerator; }
      87              : 
      88            3 :         void SetInsGenerater(CcuInsGeneratorBase* insGeneratorBase) { insGenerator = insGeneratorBase; }
      89              : 
      90              :     protected:
      91              :         std::set<std::string> registeredLoop;
      92              :         CcuInsGeneratorBase* insGenerator{nullptr};
      93              :         std::unordered_map<uint32_t, std::unordered_map<uint32_t, std::vector<std::shared_ptr<CcuRepBase>>>> depInfo;
      94              : 
      95              :     private:
      96              :         std::shared_ptr<CcuRep::CcuRepBlock> activeBlock{nullptr};
      97              :         std::shared_ptr<CcuRep::CcuRepBlock> mainBlock{nullptr};
      98              : 
      99              :         uint32_t dieId{UINT32_MAX};
     100              :         uint32_t missionId{UINT32_MAX};
     101              :         uint32_t missionKey{0};
     102              :     };
     103              : 
     104              : }; // namespace CcuRep
     105              : }; // namespace hcomm
     106              : 
     107              : #endif // _CCU_REP_CTX_H
        

Generated by: LCOV version 2.0-1