LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/stream/aicpu - rtsq_base.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 24.6 % 61 15
Test Date: 2026-08-18 17:47:01 Functions: 25.7 % 35 9

            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_RTSQ_BASE_H
      12              : #define HCCLV2_RTSQ_BASE_H
      13              : #include <vector>
      14              : #include <functional>
      15              : #include "types.h"
      16              : #include "buffer.h"
      17              : #include "notify_lite.h"
      18              : #include "reduce_op.h"
      19              : #include "data_type.h"
      20              : #include "reduce_in.h"
      21              : #include "not_support_exception.h"
      22              : #include "ub_jetty_lite.h"
      23              : 
      24              : #include "ascend_hal.h"
      25              : namespace aicpu {
      26              : void __attribute__((weak)) __attribute__((visibility("default")))
      27              : GetSqeId(const uint32_t num, uint32_t& start, uint32_t& end);
      28              : }
      29              : 
      30              : namespace Hccl {
      31              : 
      32              : constexpr u32 RTSQ_FULL_TIMEOUT_DEFAULT = 1836 + 20;
      33              : constexpr u32 RTSQ_SQE_SIZE = 64;
      34              : constexpr u32 PER_LAUNCH_SQE_CNT = 128;
      35              : 
      36              : class RtsqBase {
      37              : public:
      38              :     RtsqBase(u32 devPhyId, u32 streamId, u32 sqId);
      39              : 
      40          600 :     virtual ~RtsqBase() = default;
      41              : 
      42              :     virtual void Reset();
      43              : 
      44           21 :     inline u32 GetStreamId() const { return streamId_; }
      45              : 
      46              :     inline u32 GetSqDepth() const { return sqDepth_; }
      47              : 
      48            2 :     inline u32 GetHead() const { return sqHead_; }
      49              : 
      50            2 :     inline u32 GetTail() const { return sqTail_; }
      51              : 
      52           68 :     inline u32 GetTaskId() const { return taskId_; }
      53              : 
      54            0 :     void SetOpExecStatusCallback(std::function<void()> callback) { checkOpExecStatusCallback_ = callback; }
      55              : 
      56              :     void
      57            2 :     SetCheckExecStatusCallback(std::function<HcclResult(bool)> callback) // 自定义算子流程注册检查执行状态的回调函数
      58              :     {
      59            2 :         checkExecStatusCallback_ = callback;
      60            2 :     }
      61              : 
      62            0 :     virtual void LaunchTask() { MACRO_THROW(NotSupportException, StringFormat("not supported.")); }
      63              : 
      64            0 :     virtual void TryLaunchTask() { MACRO_THROW(NotSupportException, StringFormat("not supported.")); }
      65              : 
      66            0 :     virtual void NotifyWait(u32 notifyId)
      67              :     {
      68              :         (void)notifyId;
      69            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
      70              :     }
      71              : 
      72            0 :     virtual void NotifyWait(u32 notifyId, u32 timeout)
      73              :     {
      74              :         (void)notifyId;
      75              :         (void)timeout;
      76            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
      77              :     }
      78              : 
      79            0 :     virtual void Cnt1toNNotifyWait(u32 notifyId, u32 value)
      80              :     {
      81              :         (void)notifyId;
      82              :         (void)value;
      83            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
      84              :     }
      85              : 
      86            0 :     virtual void Cnt1toNNotifyRecord(u32 notifyId, u32 value)
      87              :     {
      88              :         (void)notifyId;
      89              :         (void)value;
      90            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
      91              :     }
      92              : 
      93            0 :     virtual void CntNto1NotifyWait(u32 notifyId, u32 value)
      94              :     {
      95              :         (void)notifyId;
      96              :         (void)value;
      97            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
      98              :     }
      99              : 
     100            0 :     virtual void CntNto1NotifyRecord(u32 notifyId, u32 value)
     101              :     {
     102              :         (void)notifyId;
     103              :         (void)value;
     104            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     105              :     }
     106              : 
     107            0 :     virtual void NotifyRecordLoc(u32 notifyId)
     108              :     {
     109              :         (void)notifyId;
     110            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     111              :     }
     112              : 
     113            0 :     virtual void NotifyRecordRmt(u32 rmtDevPhyId, u32 notifyId) // 仅 P2P 使用
     114              :     {
     115              :         (void)rmtDevPhyId;
     116              :         (void)notifyId;
     117            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     118              :     }
     119              : 
     120            0 :     virtual void SdmaCopy(u64 srcAddr, u64 dstAddr, u32 size, u32 partId)
     121              :     {
     122              :         (void)srcAddr;
     123              :         (void)dstAddr;
     124              :         (void)size;
     125              :         (void)partId;
     126            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     127              :     }
     128              : 
     129            0 :     virtual void SdmaReduce(u64 srcAddr, u64 dstAddr, u32 size, u32 partId, const ReduceIn& reduceIn)
     130              :     {
     131              :         (void)srcAddr;
     132              :         (void)dstAddr;
     133              :         (void)size;
     134              :         (void)partId;
     135              :         (void)reduceIn;
     136            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     137              :     }
     138              : 
     139            0 :     virtual void P2PWriteValue(u64 remoteAddr, u32 writeValue)
     140              :     {
     141              :         (void)remoteAddr;
     142              :         (void)writeValue;
     143            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     144              :     }
     145              : 
     146            0 :     virtual void UbDbSend(const UbJettyLiteId& jettyLiteId, u16 piValue)
     147              :     {
     148              :         (void)jettyLiteId;
     149              :         (void)piValue;
     150            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     151              :     }
     152              : 
     153            0 :     virtual void RdmaDbSend(const uint64_t& dbAddr, const uint64_t& dbValue)
     154              :     {
     155              :         (void)dbAddr;
     156              :         (void)dbValue;
     157            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     158              :     }
     159              : 
     160            0 :     virtual void UbDirectSend(const UbJettyLiteId& jettyLiteId, u32 dwqeSize, const u8* wqe)
     161              :     {
     162              :         (void)jettyLiteId;
     163              :         (void)dwqeSize;
     164              :         (void)wqe;
     165            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     166              :     }
     167              : 
     168            0 :     virtual void UbWriteValue(u64 dbAddr, u32 piValue)
     169              :     {
     170              :         (void)dbAddr;
     171              :         (void)piValue;
     172            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     173              :     }
     174              : 
     175            0 :     virtual void CCoreNotifyWait(u64 waitAddr, u64 curTurnCntAddr, bool last)
     176              :     {
     177              :         (void)waitAddr;
     178              :         (void)curTurnCntAddr;
     179              :         (void)last;
     180            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     181              :     }
     182              : 
     183            0 :     virtual void CCoreNotifyRecord(u64 recordAddr, u64 curTurnCntAddr)
     184              :     {
     185              :         (void)recordAddr;
     186              :         (void)curTurnCntAddr;
     187            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     188              :     }
     189              : 
     190           15 :     virtual u64 GetSqeAddr() const { return 0; }
     191              : 
     192            0 :     virtual uint32_t GetPendingSqeCnt() const { return 0; }
     193              : 
     194              :     u32 QuerySqHead() const;
     195              :     u32 QuerySqTail() const;
     196              : 
     197            0 :     virtual bool IsRtsqQueueSpaceSufficient() { return true; }
     198              : 
     199            0 :     virtual HcclResult SetPreStreamSyncReady()
     200              :     {
     201            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     202              :         return HCCL_SUCCESS;
     203              :     }
     204              : 
     205            0 :     virtual HcclResult SetPreStreamSyncFin()
     206              :     {
     207            0 :         MACRO_THROW(NotSupportException, StringFormat("not supported."));
     208              :         return HCCL_SUCCESS;
     209              :     }
     210              : 
     211            0 :     virtual bool GetPreStreamSyncStatus() { return false; }
     212              : 
     213              :     HcclResult GetStreamIdAndTaskIdBySqIdx(u32 sqIdx, uint16_t& streamId, uint16_t& taskId) const;
     214              : 
     215            0 :     virtual HcclResult GetLastStreamIdAndTaskId(uint16_t& streamId, uint16_t& taskId) const
     216              :     {
     217              :         (void)streamId;
     218              :         (void)taskId;
     219            0 :         return HCCL_E_NOT_SUPPORT;
     220              :     }
     221              : 
     222              : protected:
     223              :     u32 devPhyId_{0};
     224              :     u32 localDevId_{0};
     225              :     u32 streamId_{0}; // 填写到SQE中的streamId
     226              :     u32 sqId_{0};
     227              : 
     228              :     u32 sqHead_{0};
     229              :     u32 sqTail_{0};
     230              :     u32 sqDepth_{0};
     231              :     u64 sqBaseAddr_{0};
     232              : 
     233              :     u32 taskId_{0};    // 填写到SQE中的taskId,现改为由AICPU组件提供的sqeId维护
     234              :     u32 taskIdEnd_{0}; // 当前流已经申请到的最大taskId
     235              : 
     236              :     std::function<void()> checkOpExecStatusCallback_{nullptr};
     237              :     std::function<HcclResult(bool)> checkExecStatusCallback_{nullptr}; // 自定义算子流程,检查执行状态
     238              : 
     239              :     u32 QuerySqDepth() const;
     240              : 
     241              :     std::string GetHwSqDescribe() const;
     242              : 
     243              :     void ConfigSqTail(u32 value);
     244              :     void ConfigDisableToEnable(u32 value);
     245              : 
     246          338 :     inline void SetTaskIdBySqeId()
     247              :     {
     248          338 :         taskId_++; // taskId_的范围是aicpu::GetSqeId返回的[start, end), taskId累加到end时重新向aicpu申请, 不会翻转
     249          338 :         if (UNLIKELY(taskId_ >= taskIdEnd_)) {                        // taskEnd_视为未申请的taskId,不可使用
     250          288 :             constexpr u32 PER_GET_SQE_ID_NUM = 1024;                  // 一次性申请sqeId数量
     251          288 :             aicpu::GetSqeId(PER_GET_SQE_ID_NUM, taskId_, taskIdEnd_); // aicpu框架保证 taskId_ < taskIdEnd_
     252              :         }
     253          338 :         return;
     254              :     }
     255              : 
     256              : private:
     257              :     u64 QuerySqBaseAddr() const;
     258              :     u32 QueryCqeStatus() const;
     259              : 
     260              :     u32 QuerySqStatusByType(drvSqCqPropType_t givenType) const;
     261              :     void ConfigSqStatusByType(drvSqCqPropType_t givenType, u32 value) const;
     262              : };
     263              : 
     264              : } // namespace Hccl
     265              : 
     266              : #endif
        

Generated by: LCOV version 2.0-1