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 % 65 16
Test Date: 2026-07-28 12:11:00 Functions: 22.6 % 31 7

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

Generated by: LCOV version 2.0-1