LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/fault_recovery - snap_shot_parse.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) 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              : #ifndef SNAP_SHOT_PARSER_H
      11              : #define SNAP_SHOT_PARSER_H
      12              : 
      13              : #include <hccl/hccl_types.h>
      14              : #include "hccl_params_pub.h"
      15              : #include "topo_info.h"
      16              : #include "rank_table_info.h"
      17              : #include "ccu_rank_group.h"
      18              : 
      19              : namespace Hccl {
      20              : constexpr u32 SNAPSHOT_VERSION_SIZE = 128;
      21              : constexpr u32 GROUP_NAME_SIZE = 128;
      22              : 
      23              : struct SnapShotDynamic {
      24              :     vector<std::pair<u32, RankId>> levelRankPairs{};
      25              :     vector<std::pair<LinkGroup, u32>> linkGroupPair{};
      26              :     u32 submittedOpCnt{0};
      27              :     u32 opMode{0};
      28              :     OpExecuteConfig opExecuteConfig; // 存储算子粒度和通信域加速模式
      29              :     OpExecuteConfig commExecuteConfig;
      30              :     bool isLoadOp{false}; // 是否已加载过算子
      31              : };
      32              : 
      33              : struct SnapShotPub {
      34              :     char snapshotVersion[SNAPSHOT_VERSION_SIZE]; // 快照版本 一般不超过 128 Byte
      35              :     char cannVersion[SNAPSHOT_VERSION_SIZE];     // cann版本 一般不超过 128 Byte
      36              :     char hcclVersion[SNAPSHOT_VERSION_SIZE];     // hccl版本 一般不超过 128 Byte
      37              :     uint32_t step;
      38              : };
      39              : 
      40              : struct SnapShotComm {
      41              :     HcclCommConfig config;
      42              :     Hccl::CommParams commParams;
      43              :     RankTableInfo rankTableInfo;
      44              :     TopoInfo topoInfo;
      45              :     vector<std::pair<u32, RankId>>
      46              :         levelRankPairs; /* 该信息通过算法层提供的接口获取,用于获取建链时使用的linkData数据——GetPaths(u32 level, RankId
      47              :                            sRankId, RankId dRankId)-> LinkData(const NetInstance::Path &path) */
      48              :     u32 submittedOpCnt;
      49              :     u32 opMode{0};
      50              :     vector<std::pair<LinkGroup, u32>> linkGroupPair{};
      51              :     OpExecuteConfig opExecuteConfig; // 存储算子粒度和通信域加速模式
      52              :     OpExecuteConfig commExecuteConfig;
      53              :     bool isLoadOp{false}; // 是否已加载过算子
      54              : };
      55              : struct Snapshot {
      56              :     uint32_t size;
      57              :     char groupName[GROUP_NAME_SIZE]; // 通信域名称 一般不超过 128 Byte
      58              :     SnapShotComm snapShotComm;       // comm save(size, name, tembinary)
      59              : };
      60              : 
      61              : struct SnapShotSubComm {
      62              :     HcclCommConfig config;
      63              :     Hccl::CommParams commParams;
      64              :     vector<RankId> rankIds; /* 子通信域中rank在全局通信域中的rank id组成的vector */
      65              :     vector<std::pair<u32, RankId>> levelRankPairs;
      66              :     u32 submittedOpCnt;
      67              :     u32 opMode{0};
      68              :     vector<std::pair<LinkGroup, u32>> linkGroupPair{};
      69              :     OpExecuteConfig opExecuteConfig; // 存储算子粒度和通信域加速模式
      70              :     OpExecuteConfig commExecuteConfig;
      71              :     bool isLoadOp{false}; // 是否已加载过算子
      72              : };
      73              : struct SubSnapshot {
      74              :     uint32_t size;
      75              :     char groupName[GROUP_NAME_SIZE]; // 子通信域名称 一般不超过 128 Byte
      76              :     SnapShotSubComm snapShotSubComm; // comm save(size, name, tembinary)
      77              : };
      78              : 
      79              : struct CcuStatusSnapshot {
      80              :     std::vector<std::array<char, GROUP_NAME_SIZE>> useMsCommIds{};
      81              :     std::vector<std::array<char, GROUP_NAME_SIZE>> useSchedCommIds{};
      82              : };
      83              : 
      84              : struct SnapShotBuf {
      85              :     SnapShotPub snapShotPub;             /* 公共区域 */
      86              :     uint32_t groupNum;                   /* 子通信域数量 */
      87              :     Snapshot snapshot;                   /* 全局通信域 */
      88              :     vector<SubSnapshot> subSnapshot;     /* 子通信域 */
      89              :     CcuStatusSnapshot ccuStatusSnapshot; /* ccu使用情况 */
      90              : };
      91              : 
      92              : /**
      93              :  * @brief 快照数据序列化和反序列化 单例
      94              :  * @note
      95              :  */
      96              : class SnapShotParser {
      97              : public:
      98              :     SnapShotParser(const SnapShotParser&) = delete;
      99              :     SnapShotParser& operator=(const SnapShotParser&) = delete;
     100              : 
     101              :     static SnapShotParser& GetInstance();
     102              : 
     103              :     // 获取存储的完整流
     104              :     BinaryStream& GetSnapShotBuf();
     105              : 
     106              :     // 恢复通信域,recorver调用,把传入的备份流流反序列化到本地结构
     107              :     HcclResult ParseSnapshotToLocalBuff(void* snapshotBuf, uint32_t snapshotBufSize, SnapShotBuf& localBuff);
     108              : 
     109              :     // 生成 全局通信域 静态短流
     110              :     void SerializeCommonInfo(
     111              :         const CommParams& commParams, const HcclCommConfig& config, std::unique_ptr<RankTableInfo> ranktableInfo,
     112              :         std::shared_ptr<TopoInfo>& topoInfo, BinaryStream& binStream) const;
     113              : 
     114              :     // 生成 子局通信域 静态短流
     115              :     void SerializeSubCommInfo(
     116              :         const CommParams& commParams, const HcclCommConfig& subConfig, const std::vector<u32>& rankId,
     117              :         BinaryStream& binStream) const;
     118              :     // 生成 单个通信域 动态短流
     119              :     HcclResult SerializeDynamicInfo(
     120              :         const std::vector<std::pair<u32, RankId>>& levelRankPairs, u32 submittedOpCnt, BinaryStream& binStream) const;
     121              :     // 序列化 公共版本信息
     122              :     void SerializeCommVersionInfo(BinaryStream& binStream) const;
     123              : 
     124              :     // 计算BinaryStream的CRC值
     125              :     HcclResult CalcBufCrc32(BinaryStream& buf, u32& crcValue) const;
     126              : 
     127              :     // 快照恢复完成后,需要下发算子才算一个完整的流程
     128              :     void SetIsNeedLoadOp(bool status);
     129              :     bool GetIsNeedLoadOp() const;
     130              : 
     131              : private:
     132              :     // 全局通信域反序列化
     133              :     HcclResult DeserializeCommInfo(BinaryStream& binaryStream, Snapshot& snapShot);
     134              : 
     135              :     // 单个子通信域反序列化
     136              :     HcclResult DeserializeSubCommInfo(BinaryStream& stream, SubSnapshot& subSnapShot);
     137              :     // 单个通信域动态buf解析
     138              :     HcclResult DeSnapShotDynamicBuf(BinaryStream& buf, SnapShotDynamic& dynamicInfo) const;
     139              :     // 解析 所有通信域 快照动态buf
     140              :     HcclResult DeAllSnapShotDynamicBuf(BinaryStream& buf, SnapShotBuf& localBuff);
     141              :     // 解析 所有通信域 快照静态buf
     142              :     HcclResult DeAllSnapShotStaticBuf(BinaryStream& buf, SnapShotBuf& localBuff);
     143              :     // 解析 ccuStatus
     144              :     void DeserializeCcuStatusBuf(BinaryStream& buf, SnapShotBuf& localBuff) const;
     145              : 
     146              :     // 全局通信域静态信息的序列化
     147              :     void SerializeParamsInfo(const CommParams& commParams, BinaryStream& binStream) const;
     148              :     void SerializeCommConfigInfo(const HcclCommConfig& config, BinaryStream& binStream) const;
     149              :     void SerializeRankTableInfo(std::unique_ptr<RankTableInfo> ranktableInfo, BinaryStream& binStream) const;
     150              :     void SerializeTopoInfo(const std::shared_ptr<TopoInfo>& topoInfo, BinaryStream& binStream) const;
     151              : 
     152              :     // 全局通信域静态信息的反序列化
     153              :     HcclResult DeserializeParamsInfo(BinaryStream& binaryStream, Hccl::CommParams& commParams) const;
     154              :     HcclResult DeserializeCommConfigInfo(BinaryStream& binaryStream, HcclCommConfig& config) const;
     155              :     HcclResult DeserializeRankTableInfo(BinaryStream& binaryStream, RankTableInfo& rankTableInfo) const;
     156              :     HcclResult DeserializeTopoInfo(BinaryStream& binaryStream, TopoInfo& topoInfo) const;
     157              : 
     158              :     // 子通信域静态信息的序列化
     159              :     void SerializeSubCommParamsInfo(const CommParams& commParams, BinaryStream& binStream) const;
     160              :     void SerializeSubCommConfigInfo(const HcclCommConfig& subConfig, BinaryStream& binStream) const;
     161              :     void SerializeRankIds(const std::vector<u32>& rankIds, BinaryStream& binStream) const;
     162              : 
     163              :     // 子通信域静态信息的反序列化
     164              :     HcclResult DeserializeSubCommParamsInfo(BinaryStream& binaryStream, CommParams& subCommParam) const;
     165              :     HcclResult DeserializeSubCommConfigInfo(BinaryStream& binaryStream, HcclCommConfig& subConfig) const;
     166              :     HcclResult DeserializeRankIds(BinaryStream& binaryStream, vector<RankId>& rankIds) const;
     167              : 
     168              :     //  公共版本信息序列化和反序列化
     169              :     HcclResult DeserializeCommVersionInfo(BinaryStream& binaryStream, SnapShotPub& snapshotPub) const;
     170              : 
     171            3 :     SnapShotParser() {};
     172            3 :     ~SnapShotParser() {};
     173              : 
     174              :     // 校验BinaryStream的CRC值
     175              :     HcclResult CheckBufCrc32(BinaryStream& buf, const u32 otherCrcValue) const;
     176              : 
     177              : private:
     178              :     BinaryStream snapShotStream_;
     179              :     bool isNeedLoadOp{false};
     180              : };
     181              : 
     182              : } // namespace Hccl
     183              : 
     184              : #endif // SNAP_SHOT_PARSER_H
        

Generated by: LCOV version 2.0-1