LCOV - code coverage report
Current view: top level - legacy/ascend950/service/collective/alg/alg_registry - ins_coll_alg_registry.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 2 0
Test Date: 2026-07-28 12:11:00 Functions: 0.0 % 119 0

            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 HCCLV2_INS_COLL_ALG_REGISTRY
      12              : #define HCCLV2_INS_COLL_ALG_REGISTRY
      13              : 
      14              : #include <mutex>
      15              : #include <functional>
      16              : #include "ins_coll_alg_base.h"
      17              : #include "log.h"
      18              : 
      19              : namespace Hccl {
      20              : 
      21              : using InsCollAlgCreator = std::function<InsCollAlgBase *()>;
      22            0 : template <typename P> static InsCollAlgBase *DefaultCreator()
      23              : {
      24              :     static_assert(std::is_base_of<InsCollAlgBase, P>::value, "InsCollAlg type must derived from Hccl::InsCollAlgBase");
      25            0 :     return new (std::nothrow) P;
      26              : }
      27              : 
      28              : class InsCollAlgRegistry {
      29              : public:
      30              :     static InsCollAlgRegistry *Global();
      31              :     HcclResult Register(const OpType type, const std::string &funcName, const InsCollAlgCreator &collAlgCreator);
      32              :     void       PrintAllImpls();
      33              :     std::shared_ptr<InsCollAlgBase>            GetAlgImpl(const OpType type, const std::string &funcName);
      34              :     std::map<OpType, std::vector<std::string>> GetAvailAlgs();
      35              : 
      36              : private:
      37              :     std::map<OpType, std::map<std::string, const InsCollAlgCreator>> impls_;
      38              :     mutable std::mutex                                               mu_;
      39              : };
      40              : 
      41              : #define INS_REGISTER_IMPL_HELPER(ctr, type, name, insCollAlgBase)                                                      \
      42              :     static HcclResult g_func_##name##_##ctr                                                                            \
      43              :         = InsCollAlgRegistry::Global()->Register(type, std::string(#name), DefaultCreator<insCollAlgBase>)
      44              : 
      45              : #define INS_REGISTER_IMPL_HELPER_1(ctr, type, name, insCollAlgBase)                                                    \
      46              :     INS_REGISTER_IMPL_HELPER(ctr, type, name, insCollAlgBase)
      47              : 
      48              : #define INS_REGISTER_IMPL(type, name, insCollAlgBase)                                                                  \
      49              :     INS_REGISTER_IMPL_HELPER_1(__COUNTER__, type, name, insCollAlgBase)
      50              : 
      51              : #define INS_REGISTER_IMPL_BY_TEMP_HELPER(ctr, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate)                \
      52              :     static HcclResult g_func_##name##_##ctr = InsCollAlgRegistry::Global()->Register(                                  \
      53              :         type, std::string(#name), DefaultCreator<insCollAlgBase<AlgTopoMatch, InsAlgTemplate>>)
      54              : 
      55              : #define INS_REGISTER_IMPL_BY_TEMP_HELPER_1(ctr, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate)              \
      56              :     INS_REGISTER_IMPL_BY_TEMP_HELPER(ctr, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate)
      57              : 
      58              : #define INS_REGISTER_IMPL_BY_TEMP(type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate)                            \
      59              :     INS_REGISTER_IMPL_BY_TEMP_HELPER_1(__COUNTER__, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate)
      60              : 
      61              : #define INS_REGISTER_IMPL_BY_TWO_TEMPS_HELPER(ctr, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1)    \
      62              :     static HcclResult g_func_##name##_##ctr = InsCollAlgRegistry::Global()->Register(                                     \
      63              :         type, std::string(#name), DefaultCreator<insCollAlgBase<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1>>)
      64              : 
      65              : #define INS_REGISTER_IMPL_BY_TWO_TEMPS_HELPER_1(ctr, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1)  \
      66              :     INS_REGISTER_IMPL_BY_TWO_TEMPS_HELPER(ctr, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1)
      67              : 
      68              : #define INS_REGISTER_IMPL_BY_TWO_TEMPS(type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1)              \
      69              :     INS_REGISTER_IMPL_BY_TWO_TEMPS_HELPER_1(__COUNTER__, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate0,             \
      70              :         InsAlgTemplate1)
      71              : 
      72              : #define INS_REGISTER_IMPL_BY_FOUR_TEMPS_HELPER(ctr, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1, InsAlgTemplate2, InsAlgTemplate3)    \
      73              :              static HcclResult g_func_##name##_##ctr = InsCollAlgRegistry::Global()->Register(                                     \
      74              :                  type, std::string(#name), DefaultCreator<insCollAlgBase<AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1, InsAlgTemplate2, InsAlgTemplate3>>)
      75              : 
      76              : #define INS_REGISTER_IMPL_BY_FOUR_TEMPS_HELPER_1(ctr, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1, InsAlgTemplate2, InsAlgTemplate3)  \
      77              :     INS_REGISTER_IMPL_BY_FOUR_TEMPS_HELPER(ctr, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1, InsAlgTemplate2, InsAlgTemplate3)
      78              : 
      79              : #define INS_REGISTER_IMPL_BY_FOUR_TEMPS(type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate0, InsAlgTemplate1, InsAlgTemplate2, InsAlgTemplate3)              \
      80              :     INS_REGISTER_IMPL_BY_FOUR_TEMPS_HELPER_1(__COUNTER__, type, name, insCollAlgBase, AlgTopoMatch, InsAlgTemplate0,             \
      81              :         InsAlgTemplate1, InsAlgTemplate2, InsAlgTemplate3)
      82              : 
      83              : #define INS_REGISTER_IMPL_BY_TOPO_HELPER(ctr, type, name, insCollAlgBase, AlgTopoMatch)                \
      84              :     static HcclResult g_func_##name##_##ctr = InsCollAlgRegistry::Global()->Register(                                  \
      85              :         type, std::string(#name), DefaultCreator<insCollAlgBase<AlgTopoMatch>>)
      86              : 
      87              : #define INS_REGISTER_IMPL_BY_TOPO_HELPER_1(ctr, type, name, insCollAlgBase, AlgTopoMatch)                              \
      88              :     INS_REGISTER_IMPL_BY_TOPO_HELPER(ctr, type, name, insCollAlgBase, AlgTopoMatch)
      89              : 
      90              : #define INS_REGISTER_IMPL_BY_TOPO(type, name, insCollAlgBase, AlgTopoMatch)                                            \
      91              :     INS_REGISTER_IMPL_BY_TOPO_HELPER_1(__COUNTER__, type, name, insCollAlgBase, AlgTopoMatch)
      92              : 
      93              : } // namespace Hccl
      94              : 
      95              : #endif
        

Generated by: LCOV version 2.0-1