LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/resource/stream/aicpu - sqe_build_a5.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 90.8 % 119 108
Test Date: 2026-08-04 10:52:23 Functions: 90.0 % 10 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              : #ifndef HCCLV2_SQE_BUILD_A5_H
      11              : #define HCCLV2_SQE_BUILD_A5_H
      12              : #include "types.h"
      13              : #include "ub_jetty_lite.h"
      14              : #include "sqe_v82.h"
      15              : #include "log.h"
      16              : 
      17              : namespace Hccl {
      18              : 
      19              : constexpr u32 LOW_BITS = 16;
      20              : 
      21              : u32 GetKernelExecTimeoutFromEnvConfig();
      22              : 
      23           25 : inline void SetSqeHeaderTaskFields(void* sqe, u32 taskId) 
      24              : {
      25           25 :     auto header = reinterpret_cast<Rt91095StarsSqeHeader*>(sqe);
      26           25 :     header->rtStreamId = static_cast<uint16_t>(taskId);
      27           25 :     header->taskId     = static_cast<uint16_t>(taskId >> LOW_BITS);
      28           25 : }
      29              : 
      30              : inline void BuildA5SqeNotifyWait(u32 streamId, u32 taskId, u32 notifyId, uint8_t * const sqeIn)
      31              : {
      32              :     (void) streamId;
      33              :     Rt91095StarsNotifySqe *sqe = (Rt91095StarsNotifySqe *)sqeIn;
      34              :     SetSqeHeaderTaskFields(sqe, taskId);
      35              : 
      36              :     sqe->header.type       = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_WAIT);
      37              :     sqe->header.wrCqe      = 0U;
      38              : 
      39              :     sqe->cntFlag           = false;
      40              :     sqe->clrFlag           = true;
      41              :     sqe->subType           = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_SINGLE_NOTIFY_WAIT);
      42              :     sqe->kernelCredit      = RT_STARS_NEVER_TIMEOUT_KERNEL_CREDIT; // wait任务需要设置为0xff,否则会触发rtsq的超时机制,即使record了也wait不到
      43              :     sqe->notifyId          = notifyId;
      44              :     sqe->timeout           = GetKernelExecTimeoutFromEnvConfig();
      45              : }
      46              : 
      47           10 : inline void BuildA5SqeNotifyWait(u32 streamId, u32 taskId, u32 notifyId, u32 timeout, uint8_t * const sqeIn)
      48              : {
      49              :     (void) streamId;
      50           10 :     Rt91095StarsNotifySqe *sqe = (Rt91095StarsNotifySqe *)sqeIn;
      51           10 :     SetSqeHeaderTaskFields(sqe, taskId);
      52              : 
      53           10 :     sqe->header.type       = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_WAIT);
      54           10 :     sqe->header.wrCqe      = 0U;
      55              : 
      56           10 :     sqe->kernelCredit      = RT_STARS_NEVER_TIMEOUT_KERNEL_CREDIT;
      57           10 :     sqe->cntFlag           = false;
      58           10 :     sqe->clrFlag           = true;
      59           10 :     sqe->subType           = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_SINGLE_NOTIFY_WAIT);
      60           10 :     sqe->notifyId          = notifyId;
      61           10 :     sqe->timeout           = timeout;
      62           10 : }
      63              : 
      64            1 : inline void BuildA5SqeNotifyRecord(u32 streamId, u32 taskId, u32 notifyId, uint8_t * const sqeIn)
      65              : {
      66              :     (void) streamId;
      67            1 :     Rt91095StarsNotifySqe *sqe = (Rt91095StarsNotifySqe *)sqeIn;
      68            1 :     SetSqeHeaderTaskFields(sqe, taskId);
      69              : 
      70            1 :     sqe->header.type       = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_RECORD);
      71            1 :     sqe->header.wrCqe      = 0U;
      72              : 
      73            1 :     sqe->kernelCredit      = RT_STARS_DEFAULT_KERNEL_CREDIT;
      74            1 :     sqe->subType           = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_SINGLE_NOTIFY_RECORD);
      75            1 :     sqe->notifyId          = notifyId;
      76            1 : }
      77              : 
      78            1 : inline void BuildA5SqeCnt1toNNotifyRecord(u32 streamId, u32 taskId, u32 notifyId, u32 cntValue, uint8_t * const sqeIn)
      79              : {
      80              :     (void) streamId;
      81            1 :     Rt91095StarsNotifySqe *sqe = (Rt91095StarsNotifySqe *)sqeIn;
      82            1 :     SetSqeHeaderTaskFields(sqe, taskId);
      83              : 
      84            1 :     sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_RECORD);
      85            1 :     sqe->header.wrCqe  = 0U;
      86              : 
      87            1 :     sqe->kernelCredit = RT_STARS_DEFAULT_KERNEL_CREDIT;
      88            1 :     sqe->clrFlag = false;
      89            1 :     sqe->cntFlag = true;
      90            1 :     sqe->recordModeBit = 0x0U;
      91            1 :     sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_COUNT_NOTIFY_RECORD);
      92            1 :     sqe->notifyId = notifyId;
      93            1 :     sqe->cntValue = cntValue;
      94            1 : }
      95              : 
      96            1 : inline void BuildA5SqeCnt1toNNotifyWait(u32 streamId, u32 taskId, u32 notifyId, u32 cntValue, uint8_t * const sqeIn)
      97              : {
      98              :     (void) streamId;
      99            1 :     Rt91095StarsNotifySqe *sqe = (Rt91095StarsNotifySqe *)sqeIn;
     100            1 :     SetSqeHeaderTaskFields(sqe, taskId);
     101              :     
     102            1 :     sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_WAIT);
     103            1 :     sqe->header.wrCqe  = 0U;
     104              : 
     105            1 :     sqe->kernelCredit = RT_STARS_NEVER_TIMEOUT_KERNEL_CREDIT;
     106            1 :     sqe->cntFlag = true;
     107            1 :     sqe->clrFlag = true;
     108            1 :     sqe->bitmap = 1U;
     109            1 :     sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_COUNT_NOTIFY_WAIT);
     110            1 :     sqe->notifyId = notifyId;
     111            1 :     sqe->cntValue = cntValue;
     112            1 : }
     113              : 
     114            1 : inline void BuildA5SqeCntNto1NotifyRecord(u32 streamId, u32 taskId, u32 notifyId, u32 cntValue, uint8_t * const sqeIn)
     115              : {
     116              :     (void) streamId;
     117            1 :     Rt91095StarsNotifySqe *sqe = (Rt91095StarsNotifySqe *)sqeIn;
     118            1 :     SetSqeHeaderTaskFields(sqe, taskId);
     119              : 
     120            1 :     sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_RECORD);
     121            1 :     sqe->header.wrCqe  = 0U;
     122            1 :     sqe->kernelCredit = RT_STARS_DEFAULT_KERNEL_CREDIT;
     123              : 
     124            1 :     sqe->clrFlag = false;
     125            1 :     sqe->cntFlag = true;
     126            1 :     sqe->recordModeBit = 0x2U;
     127            1 :     sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_COUNT_NOTIFY_RECORD); 
     128            1 :     sqe->notifyId = notifyId; 
     129            1 :     sqe->cntValue = cntValue;
     130            1 : }
     131              : 
     132            1 : inline void BuildA5SqeCntNto1NotifyWait(u32 streamId, u32 taskId, u32 notifyId, u32 cntValue, uint8_t * const sqeIn)
     133              : {
     134              :     (void) streamId;
     135            1 :     Rt91095StarsNotifySqe *sqe = (Rt91095StarsNotifySqe *)sqeIn;
     136            1 :     SetSqeHeaderTaskFields(sqe, taskId);
     137              : 
     138            1 :     sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_NOTIFY_WAIT);
     139            1 :     sqe->header.wrCqe  = 0U;
     140              : 
     141            1 :     sqe->kernelCredit = RT_STARS_NEVER_TIMEOUT_KERNEL_CREDIT;
     142            1 :     sqe->cntFlag = true;
     143            1 :     sqe->clrFlag = true;
     144            1 :     sqe->waitModeBit = 0x1U;
     145            1 :     sqe->subType = static_cast<uint16_t>(Rt91095NotifySubType::NOTIFY_SUB_TYPE_COUNT_NOTIFY_WAIT);
     146            1 :     sqe->notifyId = notifyId;
     147            1 :     sqe->cntValue = cntValue;
     148            1 : }
     149              : 
     150            3 : inline void BuildA5SqeSdmaCopy(u32 streamId, u32 taskId, u64 dstAddr, u64 srcAddr, u32 size, u32 partId, u32 opcode,
     151              :                         uint8_t * const sqeIn)
     152              : {
     153              :     (void) streamId;
     154            3 :     Rt91095StarsMemcpySqe *sqe = (Rt91095StarsMemcpySqe *)sqeIn;
     155            3 :     SetSqeHeaderTaskFields(sqe, taskId);
     156              : 
     157            3 :     sqe->header.type           = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_SDMA);
     158            3 :     sqe->header.wrCqe          = 0U;
     159              : 
     160            3 :     sqe->opcode                = opcode;
     161            3 :     sqe->kernelCredit          = RT_STARS_DEFAULT_KERNEL_CREDIT;
     162            3 :     sqe->sssv                  = 1U;
     163            3 :     sqe->dssv                  = 1U;
     164            3 :     sqe->sns                   = 1U;
     165            3 :     sqe->dns                   = 1U;
     166            3 :     sqe->mapamPartId           = partId;
     167              : 
     168            3 :     sqe->u.strideMode0.lengthMove  = size;
     169            3 :     sqe->u.strideMode0.srcAddrLow  = static_cast<uint32_t>(srcAddr & 0x00000000ffffffffU);
     170            3 :     sqe->u.strideMode0.srcAddrHigh = static_cast<uint32_t>((srcAddr & 0xffffffff00000000U) >> 32);
     171            3 :     sqe->u.strideMode0.dstAddrLow  = static_cast<uint32_t>(dstAddr & 0x00000000ffffffffU);
     172            3 :     sqe->u.strideMode0.dstAddrHigh = static_cast<uint32_t>((dstAddr & 0xffffffff00000000U) >> 32);
     173            3 : }
     174              : 
     175            1 : inline void BuildA5SqeUbDbSend(u32 streamId, u32 taskId, const UbJettyLiteId &jettyLiteId, u16 piValue, uint8_t * const sqeIn)
     176              : {
     177              :     (void)streamId;
     178            1 :     Rt91095StarsUbdmaDBmodeSqe *sqe = (Rt91095StarsUbdmaDBmodeSqe *)sqeIn;
     179            1 :     SetSqeHeaderTaskFields(sqe, taskId);
     180              : 
     181            1 :     sqe->header.type = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_UBDMA);
     182              : 
     183            1 :     sqe->mode              = Rt91095UbDmaSqeMode::RT_91095_SQE_DOORBELL_MODE;
     184            1 :     sqe->kernelCredit      = RT_STARS_DEFAULT_KERNEL_CREDIT;
     185            1 :     sqe->doorbellNum = 1U;
     186            1 :     sqe->jettyId1    = jettyLiteId.GetJettyId();
     187            1 :     sqe->funcId1     = jettyLiteId.GetFuncId();
     188            1 :     sqe->piValue1    = piValue;
     189            1 :     sqe->dieId1      = jettyLiteId.GetDieId();
     190            1 : }
     191              : 
     192            0 : inline void BuildA5SqeP2pWriteValue(u32 streamId, u32 taskId, u64 remoteAddr, u32 writeValue, uint8_t * const sqeIn)
     193              : {
     194              :     (void) streamId;
     195            0 :     Rt91095StarsWriteValueSqe *sqe  = reinterpret_cast<Rt91095StarsWriteValueSqe *>(sqeIn);
     196            0 :     SetSqeHeaderTaskFields(sqe, taskId);
     197              :     
     198            0 :     sqe->header.type                = static_cast<uint8_t>(Rt91095StarsSqeType::RT_91095_SQE_TYPE_WRITE_VALUE);
     199              : 
     200            0 :     sqe->kernelCredit               = RT_STARS_DEFAULT_KERNEL_CREDIT;
     201            0 :     sqe->writeAddrLow               = remoteAddr & MASK_32_BIT;
     202            0 :     sqe->writeAddrHigh              = (remoteAddr >> UINT32_BIT_NUM) & MASK_17_BIT;
     203            0 :     sqe->awsize                     = RtStarsWriteValueSizeType::RT_STARS_WRITE_VALUE_SIZE_TYPE_32BIT;
     204            0 :     sqe->writeValuePart[0]          = writeValue;
     205            0 :     sqe->va                         = 1;
     206            0 : }
     207              : 
     208              : u32 GetKernelExecTimeoutFromEnvConfig();
     209              : 
     210              : void BuildA5SqeCCoreNotifyWait(u32 streamId, u32 taskId, u64 waitAddr, u64 actAddr, bool last, uint8_t * const sqeIn);
     211              : 
     212              : void BuildA5SqeCCoreNotifyRecord(u32 streamId, u32 taskId, u64 writeAddr, u64 valueAddr, uint8_t * const sqeIn);
     213              : 
     214              : void BuildA5SqeRdmaDbSend(u32 streamId, u32 taskId, u64 dbAddr, u64 dbValue, uint8_t * const sqeIn);
     215              : 
     216              : } // namespace Hccl
     217              : 
     218              : #endif
        

Generated by: LCOV version 2.0-1