hardware.cpp 2.33 KB
Newer Older
1
2
3
4
5
6
7
#include <stdint.h>
#include <hip/hip_runtime.h>
#include <hip/hip_runtime_api.h>

#include "base.h"
#include "hardware_utils.h"
#include "bootstrap.h"
8
9
#include "graph.h"
#include "hardware.h"
10
11
12
13
14

namespace sccl {
namespace hardware {

// 全局变量,全部节点的信息
15
sccl::hardware::topology::bootstrap::BootstrapComm_t bootstrap_comm;
16
17
18
19

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
scclResult_t scclGetUniqueId(scclUniqueId* unique_id) {
20
21
22
    auto handle = reinterpret_cast<BootstrapHandle_t*>(unique_id);
    NEQCHECK(sizeof(BootstrapHandle_t), SCCL_UNIQUE_ID_BYTES);
    SCCLCHECK(topology::bootstrap::bootstrapGetUniqueId(handle));
23
24
25
26
27
    return scclSuccess;
}

scclResult_t sccl_init(const scclUniqueId* unique_id, int rank, int nRanks) {
    // -------------------------- 1.获取0号rank的地址信息 ----------------------------------- //
28
    auto root_handle = reinterpret_cast<const BootstrapHandle_t*>(unique_id);
29
30
31
    EQCHECK(root_handle->magic, 0); // 检查handle是否已经更新

    // -------------------------- 2.初始化获取所有节点的node信息 ----------------------------------- //
32
    auto sccl_bootstrap = std::make_unique<topology::bootstrap::Bootstrap>(root_handle, rank, nRanks);
33
34
    SCCLCHECK(sccl_bootstrap->init(&bootstrap_comm));

35
36
37
38
39
40
    // -------------------------- 3.MPI 建图 ----------------------------------- //
    auto sccl_graph = std::make_unique<topology::graph::Graph>(rank, nRanks);
    printf("init pos 2\n");
    // 计算通信路径
    sccl_graph->calculateCommunicationPaths(&bootstrap_comm);
    printf("init pos 3\n");
41
42
43
44
45
46
47
48
49
50
51
52

    // // -------------------------- 3.MPI allgather设置unique_id的整合 ----------------------------------- //

    // -------------------------- 5.根据各个节点的基础信息计算topo结果 ----------------------------------- //

    return scclSuccess;
}

scclResult_t sccl_finalize() {
    // 设置一些全局变量的重置和销毁
    // 设置socket等硬件监听的关闭
    // void BootstrapComm::destroy() {
53
54
55
    // if(bootstrap_comm.nRanks > 0) {
    //     bootstrap_comm.destroy();
    // }
56
57
58
59
60
61

    return scclSuccess;
}

} // namespace hardware
} // namespace sccl