LCOV - code coverage report
Current view: top level - legacy/ascend910/pub_inc - dispatcher_task_types.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 42.0 % 131 55
Test Date: 2026-08-04 10:52:23 Functions: 45.8 % 24 11

            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 DISPATCHER_TASK_TYPES_H
      12              : #define DISPATCHER_TASK_TYPES_H
      13              : 
      14              : #include <memory>
      15              : #include <mutex>
      16              : #include <string>
      17              : #include <map>
      18              : #include <thread>
      19              : 
      20              : #include <hccl/hccl_types.h>
      21              : #include "hccl_common.h"
      22              : #include "workflow_pub.h"
      23              : 
      24              : namespace hccl {
      25              : enum class TaskType {
      26              :     TASK_SDMA = 0,
      27              :     TASK_RDMA,
      28              :     TASK_REDUCE_INLINE,
      29              :     TASK_REDUCE_TBE,
      30              :     TASK_NOTIFY_RECORD,
      31              :     TASK_NOTIFY_WAIT,
      32              :     TASK_HOST,
      33              :     TASK_GRAPH_LAUNCH,
      34              :     TASK_BATCH_REPORT,
      35              :     TASK_FLIP
      36              : };
      37              : 
      38              : enum class SimpleTaskType {
      39              :     SDMA = 0,
      40              :     RDMA = 1,
      41              :     LOCAL = 2,
      42              :     RESERVED = 255
      43              : };
      44              : 
      45              : enum class TaskRole {
      46              :     DST = 0,
      47              :     SRC = 1,
      48              :     RESERVED = 255
      49              : };
      50              : 
      51              : enum class LinkType {
      52              :     LINK_ONCHIP = 0,
      53              :     LINK_HCCS = 1,
      54              :     LINK_PCIE = 2,
      55              :     LINK_ROCE = 3,
      56              :     LINK_SIO = 4,
      57              :     LINK_HCCS_SW = 5,
      58              :     LINK_STANDARD_ROCE = 6,
      59              :     LINK_UB = 7,
      60              :     LINK_RESERVED = 255
      61              : };
      62              : 
      63              : enum class RdmaType {
      64              :     RDMA_SEND_NOTIFY = 0,
      65              :     RDMA_SEND_PAYLOAD = 1,
      66              :     RDMA_TYPE_RESERVED = 255
      67              : };
      68              : 
      69              : enum class ProfilerType {
      70              :     TASK_PROFILING = 0,
      71              :     TASK_EXCEPTION = 1,
      72              :     TASK_OVERFLOW,
      73              :     TASK_ALL,
      74              :     TASK_RESERVE
      75              : };
      76              : 
      77              : struct StepData {
      78              :     s32 streamID;
      79              :     s32 planeID; // bit[31..28] = 节点内8P-ring对应的物理环, bit[27..16] = rank_size, bit[15..0] = rank_id
      80              :     s32 stage;
      81              :     s32 step;
      82              : 
      83          232 :     StepData() : streamID(0), planeID(0), stage(0), step(-1) {}
      84              : };
      85              : 
      86              : struct TaskParaDMA {
      87              :     const void *src{nullptr};
      88              :     const void *dst{nullptr};
      89              :     std::size_t size{0};
      90              :     u64 notifyID{INVALID_U64};
      91              :     LinkType linkType{LinkType::LINK_ONCHIP};
      92              :     u32 remoteUserRank{INVALID_VALUE_RANKID};
      93              :     RdmaType rdmaType{RdmaType::RDMA_TYPE_RESERVED};
      94              :     u32 ctxId{INVALID_UINT}; // 子图 ctxId信息
      95           54 :     TaskParaDMA() {}
      96              : 
      97              :     TaskParaDMA(const void *inputSrc, const void *inputDst, std::size_t inputSize)
      98              :         : src(inputSrc),
      99              :           dst(inputDst),
     100              :           size(inputSize),
     101              :           notifyID(INVALID_U64),
     102              :           linkType(LinkType::LINK_ONCHIP),
     103              :           remoteUserRank(INVALID_VALUE_RANKID),
     104              :           rdmaType(RdmaType::RDMA_TYPE_RESERVED),
     105              :           ctxId(INVALID_UINT)
     106              :     {}
     107              : 
     108              :     TaskParaDMA(const void *inputSrc, const void *inputDst, std::size_t inputSize, u64 inputNotifyID)
     109              :         : src(inputSrc),
     110              :           dst(inputDst),
     111              :           size(inputSize),
     112              :           notifyID(inputNotifyID),
     113              :           linkType(LinkType::LINK_ONCHIP),
     114              :           remoteUserRank(INVALID_VALUE_RANKID),
     115              :           rdmaType(RdmaType::RDMA_TYPE_RESERVED),
     116              :           ctxId(INVALID_UINT)
     117              :     {}
     118              : 
     119            0 :     TaskParaDMA(const void *inputSrc, const void *inputDst, std::size_t inputSize, u64 inputNotifyID,
     120              :         LinkType inputLinkType, RdmaType inputRdmaType)
     121            0 :         : src(inputSrc),
     122            0 :           dst(inputDst),
     123            0 :           size(inputSize),
     124            0 :           notifyID(inputNotifyID),
     125            0 :           linkType(inputLinkType),
     126            0 :           remoteUserRank(static_cast<u32>(inputNotifyID >> 32)),  // notifyID的高32位为对端usrrank
     127            0 :           rdmaType(inputRdmaType),
     128            0 :           ctxId(INVALID_UINT)
     129            0 :     {}
     130           32 :     TaskParaDMA(const void *inputSrc, const void *inputDst, std::size_t inputSize, LinkType inputLinkType,
     131              :         u32 remoteUserRank) // 无notifyID时需要传入remoteUserRank
     132           32 :         : src(inputSrc),
     133           32 :           dst(inputDst),
     134           32 :           size(inputSize),
     135           32 :           notifyID(INVALID_U64),
     136           32 :           linkType(inputLinkType),
     137           32 :           remoteUserRank(remoteUserRank),
     138           32 :           rdmaType(RdmaType::RDMA_TYPE_RESERVED),
     139           32 :           ctxId(INVALID_UINT)
     140           32 :     {}
     141            4 :     TaskParaDMA(const void *inputSrc, const void *inputDst, std::size_t inputSize, u64 inputNotifyID,
     142              :         LinkType inputLinkType, RdmaType inputRdmaType, u32 inputCtxId)
     143            4 :         : src(inputSrc),
     144            4 :           dst(inputDst),
     145            4 :           size(inputSize),
     146            4 :           notifyID(inputNotifyID),
     147            4 :           linkType(inputLinkType),
     148            4 :           remoteUserRank(static_cast<u32>(inputNotifyID >> 32)),  // notifyID的高32位为对端usrrank
     149            4 :           rdmaType(inputRdmaType),
     150            4 :           ctxId(inputCtxId)
     151            4 :     {}
     152            0 :     TaskParaDMA(const void *inputSrc, const void *inputDst, std::size_t inputSize, LinkType inputLinkType,
     153              :         u32 remoteUserRank, RdmaType inputRdmaType, u32 inputCtxId)
     154            0 :         : src(inputSrc),
     155            0 :           dst(inputDst),
     156            0 :           size(inputSize),
     157            0 :           notifyID(INVALID_U64),
     158            0 :           linkType(inputLinkType),
     159            0 :           remoteUserRank(remoteUserRank),
     160            0 :           rdmaType(inputRdmaType),
     161            0 :           ctxId(inputCtxId)
     162            0 :     {}
     163              : };
     164              : 
     165              : struct TaskParaReduce {
     166              :     const void *src;
     167              :     const void *dst;
     168              :     std::size_t size;
     169              : 
     170              :     HcclReduceOp op;
     171              :     HcclDataType dataType;
     172              :     LinkType linkType;
     173              :     u32 remoteUserRank;
     174              :     u32 ctxId; // 子图 ctxId信息
     175           33 :     TaskParaReduce()
     176           33 :         : src(nullptr),
     177           33 :           dst(nullptr),
     178           33 :           size(0),
     179           33 :           op(HCCL_REDUCE_RESERVED),
     180           33 :           dataType(HCCL_DATA_TYPE_RESERVED),
     181           33 :           linkType(LinkType::LINK_ONCHIP),
     182           33 :           remoteUserRank(INVALID_UINT),
     183           33 :           ctxId(INVALID_UINT)
     184           33 :     {}
     185              : 
     186              :     TaskParaReduce(const void *inputSrc, const void *inputDst, std::size_t inputSize, HcclReduceOp inputOp,
     187              :         HcclDataType inputDataType)
     188              :         : src(inputSrc),
     189              :           dst(inputDst),
     190              :           size(inputSize),
     191              :           op(inputOp),
     192              :           dataType(inputDataType),
     193              :           linkType(LinkType::LINK_ONCHIP),
     194              :           remoteUserRank(INVALID_UINT),
     195              :           ctxId(INVALID_UINT)
     196              :     {}
     197              : 
     198            0 :     TaskParaReduce(const void *inputSrc, const void *inputDst, std::size_t inputSize, HcclReduceOp inputOp,
     199              :         HcclDataType inputDataType, LinkType inputLinkType)
     200            0 :         : src(inputSrc),
     201            0 :           dst(inputDst),
     202            0 :           size(inputSize),
     203            0 :           op(inputOp),
     204            0 :           dataType(inputDataType),
     205            0 :           linkType(inputLinkType),
     206            0 :           remoteUserRank(INVALID_UINT),
     207            0 :           ctxId(INVALID_UINT)
     208            0 :     {}
     209            9 :     TaskParaReduce(const void *inputSrc, const void *inputDst, std::size_t inputSize, HcclReduceOp inputOp,
     210              :         HcclDataType inputDataType, LinkType inputLinkType, u32 remoteUserRank)
     211            9 :         : src(inputSrc),
     212            9 :           dst(inputDst),
     213            9 :           size(inputSize),
     214            9 :           op(inputOp),
     215            9 :           dataType(inputDataType),
     216            9 :           linkType(inputLinkType),
     217            9 :           remoteUserRank(remoteUserRank),
     218            9 :           ctxId(INVALID_UINT)
     219            9 :     {}
     220            0 :     TaskParaReduce(const void *inputSrc, const void *inputDst, std::size_t inputSize, HcclReduceOp inputOp,
     221              :         HcclDataType inputDataType, LinkType inputLinkType, u32 remoteUserRank, u32 inputCtxId)
     222            0 :         : src(inputSrc),
     223            0 :           dst(inputDst),
     224            0 :           size(inputSize),
     225            0 :           op(inputOp),
     226            0 :           dataType(inputDataType),
     227            0 :           linkType(inputLinkType),
     228            0 :           remoteUserRank(remoteUserRank),
     229            0 :           ctxId(inputCtxId)
     230            0 :     {}
     231              : };
     232              : 
     233              : struct TaskParaNotify {
     234              :     u64 notifyID;
     235              :     s32 stage; // 用于标识stream间同步时所在的stage, 非用于stream同步的默认为-1
     236              :     u32 remoteUserRank;
     237              :     u32 ctxId; // 子图 ctxId信息
     238           49 :     TaskParaNotify() : notifyID(0), stage(INVALID_VALUE_STAGE), remoteUserRank(INVALID_UINT), ctxId(INVALID_UINT) {}
     239              :     explicit TaskParaNotify(u64 notifyIDInput)
     240              :         : notifyID(notifyIDInput),
     241              :           stage(INVALID_VALUE_STAGE),
     242              :           remoteUserRank(static_cast<u32>(notifyIDInput >> 32)), // 无remoteRank时,使用notify的高32位为remote rank
     243              :           ctxId(INVALID_UINT)
     244              :     {}
     245            0 :     TaskParaNotify(u64 notifyIDInput, s32 stageIn)
     246            0 :         : notifyID(notifyIDInput),
     247            0 :           stage(stageIn),
     248            0 :           remoteUserRank(static_cast<u32>(notifyIDInput >> 32)), // 无remoteRank时,使用notify的高32位为remote rank
     249            0 :           ctxId(INVALID_UINT)
     250            0 :     {}
     251            6 :     TaskParaNotify(u64 notifyIDInput, s32 stageIn, u32 remoteUserRank)
     252            6 :         : notifyID(notifyIDInput), stage(stageIn), remoteUserRank(remoteUserRank), ctxId(INVALID_UINT)
     253            6 :     {}
     254            0 :     TaskParaNotify(u64 notifyIDInput, s32 stageIn, u32 remoteUserRank, u32 ctxIdInput)
     255            0 :         : notifyID(notifyIDInput), stage(stageIn), remoteUserRank(remoteUserRank), ctxId(ctxIdInput)
     256            0 :     {}
     257              : };
     258              : 
     259              : struct TaskParaHost {
     260              :     u32 streamID;
     261              :     u32 taskID;
     262              :     u64 len;
     263              :     std::chrono::microseconds duration;
     264              :     std::string tag;
     265            0 :     TaskParaHost(u32 streamID, u32 taskID, u64 len, std::chrono::microseconds duration, std::string &tag)
     266            0 :         : streamID(streamID),
     267            0 :           taskID(taskID),
     268            0 :           len(len),
     269            0 :           duration(duration),
     270            0 :           tag(tag)
     271            0 :     {}
     272              : };
     273              : 
     274              : struct TaskParaGraphLaunch {
     275              :     u32 ctxNum{0};
     276              :     const void *descBuf{nullptr};
     277              :     size_t descBufLen{0};
     278              : };
     279              : 
     280              : // aicpu展开模式当前下到流上的所有task profiling信息
     281              : struct AiCPUStreamTasks {
     282              :     s32 streamID;
     283              :     void *ctxPtr;
     284            0 :     AiCPUStreamTasks(u32 streamID, void *ctxPtr) : streamID(streamID), ctxPtr(ctxPtr)
     285            0 :     {}
     286              : };
     287              : 
     288              : // 发生翻转task profiling信息
     289              : // 发生翻转的情况:1、重执行开始时;2、u16发生翻转task等于0时
     290              : struct FlipTaskPara {
     291              :     s32 streamID;
     292              :     u16 taskID;
     293              :     u32 flipNum;
     294            0 :     FlipTaskPara(s32 streamID, u16 taskID, u16 flipNum) : streamID(streamID), taskID(taskID),flipNum(flipNum)
     295            0 :     {}
     296              : };
     297              : 
     298              : struct TaskPara {
     299              :     TaskType type{TaskType::TASK_NOTIFY_RECORD};
     300              :     ProfilerType profilerType{ProfilerType::TASK_ALL};
     301              :     void *stream{nullptr};
     302              :     bool isMainStream{false};
     303              :     u64 beginTime{0};
     304              :     bool isFftsDispatcher{false};
     305              :     union {
     306              :         struct TaskParaDMA dma;
     307              :         struct TaskParaReduce reduce;
     308              :         struct TaskParaNotify notify;
     309              :         struct TaskParaHost host;
     310              :         struct TaskParaGraphLaunch graphLaunch;
     311              :         struct AiCPUStreamTasks streamTasks;
     312              :         struct FlipTaskPara flipTask;
     313              :     };
     314              : 
     315           38 :     TaskPara()
     316           38 :         : type(TaskType::TASK_NOTIFY_RECORD), profilerType(ProfilerType::TASK_ALL), stream(nullptr),
     317           38 :           isMainStream(false), beginTime(0), isFftsDispatcher(false), dma()
     318           38 :     {}
     319              : 
     320            9 :     TaskPara(TaskType type, TaskParaReduce reduce)
     321            9 :         : type(type), profilerType(ProfilerType::TASK_ALL), stream(nullptr), isMainStream(false), beginTime(0),
     322            9 :           isFftsDispatcher(false), reduce(reduce)
     323            9 :     {}
     324              : 
     325            0 :     TaskPara(TaskType type, TaskParaNotify notify)
     326            0 :         : type(type), profilerType(ProfilerType::TASK_ALL), stream(nullptr), isMainStream(false), beginTime(0),
     327            0 :           isFftsDispatcher(false), notify(notify)
     328            0 :     {}
     329              : 
     330            0 :     TaskPara(TaskType type, TaskParaHost host)
     331            0 :         : type(type), profilerType(ProfilerType::TASK_ALL), stream(nullptr), isMainStream(false), beginTime(0),
     332            0 :           isFftsDispatcher(false), host(host)
     333            0 :     {}
     334              : 
     335              :     TaskPara(TaskType type, TaskParaGraphLaunch graphLaunch)
     336              :         : type(type), profilerType(ProfilerType::TASK_ALL), stream(nullptr), isMainStream(false), beginTime(0),
     337              :           isFftsDispatcher(false), graphLaunch(graphLaunch)
     338              :     {}
     339              : 
     340            0 :     TaskPara(TaskType type, AiCPUStreamTasks streamTasks)
     341            0 :         : type(type), profilerType(ProfilerType::TASK_ALL), stream(nullptr), isMainStream(false), beginTime(0),
     342            0 :           isFftsDispatcher(false), streamTasks(streamTasks)
     343            0 :     {}
     344              : 
     345            0 :     TaskPara(TaskType type, FlipTaskPara flipTask)
     346            0 :         : type(type), profilerType(ProfilerType::TASK_ALL), stream(nullptr), isMainStream(false), beginTime(0),
     347            0 :           isFftsDispatcher(false), flipTask(flipTask)
     348            0 :     {}
     349              : 
     350           47 :     ~TaskPara() {}
     351              : };
     352              : 
     353              : } // namespace hccl
     354              : 
     355              : #endif /* DISPATCHER_TASK_TYPES_H */
        

Generated by: LCOV version 2.0-1