LCOV - code coverage report
Current view: top level - legacy/ascend910/platform/resource/dispatcher_ctx - dispatcher_ctx.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 71.1 % 76 54
Test Date: 2026-08-18 17:47:01 Functions: 66.7 % 9 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 "dispatcher_ctx.h"
      12              : #include "adapter_hal.h"
      13              : #include "dispatcher_graph_pub.h"
      14              : #include "dispatcher_pub.h"
      15              : #include "dispatcher_aicpu_pub.h"
      16              : #include "dispatcher_virtural_pub.h"
      17              : #include "dlhal_function.h"
      18              : 
      19              : namespace hccl {
      20            1 : FftsCounterCallBack DispatcherCtx::GetInitTaskCallback() const { return g_InitTaskCallback; }
      21              : 
      22            1 : FftsCounterCallBack DispatcherCtx::GetLaunchTaskCallback() const { return g_LaunchTaskCallback; }
      23              : 
      24          422 : HcclResult DispatcherCtx::Init()
      25              : {
      26          422 :     CHK_RET(DlHalFunction::GetInstance().DlHalFunctionInit());
      27              :     // 获取host侧还是device侧
      28          422 :     u32 info = 0;
      29          422 :     CHK_RET(hrtDrvGetPlatformInfo(&info));
      30          422 :     bool isDeviceSide = info == 0 ? true : false;
      31          422 :     HCCL_INFO("[DispatcherCtx][Init] isDeviceSide[%d]", isDeviceSide);
      32          422 :     CtxDispatcherType type = CtxDispatcherType::DISPATCHER_NORMAL;
      33              :     // 如果是host侧
      34          422 :     if (!isDeviceSide) {
      35           11 :         CHK_RET(hrtGetDeviceType(deviceType_));
      36           11 :         if ((deviceType_ == DevType::DEV_TYPE_910B) && GetExternalInputHcclEnableFfts()) {
      37            2 :             CHK_PRT_CONT(
      38              :                 GetWorkflowMode() == HcclWorkflowMode::HCCL_WORKFLOW_MODE_OP_BASE && !GetExternalInputHcclAicpuUnfold(),
      39              :                 HCCL_RUN_INFO("[DispatcherCtx][Init] Will use FFTS mode."));
      40            2 :             type = CtxDispatcherType::DISPATCHER_FFTS;
      41              :         } else {
      42            9 :             HCCL_RUN_INFO("[DispatcherCtx][Init] Will use NORMAL mode.");
      43            9 :             type = CtxDispatcherType::DISPATCHER_NORMAL;
      44              :         }
      45              :     } else { // 如果是device侧 那么默认aicpu
      46          411 :         HCCL_RUN_INFO("[DispatcherCtx][Init] Will use AICPU mode.");
      47          411 :         type = CtxDispatcherType::DISPATCHER_AICPU;
      48              :     }
      49          422 :     CHK_RET(DispatcherInit(type, devicePhyId_, &dispatcher_));
      50          422 :     CHK_SMART_PTR_NULL(dispatcher_);
      51              : 
      52          422 :     return HCCL_SUCCESS;
      53              : }
      54          844 : HcclResult DispatcherCtx::Destroy()
      55              : {
      56          844 :     const std::lock_guard<std::mutex> lock(destroyMutex_);
      57          844 :     if (dispatcher_ != nullptr) {
      58          422 :         DispatcherPub* dispatcher = reinterpret_cast<DispatcherPub*>(dispatcher_);
      59          422 :         delete dispatcher;
      60          422 :         dispatcher_ = nullptr;
      61              :     }
      62          844 :     return HCCL_SUCCESS;
      63          844 : }
      64         1604 : HcclDispatcher DispatcherCtx::GetDispatcher() const { return dispatcher_; }
      65              : 
      66            0 : u32 DispatcherCtx::GetWaitTimeOut() const { return waitTimeOut_; }
      67              : 
      68            0 : HcclResult DispatcherCtx::SetWaitTimeOut(u32 waitTimeOut)
      69              : {
      70            0 :     waitTimeOut_ = waitTimeOut;
      71            0 :     return HCCL_SUCCESS;
      72              : }
      73              : 
      74          422 : HcclResult DispatcherCtx::DispatcherInit(CtxDispatcherType type, const s32 devicePhyId, HcclDispatcher* dispatcher)
      75              : {
      76          422 :     CHK_RET(DlHalFunction::GetInstance().DlHalFunctionInit());
      77          422 :     CHK_PTR_NULL(dispatcher);
      78          422 :     dispatcherType_ = type;
      79          422 :     DispatcherPub* pDispatcher = nullptr;
      80          422 :     switch (type) {
      81            2 :         case CtxDispatcherType::DISPATCHER_FFTS: {
      82            2 :             u32 deviceLogicId = INVALID_UINT;
      83            2 :             CHK_RET(hrtGetDeviceIndexByPhyId(devicePhyId, deviceLogicId));
      84              : #ifndef HCCD
      85            2 :             pDispatcher = new (std::nothrow) DispatcherGraph(deviceLogicId);
      86              : #endif
      87            2 :             break;
      88              :         }
      89            9 :         case CtxDispatcherType::DISPATCHER_NORMAL: {
      90            9 :             u32 deviceLogicId = INVALID_UINT;
      91            9 :             CHK_RET(hrtGetDeviceIndexByPhyId(devicePhyId, deviceLogicId));
      92            9 :             pDispatcher = new (std::nothrow) DispatcherPub(deviceLogicId);
      93            9 :             break;
      94              :         }
      95            0 :         case CtxDispatcherType::DISPATCHER_VIRTURAL: {
      96            0 :             u32 deviceLogicId = INVALID_UINT;
      97            0 :             CHK_RET(hrtGetDeviceIndexByPhyId(devicePhyId, deviceLogicId));
      98            0 :             pDispatcher = new (std::nothrow) DispatcherVirtural(deviceLogicId);
      99            0 :             break;
     100              :         }
     101          411 :         case CtxDispatcherType::DISPATCHER_AICPU: {
     102              : #ifdef CCL_KERNEL
     103          411 :             pDispatcher = new (std::nothrow) DispatcherAiCpu(devicePhyId);
     104              : #endif
     105          411 :             break;
     106              :         }
     107            0 :         default: {
     108            0 :             HCCL_ERROR("Not support the dispatcher type[%d]", type);
     109            0 :             return HCCL_E_NOT_SUPPORT;
     110              :         }
     111              :     }
     112              : 
     113          422 :     CHK_PTR_NULL(pDispatcher);
     114          422 :     HcclResult ret = pDispatcher->Init();
     115          422 :     if (ret != HCCL_SUCCESS) {
     116            0 :         HCCL_ERROR("Dispatcher init failed, type[%d]", type);
     117            0 :         delete pDispatcher;
     118            0 :         pDispatcher = nullptr;
     119            0 :         return ret;
     120              :     }
     121          422 :     *dispatcher = pDispatcher;
     122          422 :     return HCCL_SUCCESS;
     123              : }
     124              : 
     125            0 : HcclResult DispatcherCtx::SetDispatcherHcclQos(u32 hcclQos)
     126              : {
     127            0 :     HCCL_INFO("SetDispatcherHcclQos hcclQos = %u", hcclQos);
     128            0 :     CHK_PTR_NULL(dispatcher_);
     129            0 :     auto aiCpuDispatcher = static_cast<DispatcherAiCpu*>(dispatcher_);
     130            0 :     aiCpuDispatcher->SetHcclQos(hcclQos);
     131            0 :     return HCCL_SUCCESS;
     132              : }
     133              : } // namespace hccl
        

Generated by: LCOV version 2.0-1