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: 88.0 % 100 88
Test Date: 2026-07-28 12:11:00 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         6346 : MAKE_ENUM(MemcpyKind, D2D, H2D, D2H, H2H, ADDR_D2D)
      30              : 
      31          355 : MAKE_ENUM(TaskType, LOCAL_RECORD, REMOTE_RECORD, WAIT, WAIT_VALUE, POST_BITS, WAIT_BITS, POST_VALUE, LOCAL_COPY, LOCAL_REDUCE, P2P_MEMCPY,
      32              :           SDMA_REDUCE, RDMA_SEND, UB_SEND, LOCAL_ADDR_COPY, UB_DIRECT_SEND, WRITE_VALUE // 二级指针拷贝
      33              : )
      34              : 
      35              : const std::map<MemcpyKind, rtMemcpyKind_t> MEMCPY_KIND_RT_MAP
      36              :     = {{MemcpyKind::D2D, RT_MEMCPY_DEVICE_TO_DEVICE},
      37              :        {MemcpyKind::H2D, RT_MEMCPY_HOST_TO_DEVICE},
      38              :        {MemcpyKind::D2H, RT_MEMCPY_DEVICE_TO_HOST},
      39              :        {MemcpyKind::H2H, RT_MEMCPY_HOST_TO_HOST},
      40              :        {MemcpyKind::ADDR_D2D, RT_MEMCPY_ADDR_DEVICE_TO_DEVICE}};
      41              : 
      42              : inline rtMemcpyKind_t RtMemcpyKindGet(MemcpyKind kind)
      43              : {
      44              :     return MEMCPY_KIND_RT_MAP.at(kind);
      45              : }
      46              : 
      47              : const std::map<DataType, aclDataType> DATA_TYPE_RT_MAP = {
      48              :     {DataType::INT8, ACL_INT8},   {DataType::INT16, ACL_INT16},
      49              :     {DataType::INT32, ACL_INT32}, {DataType::FP16, ACL_FLOAT16},
      50              :     {DataType::FP32, ACL_FLOAT},   {DataType::INT64, ACL_DT_UNDEFINED}, // does not support now
      51              :     {DataType::UINT64, ACL_DT_UNDEFINED},                                       // does not support now
      52              :     {DataType::UINT8, ACL_DT_UNDEFINED},                                        // does not support now
      53              :     {DataType::UINT16, ACL_DT_UNDEFINED},                                       // does not support now
      54              :     {DataType::UINT32, ACL_DT_UNDEFINED},                                       // does not support now
      55              :     {DataType::FP64, ACL_DT_UNDEFINED},                                         // does not support now
      56              :     {DataType::BFP16, ACL_BF16}, {DataType::INT128, ACL_DT_UNDEFINED} // does not support now
      57              : };
      58              : 
      59            1 : inline aclDataType RtDataTypeGet(DataType type)
      60              : {
      61            1 :     return DATA_TYPE_RT_MAP.at(type);
      62              : }
      63              : 
      64              : const std::map<ReduceOp, aclrtReduceKind> REDUCE_OP_RT_MAP
      65              :     = {{ReduceOp::SUM, ACL_RT_MEMCPY_SDMA_AUTOMATIC_SUM},
      66              :        {ReduceOp::MAX, ACL_RT_MEMCPY_SDMA_AUTOMATIC_MAX},
      67              :        {ReduceOp::MIN, ACL_RT_MEMCPY_SDMA_AUTOMATIC_MIN}};
      68              : 
      69            1 : inline aclrtReduceKind RtReduceOpGet(ReduceOp reduceOp)
      70              : {
      71            1 :     return REDUCE_OP_RT_MAP.at(reduceOp);
      72              : }
      73              : 
      74              : class BaseTask {
      75              : public:
      76           66 :     explicit BaseTask(TaskType type) : type(type), taskId(0), streamId(0){};
      77           74 :     virtual ~BaseTask()                  = default;
      78              :     virtual std::string Describe() const = 0;
      79              : 
      80           26 :     const TaskType &GetType() const
      81              :     {
      82           26 :         return type;
      83              :     }
      84              : 
      85              :     void SetTaskId(u32 id)
      86              :     {
      87              :         taskId = id;
      88              :     }
      89              : 
      90              :     void SetStreamId(u32 id)
      91              :     {
      92              :         streamId = id;
      93              :     }
      94              : 
      95              :     inline u32 GetStreamId() const
      96              :     {
      97              :         return streamId;
      98              :     }
      99              : 
     100              :     inline u32 GetTaskId() const
     101              :     {
     102              :         return taskId;
     103              :     }
     104              : 
     105              : protected:
     106              :     TaskType type;
     107              :     u32      taskId;
     108              :     u32      streamId;
     109              : };
     110              : 
     111              : class TaskLocalCopy : public BaseTask {
     112              : public:
     113            2 :     TaskLocalCopy(u64 dstAddr, u64 srcAddr, u64 size, MemcpyKind kind)
     114            2 :         : BaseTask(TaskType::LOCAL_COPY), dstAddr(dstAddr), srcAddr(srcAddr), kind(kind), size(size)
     115              :     {
     116            2 :     }
     117              :     std::string Describe() const override;
     118              : 
     119              :     inline u64 GetDstAddr() const
     120              :     {
     121              :         return dstAddr;
     122              :     }
     123              : 
     124              :     inline u64 GetSrcAddr() const
     125              :     {
     126              :         return srcAddr;
     127              :     }
     128              : 
     129              :     inline const MemcpyKind &GetKind() const
     130              :     {
     131              :         return kind;
     132              :     }
     133              : 
     134              :     inline u64 GetSize() const
     135              :     {
     136              :         return size;
     137              :     }
     138              : 
     139              : private:
     140              :     u64        dstAddr;
     141              :     u64        srcAddr;
     142              :     MemcpyKind kind;
     143              :     u64        size;
     144              : };
     145              : 
     146              : class TaskP2pMemcpy : public BaseTask {
     147              : public:
     148            6 :     TaskP2pMemcpy(u64 dstAddr, u64 srcAddr, u64 size, MemcpyKind kind)
     149            6 :         : BaseTask(TaskType::P2P_MEMCPY), dstAddr(dstAddr), srcAddr(srcAddr), kind(kind), size(size)
     150              :     {
     151            6 :     }
     152              :     std::string Describe() const override;
     153              : 
     154            4 :     u64 GetDstAddr() const
     155              :     {
     156            4 :         return dstAddr;
     157              :     }
     158            4 :     u64 GetSrcAddr() const
     159              :     {
     160            4 :         return srcAddr;
     161              :     }
     162              : 
     163            4 :     inline const MemcpyKind &GetKind() const
     164              :     {
     165            4 :         return kind;
     166              :     }
     167              : 
     168            4 :     inline u64 GetSize() const
     169              :     {
     170            4 :         return size;
     171              :     }
     172              : 
     173              : private:
     174              :     u64        dstAddr;
     175              :     u64        srcAddr;
     176              :     MemcpyKind kind;
     177              :     u64        size;
     178              : };
     179              : 
     180              : class TaskRemoteRecord : public BaseTask {
     181              : public:
     182            2 :     explicit TaskRemoteRecord(IpcRemoteNotify *notify) : BaseTask(TaskType::REMOTE_RECORD), notify(notify)
     183              :     {
     184            2 :     }
     185              :     std::string Describe() const override;
     186              : 
     187              :     inline const IpcRemoteNotify *GetNotify() const
     188              :     {
     189              :         return notify;
     190              :     }
     191              : 
     192              : private:
     193              :     IpcRemoteNotify *notify;
     194              : };
     195              : 
     196              : class TaskWait : public BaseTask {
     197              : public:
     198            2 :     explicit TaskWait(BaseLocalNotify *notify) : BaseTask(TaskType::WAIT), notify(notify)
     199              :     {
     200            2 :     }
     201              :     std::string                   Describe() const override;
     202              :     inline const BaseLocalNotify *GetNotify() const
     203              :     {
     204              :         return notify;
     205              :     }
     206              : 
     207              : private:
     208              :     BaseLocalNotify *notify;
     209              : };
     210              : 
     211              : class TaskWaitValue : public BaseTask {
     212              : public:
     213            0 :     explicit TaskWaitValue(RtsCntNotify *notify, u32 value)
     214            0 :         : BaseTask(TaskType::WAIT_VALUE), notify(notify), value(value)
     215              :     {
     216            0 :     }
     217              :     std::string                Describe() const override;
     218              :     inline const RtsCntNotify *GetNotify() const
     219              :     {
     220              :         return notify;
     221              :     }
     222              :     u32 GetValue() const
     223              :     {
     224              :         return value;
     225              :     }
     226              : 
     227              : private:
     228              :     RtsCntNotify *notify;
     229              :     u32           value;
     230              : };
     231              : 
     232              : class TaskPostBits : public BaseTask {
     233              : public:
     234            0 :     explicit TaskPostBits(RtsCntNotify *notify, u32 bitValue)
     235            0 :         : BaseTask(TaskType::POST_BITS), notify(notify), bitValue(bitValue)
     236              :     {
     237            0 :     }
     238              : 
     239              :     std::string Describe() const override;
     240              : 
     241              :     inline const RtsCntNotify *GetNotify() const
     242              :     {
     243              :         return notify;
     244              :     }
     245              :     u32 GetValue() const
     246              :     {
     247              :         return bitValue;
     248              :     }
     249              : 
     250              : private:
     251              :     RtsCntNotify *notify;
     252              :     u32           bitValue;
     253              : };
     254              : 
     255              : class TaskLocalRecord : public BaseTask {
     256              : public:
     257            2 :     explicit TaskLocalRecord(BaseLocalNotify *notify) : BaseTask(TaskType::LOCAL_RECORD), notify(notify)
     258              :     {
     259            2 :     }
     260              : 
     261              :     std::string Describe() const override;
     262              : 
     263              :     inline const BaseLocalNotify *GetNotify() const
     264              :     {
     265              :         return notify;
     266              :     }
     267              : 
     268              : private:
     269              :     BaseLocalNotify *notify;
     270              : };
     271              : 
     272              : class TaskSdmaReduce : public BaseTask {
     273              : public:
     274            6 :     TaskSdmaReduce(u64 dstAddr, u64 srcAddr, u64 size, DataType dataType, ReduceOp reduceOp)
     275           12 :         : BaseTask(TaskType::SDMA_REDUCE), dstAddr(dstAddr), srcAddr(srcAddr), size(size), dataType(dataType),
     276            6 :           reduceOp(reduceOp)
     277              :     {
     278            6 :     }
     279              :     std::string Describe() const override;
     280              : 
     281            4 :     u64 GetDstAddr() const
     282              :     {
     283            4 :         return dstAddr;
     284              :     }
     285            4 :     u64 GetSrcAddr() const
     286              :     {
     287            4 :         return srcAddr;
     288              :     }
     289              : 
     290            4 :     inline u64 GetSize() const
     291              :     {
     292            4 :         return size;
     293              :     }
     294              : 
     295              :     inline u64 GetDataCount() const
     296              :     {
     297              :         return size / DataTypeSizeGet(dataType);
     298              :     };
     299              : 
     300            4 :     inline const DataType &GetDataType() const
     301              :     {
     302            4 :         return dataType;
     303              :     }
     304              : 
     305            4 :     inline const ReduceOp &GetReduceOp() const
     306              :     {
     307            4 :         return reduceOp;
     308              :     }
     309              : 
     310              : private:
     311              :     u64      dstAddr;
     312              :     u64      srcAddr;
     313              :     u64      size;
     314              :     DataType dataType;
     315              :     ReduceOp reduceOp;
     316              : };
     317              : 
     318              : class TaskLocalReduce : public BaseTask {
     319              : public:
     320            2 :     TaskLocalReduce(u64 srcAddr1, u64 srcAddr2, u64 dstAddr, u64 size, DataType dataType, ReduceOp reduceOp)
     321            4 :         : BaseTask(TaskType::LOCAL_REDUCE), srcAddr1(srcAddr1), srcAddr2(srcAddr2), dstAddr(dstAddr), size(size),
     322            2 :           dataType(dataType), reduceOp(reduceOp)
     323              :     {
     324            2 :     }
     325              :     std::string Describe() const override;
     326              : 
     327              :     u64 GetSrcAddr1() const
     328              :     {
     329              :         return srcAddr1;
     330              :     }
     331              :     u64 GetSrcAddr2() const
     332              :     {
     333              :         return srcAddr2;
     334              :     }
     335              :     u64 GetDstAddr() const
     336              :     {
     337              :         return dstAddr;
     338              :     }
     339              : 
     340            1 :     inline u64 GetDataCount() const
     341              :     {
     342            1 :         return size / DataTypeSizeGet(dataType);
     343              :     };
     344              : 
     345              :     inline const DataType &GetDataType() const
     346              :     {
     347              :         return dataType;
     348              :     }
     349              : 
     350              :     inline const ReduceOp &GetReduceOp() const
     351              :     {
     352              :         return reduceOp;
     353              :     }
     354              : 
     355              : private:
     356              :     u64      srcAddr1;
     357              :     u64      srcAddr2;
     358              :     u64      dstAddr;
     359              :     u64      size;
     360              :     DataType dataType;
     361              :     ReduceOp reduceOp;
     362              : };
     363              : 
     364              : class TaskRdmaSend : public BaseTask {
     365              : public:
     366            5 :     TaskRdmaSend(u32 dbIndex, u64 dbInfo)
     367            5 :         : BaseTask(TaskType::RDMA_SEND), dbIndex(dbIndex), dbInfo(dbInfo), isTemplateMode(false)
     368              :     {
     369            5 :     }
     370            2 :     TaskRdmaSend(u32 qpn, u32 wqeIndex)
     371            2 :         : BaseTask(TaskType::RDMA_SEND), qpn(qpn), wqeIndex(wqeIndex), isTemplateMode(true)
     372              :     {
     373            2 :     }
     374              :     std::string Describe() const override;
     375              :     inline u32  GetQpn() const
     376              :     {
     377              :         return qpn;
     378              :     }
     379              : 
     380              :     inline u32 GetWqeIndex() const
     381              :     {
     382              :         return wqeIndex;
     383              :     }
     384              : 
     385              :     inline u32 GetDbIndex() const
     386              :     {
     387              :         return dbIndex;
     388              :     }
     389              : 
     390              :     inline u64 GetDbInfo() const
     391              :     {
     392              :         return dbInfo;
     393              :     }
     394              : 
     395            2 :     inline bool IsTemplateMode() const
     396              :     {
     397            2 :         return isTemplateMode;
     398              :     }
     399              : 
     400              : private:
     401              :     u32  qpn{0};      // 910A offload
     402              :     u32  wqeIndex{0}; // 910A offload
     403              :     u32  dbIndex;  // 910A2/A3 opbase/offload, 910A opbase
     404              :     u64  dbInfo;   // 910A2/A3 opbase/offload, 910A opbase
     405              :     bool isTemplateMode;
     406              : };
     407              : 
     408              : class TaskUbDbSend : public BaseTask {
     409              : public:
     410           16 :     TaskUbDbSend(u32 jettyId, u32 funcId, u32 piVal, u32 dieId)
     411           16 :         : BaseTask(TaskType::UB_SEND), jettyId(jettyId), funcId(funcId), piVal(piVal), dieId(dieId)
     412              :     {
     413           16 :     }
     414              :     std::string Describe() const override;
     415            5 :     inline u32  GetJettyId() const
     416              :     {
     417            5 :         return jettyId;
     418              :     }
     419              : 
     420            5 :     inline u32 GetFuncId() const
     421              :     {
     422            5 :         return funcId;
     423              :     }
     424              : 
     425            5 :     inline u32 GetPiVal() const
     426              :     {
     427            5 :         return piVal;
     428              :     }
     429              : 
     430            5 :     inline u32 GetDieId() const
     431              :     {
     432            5 :         return dieId;
     433              :     }
     434              : 
     435              : private:
     436              :     u32 jettyId;
     437              :     u32 funcId;
     438              :     u32 piVal;
     439              :     u32 dieId;
     440              : };
     441              : 
     442              : class TaskLocalAddrCopy : public BaseTask {
     443              : public:
     444            2 :     TaskLocalAddrCopy(u64 dstAddr, u64 srcAddr, u64 size)
     445            2 :         : BaseTask(TaskType::LOCAL_ADDR_COPY), dstAddr(dstAddr), srcAddr(srcAddr), size(size)
     446              :     {
     447            2 :     }
     448              :     std::string Describe() const override;
     449              : 
     450              :     u64 GetDstAddr() const
     451              :     {
     452              :         return dstAddr;
     453              :     }
     454              :     u64 GetSrcAddr() const
     455              :     {
     456              :         return srcAddr;
     457              :     }
     458              : 
     459              :     inline u64 GetSize() const
     460              :     {
     461              :         return size;
     462              :     }
     463              : 
     464              : private:
     465              :     u64 dstAddr;
     466              :     u64 srcAddr;
     467              :     u64 size;
     468              : };
     469              : 
     470              : constexpr u32 DWQE_MAX_LEN = 128;
     471              : 
     472              : class TaskUbDirectSend : public BaseTask {
     473              : public:
     474              :     TaskUbDirectSend(u32 funcId, u32 dieId, u32 jettyId, u32 dwqeSize, const u8 *dwqe);
     475              : 
     476              :     std::string Describe() const override;
     477              : 
     478            1 :     u32 GetJettyId() const
     479              :     {
     480            1 :         return jettyId;
     481              :     }
     482              : 
     483            1 :     u32 GetFuncId() const
     484              :     {
     485            1 :         return funcId;
     486              :     }
     487              : 
     488            1 :     u32 GetDieId() const
     489              :     {
     490            1 :         return dieId;
     491              :     }
     492              : 
     493            2 :     u32 GetDwqeSize() const
     494              :     {
     495            2 :         return dwqeSize;
     496              :     }
     497              : 
     498            1 :     const u8 *GetDwqePtr() const
     499              :     {
     500            1 :         return dwqe;
     501              :     }
     502              : 
     503              : private:
     504              :     u32 funcId;
     505              :     u32 dieId;
     506              :     u32 jettyId;
     507              :     u32 dwqeSize{0};
     508              :     u8  dwqe[DWQE_MAX_LEN]{0};
     509              : };
     510              : 
     511              : class TaskWriteValue : public BaseTask {
     512              : public:
     513            8 :     TaskWriteValue(u64 dbAddr, u32 piVal) : BaseTask(TaskType::WRITE_VALUE), dbAddr(dbAddr), piVal(piVal)
     514              :     {
     515            8 :     }
     516              : 
     517              :     std::string Describe() const override;
     518              : 
     519            5 :     u64 GetDbAddr() const
     520              :     {
     521            5 :         return dbAddr;
     522              :     }
     523              : 
     524            5 :     u32 GetPiVal() const
     525              :     {
     526            5 :         return piVal;
     527              :     }
     528              : 
     529              : private:
     530              :     u64 dbAddr;
     531              :     u32 piVal;
     532              : };
     533              : 
     534              : class TaskPostValue : public BaseTask {
     535              : public:
     536            0 :     explicit TaskPostValue(Rts1ToNCntNotify *notify, u32 value)
     537            0 :         : BaseTask(TaskType::POST_VALUE), notify(notify), value(value)
     538              :     {
     539            0 :     }
     540              : 
     541              :     std::string Describe() const override;
     542              : 
     543              :     inline const Rts1ToNCntNotify *GetNotify() const
     544              :     {
     545              :         return notify;
     546              :     }
     547              :     u32 GetValue() const
     548              :     {
     549              :         return value;
     550              :     }
     551              : 
     552              : private:
     553              :     Rts1ToNCntNotify *notify;
     554              :     u32               value;
     555              : };
     556              : 
     557              : class TaskWaitBits : public BaseTask {
     558              : public:
     559            0 :     explicit TaskWaitBits(Rts1ToNCntNotify *notify, u32 bitValue)
     560            0 :         : BaseTask(TaskType::WAIT_BITS), notify(notify), bitValue(bitValue)
     561              :     {
     562            0 :     }
     563              :     std::string                    Describe() const override;
     564              :     inline const Rts1ToNCntNotify *GetNotify() const
     565              :     {
     566              :         return notify;
     567              :     }
     568              :     u32 GetValue() const
     569              :     {
     570              :         return bitValue;
     571              :     }
     572              : 
     573              : private:
     574              :     Rts1ToNCntNotify *notify;
     575              :     u32               bitValue;
     576              : };
     577              : 
     578              : } // namespace Hccl
     579              : 
     580              : #endif
        

Generated by: LCOV version 2.0-1