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
191 lines (165 loc) · 3.98 KB
/
device.cpp
File metadata and controls
191 lines (165 loc) · 3.98 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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*******************************************************
* Copyright (c) 2014, 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/dim4.hpp>
#include <af/device.h>
#include <af/version.h>
#include <af/backend.h>
#include <backend.hpp>
#include <platform.hpp>
#include <Array.hpp>
#include <handle.hpp>
#include "err_common.hpp"
#include <cstring>
using namespace detail;
af_err af_set_backend(const af_backend bknd)
{
try {
ARG_ASSERT(0, bknd==getBackend());
}
CATCHALL;
return AF_SUCCESS;
}
af_err af_get_backend_count(unsigned* num_backends)
{
*num_backends = 1;
return AF_SUCCESS;
}
af_err af_get_available_backends(int* result)
{
try {
*result = getBackend();
} CATCHALL;
return AF_SUCCESS;
}
af_err af_get_backend_id(af_backend *result, const af_array in)
{
try {
ARG_ASSERT(1, in != 0);
ArrayInfo info = getInfo(in, false);
*result = info.getBackendId();
} CATCHALL;
return AF_SUCCESS;
}
af_err af_get_device_id(int *device, const af_array in)
{
try {
ARG_ASSERT(1, in != 0);
ArrayInfo info = getInfo(in, false);
*device = info.getDevId();
} CATCHALL;
return AF_SUCCESS;
}
af_err af_get_active_backend(af_backend *result)
{
*result = (af_backend)getBackend();
return AF_SUCCESS;
}
af_err af_init()
{
try {
static bool first = true;
if(first) {
getDeviceInfo();
first = false;
}
} CATCHALL;
return AF_SUCCESS;
}
af_err af_info()
{
try {
printf("%s", getDeviceInfo().c_str());
} CATCHALL;
return AF_SUCCESS;
}
af_err af_info_string(char **str, const bool verbose)
{
try {
std::string infoStr = getDeviceInfo();
af_alloc_host((void**)str, sizeof(char) * (infoStr.size() + 1));
// Need to do a deep copy
// str.c_str wont cut it
infoStr.copy(*str, infoStr.size());
(*str)[infoStr.size()] = '\0';
} CATCHALL;
return AF_SUCCESS;
}
af_err af_device_info(char* d_name, char* d_platform, char *d_toolkit, char* d_compute)
{
try {
devprop(d_name, d_platform, d_toolkit, d_compute);
} CATCHALL;
return AF_SUCCESS;
}
af_err af_get_dbl_support(bool* available, const int device)
{
try {
*available = isDoubleSupported(device);
} CATCHALL;
return AF_SUCCESS;
}
af_err af_get_device_count(int *nDevices)
{
try {
*nDevices = getDeviceCount();
} CATCHALL;
return AF_SUCCESS;
}
af_err af_get_device(int *device)
{
try {
*device = getActiveDeviceId();
} CATCHALL;
return AF_SUCCESS;
}
af_err af_set_device(const int device)
{
try {
ARG_ASSERT(0, device >= 0);
ARG_ASSERT(0, setDevice(device) >= 0);
} CATCHALL;
return AF_SUCCESS;
}
af_err af_sync(const int device)
{
try {
int dev = device == -1 ? getActiveDeviceId() : device;
detail::sync(dev);
} CATCHALL;
return AF_SUCCESS;
}
template<typename T>
static inline void eval(af_array arr)
{
getArray<T>(arr).eval();
return;
}
af_err af_eval(af_array arr)
{
try {
af_dtype type = getInfo(arr).getType();
switch (type) {
case f32: eval<float >(arr); break;
case f64: eval<double >(arr); break;
case c32: eval<cfloat >(arr); break;
case c64: eval<cdouble>(arr); break;
case s32: eval<int >(arr); break;
case u32: eval<uint >(arr); break;
case u8 : eval<uchar >(arr); break;
case b8 : eval<char >(arr); break;
case s64: eval<intl >(arr); break;
case u64: eval<uintl >(arr); break;
case s16: eval<short >(arr); break;
case u16: eval<ushort >(arr); break;
default:
TYPE_ERROR(0, type);
}
} CATCHALL;
return AF_SUCCESS;
}