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 *r_buf
, size_t *r_size
) try {
64 property_buffer buf
{ r_buf
, size
, r_size
};
67 return CL_INVALID_DEVICE
;
71 buf
.as_scalar
<cl_device_type
>() = dev
->type();
74 case CL_DEVICE_VENDOR_ID
:
75 buf
.as_scalar
<cl_uint
>() = dev
->vendor_id();
78 case CL_DEVICE_MAX_COMPUTE_UNITS
:
79 buf
.as_scalar
<cl_uint
>() = 1;
82 case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
:
83 buf
.as_scalar
<cl_uint
>() = dev
->max_block_size().size();
86 case CL_DEVICE_MAX_WORK_ITEM_SIZES
:
87 buf
.as_vector
<size_t>() = dev
->max_block_size();
90 case CL_DEVICE_MAX_WORK_GROUP_SIZE
:
91 buf
.as_scalar
<size_t>() = dev
->max_threads_per_block();
94 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
:
95 buf
.as_scalar
<cl_uint
>() = 16;
98 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
:
99 buf
.as_scalar
<cl_uint
>() = 8;
102 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
:
103 buf
.as_scalar
<cl_uint
>() = 4;
106 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
:
107 buf
.as_scalar
<cl_uint
>() = 2;
110 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
:
111 buf
.as_scalar
<cl_uint
>() = 4;
114 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
:
115 buf
.as_scalar
<cl_uint
>() = 2;
118 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF
:
119 buf
.as_scalar
<cl_uint
>() = 0;
122 case CL_DEVICE_MAX_CLOCK_FREQUENCY
:
123 buf
.as_scalar
<cl_uint
>() = 0;
126 case CL_DEVICE_ADDRESS_BITS
:
127 buf
.as_scalar
<cl_uint
>() = 32;
130 case CL_DEVICE_MAX_READ_IMAGE_ARGS
:
131 buf
.as_scalar
<cl_uint
>() = dev
->max_images_read();
134 case CL_DEVICE_MAX_WRITE_IMAGE_ARGS
:
135 buf
.as_scalar
<cl_uint
>() = dev
->max_images_write();
138 case CL_DEVICE_MAX_MEM_ALLOC_SIZE
:
139 buf
.as_scalar
<cl_ulong
>() = dev
->max_mem_alloc_size();
142 case CL_DEVICE_IMAGE2D_MAX_WIDTH
:
143 case CL_DEVICE_IMAGE2D_MAX_HEIGHT
:
144 buf
.as_scalar
<size_t>() = 1 << dev
->max_image_levels_2d();
147 case CL_DEVICE_IMAGE3D_MAX_WIDTH
:
148 case CL_DEVICE_IMAGE3D_MAX_HEIGHT
:
149 case CL_DEVICE_IMAGE3D_MAX_DEPTH
:
150 buf
.as_scalar
<size_t>() = 1 << dev
->max_image_levels_3d();
153 case CL_DEVICE_IMAGE_SUPPORT
:
154 buf
.as_scalar
<cl_bool
>() = CL_TRUE
;
157 case CL_DEVICE_MAX_PARAMETER_SIZE
:
158 buf
.as_scalar
<size_t>() = dev
->max_mem_input();
161 case CL_DEVICE_MAX_SAMPLERS
:
162 buf
.as_scalar
<cl_uint
>() = dev
->max_samplers();
165 case CL_DEVICE_MEM_BASE_ADDR_ALIGN
:
166 case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
:
167 buf
.as_scalar
<cl_uint
>() = 128;
170 case CL_DEVICE_SINGLE_FP_CONFIG
:
171 buf
.as_scalar
<cl_device_fp_config
>() =
172 CL_FP_DENORM
| CL_FP_INF_NAN
| CL_FP_ROUND_TO_NEAREST
;
175 case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE
:
176 buf
.as_scalar
<cl_device_mem_cache_type
>() = CL_NONE
;
179 case CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
:
180 buf
.as_scalar
<cl_uint
>() = 0;
183 case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
:
184 buf
.as_scalar
<cl_ulong
>() = 0;
187 case CL_DEVICE_GLOBAL_MEM_SIZE
:
188 buf
.as_scalar
<cl_ulong
>() = dev
->max_mem_global();
191 case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
:
192 buf
.as_scalar
<cl_ulong
>() = dev
->max_const_buffer_size();
195 case CL_DEVICE_MAX_CONSTANT_ARGS
:
196 buf
.as_scalar
<cl_uint
>() = dev
->max_const_buffers();
199 case CL_DEVICE_LOCAL_MEM_TYPE
:
200 buf
.as_scalar
<cl_device_local_mem_type
>() = CL_LOCAL
;
203 case CL_DEVICE_LOCAL_MEM_SIZE
:
204 buf
.as_scalar
<cl_ulong
>() = dev
->max_mem_local();
207 case CL_DEVICE_ERROR_CORRECTION_SUPPORT
:
208 buf
.as_scalar
<cl_bool
>() = CL_FALSE
;
211 case CL_DEVICE_PROFILING_TIMER_RESOLUTION
:
212 buf
.as_scalar
<size_t>() = 0;
215 case CL_DEVICE_ENDIAN_LITTLE
:
216 buf
.as_scalar
<cl_bool
>() = (dev
->endianness() == PIPE_ENDIAN_LITTLE
);
219 case CL_DEVICE_AVAILABLE
:
220 case CL_DEVICE_COMPILER_AVAILABLE
:
221 buf
.as_scalar
<cl_bool
>() = CL_TRUE
;
224 case CL_DEVICE_EXECUTION_CAPABILITIES
:
225 buf
.as_scalar
<cl_device_exec_capabilities
>() = CL_EXEC_KERNEL
;
228 case CL_DEVICE_QUEUE_PROPERTIES
:
229 buf
.as_scalar
<cl_command_queue_properties
>() = CL_QUEUE_PROFILING_ENABLE
;
233 buf
.as_string() = dev
->device_name();
236 case CL_DEVICE_VENDOR
:
237 buf
.as_string() = dev
->vendor_name();
240 case CL_DRIVER_VERSION
:
241 buf
.as_string() = PACKAGE_VERSION
;
244 case CL_DEVICE_PROFILE
:
245 buf
.as_string() = "FULL_PROFILE";
248 case CL_DEVICE_VERSION
:
249 buf
.as_string() = "OpenCL 1.1 MESA " PACKAGE_VERSION
;
252 case CL_DEVICE_EXTENSIONS
:
253 buf
.as_string() = "";
256 case CL_DEVICE_PLATFORM
:
257 buf
.as_scalar
<cl_platform_id
>() = &dev
->platform
;
260 case CL_DEVICE_HOST_UNIFIED_MEMORY
:
261 buf
.as_scalar
<cl_bool
>() = CL_TRUE
;
264 case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR
:
265 buf
.as_scalar
<cl_uint
>() = 16;
268 case CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT
:
269 buf
.as_scalar
<cl_uint
>() = 8;
272 case CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
:
273 buf
.as_scalar
<cl_uint
>() = 4;
276 case CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
:
277 buf
.as_scalar
<cl_uint
>() = 2;
280 case CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
:
281 buf
.as_scalar
<cl_uint
>() = 4;
284 case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
:
285 buf
.as_scalar
<cl_uint
>() = 2;
288 case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
:
289 buf
.as_scalar
<cl_uint
>() = 0;
292 case CL_DEVICE_OPENCL_C_VERSION
:
293 buf
.as_string() = "OpenCL C 1.1";
297 throw error(CL_INVALID_VALUE
);