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 % 8 8
Test Date: 2026-07-28 12:11:00 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           50 :     template <typename T> void Register(CcuInstType ccuInstType)
      28              :     {
      29           50 :         creators.emplace(ccuInstType,
      30           52 :                          [](const CcuCtxArg &ccuCtxArg, const std::vector<CcuTransport *> &transports,
      31              :                             const CcuTransportGroup &group) -> std::unique_ptr<CcuContext> {
      32            2 :                              return std::make_unique<T>(ccuCtxArg, transports, group);
      33              :                          });
      34           50 :     }
      35              : 
      36              :     CreateCtxFunc GetCreateFunc(CcuInstType ccuInstType) const;
      37              : 
      38              : private:
      39              :     std::unordered_map<CcuInstType, CreateCtxFunc, std::EnumClassHash> creators;
      40              : };
      41              : 
      42              : template <typename T> class CcuInstRegister {
      43              : public:
      44           48 :     explicit CcuInstRegister(CcuInstType ccuInstType)
      45              :     {
      46           48 :         CcuCtxCreatorRegistry::GetInstance().Register<T>(ccuInstType);
      47           48 :     }
      48              : };
      49              : 
      50              : } // namespace Hccl
      51              : 
      52              : #endif // CCU_CTX_CREATOR_REGISTRY_H
        

Generated by: LCOV version 2.0-1