infiniccl.cc 2.19 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"
PanZezhong's avatar
PanZezhong committed
6
#include "./maca/infiniccl_maca.h"
7
8
9
10
11
12
13
14
15
16
17
18
19

__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_:                          \
        return infiniccl::NAMESPACE_::commInitAll(comms, ndevice, device_ids);

    switch (device_type) {
        COMM_INIT_ALL(INFINI_DEVICE_NVIDIA, cuda)
Pan Zezhong's avatar
Pan Zezhong committed
20
        COMM_INIT_ALL(INFINI_DEVICE_ASCEND, ascend)
wooway777's avatar
wooway777 committed
21
        COMM_INIT_ALL(INFINI_DEVICE_CAMBRICON, cambricon)
PanZezhong's avatar
PanZezhong committed
22
        COMM_INIT_ALL(INFINI_DEVICE_METAX, maca)
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
    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_:                         \
        return infiniccl::NAMESPACE_::commDestroy(comm);

    switch (comm->device_type) {
        COMM_DESTROY(INFINI_DEVICE_NVIDIA, cuda)
Pan Zezhong's avatar
Pan Zezhong committed
41
        COMM_DESTROY(INFINI_DEVICE_ASCEND, ascend)
wooway777's avatar
wooway777 committed
42
        COMM_DESTROY(INFINI_DEVICE_CAMBRICON, cambricon)
PanZezhong's avatar
PanZezhong committed
43
44
        COMM_DESTROY(INFINI_DEVICE_METAX, maca)

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
    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_:                       \
        return infiniccl::NAMESPACE_::allReduce(sendbuf, recvbuf, count, dataype, op, comm, stream);

    switch (comm->device_type) {
        ALL_REDUCE(INFINI_DEVICE_NVIDIA, cuda)
Pan Zezhong's avatar
Pan Zezhong committed
70
        ALL_REDUCE(INFINI_DEVICE_ASCEND, ascend)
wooway777's avatar
wooway777 committed
71
        ALL_REDUCE(INFINI_DEVICE_CAMBRICON, cambricon)
PanZezhong's avatar
PanZezhong committed
72
73
        ALL_REDUCE(INFINI_DEVICE_METAX, maca)

74
75
76
77
78
79
    default:
        return INFINI_STATUS_DEVICE_TYPE_NOT_SUPPORTED;
    }

#undef ALL_REDUCE
}