summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/clover/api/device.cpp
blob: 3e8b3f821c3147309a75ab37a54dce3eec721805 (plain)
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
//
// Copyright 2012 Francisco Jerez
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//

#include "api/util.hpp"
#include "core/platform.hpp"
#include "core/device.hpp"

using namespace clover;

PUBLIC cl_int
clGetDeviceIDs(cl_platform_id platform, cl_device_type device_type,
               cl_uint num_entries, cl_device_id *devices,
               cl_uint *num_devices) {
   std::vector<cl_device_id> devs;

   if ((!num_entries && devices) ||
       (!num_devices && !devices))
      return CL_INVALID_VALUE;

   // Collect matching devices
   for (device &dev : *platform) {
      if (((device_type & CL_DEVICE_TYPE_DEFAULT) &&
           &dev == &platform->front()) ||
          (device_type & dev.type()))
         devs.push_back(&dev);
   }

   if (devs.empty())
      return CL_DEVICE_NOT_FOUND;

   // ...and return the requested data.
   if (num_devices)
      *num_devices = devs.size();
   if (devices)
      std::copy_n(devs.begin(),
                  std::min((cl_uint)devs.size(), num_entries),
                  devices);

   return CL_SUCCESS;
}

PUBLIC cl_int
clGetDeviceInfo(cl_device_id dev, cl_device_info param,
                size_t size, void *buf, size_t *size_ret) {
   if (!dev)
      return CL_INVALID_DEVICE;

   switch (param) {
   case CL_DEVICE_TYPE:
      return scalar_property<cl_device_type>(buf, size, size_ret, dev->type());

   case CL_DEVICE_VENDOR_ID:
      return scalar_property<cl_uint>(buf, size, size_ret, dev->vendor_id());

   case CL_DEVICE_MAX_COMPUTE_UNITS:
      return scalar_property<cl_uint>(buf, size, size_ret, 1);

   case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS:
      return scalar_property<cl_uint>(buf, size, size_ret,
                                      dev->max_block_size().size());

   case CL_DEVICE_MAX_WORK_ITEM_SIZES:
      return vector_property<size_t>(buf, size, size_ret,
                                     dev->max_block_size());

   case CL_DEVICE_MAX_WORK_GROUP_SIZE:
      return scalar_property<size_t>(buf, size, size_ret,
                                     dev->max_threads_per_block());

   case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR:
      return scalar_property<cl_uint>(buf, size, size_ret, 16);

   case CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT:
      return scalar_property<cl_uint>(buf, size, size_ret, 8);

   case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT:
      return scalar_property<cl_uint>(buf, size, size_ret, 4);

   case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG:
      return scalar_property<cl_uint>(buf, size, size_ret, 2);

   case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT:
      return scalar_property<cl_uint>(buf, size, size_ret, 4);

   case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE:
      return scalar_property<cl_uint>(buf, size, size_ret, 2);

   case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF:
      return scalar_property<cl_uint>(buf, size, size_ret, 0);

   case CL_DEVICE_MAX_CLOCK_FREQUENCY:
      return scalar_property<cl_uint>(buf, size, size_ret, 0);

   case CL_DEVICE_ADDRESS_BITS:
      return scalar_property<cl_uint>(buf, size, size_ret, 32);

   case CL_DEVICE_MAX_READ_IMAGE_ARGS:
      return scalar_property<cl_uint>(buf, size, size_ret,
                                      dev->max_images_read());

   case CL_DEVICE_MAX_WRITE_IMAGE_ARGS:
      return scalar_property<cl_uint>(buf, size, size_ret,
                                      dev->max_images_write());

   case CL_DEVICE_MAX_MEM_ALLOC_SIZE:
      return scalar_property<cl_ulong>(buf, size, size_ret,
                                       dev->max_mem_alloc_size());

   case CL_DEVICE_IMAGE2D_MAX_WIDTH:
   case CL_DEVICE_IMAGE2D_MAX_HEIGHT:
      return scalar_property<size_t>(buf, size, size_ret,
                                     1 << dev->max_image_levels_2d());

   case CL_DEVICE_IMAGE3D_MAX_WIDTH:
   case CL_DEVICE_IMAGE3D_MAX_HEIGHT:
   case CL_DEVICE_IMAGE3D_MAX_DEPTH:
      return scalar_property<size_t>(buf, size, size_ret,
                                     1 << dev->max_image_levels_3d());

   case CL_DEVICE_IMAGE_SUPPORT:
      return scalar_property<cl_bool>(buf, size, size_ret, CL_TRUE);

   case CL_DEVICE_MAX_PARAMETER_SIZE:
      return scalar_property<size_t>(buf, size, size_ret,
                                     dev->max_mem_input());

   case CL_DEVICE_MAX_SAMPLERS:
      return scalar_property<cl_uint>(buf, size, size_ret,
                                      dev->max_samplers());

   case CL_DEVICE_MEM_BASE_ADDR_ALIGN:
   case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE:
      return scalar_property<cl_uint>(buf, size, size_ret, 128);

   case CL_DEVICE_SINGLE_FP_CONFIG:
      return scalar_property<cl_device_fp_config>(buf, size, size_ret,
         CL_FP_DENORM | CL_FP_INF_NAN | CL_FP_ROUND_TO_NEAREST);

   case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE:
      return scalar_property<cl_device_mem_cache_type>(buf, size, size_ret,
                                                       CL_NONE);

   case CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE:
      return scalar_property<cl_uint>(buf, size, size_ret, 0);

   case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE:
      return scalar_property<cl_ulong>(buf, size, size_ret, 0);

   case CL_DEVICE_GLOBAL_MEM_SIZE:
      return scalar_property<cl_ulong>(buf, size, size_ret,
                                       dev->max_mem_global());

   case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE:
      return scalar_property<cl_ulong>(buf, size, size_ret,
                                       dev->max_const_buffer_size());

   case CL_DEVICE_MAX_CONSTANT_ARGS:
      return scalar_property<cl_uint>(buf, size, size_ret,
                                      dev->max_const_buffers());

   case CL_DEVICE_LOCAL_MEM_TYPE:
      return scalar_property<cl_device_local_mem_type>(buf, size, size_ret,
                                                       CL_LOCAL);

   case CL_DEVICE_LOCAL_MEM_SIZE:
      return scalar_property<cl_ulong>(buf, size, size_ret,
                                       dev->max_mem_local());

   case CL_DEVICE_ERROR_CORRECTION_SUPPORT:
      return scalar_property<cl_bool>(buf, size, size_ret, CL_FALSE);

   case CL_DEVICE_PROFILING_TIMER_RESOLUTION:
      return scalar_property<size_t>(buf, size, size_ret, 0);

   case CL_DEVICE_ENDIAN_LITTLE:
      return scalar_property<cl_bool>(buf, size, size_ret,
                                      dev->endianness() == PIPE_ENDIAN_LITTLE);

   case CL_DEVICE_AVAILABLE:
   case CL_DEVICE_COMPILER_AVAILABLE:
      return scalar_property<cl_bool>(buf, size, size_ret, CL_TRUE);

   case CL_DEVICE_EXECUTION_CAPABILITIES:
      return scalar_property<cl_device_exec_capabilities>(buf, size, size_ret,
                                                          CL_EXEC_KERNEL);

   case CL_DEVICE_QUEUE_PROPERTIES:
      return scalar_property<cl_command_queue_properties>(buf, size, size_ret,
         CL_QUEUE_PROFILING_ENABLE);

   case CL_DEVICE_NAME:
      return string_property(buf, size, size_ret, dev->device_name());

   case CL_DEVICE_VENDOR:
      return string_property(buf, size, size_ret, dev->vendor_name());

   case CL_DRIVER_VERSION:
      return string_property(buf, size, size_ret, PACKAGE_VERSION);

   case CL_DEVICE_PROFILE:
      return string_property(buf, size, size_ret, "FULL_PROFILE");

   case CL_DEVICE_VERSION:
      return string_property(buf, size, size_ret,
                             "OpenCL 1.1 MESA " PACKAGE_VERSION);

   case CL_DEVICE_EXTENSIONS:
      return string_property(buf, size, size_ret, "");

   case CL_DEVICE_PLATFORM:
      return scalar_property<cl_platform_id>(buf, size, size_ret,
                                             &dev->platform);

   case CL_DEVICE_HOST_UNIFIED_MEMORY:
      return scalar_property<cl_bool>(buf, size, size_ret, CL_TRUE);

   case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR:
      return scalar_property<cl_uint>(buf, size, size_ret, 16);

   case CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT:
      return scalar_property<cl_uint>(buf, size, size_ret, 8);

   case CL_DEVICE_NATIVE_VECTOR_WIDTH_INT:
      return scalar_property<cl_uint>(buf, size, size_ret, 4);

   case CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG:
      return scalar_property<cl_uint>(buf, size, size_ret, 2);

   case CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT:
      return scalar_property<cl_uint>(buf, size, size_ret, 4);

   case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE:
      return scalar_property<cl_uint>(buf, size, size_ret, 2);

   case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF:
      return scalar_property<cl_uint>(buf, size, size_ret, 0);

   case CL_DEVICE_OPENCL_C_VERSION:
      return string_property(buf, size, size_ret, "OpenCL C 1.1");

   default:
      return CL_INVALID_VALUE;
   }
}