infiniccl.cc 2.53 KB
Newer Older
1
2
#include "infiniccl.h"

Pan Zezhong's avatar
Pan Zezhong committed
3
#include "./ascend/infiniccl_ascend.h"
wooway777's avatar
wooway777 committed
4
#include "./cambricon/infiniccl_cambricon.h"
5
#include "./cuda/infiniccl_cuda.h"
6
#include "./metax/infiniccl_metax.h"
spike-zhu's avatar
spike-zhu committed
7
#include "./moore/infiniccl_moore.h"
8
9
10
11
12
13
14
15
16

__C infiniStatus_t infinicclCommInitAll(
    infiniDevice_t device_type,
    infinicclComm_t *comms,
    int ndevice,
    const int *device_ids) {

#define COMM_INIT_ALL(CASE_, NAMESPACE_) \
    case CASE_:                          \
YdrMaster's avatar
YdrMaster committed
17
        return infiniccl::NAMESPACE_::commInitAll(comms, ndevice, device_ids)
18
19

    switch (device_type) {
YdrMaster's avatar
YdrMaster committed
20
21
22
        COMM_INIT_ALL(INFINI_DEVICE_NVIDIA, cuda);
        COMM_INIT_ALL(INFINI_DEVICE_ILUVATAR, cuda);
        COMM_INIT_ALL(INFINI_DEVICE_ASCEND, ascend);
23
        COMM_INIT_ALL(INFINI_DEVICE_CAMBRICON, cambricon);
YdrMaster's avatar
YdrMaster committed
24
        COMM_INIT_ALL(INFINI_DEVICE_METAX, metax);
spike-zhu's avatar
spike-zhu committed
25
        COMM_INIT_ALL(INFINI_DEVICE_MOORE, moore);
26
27
28
29
30
31
32
33
34
35
36
37
38
39
    default:
        return INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED;
    }

#undef COMM_INIT_ALL
}

__C infiniStatus_t infinicclCommDestroy(infinicclComm_t comm) {
    if (comm == nullptr) {
        return INFINI_STATUS_SUCCESS;
    }

#define COMM_DESTROY(CASE_, NAMESPACE_) \
    case CASE_:                         \
YdrMaster's avatar
YdrMaster committed
40
        return infiniccl::NAMESPACE_::commDestroy(comm)
41
42

    switch (comm->device_type) {
YdrMaster's avatar
YdrMaster committed
43
44
45
        COMM_DESTROY(INFINI_DEVICE_NVIDIA, cuda);
        COMM_DESTROY(INFINI_DEVICE_ILUVATAR, cuda);
        COMM_DESTROY(INFINI_DEVICE_ASCEND, ascend);
46
        COMM_DESTROY(INFINI_DEVICE_CAMBRICON, cambricon);
YdrMaster's avatar
YdrMaster committed
47
        COMM_DESTROY(INFINI_DEVICE_METAX, metax);
spike-zhu's avatar
spike-zhu committed
48
        COMM_DESTROY(INFINI_DEVICE_MOORE, moore);
PanZezhong's avatar
PanZezhong committed
49

50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
    default:
        return INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED;
    }
#undef COMM_DESTROY
}

__C infiniStatus_t infinicclAllReduce(
    void *sendbuf,
    void *recvbuf,
    size_t count,
    infiniDtype_t dataype,
    infinicclReduceOp_t op,
    infinicclComm_t comm,
    infinirtStream_t stream) {

    if (comm == nullptr) {
        return INFINI_STATUS_NULL_POINTER;
    }

#define ALL_REDUCE(CASE_, NAMESPACE_) \
    case CASE_:                       \
YdrMaster's avatar
YdrMaster committed
71
        return infiniccl::NAMESPACE_::allReduce(sendbuf, recvbuf, count, dataype, op, comm, stream)
72
73

    switch (comm->device_type) {
YdrMaster's avatar
YdrMaster committed
74
75
76
        ALL_REDUCE(INFINI_DEVICE_NVIDIA, cuda);
        ALL_REDUCE(INFINI_DEVICE_ILUVATAR, cuda);
        ALL_REDUCE(INFINI_DEVICE_ASCEND, ascend);
77
        ALL_REDUCE(INFINI_DEVICE_CAMBRICON, cambricon);
YdrMaster's avatar
YdrMaster committed
78
        ALL_REDUCE(INFINI_DEVICE_METAX, metax);
spike-zhu's avatar
spike-zhu committed
79
        ALL_REDUCE(INFINI_DEVICE_MOORE, moore);
PanZezhong's avatar
PanZezhong committed
80

81
82
83
84
85
86
    default:
        return INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED;
    }

#undef ALL_REDUCE
}