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 d_platform
, cl_device_type device_type
,
31 cl_uint num_entries
, cl_device_id
*devices
,
32 cl_uint
*num_devices
) {
33 auto &platform
= obj(d_platform
);
34 std::vector
<cl_device_id
> devs
;
36 if ((!num_entries
&& devices
) ||
37 (!num_devices
&& !devices
))
38 return CL_INVALID_VALUE
;
40 // Collect matching devices
41 for (device
&dev
: platform
) {
42 if (((device_type
& CL_DEVICE_TYPE_DEFAULT
) &&
43 &dev
== &platform
.front()) ||
44 (device_type
& dev
.type()))
49 return CL_DEVICE_NOT_FOUND
;
51 // ...and return the requested data.
53 *num_devices
= devs
.size();
55 std::copy_n(devs
.begin(),
56 std::min((cl_uint
)devs
.size(), num_entries
),
63 clGetDeviceInfo(cl_device_id dev
, cl_device_info param
,
64 size_t size
, void *r_buf
, size_t *r_size
) try {
65 property_buffer buf
{ r_buf
, size
, r_size
};
68 return CL_INVALID_DEVICE
;
72 buf
.as_scalar
<cl_device_type
>() = dev
->type();
75 case CL_DEVICE_VENDOR_ID
:
76 buf
.as_scalar
<cl_uint
>() = dev
->vendor_id();
79 case CL_DEVICE_MAX_COMPUTE_UNITS
:
80 buf
.as_scalar
<cl_uint
>() = 1;
83 case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS
:
84 buf
.as_scalar
<cl_uint
>() = dev
->max_block_size().size();
87 case CL_DEVICE_MAX_WORK_ITEM_SIZES
:
88 buf
.as_vector
<size_t>() = dev
->max_block_size();
91 case CL_DEVICE_MAX_WORK_GROUP_SIZE
:
92 buf
.as_scalar
<size_t>() = dev
->max_threads_per_block();
95 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR
:
96 buf
.as_scalar
<cl_uint
>() = 16;
99 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT
:
100 buf
.as_scalar
<cl_uint
>() = 8;
103 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT
:
104 buf
.as_scalar
<cl_uint
>() = 4;
107 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG
:
108 buf
.as_scalar
<cl_uint
>() = 2;
111 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT
:
112 buf
.as_scalar
<cl_uint
>() = 4;
115 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE
:
116 buf
.as_scalar
<cl_uint
>() = 2;
119 case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF
:
120 buf
.as_scalar
<cl_uint
>() = 0;
123 case CL_DEVICE_MAX_CLOCK_FREQUENCY
:
124 buf
.as_scalar
<cl_uint
>() = 0;
127 case CL_DEVICE_ADDRESS_BITS
:
128 buf
.as_scalar
<cl_uint
>() = 32;
131 case CL_DEVICE_MAX_READ_IMAGE_ARGS
:
132 buf
.as_scalar
<cl_uint
>() = dev
->max_images_read();
135 case CL_DEVICE_MAX_WRITE_IMAGE_ARGS
:
136 buf
.as_scalar
<cl_uint
>() = dev
->max_images_write();
139 case CL_DEVICE_MAX_MEM_ALLOC_SIZE
:
140 buf
.as_scalar
<cl_ulong
>() = dev
->max_mem_alloc_size();
143 case CL_DEVICE_IMAGE2D_MAX_WIDTH
:
144 case CL_DEVICE_IMAGE2D_MAX_HEIGHT
:
145 buf
.as_scalar
<size_t>() = 1 << dev
->max_image_levels_2d();
148 case CL_DEVICE_IMAGE3D_MAX_WIDTH
:
149 case CL_DEVICE_IMAGE3D_MAX_HEIGHT
:
150 case CL_DEVICE_IMAGE3D_MAX_DEPTH
:
151 buf
.as_scalar
<size_t>() = 1 << dev
->max_image_levels_3d();
154 case CL_DEVICE_IMAGE_SUPPORT
:
155 buf
.as_scalar
<cl_bool
>() = CL_TRUE
;
158 case CL_DEVICE_MAX_PARAMETER_SIZE
:
159 buf
.as_scalar
<size_t>() = dev
->max_mem_input();
162 case CL_DEVICE_MAX_SAMPLERS
:
163 buf
.as_scalar
<cl_uint
>() = dev
->max_samplers();
166 case CL_DEVICE_MEM_BASE_ADDR_ALIGN
:
167 case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE
:
168 buf
.as_scalar
<cl_uint
>() = 128;
171 case CL_DEVICE_SINGLE_FP_CONFIG
:
172 buf
.as_scalar
<cl_device_fp_config
>() =
173 CL_FP_DENORM
| CL_FP_INF_NAN
| CL_FP_ROUND_TO_NEAREST
;
176 case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE
:
177 buf
.as_scalar
<cl_device_mem_cache_type
>() = CL_NONE
;
180 case CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE
:
181 buf
.as_scalar
<cl_uint
>() = 0;
184 case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE
:
185 buf
.as_scalar
<cl_ulong
>() = 0;
188 case CL_DEVICE_GLOBAL_MEM_SIZE
:
189 buf
.as_scalar
<cl_ulong
>() = dev
->max_mem_global();
192 case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE
:
193 buf
.as_scalar
<cl_ulong
>() = dev
->max_const_buffer_size();
196 case CL_DEVICE_MAX_CONSTANT_ARGS
:
197 buf
.as_scalar
<cl_uint
>() = dev
->max_const_buffers();
200 case CL_DEVICE_LOCAL_MEM_TYPE
:
201 buf
.as_scalar
<cl_device_local_mem_type
>() = CL_LOCAL
;
204 case CL_DEVICE_LOCAL_MEM_SIZE
:
205 buf
.as_scalar
<cl_ulong
>() = dev
->max_mem_local();
208 case CL_DEVICE_ERROR_CORRECTION_SUPPORT
:
209 buf
.as_scalar
<cl_bool
>() = CL_FALSE
;
212 case CL_DEVICE_PROFILING_TIMER_RESOLUTION
:
213 buf
.as_scalar
<size_t>() = 0;
216 case CL_DEVICE_ENDIAN_LITTLE
:
217 buf
.as_scalar
<cl_bool
>() = (dev
->endianness() == PIPE_ENDIAN_LITTLE
);
220 case CL_DEVICE_AVAILABLE
:
221 case CL_DEVICE_COMPILER_AVAILABLE
:
222 buf
.as_scalar
<cl_bool
>() = CL_TRUE
;
225 case CL_DEVICE_EXECUTION_CAPABILITIES
:
226 buf
.as_scalar
<cl_device_exec_capabilities
>() = CL_EXEC_KERNEL
;
229 case CL_DEVICE_QUEUE_PROPERTIES
:
230 buf
.as_scalar
<cl_command_queue_properties
>() = CL_QUEUE_PROFILING_ENABLE
;
234 buf
.as_string() = dev
->device_name();
237 case CL_DEVICE_VENDOR
:
238 buf
.as_string() = dev
->vendor_name();
241 case CL_DRIVER_VERSION
:
242 buf
.as_string() = PACKAGE_VERSION
;
245 case CL_DEVICE_PROFILE
:
246 buf
.as_string() = "FULL_PROFILE";
249 case CL_DEVICE_VERSION
:
250 buf
.as_string() = "OpenCL 1.1 MESA " PACKAGE_VERSION
;
253 case CL_DEVICE_EXTENSIONS
:
254 buf
.as_string() = "";
257 case CL_DEVICE_PLATFORM
:
258 buf
.as_scalar
<cl_platform_id
>() = desc(dev
->platform
);
261 case CL_DEVICE_HOST_UNIFIED_MEMORY
:
262 buf
.as_scalar
<cl_bool
>() = CL_TRUE
;
265 case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR
:
266 buf
.as_scalar
<cl_uint
>() = 16;
269 case CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT
:
270 buf
.as_scalar
<cl_uint
>() = 8;
273 case CL_DEVICE_NATIVE_VECTOR_WIDTH_INT
:
274 buf
.as_scalar
<cl_uint
>() = 4;
277 case CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG
:
278 buf
.as_scalar
<cl_uint
>() = 2;
281 case CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT
:
282 buf
.as_scalar
<cl_uint
>() = 4;
285 case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE
:
286 buf
.as_scalar
<cl_uint
>() = 2;
289 case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF
:
290 buf
.as_scalar
<cl_uint
>() = 0;
293 case CL_DEVICE_OPENCL_C_VERSION
:
294 buf
.as_string() = "OpenCL C 1.1";
298 throw error(CL_INVALID_VALUE
);