paths.h 1.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#pragma once

#include <vector>
#include <queue>
#include <unordered_map>
#include <cstring> // 为了使用strlen

#include "base.h"
#include "graph_utils.h"

namespace sccl {
namespace hardware {
namespace topology {
namespace graph {

class PathFinder {
public:
    // 构造函数
    PathFinder(const BootstrapComm_t* bootstrap_comm);

21
22
    // 计算拓扑图中GPU节点之间的点对点映射
    scclResult_t computeTopoGpuP2pMap(scclTopoGraph_t* graph);
23
24
25
26
27

    // 打印函数
    void printGpuPaths();

private:
28
29
    // 获取所有GPU到GPU的路径函数
    void findGpuPaths();
30

31
    // 使用广度优先搜索(BFS)查找从起始GPU节点到其他GPU节点的最短路径
32
33
34
35
36
    void bfsFindGpuPaths(uint64_t start_node_id);

    // 根据node.id查找节点的函数
    const scclTopoNode_t* findNodeById(uint64_t id) const;

37
38
39
40
41
42
43
44
45
46
47
    // 根据path中node确定link的类型
    scclResult_t determineLinkType(const std::vector<uint64_t>& path, LinkType_t* link_type);

private:
    ByteSpanArray<scclTopoNode_t> node_container_; // 使用NodeContainer来存储nodes数据

    std::unordered_map<uint64_t, std::vector<uint64_t>> graph_node_neighbors_;   // 使用无序映射存储图的节点和它们的邻居
    std::unordered_map<uint64_t, std::vector<std::vector<uint64_t>>> gpu_paths_; // 使用无序映射存储从每个GPU节点到其他GPU节点的所有路径
    // 存储node.id到nodes_span索引的映射
    std::unordered_map<uint64_t, size_t> id_to_index_;

48
49
50
51
52
53
54
55
56
57
58
59
    int rank        = -1; // 当前节点的全局排名
    int nRanks      = 0;  // 总的节点数量
    int localRank   = -1; // 当前节点在本地计算节点中的排名
    int nLocalRanks = 0;  // 本地计算节点中的节点总数
    int interRank   = -1; // 整个节点在全部节点中的位置
    int nInterRanks = 0;  // 全局拥有节点的个数
};

} // namespace graph
} // namespace topology
} // namespace hardware
} // namespace sccl