handle.cc 1.96 KB
Newer Older
PanZezhongQY's avatar
PanZezhongQY committed
1
2
3
4
5
6
7
8
9
10
11
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
40
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
67
68
69
70
71
72
73
74
#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
#ifdef ENABLE_ASCEND_NPU
#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
        case DevAscendNpu: {
            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
#ifdef ENABLE_ASCEND_NPU
        case DevAscendNpu: {
            return deleteAscendHandle((infiniopAscendHandle_t) handle);
        }
#endif
    }
    return INFINIOP_STATUS_DEVICE_TYPE_NOT_SUPPORTED;
}