LCOV - code coverage report
Current view: top level - acl/acl_tdt_queue - queue_manager.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 34 48 70.8 %
Date: 2026-08-27 13:24:42 Functions: 3 3 100.0 %

          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 "queue_manager.h"
      12             : #include "log_inner.h"
      13             : #include "queue.h"
      14             : #include "queue_process.h"
      15             : #include "queue_process_host.h"
      16             : #include "queue_process_sp.h"
      17             : #include "queue_process_ccpu.h"
      18             : 
      19             : namespace acl {
      20          17 :     QueueManager& QueueManager::GetInstance()
      21             :     {
      22          17 :         static QueueManager instance;
      23          17 :         (void)GetRunningEnv(instance.env_);
      24          17 :         return instance;
      25             :     }
      26             : 
      27          20 :     aclError QueueManager::GetRunningEnv(RunEnv &runningEnv)
      28             :     {
      29             :         // get acl run mode
      30          20 :         if (runningEnv != ACL_ACL_ENV_UNKNOWN) {
      31          16 :             return ACL_SUCCESS;
      32             :         }
      33           4 :         aclrtRunMode aclRunMode;
      34           4 :         const aclError getRunModeRet = aclrtGetRunMode(&aclRunMode);
      35           4 :         if (getRunModeRet != ACL_SUCCESS) {
      36           1 :             ACL_LOG_CALL_ERROR("[Get][RunMode]get run mode failed, result = %d.", getRunModeRet);
      37           1 :             return getRunModeRet;
      38             :         }
      39           3 :         if (aclRunMode == ACL_HOST) {
      40           1 :             runningEnv = ACL_ENV_HOST;
      41           2 :         } else if (aclRunMode == ACL_DEVICE) {
      42             :             // get env config
      43           2 :             const char_t *sharePoolPreConfig = nullptr;
      44           2 :             MM_SYS_GET_ENV(MM_ENV_SHAREGROUP_PRECONFIG, sharePoolPreConfig);
      45           2 :             if (sharePoolPreConfig == nullptr) {
      46           2 :                 ACL_LOG_INFO("This is not share group preconfig");
      47           2 :                 runningEnv = ACL_ENV_DEVICE_CCPU;
      48             :             } else {
      49           0 :                 ACL_LOG_INFO("This is share group preconfig");
      50           0 :                 runningEnv = ACL_ENV_DEVICE_SP;
      51             :             }
      52             :         } else {
      53           0 :             ACL_LOG_INNER_ERROR("[Get][RunMode]get run mode failed, result = %d.", getRunModeRet);
      54           0 :             return ACL_ERROR_FAILURE;
      55             :         }
      56           3 :         return ACL_SUCCESS;
      57             :     }
      58             : 
      59          18 :     QueueProcessor *QueueManager::GetQueueProcessor()
      60             :     {
      61          18 :         if (queueProcessProc_ != nullptr) {
      62          16 :             return queueProcessProc_.get();
      63             :         }
      64           4 :         const std::lock_guard<std::mutex> groupLock(muCreateProcessProc_);
      65           2 :         if (queueProcessProc_ != nullptr) {
      66           0 :             return queueProcessProc_.get();
      67             :         }
      68             :         try {
      69           2 :             switch (env_) {
      70           1 :                 case ACL_ENV_HOST:
      71           2 :                     queueProcessProc_ = std::unique_ptr<QueueProcessorHost>(new (std::nothrow)QueueProcessorHost());
      72           1 :                     break;
      73           0 :                 case ACL_ENV_DEVICE_SP:
      74           0 :                     queueProcessProc_ = std::unique_ptr<QueueProcessorSp>(new (std::nothrow)QueueProcessorSp());
      75           0 :                     break;
      76           0 :                 case ACL_ENV_DEVICE_CCPU:
      77           0 :                     queueProcessProc_ = std::unique_ptr<QueueProcessorCcpu>(new (std::nothrow)QueueProcessorCcpu());
      78           0 :                     break;
      79           1 :                 default:
      80           1 :                     ACL_LOG_INNER_ERROR("[Check][Runenv]check runenv failed.");
      81           1 :                     return nullptr;
      82             :             }
      83           0 :         } catch (...) {
      84           0 :             ACL_LOG_INNER_ERROR("[Define][Object]define object queue processor with unique_ptr failed.");
      85           0 :             return nullptr;
      86             :         }
      87           1 :         return queueProcessProc_.get();
      88             :     }
      89             : }

Generated by: LCOV version 1.14