LCOV - code coverage report
Current view: top level - acl/acl_tdt_queue - queue_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 67.3 % 52 35
Test Date: 2026-07-28 10:53:01 Functions: 100.0 % 3 3

            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              :     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            2 :     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            1 :                 queueProcessProc_ = std::unique_ptr<QueueProcessorHost>(new (std::nothrow) QueueProcessorHost());
      72            1 :                 ACL_CHECK_MALLOC_RESULT_REPORT_RET(queueProcessProc_.get(), sizeof(QueueProcessorHost), "new", nullptr);
      73            1 :                 break;
      74            0 :             case ACL_ENV_DEVICE_SP:
      75            0 :                 queueProcessProc_ = std::unique_ptr<QueueProcessorSp>(new (std::nothrow) QueueProcessorSp());
      76            0 :                 ACL_CHECK_MALLOC_RESULT_REPORT_RET(queueProcessProc_.get(), sizeof(QueueProcessorSp), "new", nullptr);
      77            0 :                 break;
      78            0 :             case ACL_ENV_DEVICE_CCPU:
      79            0 :                 queueProcessProc_ = std::unique_ptr<QueueProcessorCcpu>(new (std::nothrow) QueueProcessorCcpu());
      80            0 :                 ACL_CHECK_MALLOC_RESULT_REPORT_RET(queueProcessProc_.get(), sizeof(QueueProcessorCcpu), "new", nullptr);
      81            0 :                 break;
      82            1 :             default:
      83            1 :                 ACL_LOG_INNER_ERROR("Failed to check runenv.");
      84            1 :                 return nullptr;
      85              :         }
      86            0 :     } catch (...) {
      87            0 :         ACL_LOG_INNER_ERROR("Failed to create queue processor with unique_ptr.");
      88            0 :         return nullptr;
      89            0 :     }
      90            1 :     return queueProcessProc_.get();
      91            2 : }
      92              : } // namespace acl
        

Generated by: LCOV version 2.0-1