LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/device/common - sqe_context_utils.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 42.4 % 177 75
Test Date: 2026-08-18 17:47:01 Functions: 41.2 % 17 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              : 
      11              : #include "common/aicpu_sqe_context.h"
      12              : 
      13              : #include <sstream>
      14              : #include <unordered_map>
      15              : 
      16              : #include "common/aicpu_hccl_common.h"
      17              : #include "utils/hccl_aicpu_utils.h"
      18              : #include "securec.h"
      19              : 
      20              : namespace {
      21          157 : void ParseNotifySqe(const uint8_t* sqeLocal, uint32_t addInfo, SqeInfo* info)
      22              : {
      23          157 :     auto sqe = reinterpret_cast<const rtStarsNotifySqeV1_t*>(sqeLocal);
      24          157 :     info->type = sqe->header.type;
      25          157 :     info->streamId = sqe->header.rtStreamId;
      26          157 :     info->taskId = sqe->header.taskId;
      27          157 :     info->notifyId = sqe->notify_id;
      28          157 :     info->remoteRank = addInfo;
      29          157 : }
      30           28 : void ParseWriteValueSqe(const uint8_t* sqeLocal, uint32_t addInfo, SqeInfo* info)
      31              : {
      32           28 :     auto sqe = reinterpret_cast<const rtStarsWriteValueSqe_t*>(sqeLocal);
      33           28 :     info->type = sqe->header.type;
      34           28 :     info->streamId = sqe->header.rtStreamId;
      35           28 :     info->taskId = sqe->header.taskId;
      36           28 :     info->subType = sqe->sub_type;
      37           28 :     info->eventId = sqe->res7;
      38           28 :     info->addr1High = sqe->write_addr_high;
      39           28 :     info->addr1Low = sqe->write_addr_low;
      40           28 :     info->remoteRank = addInfo;
      41           28 :     info->length = sqe->rdmaWrLenth;            // rdma wr len
      42           28 :     info->taskRelated.rdmaType = sqe->rdmaType; // rdma type
      43           28 : }
      44            0 : void ParseFlipPlaceHolderSqe(const uint8_t* sqeLocal, uint32_t addInfo, SqeInfo* info)
      45              : {
      46            0 :     auto sqe = reinterpret_cast<const rtStarsPlaceHolderSqe_t*>(sqeLocal);
      47            0 :     info->type = sqe->header.type;
      48            0 :     info->streamId = sqe->header.rtStreamId;
      49            0 :     info->taskId = sqe->header.taskId;
      50            0 :     info->length = sqe->u.flip_task_info.flipNumReport;
      51            0 :     info->remoteRank = addInfo;
      52            0 : }
      53            0 : void ParseCacheMemcpyPlaceholderSqe(const uint8_t* sqeLocal, uint32_t addInfo, SqeInfo* info)
      54              : {
      55            0 :     auto sqe = reinterpret_cast<const rtStarsPlaceHolderSqe_t*>(sqeLocal);
      56            0 :     info->type = sqe->header.type;
      57            0 :     info->streamId = sqe->header.rtStreamId;
      58            0 :     info->taskId = sqe->header.taskId;
      59              :     // 注意: cache hit后重新生成的placeholder SQE中的src/dst addr为0 (无需刷新, 因为addr字段只在第一次cache miss时使用,
      60              :     // 用于确定memory type和target rank)
      61            0 :     info->addr1High = sqe->u.cache_memcpy_task_info.src_addr_high;
      62            0 :     info->addr1Low = sqe->u.cache_memcpy_task_info.src_addr_low;
      63            0 :     info->addr2High = sqe->u.cache_memcpy_task_info.dst_addr_high;
      64            0 :     info->addr2Low = sqe->u.cache_memcpy_task_info.dst_addr_low;
      65            0 :     info->remoteRank = addInfo >> 16; // 16 bit
      66            0 :     info->dataType = static_cast<uint16_t>(addInfo);
      67            0 :     info->taskRelated.linkType = static_cast<uint8_t>(sqe->u.cache_memcpy_task_info.linkType); // linkType
      68            0 : }
      69            0 : void ParseCacheNotifyPlaceholderSqe(const uint8_t* sqeLocal, uint32_t addInfo, SqeInfo* info)
      70              : {
      71            0 :     auto sqe = reinterpret_cast<const rtStarsPlaceHolderSqe_t*>(sqeLocal);
      72            0 :     info->type = sqe->header.type;
      73            0 :     info->streamId = sqe->header.rtStreamId;
      74            0 :     info->taskId = sqe->header.taskId;
      75            0 :     info->notifyId = sqe->u.cache_notify_task_info.notify_id;
      76            0 :     info->remoteRank = addInfo;
      77            0 : }
      78            0 : void ParseCacheWriteValuePlaceholderSqe(const uint8_t* sqeLocal, uint32_t addInfo, SqeInfo* info)
      79              : {
      80            0 :     auto sqe = reinterpret_cast<const rtStarsPlaceHolderSqe_t*>(sqeLocal);
      81            0 :     info->type = sqe->header.type;
      82            0 :     info->streamId = sqe->header.rtStreamId;
      83            0 :     info->taskId = sqe->header.taskId;
      84            0 :     info->subType = RT_STARS_WRITE_VALUE_SUB_TYPE_NOTIFY_RECORD_IPC_NO_PCIE;
      85            0 :     info->addr1High = sqe->u.cache_write_value_task_info.write_addr_high;
      86            0 :     info->addr1Low = sqe->u.cache_write_value_task_info.write_addr_low;
      87            0 :     info->remoteRank = addInfo;
      88            0 : }
      89            0 : void ParseCacheMemcpyRecordPlaceholderSqe(const uint8_t* sqeLocal, uint32_t addInfo, SqeInfo* info)
      90              : {
      91            0 :     auto sqe = reinterpret_cast<const rtStarsPlaceHolderSqe_t*>(sqeLocal);
      92            0 :     info->type = sqe->header.type;
      93            0 :     info->streamId = sqe->header.rtStreamId;
      94            0 :     info->taskId = sqe->header.taskId;
      95            0 :     info->opCode = sqe->u.cache_memcpy_record_task_info.opcode;
      96            0 :     info->length = sqe->u.cache_memcpy_record_task_info.length;
      97            0 :     info->addr1High = sqe->u.cache_memcpy_record_task_info.src_addr_high;
      98            0 :     info->addr1Low = sqe->u.cache_memcpy_record_task_info.src_addr_low;
      99            0 :     info->addr2High = sqe->u.cache_memcpy_record_task_info.dst_addr_high;
     100            0 :     info->addr2Low = sqe->u.cache_memcpy_record_task_info.dst_addr_low;
     101            0 :     info->partId = sqe->u.cache_memcpy_record_task_info.partid;
     102            0 :     info->remoteRank = addInfo >> 16; // 16 bit
     103            0 :     info->dataType = static_cast<uint16_t>(addInfo);
     104            0 :     info->taskRelated.linkType = static_cast<uint8_t>(sqe->u.cache_memcpy_record_task_info.linkType); // linkType
     105            0 : }
     106            0 : void ParseEventSqe(const uint8_t* sqeLocal, uint32_t /* addInfo */, SqeInfo* info)
     107              : {
     108            0 :     auto sqe = reinterpret_cast<const rtStarsEventSqe_t*>(sqeLocal);
     109            0 :     info->type = sqe->header.type;
     110            0 :     info->streamId = sqe->header.rtStreamId;
     111            0 :     info->taskId = sqe->header.taskId;
     112            0 :     info->eventId = sqe->eventId;
     113            0 : }
     114           16 : void ParseMemcpyAsyncSqe(const uint8_t* sqeLocal, uint32_t addInfo, SqeInfo* info)
     115              : {
     116           16 :     auto sqe = reinterpret_cast<const rtStarsMemcpyAsyncSqe_t*>(sqeLocal);
     117           16 :     info->type = sqe->header.type;
     118           16 :     info->streamId = sqe->header.rtStreamId;
     119           16 :     info->taskId = sqe->header.taskId;
     120           16 :     info->opCode = sqe->opcode;
     121           16 :     info->length = sqe->length;
     122           16 :     info->addr1High = sqe->src_addr_high;
     123           16 :     info->addr1Low = sqe->src_addr_low;
     124           16 :     info->addr2High = sqe->dst_addr_high;
     125           16 :     info->addr2Low = sqe->dst_addr_low;
     126           16 :     info->partId = sqe->partid;
     127           16 :     info->remoteRank = addInfo >> 16; // 16 bit
     128           16 :     info->dataType = static_cast<uint16_t>(addInfo);
     129           16 :     info->taskRelated.linkType = static_cast<uint8_t>(sqe->linkType); // linkType
     130           16 : }
     131            4 : void ParseCcoreWaitStartSqe(const uint8_t* sqeLocal, uint32_t addInfo, SqeInfo* info)
     132              : {
     133            4 :     auto sqe = reinterpret_cast<const rtStarsCcoreWaitStartSqe_t*>(sqeLocal);
     134            4 :     info->type = sqe->sqeHeader.type;
     135            4 :     info->streamId = sqe->sqeHeader.rtStreamId;
     136            4 :     info->taskId = sqe->sqeHeader.taskId;
     137            4 :     info->addr1High = sqe->ldrImm2.immdAddrHigh;
     138            4 :     info->addr1Low = sqe->ldrImm2.immdAddrLow;
     139            4 :     info->condValue = addInfo >> 16; // 16 bit
     140            4 :     info->isLast = addInfo & 1;
     141            4 : }
     142            2 : void ParseCcoreWriteValueSqe(const uint8_t* sqeLocal, uint32_t addInfo, SqeInfo* info)
     143              : {
     144            2 :     auto sqe = reinterpret_cast<const rtStarsCcoreWriteValueSqe_t*>(sqeLocal);
     145            2 :     info->type = sqe->sqeHeader.type;
     146            2 :     info->streamId = sqe->sqeHeader.rtStreamId;
     147            2 :     info->taskId = sqe->sqeHeader.taskId;
     148            2 :     info->addr1High = sqe->lhwi1.immd;
     149            2 :     info->addr1Low = sqe->llwi1.immdHigh;
     150            2 :     info->addr2High = sqe->llwi1.immdLow;
     151            2 :     info->condValue = addInfo;
     152            2 : }
     153            0 : void ParseNotifySqeV2(const uint8_t* sqeLocal, uint32_t /* addInfo */, SqeInfo* info)
     154              : {
     155            0 :     auto sqe = reinterpret_cast<const rtStarsNotifySqeV2_t*>(sqeLocal);
     156            0 :     info->type = sqe->header.type;
     157            0 :     info->streamId = sqe->header.rt_stream_id;
     158            0 :     info->taskId = sqe->header.task_id;
     159            0 :     info->notifyId = sqe->notify_id;
     160            0 : }
     161            0 : void ParseWriteValueSqeV2(const uint8_t* sqeLocal, uint32_t /* addInfo */, SqeInfo* info)
     162              : {
     163            0 :     auto sqe = reinterpret_cast<const rtStarsWriteValueSqeV2_t*>(sqeLocal);
     164            0 :     info->type = sqe->header.type;
     165            0 :     info->streamId = sqe->header.rt_stream_id;
     166            0 :     info->taskId = sqe->header.task_id;
     167            0 :     info->addr1High = sqe->reg_addr_high;
     168            0 :     info->addr1Low = sqe->reg_addr_low;
     169            0 : }
     170            0 : void ParseEventSqeV2(const uint8_t* sqeLocal, uint32_t /* addInfo */, SqeInfo* info)
     171              : {
     172            0 :     auto sqe = reinterpret_cast<const rtStarsEventSqeV2_t*>(sqeLocal);
     173            0 :     info->type = sqe->type;
     174            0 :     info->streamId = sqe->rt_stream_id;
     175            0 :     info->taskId = sqe->task_id;
     176            0 :     info->eventId = sqe->event_id;
     177            0 : }
     178            0 : void ParseMemcpyAsyncSqeV2(const uint8_t* sqeLocal, uint32_t /* addInfo */, SqeInfo* info)
     179              : {
     180            0 :     auto sqe = reinterpret_cast<const rtStarsMemcpyAsyncSqeV2_t*>(sqeLocal);
     181            0 :     info->type = sqe->type;
     182            0 :     info->streamId = sqe->rt_stream_id;
     183            0 :     info->taskId = sqe->task_id;
     184            0 :     info->opCode = sqe->opcode;
     185            0 :     info->length = sqe->length;
     186            0 :     info->addr1High = sqe->src_addr_high;
     187            0 :     info->addr1Low = sqe->src_addr_low;
     188            0 :     info->addr2High = sqe->dst_addr_high;
     189            0 :     info->addr2Low = sqe->dst_addr_low;
     190            0 : }
     191              : } // namespace
     192              : 
     193         2304 : HcclResult SqeContextUtils::QuerySqeInfo(const uint8_t* sqeLocal, uint8_t sqeType, uint32_t addInfo, SqeInfo* info)
     194              : {
     195              :     static const std::unordered_map<uint8_t, void (*)(const uint8_t*, uint32_t, SqeInfo*)> funcMap
     196              :         = {{SqeType::NOTIFY_SQE, ParseNotifySqe},
     197              :            {SqeType::WRITE_VALUE_SQE, ParseWriteValueSqe},
     198              :            {SqeType::EVENT_SQE, ParseEventSqe},
     199              :            {SqeType::MEMCPY_ASYNC_SQE, ParseMemcpyAsyncSqe},
     200              :            {SqeType::CCORE_WAIT_START_SQE, ParseCcoreWaitStartSqe},
     201              :            {SqeType::CCORE_WRITE_VALUE_SQE, ParseCcoreWriteValueSqe},
     202              :            {SqeType::NOTIFY_SQE_V2, ParseNotifySqeV2},
     203              :            {SqeType::WRITE_VALUE_SQE_V2, ParseWriteValueSqeV2},
     204              :            {SqeType::EVENT_SQE_V2, ParseEventSqeV2},
     205              :            {SqeType::MEMCPY_ASYNC_SQE_V2, ParseMemcpyAsyncSqeV2},
     206              :            {SqeType::RDMA_DB_SEND_SQE, ParseWriteValueSqe},
     207              :            {SqeType::FLIP_PLACEHOLDER_SQE, ParseFlipPlaceHolderSqe},
     208              :            {SqeType::CACHE_MEMCPY_PLACEHOLDER_SQE, ParseCacheMemcpyPlaceholderSqe},
     209              :            {SqeType::CACHE_NOTIFY_PLACEHOLDER_SQE, ParseCacheNotifyPlaceholderSqe},
     210              :            {SqeType::CACHE_WRITE_VALUE_PLACEHOLDER_SQE, ParseCacheWriteValuePlaceholderSqe},
     211         2308 :            {SqeType::CACHE_MEMCPY_RECORD_PLACEHOLDER_SQE, ParseCacheMemcpyRecordPlaceholderSqe}};
     212         2304 :     auto it = funcMap.find(sqeType);
     213         2304 :     if (it == funcMap.cend()) {
     214         2097 :         HCCL_WARNING("sqetype:%u is unsupported", sqeType);
     215         2097 :         return HCCL_E_NOT_SUPPORT;
     216              :     }
     217          207 :     CHK_PTR_NULL(info);
     218          207 :     (it->second)(sqeLocal, addInfo, info);
     219          207 :     info->valid = 1;
     220          207 :     return HCCL_SUCCESS;
     221              : }
     222              : 
     223           25 : std::string SqeContextUtils::RtsqTaskTypeToStr(uint8_t type)
     224              : {
     225           25 :     switch (type) {
     226           14 :         case RT_STARS_SQE_TYPE_NOTIFY_WAIT:
     227           28 :             return "NOTIFY WAIT";
     228            0 :         case RT_STARS_SQE_TYPE_NOTIFY_RECORD:
     229            0 :             return "NOTIFY RECORD";
     230            0 :         case RT_STARS_SQE_TYPE_WRITE_VALUE:
     231            0 :             return "WRITE VALUE";
     232            0 :         case RT_STARS_SQE_TYPE_SDMA:
     233            0 :             return "SDMA";
     234            2 :         case RT_STARS_SQE_TYPE_COND:
     235            4 :             return "COND";
     236            9 :         default:
     237            9 :             return std::to_string(type);
     238              :     }
     239              : }
        

Generated by: LCOV version 2.0-1