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
|
#include "OpenCL/cl.h"
#include "OpenCL/cl_platform.h"
#include "core/device.h"
#include "pipe/p_screen.h"
#include "pipe/p_format.h"
#include "util/u_memory.h"
#include <string>
// Device APIs
struct CLConstValue {
CLConstValue(int _id)
: id(_id)
{}
virtual void param(size_t param_value_size,
void * param_value,
size_t *param_value_size_ret)
{}
int id;
};
template <class T>
struct CLConstValueTemplate : public CLConstValue {
CLConstValueTemplate(int _id, T _value)
: CLConstValue(id), value(_value)
{}
T value;
};
const CLConstValue values[] = {
CLConstValueTemplate<std::string>(CL_DEVICE_NAME, std::string("hello")),
CLConstValueTemplate<int>(CL_DEVICE_TYPE, (int)3)
};
static void
create_gpu_device(cl_device_id * devices,
cl_uint * num_devices,
cl_uint num_entries)
{
}
static void
create_cpu_device(cl_device_id * devices,
cl_uint * num_devices,
cl_uint num_entries)
{
Device *device = Device::create(CL_DEVICE_TYPE_CPU);
devices[0] = (cl_device_id)device;
*num_devices = 1;
}
static void
create_accel_device(cl_device_id * devices,
cl_uint * num_devices,
cl_uint num_entries)
{
}
cl_int
clGetDeviceIDs(cl_device_type device_type,
cl_uint num_entries,
cl_device_id * devices,
cl_uint * num_devices)
{
cl_bool gpu, cpu, accelerator;
cl_uint original_num_entries = num_entries;
gpu = (device_type & CL_DEVICE_TYPE_DEFAULT) ||
(device_type & CL_DEVICE_TYPE_GPU) ||
(device_type & CL_DEVICE_TYPE_ALL);
cpu = (device_type & CL_DEVICE_TYPE_CPU) ||
(device_type & CL_DEVICE_TYPE_ALL);
accelerator = (device_type & CL_DEVICE_TYPE_ACCELERATOR) ||
(device_type & CL_DEVICE_TYPE_ALL);
if (!gpu && !cpu && !accelerator)
return CL_INVALID_DEVICE_TYPE;
if ((!num_entries && devices) || (!num_devices && !devices))
return CL_INVALID_VALUE;
if (gpu && num_entries > 0) {
cl_uint num_gpus = 0;
create_gpu_device(devices, &num_gpus, num_entries);
num_entries -= num_gpus;
if (num_devices)
*num_devices += num_gpus;
}
if (cpu && num_entries > 0) {
cl_uint num_cpus = 0;
create_cpu_device(devices, &num_cpus, num_entries);
num_entries -= num_cpus;
if (num_devices)
*num_devices += num_cpus;
}
if (accelerator && num_entries) {
cl_uint num_accels = 0;
create_accel_device(devices, &num_accels, num_entries);
num_entries -= num_accels;
if (num_devices)
*num_devices += num_accels;
}
if (original_num_entries == num_entries)
return CL_DEVICE_NOT_FOUND;
return CL_SUCCESS;
}
cl_int
clGetDeviceInfo(cl_device_id device,
cl_device_info opcode,
size_t param_value_size,
void * param_value,
size_t * param_value_size_ret)
{
if (!device)
return CL_INVALID_DEVICE;
return device->info(opcode, param_value_size, param_value,
param_value_size_ret);
}
|