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
170 lines (132 loc) · 4.71 KB
/
device.cpp
File metadata and controls
170 lines (132 loc) · 4.71 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/*******************************************************
* 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::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
CALL(af_get_backend_id, result, in);
}
af_err af_get_device_id(int *device, const af_array in) {
CHECK_ARRAYS(in);
CALL(af_get_device_id, device, in);
}
af_err af_get_active_backend(af_backend *result) {
*result = unified::getActiveBackend();
return AF_SUCCESS;
}
af_err af_info() { CALL_NO_PARAMS(af_info); }
af_err af_init() { CALL_NO_PARAMS(af_init); }
af_err af_info_string(char **str, const bool verbose) {
CALL(af_info_string, str, verbose);
}
af_err af_device_info(char *d_name, char *d_platform, char *d_toolkit,
char *d_compute) {
CALL(af_device_info, d_name, d_platform, d_toolkit, d_compute);
}
af_err af_get_device_count(int *num_of_devices) {
CALL(af_get_device_count, num_of_devices);
}
af_err af_get_dbl_support(bool *available, const int device) {
CALL(af_get_dbl_support, available, device);
}
af_err af_get_half_support(bool *available, const int device) {
CALL(af_get_half_support, available, device);
}
af_err af_set_device(const int device) { CALL(af_set_device, device); }
af_err af_get_device(int *device) { CALL(af_get_device, device); }
af_err af_sync(const int device) { CALL(af_sync, device); }
af_err af_alloc_device(void **ptr, const dim_t bytes) {
CALL(af_alloc_device, ptr, bytes);
}
af_err af_alloc_pinned(void **ptr, const dim_t bytes) {
CALL(af_alloc_pinned, ptr, bytes);
}
af_err af_free_device(void *ptr) { CALL(af_free_device, ptr); }
af_err af_free_pinned(void *ptr) { CALL(af_free_pinned, ptr); }
af_err af_alloc_host(void **ptr, const dim_t bytes) {
*ptr = malloc(bytes); // NOLINT(hicpp-no-malloc)
return (*ptr == NULL) ? AF_ERR_NO_MEM : AF_SUCCESS;
}
af_err af_free_host(void *ptr) {
free(ptr); // NOLINT(hicpp-no-malloc)
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) {
CALL(af_device_array, 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) {
CALL(af_device_mem_info, alloc_bytes, alloc_buffers, lock_bytes,
lock_buffers);
}
af_err af_print_mem_info(const char *msg, const int device_id) {
CALL(af_print_mem_info, msg, device_id);
}
af_err af_device_gc() { CALL_NO_PARAMS(af_device_gc); }
af_err af_set_mem_step_size(const size_t step_bytes) {
CALL(af_set_mem_step_size, step_bytes);
}
af_err af_get_mem_step_size(size_t *step_bytes) {
CALL(af_get_mem_step_size, step_bytes);
}
af_err af_lock_device_ptr(const af_array arr) {
CHECK_ARRAYS(arr);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
CALL(af_lock_device_ptr, arr);
#pragma GCC diagnostic pop
}
af_err af_unlock_device_ptr(const af_array arr) {
CHECK_ARRAYS(arr);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
CALL(af_unlock_device_ptr, arr);
#pragma GCC diagnostic pop
}
af_err af_lock_array(const af_array arr) {
CHECK_ARRAYS(arr);
CALL(af_lock_array, arr);
}
af_err af_unlock_array(const af_array arr) {
CHECK_ARRAYS(arr);
CALL(af_unlock_array, arr);
}
af_err af_is_locked_array(bool *res, const af_array arr) {
CHECK_ARRAYS(arr);
CALL(af_is_locked_array, res, arr);
}
af_err af_get_device_ptr(void **ptr, const af_array arr) {
CHECK_ARRAYS(arr);
CALL(af_get_device_ptr, ptr, arr);
}
af_err af_eval_multiple(const int num, af_array *arrays) {
for (int i = 0; i < num; i++) { CHECK_ARRAYS(arrays[i]); }
CALL(af_eval_multiple, num, arrays);
}
af_err af_set_manual_eval_flag(bool flag) {
CALL(af_set_manual_eval_flag, flag);
}
af_err af_get_manual_eval_flag(bool *flag) {
CALL(af_get_manual_eval_flag, flag);
}