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

Generated by: LCOV version 2.0-1