LCOV - code coverage report
Current view: top level - legacy/ascend910/framework/device - hccl_aicpu_interface.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 29.8 % 94 28
Test Date: 2026-08-17 10:19:35 Functions: 25.0 % 4 1

            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 "hccl_aicpu_interface.h"
      12              : 
      13              : #include <sstream>
      14              : #include <dlfcn.h>
      15              : #include "common/aicpu_hccl_common.h"
      16              : #include "common/aicpu_hccl_def.h"
      17              : #include "common/aicpu_sqe_context.h"
      18              : #include "profiling_manager_device.h"
      19              : #include "framework/aicpu_hccl_process.h"
      20              : #include "utils/hccl_aicpu_utils.h"
      21              : #include "framework/aicpu_communicator.h"
      22              : #include "utils/aicpu_hdc_utils.h"
      23              : #include "hccl_group_utils.h"
      24              : #include "hccl_dl.h"
      25              : 
      26              : extern "C" {
      27            0 : __attribute__((visibility("default"))) uint32_t RunAicpuKfcResInitV2(void* args)
      28              : {
      29            0 :     if (args == nullptr) {
      30            0 :         HCCL_ERROR("args is null.");
      31            0 :         return HCCL_E_PARA;
      32              :     }
      33              : 
      34            0 :     KFCResInitTask* ctxArgs = reinterpret_cast<KFCResInitTask*>(args);
      35            0 :     HCCL_INFO("RunAicpuKfcResInitV2 isCustom %u, context %#llx", ctxArgs->isCustom, ctxArgs->context);
      36            0 :     if (ctxArgs->context == 0) { // for OneSideComm
      37            0 :         CHK_RET(hrtSetWorkModeAicpu(true));
      38            0 :         HCCL_INFO("RunAicpuKfcResInitV2 done as context is null, set aicpu work mode");
      39            0 :         return HCCL_SUCCESS;
      40              :     }
      41            0 :     return AicpuHcclProcess::AicpuRpcResInitV2(reinterpret_cast<HcclOpResParam*>(ctxArgs->context), ctxArgs->isCustom);
      42              : }
      43              : 
      44            1 : __attribute__((visibility("default"))) uint32_t RunAicpuRpcSrvLaunchV2(void* args)
      45              : {
      46            1 :     if (args == nullptr) {
      47            0 :         HCCL_ERROR("RunAicpuRpcSrvLaunchV2 args is null.");
      48            0 :         return HCCL_E_PARA;
      49              :     }
      50              : 
      51            1 :     KFCTaskComm* task = reinterpret_cast<KFCTaskComm*>(args);
      52            1 :     OpTilingData* tilingData = reinterpret_cast<OpTilingData*>(reinterpret_cast<std::uintptr_t>(task) + sizeof(u64));
      53            1 :     if (tilingData == nullptr) {
      54            0 :         HCCL_ERROR("RunAicpuRpcSrvLaunchV2 tilingData args is null.");
      55            0 :         return HCCL_E_PARA;
      56              :     }
      57              : 
      58            1 :     const HcclCMDType opType = static_cast<HcclCMDType>(tilingData->opType);
      59            1 :     if ((opType == HcclCMDType::HCCL_CMD_BATCH_GET) || (opType == HcclCMDType::HCCL_CMD_BATCH_PUT)) {
      60            0 :         return AicpuHcclProcess::HandleOneSideService(tilingData);
      61              :     }
      62              : 
      63            1 :     HcclOpResParam* commParam = reinterpret_cast<HcclOpResParam*>(task->context);
      64            1 :     if (commParam == nullptr) {
      65            0 :         HCCL_ERROR("RunAicpuRpcSrvLaunchV2 context args is null.");
      66            0 :         return HCCL_E_PARA;
      67              :     }
      68            1 :     HCCL_INFO("RunAicpuRpcSrvLaunchV2 KFCTask task %p, context %p, tilingData %p", task, commParam, tilingData);
      69              : 
      70            1 :     std::string group = commParam->hcomId;
      71            1 :     hccl::HcclCommAicpu* hcclCommAicpu = AicpuHcclProcess::AicpuGetCommbyGroup(group);
      72            1 :     if (hcclCommAicpu == nullptr) {
      73            0 :         HCCL_ERROR("RunAicpuRpcSrvLaunchV2 get Hcclcomm error group[%s], tag[%s]", commParam->hcomId, tilingData->tag);
      74            0 :         return HCCL_E_INTERNAL;
      75              :     }
      76            1 :     HCCL_INFO(
      77              :         "[RunAicpuRpcSrvLaunchV2] isZeroCopy [%d], isSymmetricMemory [%d], workflowMode[%d]", tilingData->isZeroCopy,
      78              :         tilingData->isSymmetricMemory, tilingData->workflowMode);
      79            1 :     hcclCommAicpu->SetZeroCopyEnable(tilingData->isZeroCopy);
      80            1 :     hcclCommAicpu->SetSymmetricMemoryEnable(tilingData->isSymmetricMemory);
      81            1 :     DfxExtendInfo* dfxInfo = hcclCommAicpu->GetDfxExtendInfo();
      82            1 :     if ((dfxInfo->cqeStatus != dfx::CqeStatus::kDefault) || (dfxInfo->pollStatus == PollStatus::kStopAsException)) {
      83            0 :         AicpuHcclProcess::AicpuReleaseCommbyGroup(group);
      84            0 :         HCCL_ERROR(
      85              :             "RunAicpuRpcSrvLaunchV2 exist errors before, cqeStatus:%d, pollStatus:%d, group[%s], sqeType[%u]",
      86              :             dfxInfo->cqeStatus, dfxInfo->pollStatus, commParam->hcomId, dfxInfo->cqeException.sqeType);
      87            0 :         if (dfxInfo->cqeException.sqeType == RT_STARS_SQE_TYPE_SDMA) {
      88            0 :             return TS_ERROR_AICPU_SDMA;
      89              :         }
      90            0 :         return HCCL_E_INTERNAL;
      91              :     }
      92            1 :     SetWorkflowMode(static_cast<HcclWorkflowMode>(tilingData->workflowMode));
      93            1 :     HCCL_DEBUG("[NsRecovery]check the suspending status in hcclCommAicpu");
      94            1 :     HcclComSuspendingFlag kfcFlag = HcclComSuspendingFlag ::isResume;
      95            1 :     CHK_RET(hcclCommAicpu->GetSuspendingFlag(kfcFlag));
      96            1 :     if (kfcFlag == HcclComSuspendingFlag::isSuspending) {
      97            1 :         HCCL_RUN_WARNING("[NsRecovery] the op should not be launched in hcclCommAicpu on the suspending status");
      98            1 :         HCCL_RUN_WARNING("[NsRecovery] Possible reason: flag not refresh, not enough time between resume and launch");
      99            1 :         AicpuHcclProcess::AicpuReleaseCommbyGroup(group);
     100            1 :         return 0;
     101              :     }
     102            0 :     hcclCommAicpu->SetNsStopLaunchStatus(false);
     103            0 :     HcclResult res = AicpuHcclProcess::AicpuRunRpcServerV2(hcclCommAicpu, tilingData, commParam);
     104            0 :     AicpuHcclProcess::AicpuReleaseCommbyGroup(group);
     105            0 :     if (res != HCCL_SUCCESS) {
     106            0 :         if (res == HCCL_E_OPRETRY_FAIL) {
     107            0 :             HCCL_RUN_INFO("Retry failed, support step retry");
     108            0 :             return TS_ERROR_RETRY_CONSTRAINT;
     109            0 :         } else if (res != HCCL_E_SUSPENDING) {
     110            0 :             if (dfxInfo->cqeException.sqeType == RT_STARS_SQE_TYPE_SDMA) {
     111            0 :                 HCCL_ERROR("run AicpuRunRpcServerV2 failed. ret[%u]", TS_ERROR_AICPU_SDMA);
     112            0 :                 return TS_ERROR_AICPU_SDMA;
     113              :             }
     114            0 :             HCCL_ERROR("run AicpuRunRpcServerV2 failed. ret[%d]", res);
     115            0 :             return res;
     116              :         } else {
     117            0 :             HCCL_INFO("aicpu is suspended");
     118            0 :             return AICPUSUSPENDING_ERROR;
     119              :         }
     120              :     }
     121            0 :     HCCL_INFO("end RunAicpuRpcSrvLaunchV2");
     122            0 :     return 0;
     123            1 : }
     124              : 
     125            0 : __attribute__((visibility("default"))) uint32_t RunAicpuNotifyRecord(void* args)
     126              : {
     127            0 :     if (args == nullptr) {
     128            0 :         HCCL_ERROR("RunAicpuNotifyRecord args is null.");
     129            0 :         return HCCL_E_PARA;
     130              :     }
     131            0 :     ThreadNotifyRecordParam* param = reinterpret_cast<ThreadNotifyRecordParam*>(args);
     132            0 :     HCCL_INFO(
     133              :         "[RunAicpuNotifyRecord] thread[0x%llx], dstThread[0x%llx], dstNotifyIdx[%u]", param->thread, param->dstThread,
     134              :         param->dstNotifyIdx);
     135            0 :     int32_t ret = HcommThreadNotifyRecordOnThread(param->thread, param->dstThread, param->dstNotifyIdx);
     136            0 :     if (ret != HCCL_SUCCESS) {
     137            0 :         HCCL_ERROR("RunAicpuNotifyRecord failed. ret[%d]", ret);
     138            0 :         return ret;
     139              :     }
     140            0 :     HCCL_INFO("RunAicpuNotifyRecord success.");
     141            0 :     return HCCL_SUCCESS;
     142              : }
     143              : 
     144            0 : __attribute__((visibility("default"))) uint32_t RunAicpuNotifyWait(void* args)
     145              : {
     146            0 :     if (args == nullptr) {
     147            0 :         HCCL_ERROR("RunAicpuNotifyWait args is null.");
     148            0 :         return HCCL_E_PARA;
     149              :     }
     150            0 :     ThreadNotifyWaitParam* param = reinterpret_cast<ThreadNotifyWaitParam*>(args);
     151            0 :     HCCL_INFO("[RunAicpuNotifyWait] thread[0x%llx], notifyIdx[%u]", param->thread, param->notifyIdx);
     152            0 :     int32_t ret = HcommThreadNotifyWaitOnThreadWithDefaultTimeout(param->thread, param->notifyIdx);
     153            0 :     if (ret != HCCL_SUCCESS) {
     154            0 :         HCCL_ERROR("RunAicpuNotifyWait failed. ret[%d]", ret);
     155            0 :         return ret;
     156              :     }
     157            0 :     HCCL_INFO("RunAicpuNotifyWait success.");
     158            0 :     return HCCL_SUCCESS;
     159              : }
     160              : 
     161              : } // extern "C"
        

Generated by: LCOV version 2.0-1