LCOV - code coverage report
Current view: top level - legacy/ascend910/algorithm/base/communicator - search_path.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.4 % 38 37
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 2 2

            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              : #ifndef SEARCH_PATH_H
      11              : #define SEARCH_PATH_H
      12              : 
      13              : class SearchPath {
      14              : public:
      15          759 :     std::vector<u32> Search(const std::vector<u32> &nicList, bool isDoubleRingMap = false)
      16              :     {
      17          759 :         if (isDoubleRingMap && nicList.size() <= 1) {    // 单卡不满足doubleRing
      18          469 :             return {};
      19              :         }
      20          290 :         if (nicList.size() == 0 || nicList.size() == 1) {
      21            0 :             return nicList;
      22              :         }
      23              : 
      24          290 :         result_.clear();
      25          290 :         std::vector<bool> arrived(nicList.size(), 0);
      26          290 :         nicSet_.clear();
      27         1486 :         for (auto i : nicList) {
      28         1196 :             nicSet_.insert(i);
      29              :         }
      30              : 
      31          291 :         if (dfs(nicList, arrived, 0, nicList[0], isDoubleRingMap)) {
      32          285 :             return result_;
      33              :         } else {
      34            5 :             return {};
      35              :         }
      36          290 :     }
      37              : 
      38              : private:
      39         1201 :     bool dfs(const std::vector<u32> &nicList, std::vector<bool> &arrived, u32 idx, u32 nowNicIdx, bool isDoubleRingMap)
      40              :     {
      41         1201 :         std::map<int, std::vector<u32>> reachableMap = isDoubleRingMap ? reachableDoubleRing_ : reachableRank_;
      42              :         // the last nic, it must reachable to result_[0]
      43         1202 :         if (idx == nicList.size() - 1) {
      44         1442 :             for (auto i : reachableMap[nowNicIdx]) {
      45         1438 :                 if (i == result_[0]) {
      46          285 :                     result_.push_back(nowNicIdx);
      47          285 :                     std::string valueStr = "";
      48         1471 :                     for (auto j : result_) {
      49         1186 :                         valueStr.append(std::to_string(j));
      50              :                     }
      51          285 :                     HCCL_INFO("find path success: %s",valueStr.c_str());
      52          284 :                     return true;
      53          284 :                 }
      54              :             }
      55              : 
      56            4 :             return false;
      57              :         }
      58              : 
      59          912 :         arrived[nowNicIdx] = true;
      60          913 :         result_.push_back(nowNicIdx);
      61              : 
      62         1169 :         for (auto i : reachableMap[nowNicIdx]) {
      63         1158 :             if (nicSet_.count(i) == 0 || arrived[i]) {
      64          246 :                 continue;
      65              :             }
      66              : 
      67          912 :             if (dfs(nicList, arrived, idx + 1, i, isDoubleRingMap)) {
      68          900 :                 return true;
      69              :             }
      70              :         }
      71              : 
      72           12 :         arrived[nowNicIdx] = false;
      73           12 :         result_.pop_back();
      74           12 :         return false;
      75         1201 :     }
      76              : 
      77              :     std::vector<u32> result_;
      78              :     std::set<u32> nicSet_;
      79              :     // 适配910_93设备双轨组网,可通过SIO串联
      80              :     std::map<int, std::vector<u32>> reachableRank_ = {
      81              :     {0, {1, 2, 4, 6, 8, 10, 12, 14}},
      82              :     {1, {0, 3, 5, 7, 9, 11, 13, 15}},
      83              :     {2, {3, 4, 6, 8, 10, 12, 14, 0}},
      84              :     {3, {2, 5, 7, 9, 11, 13, 15, 1}},
      85              :     {4, {5, 6, 8, 10, 12, 14, 0, 2}},
      86              :     {5, {4, 7, 9, 11, 13, 15, 1, 3}},
      87              :     {6, {7, 8, 10, 12, 14, 0, 2, 4}},
      88              :     {7, {6, 9, 11, 13, 15, 1, 3, 5}},
      89              :     {8, {9, 10, 12, 14, 0, 2, 4, 6}},
      90              :     {9, {8, 11, 13, 15, 1, 3, 5, 7}},
      91              :     {10, {11, 12, 14, 0, 2, 4, 6, 8}},
      92              :     {11, {10, 13, 15, 1, 3, 5, 7, 9}},
      93              :     {12, {13, 14, 0, 2, 4, 6, 8, 10}},
      94              :     {13, {12, 15, 1, 3, 5, 7, 9, 11}},
      95              :     {14, {15, 0, 2, 4, 6, 8, 10, 12}},
      96              :     {15, {14, 1, 3, 5, 7, 9, 11, 13}}};
      97              : 
      98              :     std::map<int, std::vector<u32>> reachableDoubleRing_ = {
      99              :     {0, {1}},
     100              :     {1, {0, 2, 4, 6, 8, 10, 12, 14}},
     101              :     {2, {3}},
     102              :     {3, {4, 6, 8, 10, 12, 14, 0, 2}},
     103              :     {4, {5}},
     104              :     {5, {6, 8, 10, 12, 14, 0, 2, 4}},
     105              :     {6, {7}},
     106              :     {7, {8, 10, 12, 14, 0, 2, 4, 6}},
     107              :     {8, {9}},
     108              :     {9, {10, 12, 14, 0, 2, 4, 6, 8}},
     109              :     {10, {11}},
     110              :     {11, {12, 14, 0, 2, 4, 6, 8, 10}},
     111              :     {12, {13}},
     112              :     {13, {14, 0, 2, 4, 6, 8, 10, 12}},
     113              :     {14, {15}},
     114              :     {15, {0, 2, 4, 6, 8, 10, 12,14}}};
     115              : };
     116              : #endif
        

Generated by: LCOV version 2.0-1