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