forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevice.cpp
More file actions
151 lines (114 loc) · 4.05 KB
/
device.cpp
File metadata and controls
151 lines (114 loc) · 4.05 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*******************************************************
* Copyright (c) 2015, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* http://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#include <af/array.h>
#include <af/backend.h>
#include <af/device.h>
#include "symbol_manager.hpp"
af_err af_set_backend(const af_backend bknd) {
return unified::AFSymbolManager::getInstance().setBackend(bknd);
}
af_err af_get_backend_count(unsigned *num_backends) {
*num_backends = unified::AFSymbolManager::getInstance().getBackendCount();
return AF_SUCCESS;
}
af_err af_get_available_backends(int *result) {
*result = unified::AFSymbolManager::getInstance().getAvailableBackends();
return AF_SUCCESS;
}
af_err af_get_backend_id(af_backend *result, const af_array in) {
// DO NOT CALL CHECK_ARRAYS HERE.
// IT WILL RESULT IN AN INFINITE RECURSION
return CALL(result, in);
}
af_err af_get_device_id(int *device, const af_array in) {
CHECK_ARRAYS(in);
return CALL(device, in);
}
af_err af_get_active_backend(af_backend *result) {
*result = unified::AFSymbolManager::getInstance().getActiveBackend();
return AF_SUCCESS;
}
af_err af_info() { return CALL_NO_PARAMS(); }
af_err af_init() { return CALL_NO_PARAMS(); }
af_err af_info_string(char **str, const bool verbose) {
return CALL(str, verbose);
}
af_err af_device_info(char *d_name, char *d_platform, char *d_toolkit,
char *d_compute) {
return CALL(d_name, d_platform, d_toolkit, d_compute);
}
af_err af_get_device_count(int *num_of_devices) { return CALL(num_of_devices); }
af_err af_get_dbl_support(bool *available, const int device) {
return CALL(available, device);
}
af_err af_set_device(const int device) { return CALL(device); }
af_err af_get_device(int *device) { return CALL(device); }
af_err af_sync(const int device) { return CALL(device); }
af_err af_alloc_device(void **ptr, const dim_t bytes) {
return CALL(ptr, bytes);
}
af_err af_alloc_pinned(void **ptr, const dim_t bytes) {
return CALL(ptr, bytes);
}
af_err af_free_device(void *ptr) { return CALL(ptr); }
af_err af_free_pinned(void *ptr) { return CALL(ptr); }
af_err af_alloc_host(void **ptr, const dim_t bytes) {
*ptr = malloc(bytes);
return (*ptr == NULL) ? AF_ERR_NO_MEM : AF_SUCCESS;
}
af_err af_free_host(void *ptr) {
free(ptr);
return AF_SUCCESS;
}
af_err af_device_array(af_array *arr, void *data, const unsigned ndims,
const dim_t *const dims, const af_dtype type) {
return CALL(arr, data, ndims, dims, type);
}
af_err af_device_mem_info(size_t *alloc_bytes, size_t *alloc_buffers,
size_t *lock_bytes, size_t *lock_buffers) {
return CALL(alloc_bytes, alloc_buffers, lock_bytes, lock_buffers);
}
af_err af_print_mem_info(const char *msg, const int device_id) {
return CALL(msg, device_id);
}
af_err af_device_gc() { return CALL_NO_PARAMS(); }
af_err af_set_mem_step_size(const size_t step_bytes) {
return CALL(step_bytes);
}
af_err af_get_mem_step_size(size_t *step_bytes) { return CALL(step_bytes); }
af_err af_lock_device_ptr(const af_array arr) {
CHECK_ARRAYS(arr);
return CALL(arr);
}
af_err af_unlock_device_ptr(const af_array arr) {
CHECK_ARRAYS(arr);
return CALL(arr);
}
af_err af_lock_array(const af_array arr) {
CHECK_ARRAYS(arr);
return CALL(arr);
}
af_err af_unlock_array(const af_array arr) {
CHECK_ARRAYS(arr);
return CALL(arr);
}
af_err af_is_locked_array(bool *res, const af_array arr) {
CHECK_ARRAYS(arr);
return CALL(res, arr);
}
af_err af_get_device_ptr(void **ptr, const af_array arr) {
CHECK_ARRAYS(arr);
return CALL(ptr, arr);
}
af_err af_eval_multiple(const int num, af_array *arrays) {
for (int i = 0; i < num; i++) { CHECK_ARRAYS(arrays[i]); }
return CALL(num, arrays);
}
af_err af_set_manual_eval_flag(bool flag) { return CALL(flag); }
af_err af_get_manual_eval_flag(bool *flag) { return CALL(flag); }