handle.cc 1.98 KB
Newer Older
PanZezhongQY's avatar
PanZezhongQY committed
1
2
3
4
5
6
7
8
9
10
#include "infiniop/handle.h"
#ifdef ENABLE_CPU_API
#include "./cpu/cpu_handle.h"
#endif
#ifdef ENABLE_CUDA_API
#include "./cuda/cuda_handle.h"
#endif
#ifdef ENABLE_CAMBRICON_MLU
#include "./bang/bang_handle.h"
#endif
Pan Zezhong's avatar
Pan Zezhong committed
11
#ifdef ENABLE_ASCEND_API
PanZezhongQY's avatar
PanZezhongQY committed
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "./ascend/ascend_handle.h"
#endif


__C infiniopStatus_t infiniopCreateHandle(infiniopHandle_t *handle_ptr, infiniDevice_t device, int device_id) {
    if (handle_ptr == nullptr) {
        return INFINIOP_STATUS_NULL_POINTER;
    }
    if (device_id < 0) {
        return INFINIOP_STATUS_BAD_DEVICE;
    }

    switch (device) {
#ifdef ENABLE_CPU_API
        case INFINI_DEVICE_CPU:
            return createCpuHandle((infiniopCpuHandle_t *) handle_ptr);
#endif
#ifdef ENABLE_CUDA_API
        case INFINI_DEVICE_NVIDIA: {
            return createCudaHandle((infiniopCudaHandle_t *) handle_ptr, device_id, device);
        }
#endif
#ifdef ENABLE_CAMBRICON_API
        case DevCambriconMlu: {
            return createBangHandle((infiniopBangHandle_t *) handle_ptr, device_id);
        }
#endif
#ifdef ENABLE_ASCEND_API
Pan Zezhong's avatar
Pan Zezhong committed
40
        case INFINI_DEVICE_ASCEND: {
PanZezhongQY's avatar
PanZezhongQY committed
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
            return createAscendHandle((infiniopAscendHandle_t *) handle_ptr, device_id);
        }
#endif
    }
    return INFINIOP_STATUS_DEVICE_TYPE_NOT_SUPPORTED;
}


__C infiniopStatus_t infiniopDestroyHandle(infiniopHandle_t handle) {
    switch (handle->device) {
#ifdef ENABLE_CPU_API
        case INFINI_DEVICE_CPU:
            delete handle;
            return INFINIOP_STATUS_SUCCESS;
#endif
#ifdef ENABLE_CUDA_API
        case INFINI_DEVICE_NVIDIA: {
            return deleteCudaHandle((infiniopCudaHandle_t) handle);
        }
#endif
#ifdef ENABLE_CAMBRICON_MLU
        case DevCambriconMlu: {
            delete (infiniopBangHandle_t) handle;
            return STATUS_SUCCESS;
        }
#endif
Pan Zezhong's avatar
Pan Zezhong committed
67
68
#ifdef ENABLE_ASCEND_API
        case INFINI_DEVICE_ASCEND: {
PanZezhongQY's avatar
PanZezhongQY committed
69
70
71
72
73
74
            return deleteAscendHandle((infiniopAscendHandle_t) handle);
        }
#endif
    }
    return INFINIOP_STATUS_DEVICE_TYPE_NOT_SUPPORTED;
}