LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/base/alg_template - alg_template_register.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-08-04 10:52:23 Functions: 25.2 % 103 26

            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              : #pragma once
      12              : 
      13              : #include <vector>
      14              : #include <functional>
      15              : #include <memory>
      16              : 
      17              : #include "alg_template_base_pub.h"
      18              : 
      19              : namespace hccl {
      20              : 
      21              : using AlgTemplateCreator = std::function<AlgTemplateBase *(const HcclDispatcher)>;
      22              : 
      23              : template <typename P>
      24          179 : static AlgTemplateBase *DefaultTemplateCreator(const HcclDispatcher dispatcher)
      25              : {
      26              :     static_assert(std::is_base_of<AlgTemplateBase, P>::value,
      27              :         "Template type must derived from Hccl::AlgTemplateBase");
      28          179 :     return new (std::nothrow) P(dispatcher);
      29              : }
      30              : 
      31              : class AlgTemplateRegistry {
      32              : public:
      33              :     static AlgTemplateRegistry &Instance();
      34              :     AlgTemplateRegistry();
      35              :     HcclResult Register(const TemplateType type, const AlgTemplateCreator &algTemplateCreator);
      36              :     std::unique_ptr<AlgTemplateBase> GetAlgTemplate(const TemplateType type,
      37              :         const HcclDispatcher dispatcher);
      38              : 
      39              : private:
      40              :     std::vector<AlgTemplateCreator> tempCreators_;
      41              :     mutable std::mutex mu_;
      42              : };
      43              : 
      44              : #define REGISTER_TEMPLATE_HELPER(ctr, type, algTempBase)       \
      45              :     static HcclResult g_func_##algTempBase##_##ctr             \
      46              :         = AlgTemplateRegistry::Instance().Register(type, DefaultTemplateCreator<algTempBase>)
      47              : 
      48              : #define REGISTER_TEMPLATE(type, algTempBase) REGISTER_TEMPLATE_HELPER(__COUNTER__, type, algTempBase)
      49              : 
      50              : }   // namespace hccl
        

Generated by: LCOV version 2.0-1