bootstrap.h 2.46 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

    // 广播节点信息
32
    scclResult_t bootstrapAllGather(struct scclNodeInfo*);
33
34

private:
35
36
37
    // 创建根节点的数据广播
    scclResult_t bootstrapRootGatherAndBroadcast(void* send_data, void* recv_data);

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

41
    // scclResult_t bootstrapGetAllNodes(const struct scclNodeInfo* , struct BootstrapComm* comm);
42
43

private:
44
45
46
47
48
49
    int rank, nRanks;             // 初始化阶段获取MPI的值
    int localRank, nLocalRanks;   // 通过bootstrapRootGatherAndBroadcast函数确定值
    volatile uint32_t* abortFlag; // 中止标志,非阻塞套接字设置

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

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

57
58
59
60
61
62
    // 标志是否已经初始化
    // 线程池变量
    int max_pthreads               = 0;       // 用于存储最大并行线程数的整型变量
    class ThreadPool* pthread_pool = nullptr; // 指向ThreadPool类实例的指针,初始值为nullptr
    scclIpcSocket_t* ipcsocket     = nullptr; // 指向scclIpcSocket类实例的指针,初始值为nullptr
    scclSocket_t* my_listen_sock   = nullptr; // 指向scclSocket类实例的指针,初始值为nullptr
63
64
};

lishen's avatar
lishen committed
65
66
67
68
} // namespace bootstrap
} // namespace topology
} // namespace hardware
} // namespace sccl