bootstrap.h 2.35 KB
Newer Older
lishen's avatar
lishen committed
1
2
3
4
#pragma once

#include <string.h>
#include "base.h"
5
6
7
8
#include "socket.h"
#include "bootstrap_utils.h"
#include "bootstrap_net.h"
#include "thread_pool.h"
9
#include "ipc_socket.h"
lishen's avatar
lishen committed
10
11
12
13
14
15

namespace sccl {
namespace hardware {
namespace topology {
namespace bootstrap {

16
17
18
19
20
21
22
23
typedef class sccl::hardware::net::ipc_socket::scclIpcSocket scclIpcSocket_t;

///////////////////////////////////// 用于初始化时的功能函数 //////////////////////////////////////////
scclResult_t bootstrapGetUniqueId(struct BootstrapHandle* handle);
scclResult_t bootstrapCreateRoot(struct BootstrapHandle* handle);

///////////////////////////////////// 用于初始化时的类 //////////////////////////////////////////
class Bootstrap {
24
public:
25
26
    Bootstrap(const struct BootstrapHandle*, int rank, int nRanks);
    ~Bootstrap();
27
28

    // 初始化bootstrap通信环境
29
    scclResult_t init(struct BootstrapComm* bootstrap_comm);
30
31

private:
32
    // 创建根节点的数据广播
33
    scclResult_t bootstrapRootGatherAndBroadcast(struct BootstrapNodeBasic* send_data_basic, std::vector<struct BootstrapNodeBasic>& recv_data_basic);
34

35
    // 初始化唯一ID信息结构体
36
    scclResult_t bootstrapCommInitNodeInfo(scclNet_t* scclNet, struct scclNodeInfo* node_info);
37

38
39
40
    // 广播节点信息
    scclResult_t
    bootstrapCommAllGather(std::vector<struct BootstrapNodeBasic>& all_node_basic, struct scclNodeInfo* node_info, struct scclNodeInfoSet* node_info_set);
41
42

private:
43
44
45
46
47
    int rank, nRanks;           // 初始化阶段获取MPI的值
    int localRank, nLocalRanks; // 通过bootstrapRootGatherAndBroadcast函数确定值
    int interRank, nInterRanks; // 整个节点在全部节点中的位置

    // TODO: 用于控制套接字终端的变量,目前不知道在哪里使用
48
49
50
51
    volatile uint32_t* abortFlag; // 中止标志,非阻塞套接字设置

    // 外部传入的0号节点的基础信息
    const struct BootstrapHandle* root_handle;
52

53
54
55
56
57
    // 初始化标志
    bool socketInitDone;
    // 互斥锁,用于保护初始化过程的线程安全
    pthread_mutex_t bootstrapMutex = PTHREAD_MUTEX_INITIALIZER;
    pthread_cond_t bootstrapCond   = PTHREAD_COND_INITIALIZER;
58

59
60
    // 节点内通信的类
    scclIpcSocket_t* ipcsocket = nullptr; // 指向scclIpcSocket类实例的指针,初始值为nullptr
61
62
};

lishen's avatar
lishen committed
63
64
65
66
} // namespace bootstrap
} // namespace topology
} // namespace hardware
} // namespace sccl