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 OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
23 #include "api/util.hpp"
24 #include "core/platform.hpp"
25 #include "core/device.hpp"
27 using namespace clover
;
30 clGetDeviceIDs(cl_platform_id platform
, cl_device_type device_type
,
31 cl_uint num_entries
, cl_device_id
*devices
,
32 cl_uint
*num_devices
) {
33 std::vector
<cl_device_id
> devs
;
35 if ((!num_entries
&& devices
) ||
36 (!num_devices
&& !devices
))
37 return CL_INVALID_VALUE
;
39 // Collect matching devices
40 for (device
&dev
: *platform
) {
41 if (((device_type
& CL_DEVICE_TYPE_DEFAULT
) &&
42 &dev
== &platform
->front()) ||
43 (device_type
& dev
.type()))
48 return CL_DEVICE_NOT_FOUND
;
50 // ...and return the requested data.
52 *num_devices
= devs
.size();
54 std::copy_n(devs
.begin(),
55 std::min((cl_uint
)devs
.size(), num_entries
),
62 clGetDeviceInfo(cl_device_id dev
, cl_device_info param
,
63 size_t size
, void *buf
, size_t *size_ret
) {
65 return CL_INVALID_DEVICE
;
69 return scalar_property
<cl_device_type
>(buf
, size
, size_ret
, dev
->type());
71 case CL_DEVICE_VENDOR_ID
:
72 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, dev
->vendor_id());
74 case CL_DEVICE_MAX_COMPUTE_UNITS
:
75 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 1);
77 case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
:
78 return scalar_property
<cl_uint
>(buf
, size
, size_ret
,
79 dev
->max_block_size().size());
81 case CL_DEVICE_MAX_WORK_ITEM_SIZES
:
82 return vector_property
<size_t>(buf
, size
, size_ret
,
83 dev
->max_block_size());
85 case CL_DEVICE_MAX_WORK_GROUP_SIZE
:
86 return scalar_property
<size_t>(buf
, size
, size_ret
,
87 dev
->max_threads_per_block());
89 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
:
90 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 16);
92 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
:
93 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 8);
95 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
:
96 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 4);
98 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
:
99 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 2);
101 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
:
102 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 4);
104 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
:
105 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 2);
107 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF
:
108 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 0);
110 case CL_DEVICE_MAX_CLOCK_FREQUENCY
:
111 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 0);
113 case CL_DEVICE_ADDRESS_BITS
:
114 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 32);
116 case CL_DEVICE_MAX_READ_IMAGE_ARGS
:
117 return scalar_property
<cl_uint
>(buf
, size
, size_ret
,
118 dev
->max_images_read());
120 case CL_DEVICE_MAX_WRITE_IMAGE_ARGS
:
121 return scalar_property
<cl_uint
>(buf
, size
, size_ret
,
122 dev
->max_images_write());
124 case CL_DEVICE_MAX_MEM_ALLOC_SIZE
:
125 return scalar_property
<cl_ulong
>(buf
, size
, size_ret
,
126 dev
->max_mem_alloc_size());
128 case CL_DEVICE_IMAGE2D_MAX_WIDTH
:
129 case CL_DEVICE_IMAGE2D_MAX_HEIGHT
:
130 return scalar_property
<size_t>(buf
, size
, size_ret
,
131 1 << dev
->max_image_levels_2d());
133 case CL_DEVICE_IMAGE3D_MAX_WIDTH
:
134 case CL_DEVICE_IMAGE3D_MAX_HEIGHT
:
135 case CL_DEVICE_IMAGE3D_MAX_DEPTH
:
136 return scalar_property
<size_t>(buf
, size
, size_ret
,
137 1 << dev
->max_image_levels_3d());
139 case CL_DEVICE_IMAGE_SUPPORT
:
140 return scalar_property
<cl_bool
>(buf
, size
, size_ret
, CL_TRUE
);
142 case CL_DEVICE_MAX_PARAMETER_SIZE
:
143 return scalar_property
<size_t>(buf
, size
, size_ret
,
144 dev
->max_mem_input());
146 case CL_DEVICE_MAX_SAMPLERS
:
147 return scalar_property
<cl_uint
>(buf
, size
, size_ret
,
148 dev
->max_samplers());
150 case CL_DEVICE_MEM_BASE_ADDR_ALIGN
:
151 case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
:
152 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 128);
154 case CL_DEVICE_SINGLE_FP_CONFIG
:
155 return scalar_property
<cl_device_fp_config
>(buf
, size
, size_ret
,
156 CL_FP_DENORM
| CL_FP_INF_NAN
| CL_FP_ROUND_TO_NEAREST
);
158 case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE
:
159 return scalar_property
<cl_device_mem_cache_type
>(buf
, size
, size_ret
,
162 case CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
:
163 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 0);
165 case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
:
166 return scalar_property
<cl_ulong
>(buf
, size
, size_ret
, 0);
168 case CL_DEVICE_GLOBAL_MEM_SIZE
:
169 return scalar_property
<cl_ulong
>(buf
, size
, size_ret
,
170 dev
->max_mem_global());
172 case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
:
173 return scalar_property
<cl_ulong
>(buf
, size
, size_ret
,
174 dev
->max_const_buffer_size());
176 case CL_DEVICE_MAX_CONSTANT_ARGS
:
177 return scalar_property
<cl_uint
>(buf
, size
, size_ret
,
178 dev
->max_const_buffers());
180 case CL_DEVICE_LOCAL_MEM_TYPE
:
181 return scalar_property
<cl_device_local_mem_type
>(buf
, size
, size_ret
,
184 case CL_DEVICE_LOCAL_MEM_SIZE
:
185 return scalar_property
<cl_ulong
>(buf
, size
, size_ret
,
186 dev
->max_mem_local());
188 case CL_DEVICE_ERROR_CORRECTION_SUPPORT
:
189 return scalar_property
<cl_bool
>(buf
, size
, size_ret
, CL_FALSE
);
191 case CL_DEVICE_PROFILING_TIMER_RESOLUTION
:
192 return scalar_property
<size_t>(buf
, size
, size_ret
, 0);
194 case CL_DEVICE_ENDIAN_LITTLE
:
195 return scalar_property
<cl_bool
>(buf
, size
, size_ret
, CL_TRUE
);
197 case CL_DEVICE_AVAILABLE
:
198 case CL_DEVICE_COMPILER_AVAILABLE
:
199 return scalar_property
<cl_bool
>(buf
, size
, size_ret
, CL_TRUE
);
201 case CL_DEVICE_EXECUTION_CAPABILITIES
:
202 return scalar_property
<cl_device_exec_capabilities
>(buf
, size
, size_ret
,
205 case CL_DEVICE_QUEUE_PROPERTIES
:
206 return scalar_property
<cl_command_queue_properties
>(buf
, size
, size_ret
,
207 CL_QUEUE_PROFILING_ENABLE
);
210 return string_property(buf
, size
, size_ret
, dev
->device_name());
212 case CL_DEVICE_VENDOR
:
213 return string_property(buf
, size
, size_ret
, dev
->vendor_name());
215 case CL_DRIVER_VERSION
:
216 return string_property(buf
, size
, size_ret
, PACKAGE_VERSION
);
218 case CL_DEVICE_PROFILE
:
219 return string_property(buf
, size
, size_ret
, "FULL_PROFILE");
221 case CL_DEVICE_VERSION
:
222 return string_property(buf
, size
, size_ret
,
223 "OpenCL 1.1 MESA " PACKAGE_VERSION
);
225 case CL_DEVICE_EXTENSIONS
:
226 return string_property(buf
, size
, size_ret
, "");
228 case CL_DEVICE_PLATFORM
:
229 return scalar_property
<cl_platform_id
>(buf
, size
, size_ret
,
232 case CL_DEVICE_HOST_UNIFIED_MEMORY
:
233 return scalar_property
<cl_bool
>(buf
, size
, size_ret
, CL_TRUE
);
235 case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR
:
236 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 16);
238 case CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT
:
239 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 8);
241 case CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
:
242 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 4);
244 case CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
:
245 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 2);
247 case CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
:
248 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 4);
250 case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
:
251 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 2);
253 case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
:
254 return scalar_property
<cl_uint
>(buf
, size
, size_ret
, 0);
256 case CL_DEVICE_OPENCL_C_VERSION
:
257 return string_property(buf
, size
, size_ret
, "OpenCL C 1.1");
260 return CL_INVALID_VALUE
;