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-18 17:47:01 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, "Template type must derived from Hccl::AlgTemplateBase");
      27          179 :     return new (std::nothrow) P(dispatcher);
      28              : }
      29              : 
      30              : class AlgTemplateRegistry {
      31              : public:
      32              :     static AlgTemplateRegistry& Instance();
      33              :     AlgTemplateRegistry();
      34              :     HcclResult Register(const TemplateType type, const AlgTemplateCreator& algTemplateCreator);
      35              :     std::unique_ptr<AlgTemplateBase> GetAlgTemplate(const TemplateType type, const HcclDispatcher dispatcher);
      36              : 
      37              : private:
      38              :     std::vector<AlgTemplateCreator> tempCreators_;
      39              :     mutable std::mutex mu_;
      40              : };
      41              : 
      42              : #define REGISTER_TEMPLATE_HELPER(ctr, type, algTempBase) \
      43              :     static HcclResult g_func_##algTempBase##_##ctr       \
      44              :         = AlgTemplateRegistry::Instance().Register(type, DefaultTemplateCreator<algTempBase>)
      45              : 
      46              : #define REGISTER_TEMPLATE(type, algTempBase) REGISTER_TEMPLATE_HELPER(__COUNTER__, type, algTempBase)
      47              : 
      48              : } // namespace hccl
        

Generated by: LCOV version 2.0-1