LCOV - code coverage report
Current view: top level - legacy/ascend950/framework/ccu/ccu_manager - ccu_ctx_creator_registry.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 6 6
Test Date: 2026-08-18 17:47:01 Functions: 67.4 % 144 97

            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              : #ifndef CCU_CTX_CREATOR_REGISTRY_H
      12              : #define CCU_CTX_CREATOR_REGISTRY_H
      13              : 
      14              : #include <memory>
      15              : #include "ccu_ctx.h"
      16              : #include "ccu_ins.h"
      17              : 
      18              : namespace Hccl {
      19              : 
      20              : class CcuCtxCreatorRegistry {
      21              : public:
      22              :     using CreateCtxFunc = std::function<std::unique_ptr<CcuContext>(
      23              :         const CcuCtxArg& ccuCtxArg, const std::vector<CcuTransport*>& transports, const CcuTransportGroup& group)>;
      24              : 
      25              :     static CcuCtxCreatorRegistry& GetInstance();
      26              : 
      27              :     template <typename T>
      28           50 :     void Register(CcuInstType ccuInstType)
      29              :     {
      30           50 :         creators.emplace(
      31              :             ccuInstType,
      32           52 :             [](const CcuCtxArg& ccuCtxArg, const std::vector<CcuTransport*>& transports,
      33              :                const CcuTransportGroup& group) -> std::unique_ptr<CcuContext> {
      34            2 :                 return std::make_unique<T>(ccuCtxArg, transports, group);
      35              :             });
      36           50 :     }
      37              : 
      38              :     CreateCtxFunc GetCreateFunc(CcuInstType ccuInstType) const;
      39              : 
      40              : private:
      41              :     std::unordered_map<CcuInstType, CreateCtxFunc, std::EnumClassHash> creators;
      42              : };
      43              : 
      44              : template <typename T>
      45              : class CcuInstRegister {
      46              : public:
      47           48 :     explicit CcuInstRegister(CcuInstType ccuInstType) { CcuCtxCreatorRegistry::GetInstance().Register<T>(ccuInstType); }
      48              : };
      49              : 
      50              : } // namespace Hccl
      51              : 
      52              : #endif // CCU_CTX_CREATOR_REGISTRY_H
        

Generated by: LCOV version 2.0-1