LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/task - task.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 81.7 % 109 89
Test Date: 2026-08-18 17:47:01 Functions: 87.5 % 56 49

            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 HCCLV2_TASK_H
      12              : #define HCCLV2_TASK_H
      13              : 
      14              : #include <map>
      15              : #include <string>
      16              : #include "data_type.h"
      17              : #include "reduce_op.h"
      18              : #include "orion_adapter_rts.h"
      19              : #include "rts_cnt_notify.h"
      20              : #include "rts_1ton_cnt_notify.h"
      21              : #include "ipc_local_notify.h"
      22              : #include "ipc_remote_notify.h"
      23              : 
      24              : namespace Hccl {
      25              : using namespace std;
      26              : class BaseLocalNotify;
      27              : class IpcRemoteNotify;
      28              : 
      29         7890 : MAKE_ENUM(MemcpyKind, D2D, H2D, D2H, H2H, ADDR_D2D)
      30              : 
      31          355 : MAKE_ENUM(
      32              :     TaskType, LOCAL_RECORD, REMOTE_RECORD, WAIT, WAIT_VALUE, POST_BITS, WAIT_BITS, POST_VALUE, LOCAL_COPY, LOCAL_REDUCE,
      33              :     P2P_MEMCPY, SDMA_REDUCE, RDMA_SEND, UB_SEND, LOCAL_ADDR_COPY, UB_DIRECT_SEND, WRITE_VALUE // 二级指针拷贝
      34              : )
      35              : 
      36              : const std::map<MemcpyKind, rtMemcpyKind_t> MEMCPY_KIND_RT_MAP
      37              :     = {{MemcpyKind::D2D, RT_MEMCPY_DEVICE_TO_DEVICE},
      38              :        {MemcpyKind::H2D, RT_MEMCPY_HOST_TO_DEVICE},
      39              :        {MemcpyKind::D2H, RT_MEMCPY_DEVICE_TO_HOST},
      40              :        {MemcpyKind::H2H, RT_MEMCPY_HOST_TO_HOST},
      41              :        {MemcpyKind::ADDR_D2D, RT_MEMCPY_ADDR_DEVICE_TO_DEVICE}};
      42              : 
      43              : inline rtMemcpyKind_t RtMemcpyKindGet(MemcpyKind kind) { return MEMCPY_KIND_RT_MAP.at(kind); }
      44              : 
      45              : const std::map<DataType, aclDataType> DATA_TYPE_RT_MAP = {
      46              :     {DataType::INT8, ACL_INT8},           {DataType::INT16, ACL_INT16},
      47              :     {DataType::INT32, ACL_INT32},         {DataType::FP16, ACL_FLOAT16},
      48              :     {DataType::FP32, ACL_FLOAT},          {DataType::INT64, ACL_DT_UNDEFINED}, // does not support now
      49              :     {DataType::UINT64, ACL_DT_UNDEFINED},                                      // does not support now
      50              :     {DataType::UINT8, ACL_DT_UNDEFINED},                                       // does not support now
      51              :     {DataType::UINT16, ACL_DT_UNDEFINED},                                      // does not support now
      52              :     {DataType::UINT32, ACL_DT_UNDEFINED},                                      // does not support now
      53              :     {DataType::FP64, ACL_DT_UNDEFINED},                                        // does not support now
      54              :     {DataType::BFP16, ACL_BF16},          {DataType::INT128, ACL_DT_UNDEFINED} // does not support now
      55              : };
      56              : 
      57            1 : inline aclDataType RtDataTypeGet(DataType type) { return DATA_TYPE_RT_MAP.at(type); }
      58              : 
      59              : const std::map<ReduceOp, aclrtReduceKind> REDUCE_OP_RT_MAP
      60              :     = {{ReduceOp::SUM, ACL_RT_MEMCPY_SDMA_AUTOMATIC_SUM},
      61              :        {ReduceOp::MAX, ACL_RT_MEMCPY_SDMA_AUTOMATIC_MAX},
      62              :        {ReduceOp::MIN, ACL_RT_MEMCPY_SDMA_AUTOMATIC_MIN}};
      63              : 
      64            1 : inline aclrtReduceKind RtReduceOpGet(ReduceOp reduceOp) { return REDUCE_OP_RT_MAP.at(reduceOp); }
      65              : 
      66              : class BaseTask {
      67              : public:
      68           66 :     explicit BaseTask(TaskType type) : type(type), taskId(0), streamId(0) {};
      69           74 :     virtual ~BaseTask() = default;
      70              :     virtual std::string Describe() const = 0;
      71              : 
      72           26 :     const TaskType& GetType() const { return type; }
      73              : 
      74              :     void SetTaskId(u32 id) { taskId = id; }
      75              : 
      76              :     void SetStreamId(u32 id) { streamId = id; }
      77              : 
      78              :     inline u32 GetStreamId() const { return streamId; }
      79              : 
      80              :     inline u32 GetTaskId() const { return taskId; }
      81              : 
      82              : protected:
      83              :     TaskType type;
      84              :     u32 taskId;
      85              :     u32 streamId;
      86              : };
      87              : 
      88              : class TaskLocalCopy : public BaseTask {
      89              : public:
      90            2 :     TaskLocalCopy(u64 dstAddr, u64 srcAddr, u64 size, MemcpyKind kind)
      91            2 :         : BaseTask(TaskType::LOCAL_COPY),
      92            2 :           dstAddr(dstAddr),
      93            2 :           srcAddr(srcAddr),
      94            2 :           kind(kind),
      95            2 :           size(size)
      96            2 :     {}
      97              :     std::string Describe() const override;
      98              : 
      99              :     inline u64 GetDstAddr() const { return dstAddr; }
     100              : 
     101              :     inline u64 GetSrcAddr() const { return srcAddr; }
     102              : 
     103              :     inline const MemcpyKind& GetKind() const { return kind; }
     104              : 
     105              :     inline u64 GetSize() const { return size; }
     106              : 
     107              : private:
     108              :     u64 dstAddr;
     109              :     u64 srcAddr;
     110              :     MemcpyKind kind;
     111              :     u64 size;
     112              : };
     113              : 
     114              : class TaskP2pMemcpy : public BaseTask {
     115              : public:
     116            6 :     TaskP2pMemcpy(u64 dstAddr, u64 srcAddr, u64 size, MemcpyKind kind)
     117            6 :         : BaseTask(TaskType::P2P_MEMCPY),
     118            6 :           dstAddr(dstAddr),
     119            6 :           srcAddr(srcAddr),
     120            6 :           kind(kind),
     121            6 :           size(size)
     122            6 :     {}
     123              :     std::string Describe() const override;
     124              : 
     125            4 :     u64 GetDstAddr() const { return dstAddr; }
     126            4 :     u64 GetSrcAddr() const { return srcAddr; }
     127              : 
     128            4 :     inline const MemcpyKind& GetKind() const { return kind; }
     129              : 
     130            4 :     inline u64 GetSize() const { return size; }
     131              : 
     132              : private:
     133              :     u64 dstAddr;
     134              :     u64 srcAddr;
     135              :     MemcpyKind kind;
     136              :     u64 size;
     137              : };
     138              : 
     139              : class TaskRemoteRecord : public BaseTask {
     140              : public:
     141            2 :     explicit TaskRemoteRecord(IpcRemoteNotify* notify) : BaseTask(TaskType::REMOTE_RECORD), notify(notify) {}
     142              :     std::string Describe() const override;
     143              : 
     144              :     inline const IpcRemoteNotify* GetNotify() const { return notify; }
     145              : 
     146              : private:
     147              :     IpcRemoteNotify* notify;
     148              : };
     149              : 
     150              : class TaskWait : public BaseTask {
     151              : public:
     152            2 :     explicit TaskWait(BaseLocalNotify* notify) : BaseTask(TaskType::WAIT), notify(notify) {}
     153              :     std::string Describe() const override;
     154              :     inline const BaseLocalNotify* GetNotify() const { return notify; }
     155              : 
     156              : private:
     157              :     BaseLocalNotify* notify;
     158              : };
     159              : 
     160              : class TaskWaitValue : public BaseTask {
     161              : public:
     162            0 :     explicit TaskWaitValue(RtsCntNotify* notify, u32 value)
     163            0 :         : BaseTask(TaskType::WAIT_VALUE),
     164            0 :           notify(notify),
     165            0 :           value(value)
     166            0 :     {}
     167              :     std::string Describe() const override;
     168              :     inline const RtsCntNotify* GetNotify() const { return notify; }
     169              :     u32 GetValue() const { return value; }
     170              : 
     171              : private:
     172              :     RtsCntNotify* notify;
     173              :     u32 value;
     174              : };
     175              : 
     176              : class TaskPostBits : public BaseTask {
     177              : public:
     178            0 :     explicit TaskPostBits(RtsCntNotify* notify, u32 bitValue)
     179            0 :         : BaseTask(TaskType::POST_BITS),
     180            0 :           notify(notify),
     181            0 :           bitValue(bitValue)
     182            0 :     {}
     183              : 
     184              :     std::string Describe() const override;
     185              : 
     186              :     inline const RtsCntNotify* GetNotify() const { return notify; }
     187              :     u32 GetValue() const { return bitValue; }
     188              : 
     189              : private:
     190              :     RtsCntNotify* notify;
     191              :     u32 bitValue;
     192              : };
     193              : 
     194              : class TaskLocalRecord : public BaseTask {
     195              : public:
     196            2 :     explicit TaskLocalRecord(BaseLocalNotify* notify) : BaseTask(TaskType::LOCAL_RECORD), notify(notify) {}
     197              : 
     198              :     std::string Describe() const override;
     199              : 
     200              :     inline const BaseLocalNotify* GetNotify() const { return notify; }
     201              : 
     202              : private:
     203              :     BaseLocalNotify* notify;
     204              : };
     205              : 
     206              : class TaskSdmaReduce : public BaseTask {
     207              : public:
     208            6 :     TaskSdmaReduce(u64 dstAddr, u64 srcAddr, u64 size, DataType dataType, ReduceOp reduceOp)
     209            6 :         : BaseTask(TaskType::SDMA_REDUCE),
     210            6 :           dstAddr(dstAddr),
     211            6 :           srcAddr(srcAddr),
     212            6 :           size(size),
     213            6 :           dataType(dataType),
     214            6 :           reduceOp(reduceOp)
     215            6 :     {}
     216              :     std::string Describe() const override;
     217              : 
     218            4 :     u64 GetDstAddr() const { return dstAddr; }
     219            4 :     u64 GetSrcAddr() const { return srcAddr; }
     220              : 
     221            4 :     inline u64 GetSize() const { return size; }
     222              : 
     223              :     inline u64 GetDataCount() const { return size / DataTypeSizeGet(dataType); };
     224              : 
     225            4 :     inline const DataType& GetDataType() const { return dataType; }
     226              : 
     227            4 :     inline const ReduceOp& GetReduceOp() const { return reduceOp; }
     228              : 
     229              : private:
     230              :     u64 dstAddr;
     231              :     u64 srcAddr;
     232              :     u64 size;
     233              :     DataType dataType;
     234              :     ReduceOp reduceOp;
     235              : };
     236              : 
     237              : class TaskLocalReduce : public BaseTask {
     238              : public:
     239            2 :     TaskLocalReduce(u64 srcAddr1, u64 srcAddr2, u64 dstAddr, u64 size, DataType dataType, ReduceOp reduceOp)
     240            2 :         : BaseTask(TaskType::LOCAL_REDUCE),
     241            2 :           srcAddr1(srcAddr1),
     242            2 :           srcAddr2(srcAddr2),
     243            2 :           dstAddr(dstAddr),
     244            2 :           size(size),
     245            2 :           dataType(dataType),
     246            2 :           reduceOp(reduceOp)
     247            2 :     {}
     248              :     std::string Describe() const override;
     249              : 
     250              :     u64 GetSrcAddr1() const { return srcAddr1; }
     251              :     u64 GetSrcAddr2() const { return srcAddr2; }
     252              :     u64 GetDstAddr() const { return dstAddr; }
     253              : 
     254            1 :     inline u64 GetDataCount() const { return size / DataTypeSizeGet(dataType); };
     255              : 
     256              :     inline const DataType& GetDataType() const { return dataType; }
     257              : 
     258              :     inline const ReduceOp& GetReduceOp() const { return reduceOp; }
     259              : 
     260              : private:
     261              :     u64 srcAddr1;
     262              :     u64 srcAddr2;
     263              :     u64 dstAddr;
     264              :     u64 size;
     265              :     DataType dataType;
     266              :     ReduceOp reduceOp;
     267              : };
     268              : 
     269              : class TaskRdmaSend : public BaseTask {
     270              : public:
     271            5 :     TaskRdmaSend(u32 dbIndex, u64 dbInfo)
     272            5 :         : BaseTask(TaskType::RDMA_SEND),
     273            5 :           dbIndex(dbIndex),
     274            5 :           dbInfo(dbInfo),
     275            5 :           isTemplateMode(false)
     276            5 :     {}
     277            2 :     TaskRdmaSend(u32 qpn, u32 wqeIndex)
     278            2 :         : BaseTask(TaskType::RDMA_SEND),
     279            2 :           qpn(qpn),
     280            2 :           wqeIndex(wqeIndex),
     281            2 :           isTemplateMode(true)
     282            2 :     {}
     283              :     std::string Describe() const override;
     284              :     inline u32 GetQpn() const { return qpn; }
     285              : 
     286              :     inline u32 GetWqeIndex() const { return wqeIndex; }
     287              : 
     288              :     inline u32 GetDbIndex() const { return dbIndex; }
     289              : 
     290              :     inline u64 GetDbInfo() const { return dbInfo; }
     291              : 
     292            2 :     inline bool IsTemplateMode() const { return isTemplateMode; }
     293              : 
     294              : private:
     295              :     u32 qpn{0};      // 910A offload
     296              :     u32 wqeIndex{0}; // 910A offload
     297              :     u32 dbIndex;     // 910A2/A3 opbase/offload, 910A opbase
     298              :     u64 dbInfo;      // 910A2/A3 opbase/offload, 910A opbase
     299              :     bool isTemplateMode;
     300              : };
     301              : 
     302              : class TaskUbDbSend : public BaseTask {
     303              : public:
     304           16 :     TaskUbDbSend(u32 jettyId, u32 funcId, u32 piVal, u32 dieId)
     305           16 :         : BaseTask(TaskType::UB_SEND),
     306           16 :           jettyId(jettyId),
     307           16 :           funcId(funcId),
     308           16 :           piVal(piVal),
     309           16 :           dieId(dieId)
     310           16 :     {}
     311              :     std::string Describe() const override;
     312            5 :     inline u32 GetJettyId() const { return jettyId; }
     313              : 
     314            5 :     inline u32 GetFuncId() const { return funcId; }
     315              : 
     316            5 :     inline u32 GetPiVal() const { return piVal; }
     317              : 
     318            5 :     inline u32 GetDieId() const { return dieId; }
     319              : 
     320              : private:
     321              :     u32 jettyId;
     322              :     u32 funcId;
     323              :     u32 piVal;
     324              :     u32 dieId;
     325              : };
     326              : 
     327              : class TaskLocalAddrCopy : public BaseTask {
     328              : public:
     329            2 :     TaskLocalAddrCopy(u64 dstAddr, u64 srcAddr, u64 size)
     330            2 :         : BaseTask(TaskType::LOCAL_ADDR_COPY),
     331            2 :           dstAddr(dstAddr),
     332            2 :           srcAddr(srcAddr),
     333            2 :           size(size)
     334            2 :     {}
     335              :     std::string Describe() const override;
     336              : 
     337              :     u64 GetDstAddr() const { return dstAddr; }
     338              :     u64 GetSrcAddr() const { return srcAddr; }
     339              : 
     340              :     inline u64 GetSize() const { return size; }
     341              : 
     342              : private:
     343              :     u64 dstAddr;
     344              :     u64 srcAddr;
     345              :     u64 size;
     346              : };
     347              : 
     348              : constexpr u32 DWQE_MAX_LEN = 128;
     349              : 
     350              : class TaskUbDirectSend : public BaseTask {
     351              : public:
     352              :     TaskUbDirectSend(u32 funcId, u32 dieId, u32 jettyId, u32 dwqeSize, const u8* dwqe);
     353              : 
     354              :     std::string Describe() const override;
     355              : 
     356            1 :     u32 GetJettyId() const { return jettyId; }
     357              : 
     358            1 :     u32 GetFuncId() const { return funcId; }
     359              : 
     360            1 :     u32 GetDieId() const { return dieId; }
     361              : 
     362            2 :     u32 GetDwqeSize() const { return dwqeSize; }
     363              : 
     364            1 :     const u8* GetDwqePtr() const { return dwqe; }
     365              : 
     366              : private:
     367              :     u32 funcId;
     368              :     u32 dieId;
     369              :     u32 jettyId;
     370              :     u32 dwqeSize{0};
     371              :     u8 dwqe[DWQE_MAX_LEN]{0};
     372              : };
     373              : 
     374              : class TaskWriteValue : public BaseTask {
     375              : public:
     376            8 :     TaskWriteValue(u64 dbAddr, u32 piVal) : BaseTask(TaskType::WRITE_VALUE), dbAddr(dbAddr), piVal(piVal) {}
     377              : 
     378              :     std::string Describe() const override;
     379              : 
     380            5 :     u64 GetDbAddr() const { return dbAddr; }
     381              : 
     382            5 :     u32 GetPiVal() const { return piVal; }
     383              : 
     384              : private:
     385              :     u64 dbAddr;
     386              :     u32 piVal;
     387              : };
     388              : 
     389              : class TaskPostValue : public BaseTask {
     390              : public:
     391            0 :     explicit TaskPostValue(Rts1ToNCntNotify* notify, u32 value)
     392            0 :         : BaseTask(TaskType::POST_VALUE),
     393            0 :           notify(notify),
     394            0 :           value(value)
     395            0 :     {}
     396              : 
     397              :     std::string Describe() const override;
     398              : 
     399              :     inline const Rts1ToNCntNotify* GetNotify() const { return notify; }
     400              :     u32 GetValue() const { return value; }
     401              : 
     402              : private:
     403              :     Rts1ToNCntNotify* notify;
     404              :     u32 value;
     405              : };
     406              : 
     407              : class TaskWaitBits : public BaseTask {
     408              : public:
     409            0 :     explicit TaskWaitBits(Rts1ToNCntNotify* notify, u32 bitValue)
     410            0 :         : BaseTask(TaskType::WAIT_BITS),
     411            0 :           notify(notify),
     412            0 :           bitValue(bitValue)
     413            0 :     {}
     414              :     std::string Describe() const override;
     415              :     inline const Rts1ToNCntNotify* GetNotify() const { return notify; }
     416              :     u32 GetValue() const { return bitValue; }
     417              : 
     418              : private:
     419              :     Rts1ToNCntNotify* notify;
     420              :     u32 bitValue;
     421              : };
     422              : 
     423              : } // namespace Hccl
     424              : 
     425              : #endif
        

Generated by: LCOV version 2.0-1