LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/selector - selector_registry.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 54.8 % 31 17
Test Date: 2026-08-18 17:47:01 Functions: 60.0 % 5 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 "selector_registry.h"
      12              : 
      13              : #include <string>
      14              : #include <iostream>
      15              : #include <map>
      16              : #include <mutex>
      17              : #include <new>
      18              : 
      19              : namespace Hccl {
      20              : 
      21           30 : SelectorRegistry* SelectorRegistry::Global()
      22              : {
      23           30 :     static SelectorRegistry* globalSelectorRegistry = new (std::nothrow) SelectorRegistry;
      24           30 :     return globalSelectorRegistry;
      25              : }
      26              : 
      27            1 : HcclResult SelectorRegistry::Register(u32 priority, BaseSelector* selector)
      28              : {
      29            1 :     if (selector == nullptr) {
      30            0 :         HCCL_ERROR("[Algo][Selector] selector is null, register priority %u failed.", priority);
      31            0 :         return HcclResult::HCCL_E_MEMORY;
      32              :     }
      33            1 :     const std::lock_guard<std::mutex> lock(mu_);
      34            1 :     if (impls_.count(priority) != 0) {
      35            0 :         HCCL_ERROR("[Algo][Selector] priority %u already registered.", priority);
      36            0 :         return HcclResult::HCCL_E_PARA;
      37              :     }
      38              : 
      39            1 :     impls_[priority] = selector;
      40            1 :     return HcclResult::HCCL_SUCCESS;
      41            1 : }
      42              : 
      43           14 : HcclResult SelectorRegistry::RegisterByOpType(const OpType opType, u32 priority, BaseSelector* selector)
      44              : {
      45           14 :     if (selector == nullptr) {
      46            0 :         HCCL_ERROR("[Algo][Selector] selector is null, register opType %d priority %u failed.", opType, priority);
      47            0 :         return HcclResult::HCCL_E_MEMORY;
      48              :     }
      49           14 :     const std::lock_guard<std::mutex> lock(mu_);
      50           14 :     if (opTypeImpls_[opType].count(priority) != 0) {
      51            0 :         HCCL_ERROR("[Algo][Selector] opType %d priority %u already registered.", opType, priority);
      52            0 :         return HcclResult::HCCL_E_PARA;
      53              :     }
      54           14 :     opTypeImpls_[opType][priority] = selector;
      55           14 :     return HcclResult::HCCL_SUCCESS;
      56           14 : }
      57              : 
      58            0 : std::map<u32, BaseSelector*> SelectorRegistry::GetSelectorsByOpType(const OpType opType)
      59              : {
      60            0 :     if (opTypeImpls_.count(opType) == 0) {
      61            0 :         HCCL_WARNING("[Algo][Selector] opType %d has no selector registered.", opType);
      62            0 :         return {};
      63              :     }
      64            0 :     return opTypeImpls_[opType];
      65              : }
      66              : 
      67            0 : std::map<u32, BaseSelector*> SelectorRegistry::GetAllSelectors() { return impls_; }
      68              : 
      69              : } // namespace Hccl
        

Generated by: LCOV version 2.0-1