LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/device/common - aicpu_hccl_def.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 14 14
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 8 8

            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 __AICPU_HCCL_DEF_H__
      12              : #define __AICPU_HCCL_DEF_H__
      13              : 
      14              : #include <cstdint>
      15              : #include "hccl_common.h"
      16              : #include "aicpu_operator_pub.h"
      17              : #include "aicpu_hccl_sqcq.h"
      18              : #include "aicpu_hccl_sqcqv1.h"
      19              : #include "aicpu_hccl_sqcqv2.h"
      20              : #include "profiling_extend_info.h"
      21              : #include "common.h"
      22              : 
      23              : constexpr u32 AC_MAX_RANK_NUM = 32U;
      24              : constexpr u32 HCCL_COMM_DOMAIN_KEY_MAX_LEN = 128;
      25              : constexpr u32 TILING_TURN_MAX = 32;
      26              : constexpr u32 AC_MAX_PROF_LOOP = 30U;
      27              : constexpr u32 AC_MAX_PROF_COMM_CNT = 1024U;
      28              : 
      29              : using HccCommResParamTask = HcclCombinOpParam;
      30              : 
      31              : // 重执行状态
      32              : enum class HcclOpExecFSM {
      33              :     HCCL_OP_EXEC_FSM_INIT = 0,
      34              :     HCCL_OP_EXEC_FSM_LAUNCH,
      35              :     HCCL_OP_EXEC_FSM_WAIT_END,
      36              :     HCCL_OP_EXEC_FSM_STOPPING,
      37              :     HCCL_OP_EXEC_FSM_STOPPED,
      38              :     HCCL_OP_EXEC_FSM_CHANGE_LINK,
      39              :     HCCL_OP_EXEC_FSM_WAIT_RETRY,
      40              :     HCCL_OP_EXEC_FSM_RETRY,
      41              :     HCCL_OP_EXEC_FSM_END,
      42              :     HCCL_OP_EXEC_FSM_ERROR,
      43              :     HCCL_OP_EXEC_STOP_LAUNCH,
      44              : };
      45              : 
      46              : enum AicpuCcOpFinishMode {
      47              :     AICPUSUSPENDING_ERROR = 301U,
      48              : };
      49              : 
      50              : struct KFCTaskComm {
      51              :     u64 context;     // HCCL通信context
      52              :     u64 tilingData;  // 通信
      53              : };
      54              : 
      55              : struct AicpuComProfCommLoop {
      56              :     // addr消息处理耗时
      57              :     u64 hccExecStartTime;
      58              :     u64 sendTaskStartTime;
      59              :     u64 sendSqeFinishTime;
      60              : 
      61              :     u64 dataLen;
      62              : };
      63              : 
      64              : enum AicpuCCExecOp {
      65              :     CC_EXE_TWO_SHOT_8_STREAM = 0, /**< two shot算法,适用于大数据量通信场景*/
      66              :     CC_EXE_ONE_SHOT_8_STREAM = 1, /**< one shot算法,适用于小数据量通信场景*/
      67              :     CC_EXE_ONE_SHOT_4_STREAM = 2, /**< one shot算法,4条流,需要执行两轮通信 */
      68              :     CC_EXE_ONE_SHOT_1_STREAM = 3, /**< one shot算法,1条流,需要执行三轮通信 */
      69              :     CC_EXE_TWO_SHOT_1_STREAM = 4,
      70              :     CC_EXE_ONE_SHOT_HD = 5,
      71              :     CC_EXE_ONE_SHOT_SINGLE_RING = 6,
      72              : };
      73              : 
      74              : struct AicpuComProf {
      75              :     // 初始化耗时
      76              :     u64 launchEntryTime;
      77              :     u64 commInitEndTime;
      78              : 
      79              :     // sqe填写发送统计数据
      80              :     u32 fillSqeCnt;
      81              :     u64 fillSqeTimes;
      82              :     u32 sendSqeBatch;
      83              :     u64 sendSqeTimes;
      84              : 
      85              :     // 记录具体每轮通信信息
      86              :     u32 workCnt;
      87              :     AicpuComProfCommLoop commLoop[AC_MAX_PROF_COMM_CNT];
      88              :     u64 tid;
      89              :     s32 clusterId;
      90              :     u32 rankId;
      91              : 
      92              :     // 记录trace上报耗时
      93              :     u64 traceSubmitTime;
      94              :     u64 traceCtxTime;
      95              :     u64 traceSqeTime;
      96              : 
      97              :     // 尾处理耗时
      98              :     u64 receiveFinalizeTime;
      99              :     u64 endTime;
     100              : };
     101              : 
     102              : struct AicpuComRankInfo {
     103              :     u32 rankId;
     104              :     u64 window;  // default size 200*1024*1024
     105              :     u64 windowOut;
     106              : };
     107              : 
     108              : struct AicpuComSignalInfo {
     109              :     u64 address;  // notify地址
     110              :     s32 actualNotifyId;
     111              : };
     112              : 
     113              : // preparePosition标记
     114              : enum TASK_PREPARE_POSITION {
     115              :     TASK_PREPARE_HOST = 0,        // host模式,通信由host下发
     116              :     TASK_PREPARE_KERNEL = 1,      // kernel模式,通信由kernel下发
     117              :     TASK_PREPARE_RESERVED = 100
     118              : };
     119              : 
     120              : enum class DfxKfcStatus : int64_t {
     121              :     kDefault = 0,
     122              :     kOneStart,
     123              :     kOneFinished,
     124              :     kTimeOut,
     125              : };
     126              : 
     127              : enum class CommandToKfc : int64_t {
     128              :     kDefault = 0,
     129              :     kClear,
     130              :     kStop,
     131              :     kRestart
     132              : };
     133              : 
     134              : enum class CommandToBackGroud : int64_t {
     135              :     kDefault = 0,
     136              :     kStop,
     137              : };
     138              : 
     139              : struct KfcRestartConfig {
     140              :     uint32_t tryRestartTimes{0U};
     141              :     uint32_t maxRestartTimes{1U}; // 最多重执行一次
     142              : };
     143              : 
     144              : struct TaskExceptionCqe {
     145              :     uint8_t sqeType{0};
     146              :     uint32_t errorCode{0};
     147              : };
     148              : 
     149              : struct DfxExtendInfo {
     150              :     DfxKfcStatus kfcStatus = DfxKfcStatus::kDefault;
     151              :     CqeStatus cqeStatus = CqeStatus::kDefault;
     152              :     PollStatus pollStatus = PollStatus::kDefault;
     153              :     TaskExceptionCqe cqeException;
     154              :     CommandToKfc commandToKfc = CommandToKfc::kDefault;
     155              :     KfcRestartConfig kfcRestartConfig;
     156              :     CommandToBackGroud commandToBackGroud = CommandToBackGroud::kDefault;
     157              :     dfx::DfxTimeOutConfig dfxTimeOutConfig;
     158              : };
     159              : 
     160              : // record the communication global info.
     161              : struct AicpuComContext {
     162              :     char hcomId[HCCL_COMM_DOMAIN_KEY_MAX_LEN];
     163              :     u32 devId;
     164              :     u32 ssid;
     165              :     u32 rankId;   // self rank id
     166              :     u32 rankNum;  // total rank, include self
     167              : 
     168              :     HcclCMDType commType;    // AllReduce, scatter..
     169              :     HcclReduceOp reducekind;  // ADD,MAX,MIN,EQUAL
     170              : 
     171              :     AicpuCCExecOp commOpType;  // twoshot.onshot...
     172              :     u32 unitSize;
     173              :     u64 commLen;
     174              :     u64 totalCnt; // 发送总数据个数
     175              :     u64 windowSize;
     176              : 
     177              :     u64 workSpaceAddr;
     178              :     u32 notifyOff;       // device notify write/read value偏移
     179              :     u16 notifyBeginCnt;  // notify write value的使用个数
     180              :     u16 notifyEndCnt;    // notify read value的使用个数
     181              :     u8 useBufferType;   // 使用recvbuf类型
     182              :     u64 winOffset;
     183              : 
     184              :     u64 kfcNotifyId;  // 用于主流全部任务最后添加record,激活kfc流(即内部创建用于launch
     185              :                       // kfc算子的流)wait,kfc流开始执行下一个算子
     186              :     u32 eventIds[AC_MAX_RANK_NUM];
     187              : 
     188              :     u32 curTurnCnt;  // 当前算法执行通信轮次
     189              :     u32 turnValue[TILING_TURN_MAX * AC_MAX_RANK_NUM];
     190              :     u32 totalTurnCnt; // 需要通信总轮次
     191              : 
     192              :     // profiling
     193              :     AicpuComProf acprof[AC_MAX_PROF_LOOP];
     194              : 
     195              :     AicpuComRankInfo rankInfo[AC_MAX_RANK_NUM];
     196              :     HcclComStreamInfo streamInfo[AC_MAX_RANK_NUM];
     197              :     int logLevel;
     198              : 
     199              :     AicpuComSignalInfo noIpcPreNotify[AC_MAX_RANK_NUM];
     200              :     AicpuComSignalInfo noIpcPostNotify[AC_MAX_RANK_NUM];
     201              :     AicpuComSignalInfo ipcPreRecordNotify[AC_MAX_RANK_NUM];
     202              :     AicpuComSignalInfo ipcPreWaitNotify[AC_MAX_RANK_NUM];
     203              :     AicpuComSignalInfo ipcPostRecordNotify[AC_MAX_RANK_NUM];
     204              :     AicpuComSignalInfo ipcPostWaitNotify[AC_MAX_RANK_NUM];
     205              :     AicpuComSignalInfo aicpuOpNotify[2]; // 集合通信AICPU展开资源
     206              : 
     207              :     uint8_t commAlg; // 指定通信算法
     208              :     bool directlySendMainSteramSqe;  // 消除头开销,第一需要直接执行时先下发主流
     209              :     bool alreadyInit;
     210              :     bool determinism;
     211              :     bool retryEnable;
     212              :     s32 clusterId;
     213              :     DevType devType = DevType::DEV_TYPE_COUNT;
     214              :     uint8_t debugMode = 0;
     215              :     u64 overflowAddr;
     216              :     TASK_PREPARE_POSITION preparePosition; // mc2高阶api,记录当前的模式
     217              :     u32 msgPosForKernel;     // mc2高阶api,记录当前处理的msg的位置
     218              :     u8 curTurnCntForKernel;  // mc2高阶api,记录当前msg的通信轮次
     219              :     u8 onlyRead;  // 只使用 SDMA 读进行拷贝
     220              :     DfxExtendInfo dfxExtendInfo;
     221              : 
     222              :     int sendCntRecord[4]; // 4 记录aicpu过程中的sendCnt,最多记录4次
     223              :     int recvCntRecord[4]; // 4 记录aicpu过程中的recvCnt,最多记录4次
     224              :     u32 retryHoldTime;
     225              :     u32 retryIntervalTime;
     226              :     u32 opIndex;
     227              :     bool isOpLaunch = false; //每个算子下发记录 (kNull/KRunning)
     228              :     bool isStopLaunch = false;  //MC2测试用例下,主线程是否实现停止算子展开
     229              :     bool endStopLaunch = false;  //NsStopLaunch是否处理 (背景线程/主线程)
     230              :     bool commOpenStatus = false; //通信域使用情况
     231              :     bool isRunning = false;
     232              :     std::shared_ptr<hccl::HDCommunicate> kfcControlTransferH2D{nullptr};
     233              :     std::shared_ptr<hccl::HDCommunicate> kfcStatusTransferD2H{nullptr};
     234              :     dfx::ProfilingExtendInfo profilingExtendInfo;
     235              :     u8 totalTurnCntForKernel; // mc2高阶api,记录当前msg的总通信轮次
     236              :     bool skipLocalDataCopy; // 通信算法是否拷贝本卡数据,根据isCommOut配置
     237              :                             // isCommOut = 1时,该项为0;isCommOut = 0时,该项为1
     238              :     u64 gatherOut;
     239              :     std::vector<struct hccl::TransportDeviceNormalData> ibversData;
     240              :     bool multiServerFlag;
     241              :     int64_t chipId;
     242              : };
     243              : 
     244              : extern AicpuComContext *AicpuGetComContext();
     245              : extern void AicpuGetAllComContext(AicpuComContext *&contextBase, uint32_t &contextNum);
     246              : 
     247    229115397 : template <typename T> void AicpuUpdatComContextMumber(u64 offset, T value)
     248              : {
     249    229115397 :     AicpuComContext *contextBase = nullptr;
     250    229115397 :     uint32_t contextNum = 0;
     251    229115397 :     AicpuGetAllComContext(contextBase, contextNum);
     252    687346191 :     for (uint32_t i = 0; i < contextNum; i++) {
     253    458230794 :         T *dst = reinterpret_cast<T *>(reinterpret_cast<u64>(&contextBase[i]) + offset);
     254    458230794 :         *dst = value;
     255              :     }
     256    458230794 :     return;
     257              : };
     258              : 
     259              : struct KfcState {
     260           94 :     KfcState() {
     261           94 :         AicpuUpdatComContextMumber(offsetof(AicpuComContext, isRunning), true);
     262           94 :     }
     263           94 :     ~KfcState() {
     264           94 :         AicpuUpdatComContextMumber(offsetof(AicpuComContext, isRunning), false);
     265           94 :     }
     266              : };
     267              : #endif
        

Generated by: LCOV version 2.0-1