2 // Copyright 2012 Francisco Jerez
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
11 // The above copyright notice and this permission notice shall be included in
12 // all copies or substantial portions of the Software.
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 // THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 // OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #include "api/util.hpp"
24 #include "core/device.hpp"
26 using namespace clover
;
28 static device_registry registry
;
31 clGetDeviceIDs(cl_platform_id platform
, cl_device_type device_type
,
32 cl_uint num_entries
, cl_device_id
*devices
,
33 cl_uint
*num_devices
) {
34 std::vector
<cl_device_id
> devs
;
37 return CL_INVALID_PLATFORM
;
39 if ((!num_entries
&& devices
) ||
40 (!num_devices
&& !devices
))
41 return CL_INVALID_VALUE
;
43 // Collect matching devices
44 for (device
&dev
: registry
) {
45 if (((device_type
& CL_DEVICE_TYPE_DEFAULT
) &&
46 &dev
== ®istry
.front()) ||
47 (device_type
& dev
.type()))
52 return CL_DEVICE_NOT_FOUND
;
54 // ...and return the requested data.
56 *num_devices
= devs
.size();
58 std::copy_n(devs
.begin(),
59 std::min((cl_uint
)devs
.size(), num_entries
),
66 clGetDeviceInfo(cl_device_id dev
, cl_device_info param
,
67 size_t size
, void *buf
, size_t *size_ret
) {
69 return CL_INVALID_DEVICE
;
73 return scalar_property
<cl_device_type
>(buf
, size
, size_ret
, dev
->type());
75 case CL_DEVICE_VENDOR_ID
:
76 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, dev
->vendor_id());
78 case CL_DEVICE_MAX_COMPUTE_UNITS
:
79 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 1);
81 case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
:
82 return scalar_property
<cl_uint
>(buf
, size
, size_ret
,
83 dev
->max_block_size().size());
85 case CL_DEVICE_MAX_WORK_ITEM_SIZES
:
86 return vector_property
<size_t>(buf
, size
, size_ret
,
87 dev
->max_block_size());
89 case CL_DEVICE_MAX_WORK_GROUP_SIZE
:
90 return scalar_property
<size_t>(buf
, size
, size_ret
,
91 dev
->max_threads_per_block());
93 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
:
94 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 16);
96 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
:
97 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 8);
99 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
:
100 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 4);
102 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
:
103 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 2);
105 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
:
106 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 4);
108 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
:
109 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 2);
111 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF
:
112 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 0);
114 case CL_DEVICE_MAX_CLOCK_FREQUENCY
:
115 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 0);
117 case CL_DEVICE_ADDRESS_BITS
:
118 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 32);
120 case CL_DEVICE_MAX_READ_IMAGE_ARGS
:
121 return scalar_property
<cl_uint
>(buf
, size
, size_ret
,
122 dev
->max_images_read());
124 case CL_DEVICE_MAX_WRITE_IMAGE_ARGS
:
125 return scalar_property
<cl_uint
>(buf
, size
, size_ret
,
126 dev
->max_images_write());
128 case CL_DEVICE_MAX_MEM_ALLOC_SIZE
:
129 return scalar_property
<cl_ulong
>(buf
, size
, size_ret
, 0);
131 case CL_DEVICE_IMAGE2D_MAX_WIDTH
:
132 case CL_DEVICE_IMAGE2D_MAX_HEIGHT
:
133 return scalar_property
<size_t>(buf
, size
, size_ret
,
134 1 << dev
->max_image_levels_2d());
136 case CL_DEVICE_IMAGE3D_MAX_WIDTH
:
137 case CL_DEVICE_IMAGE3D_MAX_HEIGHT
:
138 case CL_DEVICE_IMAGE3D_MAX_DEPTH
:
139 return scalar_property
<size_t>(buf
, size
, size_ret
,
140 1 << dev
->max_image_levels_3d());
142 case CL_DEVICE_IMAGE_SUPPORT
:
143 return scalar_property
<cl_bool
>(buf
, size
, size_ret
, CL_TRUE
);
145 case CL_DEVICE_MAX_PARAMETER_SIZE
:
146 return scalar_property
<size_t>(buf
, size
, size_ret
,
147 dev
->max_mem_input());
149 case CL_DEVICE_MAX_SAMPLERS
:
150 return scalar_property
<cl_uint
>(buf
, size
, size_ret
,
151 dev
->max_samplers());
153 case CL_DEVICE_MEM_BASE_ADDR_ALIGN
:
154 case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
:
155 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 128);
157 case CL_DEVICE_SINGLE_FP_CONFIG
:
158 return scalar_property
<cl_device_fp_config
>(buf
, size
, size_ret
,
159 CL_FP_DENORM
| CL_FP_INF_NAN
| CL_FP_ROUND_TO_NEAREST
);
161 case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE
:
162 return scalar_property
<cl_device_mem_cache_type
>(buf
, size
, size_ret
,
165 case CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
:
166 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 0);
168 case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
:
169 return scalar_property
<cl_ulong
>(buf
, size
, size_ret
, 0);
171 case CL_DEVICE_GLOBAL_MEM_SIZE
:
172 return scalar_property
<cl_ulong
>(buf
, size
, size_ret
,
173 dev
->max_mem_global());
175 case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
:
176 return scalar_property
<cl_ulong
>(buf
, size
, size_ret
,
177 dev
->max_const_buffer_size());
179 case CL_DEVICE_MAX_CONSTANT_ARGS
:
180 return scalar_property
<cl_uint
>(buf
, size
, size_ret
,
181 dev
->max_const_buffers());
183 case CL_DEVICE_LOCAL_MEM_TYPE
:
184 return scalar_property
<cl_device_local_mem_type
>(buf
, size
, size_ret
,
187 case CL_DEVICE_LOCAL_MEM_SIZE
:
188 return scalar_property
<cl_ulong
>(buf
, size
, size_ret
,
189 dev
->max_mem_local());
191 case CL_DEVICE_ERROR_CORRECTION_SUPPORT
:
192 return scalar_property
<cl_bool
>(buf
, size
, size_ret
, CL_FALSE
);
194 case CL_DEVICE_PROFILING_TIMER_RESOLUTION
:
195 return scalar_property
<size_t>(buf
, size
, size_ret
, 0);
197 case CL_DEVICE_ENDIAN_LITTLE
:
198 return scalar_property
<cl_bool
>(buf
, size
, size_ret
, CL_TRUE
);
200 case CL_DEVICE_AVAILABLE
:
201 case CL_DEVICE_COMPILER_AVAILABLE
:
202 return scalar_property
<cl_bool
>(buf
, size
, size_ret
, CL_TRUE
);
204 case CL_DEVICE_EXECUTION_CAPABILITIES
:
205 return scalar_property
<cl_device_exec_capabilities
>(buf
, size
, size_ret
,
208 case CL_DEVICE_QUEUE_PROPERTIES
:
209 return scalar_property
<cl_command_queue_properties
>(buf
, size
, size_ret
,
210 CL_QUEUE_PROFILING_ENABLE
);
213 return string_property(buf
, size
, size_ret
, dev
->device_name());
215 case CL_DEVICE_VENDOR
:
216 return string_property(buf
, size
, size_ret
, dev
->vendor_name());
218 case CL_DRIVER_VERSION
:
219 return string_property(buf
, size
, size_ret
, MESA_VERSION
);
221 case CL_DEVICE_PROFILE
:
222 return string_property(buf
, size
, size_ret
, "FULL_PROFILE");
224 case CL_DEVICE_VERSION
:
225 return string_property(buf
, size
, size_ret
, "OpenCL 1.1 MESA " MESA_VERSION
);
227 case CL_DEVICE_EXTENSIONS
:
228 return string_property(buf
, size
, size_ret
, "");
230 case CL_DEVICE_PLATFORM
:
231 return scalar_property
<cl_platform_id
>(buf
, size
, size_ret
, NULL
);
233 case CL_DEVICE_HOST_UNIFIED_MEMORY
:
234 return scalar_property
<cl_bool
>(buf
, size
, size_ret
, CL_TRUE
);
236 case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR
:
237 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 16);
239 case CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT
:
240 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 8);
242 case CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
:
243 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 4);
245 case CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
:
246 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 2);
248 case CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
:
249 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 4);
251 case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
:
252 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 2);
254 case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
:
255 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 0);
257 case CL_DEVICE_OPENCL_C_VERSION
:
258 return string_property(buf
, size
, size_ret
, "OpenCL C 1.1");
261 return CL_INVALID_VALUE
;