LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/device/utils - aicpu_hdc_utils.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 81.4 % 59 48
Test Date: 2026-07-28 12:11:00 Functions: 75.0 % 8 6

            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 "aicpu_hdc_utils.h"
      12              : 
      13              : using namespace hccl;
      14              : 
      15           59 : HcclResult AicpuHdcUtils::InitOpExecStatus(std::shared_ptr<hccl::HDCommunicate> d2hTransfer, HcclOpIdentifier &opId)
      16              : {
      17           59 :     if (!d2hTransfer) {
      18            2 :         return HCCL_SUCCESS;
      19              :     }
      20           57 :     KfcExecStatus status;
      21           57 :     status.opId = opId;
      22           57 :     status.execStatus.kfcStatus = KfcStatus::kRuning;
      23           57 :     status.execStatus.kfcError = KfcError::kNone;
      24           57 :     status.execStatus.retryInfo.retryCount = 0;
      25           57 :     HCCL_INFO("InitOpExecStatus: id:%u", status.opId.index);
      26           57 :     return d2hTransfer->Put(0, sizeof(status), reinterpret_cast<uint8_t *>(&status));
      27              : }
      28              : 
      29            0 : HcclResult AicpuHdcUtils::SetErrorMessage(std::shared_ptr<hccl::HDCommunicate> d2hTransfer, ErrorMessageReport &emrInfo)
      30              : {
      31            0 :     if (!d2hTransfer) {
      32            0 :         return HCCL_SUCCESS;
      33              :     }
      34              : 
      35            0 :     return d2hTransfer->Put(sizeof(HcclOpIdentifier) + sizeof(ExecStatusDef),
      36            0 :         sizeof(emrInfo), reinterpret_cast<uint8_t *>(&emrInfo));
      37              : }
      38              : 
      39           95 : HcclResult AicpuHdcUtils::SetOpExecStatus(std::shared_ptr<HDCommunicate> d2hTransfer, KfcStatus state,
      40              :     KfcError errorCode, u32 retryCount)
      41              : {
      42           95 :     if (!d2hTransfer) {
      43           11 :         return HCCL_SUCCESS;
      44              :     }
      45           84 :     KfcExecStatus status;
      46           84 :     status.execStatus.kfcStatus = state;
      47           84 :     status.execStatus.kfcError = errorCode;
      48           84 :     status.execStatus.retryInfo.retryCount = retryCount;
      49           84 :     HCCL_INFO("SetOpExecStatus: state:%u", state);
      50           84 :     return d2hTransfer->Put(sizeof(status.opId), sizeof(status.execStatus),
      51           84 :         reinterpret_cast<uint8_t *>(&status.execStatus));
      52              : }
      53              : 
      54     31601380 : HcclResult AicpuHdcUtils::GetOpExecCtrlCmd(std::shared_ptr<HDCommunicate> h2dTransfer, KfcCommand &cmd)
      55              : {
      56     31601380 :     if (!h2dTransfer) {
      57         1606 :         return HCCL_SUCCESS;
      58              :     }
      59              :     static KfcCommand lastCmd = KfcCommand::kNone;
      60     31599774 :     KfcCommand newCmd = KfcCommand::kNone;
      61     31599774 :     CHK_RET(h2dTransfer->Get(0, sizeof(newCmd), reinterpret_cast<uint8_t *>(&newCmd)));
      62              : 
      63     31599774 :     if ((newCmd == KfcCommand::kExit) || (newCmd == KfcCommand::kStopLaunch)||(newCmd == KfcCommand::NsStopLaunch)) {
      64       449326 :         cmd = newCmd;
      65              :     } else {
      66     31150448 :         cmd = (lastCmd != newCmd) ? newCmd : KfcCommand::kNone;
      67              :     }
      68     31599774 :     lastCmd = newCmd;
      69     31599774 :     if (cmd != KfcCommand::kNone) {
      70       449343 :         HCCL_INFO("hccl aicpu get cmd:%u", cmd);
      71              :     }
      72     31599774 :     return HCCL_SUCCESS;
      73              : }
      74              : 
      75           64 : HcclResult AicpuHdcUtils::GetSuspendingStatus(std::shared_ptr<HDCommunicate> h2dTransfer, HcclComSuspendingFlag &kfcFlag)
      76              : {
      77           64 :     if (!h2dTransfer) {
      78            2 :         return HCCL_SUCCESS;
      79              :     }
      80           62 :     u32 startOffset = sizeof(KfcCommand) + sizeof(BackgroundCommand);
      81           62 :     CHK_RET(h2dTransfer->Get(startOffset, sizeof(HcclComSuspendingFlag), reinterpret_cast<uint8_t *>(&kfcFlag)));
      82           62 :     return HCCL_SUCCESS;
      83              : }
      84              : 
      85         8101 : HcclResult AicpuHdcUtils::GetBackGroundCommand(std::shared_ptr<HDCommunicate> h2dTransfer, BackgroundCommand &bgCmd)
      86              : {
      87         8101 :     if (!h2dTransfer) {
      88          800 :         return HCCL_SUCCESS;
      89              :     }
      90         7301 :     u32 startOffset = sizeof(KfcCommand);
      91         7301 :     CHK_RET(h2dTransfer->Get(startOffset, sizeof(BackgroundCommand), reinterpret_cast<uint8_t *>(&bgCmd)));
      92         7301 :     return HCCL_SUCCESS;
      93              : }
      94              : 
      95            1 : HcclResult AicpuHdcUtils::ResponseBackGroundStatus(std::shared_ptr<HDCommunicate> d2hTransfer, KfcExecStatus&kfcStatus)
      96              : {
      97            1 :     if (!d2hTransfer) {
      98            0 :         return HCCL_SUCCESS;
      99              :     }
     100            1 :     CHK_RET(d2hTransfer->Put(0, sizeof(KfcExecStatus), reinterpret_cast<uint8_t *>(&kfcStatus)));
     101            1 :     return HCCL_SUCCESS;
     102              : }
     103              : 
     104            0 : HcclResult AicpuHdcUtils::GetKfcCommand(const std::shared_ptr<HDCommunicate> &h2dTransfer, KfcCommand &cmd)
     105              : {
     106            0 :     if (!h2dTransfer) {
     107            0 :         return HCCL_SUCCESS;
     108              :     }   
     109            0 :     CHK_RET(h2dTransfer->Get(0, sizeof(KfcCommand), reinterpret_cast<uint8_t *>(&cmd)));
     110            0 :     return HCCL_SUCCESS;
     111              : }
        

Generated by: LCOV version 2.0-1