1bf215546Sopenharmony_ci// 2bf215546Sopenharmony_ci// Copyright 2012 Francisco Jerez 3bf215546Sopenharmony_ci// 4bf215546Sopenharmony_ci// Permission is hereby granted, free of charge, to any person obtaining a 5bf215546Sopenharmony_ci// copy of this software and associated documentation files (the "Software"), 6bf215546Sopenharmony_ci// to deal in the Software without restriction, including without limitation 7bf215546Sopenharmony_ci// the rights to use, copy, modify, merge, publish, distribute, sublicense, 8bf215546Sopenharmony_ci// and/or sell copies of the Software, and to permit persons to whom the 9bf215546Sopenharmony_ci// Software is furnished to do so, subject to the following conditions: 10bf215546Sopenharmony_ci// 11bf215546Sopenharmony_ci// The above copyright notice and this permission notice shall be included in 12bf215546Sopenharmony_ci// all copies or substantial portions of the Software. 13bf215546Sopenharmony_ci// 14bf215546Sopenharmony_ci// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15bf215546Sopenharmony_ci// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16bf215546Sopenharmony_ci// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17bf215546Sopenharmony_ci// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18bf215546Sopenharmony_ci// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19bf215546Sopenharmony_ci// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20bf215546Sopenharmony_ci// OTHER DEALINGS IN THE SOFTWARE. 21bf215546Sopenharmony_ci// 22bf215546Sopenharmony_ci 23bf215546Sopenharmony_ci#include "api/util.hpp" 24bf215546Sopenharmony_ci#include "core/platform.hpp" 25bf215546Sopenharmony_ci#include "core/device.hpp" 26bf215546Sopenharmony_ci#include "git_sha1.h" 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ciusing namespace clover; 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_cinamespace { 31bf215546Sopenharmony_ci std::string 32bf215546Sopenharmony_ci supported_il_versions_as_string(const device &dev) { 33bf215546Sopenharmony_ci std::string il_versions_string; 34bf215546Sopenharmony_ci 35bf215546Sopenharmony_ci for (const auto &il_version : dev.supported_il_versions()) { 36bf215546Sopenharmony_ci if (!il_versions_string.empty()) 37bf215546Sopenharmony_ci il_versions_string += " "; 38bf215546Sopenharmony_ci 39bf215546Sopenharmony_ci il_versions_string += std::string(il_version.name) + "_" + 40bf215546Sopenharmony_ci std::to_string(CL_VERSION_MAJOR(il_version.version)) + "." + 41bf215546Sopenharmony_ci std::to_string(CL_VERSION_MINOR(il_version.version)); 42bf215546Sopenharmony_ci } 43bf215546Sopenharmony_ci return il_versions_string; 44bf215546Sopenharmony_ci } 45bf215546Sopenharmony_ci} 46bf215546Sopenharmony_ci 47bf215546Sopenharmony_ciCLOVER_API cl_int 48bf215546Sopenharmony_ciclGetDeviceIDs(cl_platform_id d_platform, cl_device_type device_type, 49bf215546Sopenharmony_ci cl_uint num_entries, cl_device_id *rd_devices, 50bf215546Sopenharmony_ci cl_uint *rnum_devices) try { 51bf215546Sopenharmony_ci auto &platform = obj(d_platform); 52bf215546Sopenharmony_ci std::vector<cl_device_id> d_devs; 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_ci if ((!num_entries && rd_devices) || 55bf215546Sopenharmony_ci (!rnum_devices && !rd_devices)) 56bf215546Sopenharmony_ci throw error(CL_INVALID_VALUE); 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci // Collect matching devices 59bf215546Sopenharmony_ci for (device &dev : platform) { 60bf215546Sopenharmony_ci if (((device_type & CL_DEVICE_TYPE_DEFAULT) && 61bf215546Sopenharmony_ci dev == platform.front()) || 62bf215546Sopenharmony_ci (device_type & dev.type())) 63bf215546Sopenharmony_ci d_devs.push_back(desc(dev)); 64bf215546Sopenharmony_ci } 65bf215546Sopenharmony_ci 66bf215546Sopenharmony_ci if (d_devs.empty()) 67bf215546Sopenharmony_ci throw error(CL_DEVICE_NOT_FOUND); 68bf215546Sopenharmony_ci 69bf215546Sopenharmony_ci // ...and return the requested data. 70bf215546Sopenharmony_ci if (rnum_devices) 71bf215546Sopenharmony_ci *rnum_devices = d_devs.size(); 72bf215546Sopenharmony_ci if (rd_devices) 73bf215546Sopenharmony_ci copy(range(d_devs.begin(), 74bf215546Sopenharmony_ci std::min((unsigned)d_devs.size(), num_entries)), 75bf215546Sopenharmony_ci rd_devices); 76bf215546Sopenharmony_ci 77bf215546Sopenharmony_ci return CL_SUCCESS; 78bf215546Sopenharmony_ci 79bf215546Sopenharmony_ci} catch (error &e) { 80bf215546Sopenharmony_ci return e.get(); 81bf215546Sopenharmony_ci} 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_ciCLOVER_API cl_int 84bf215546Sopenharmony_ciclCreateSubDevices(cl_device_id d_dev, 85bf215546Sopenharmony_ci const cl_device_partition_property *props, 86bf215546Sopenharmony_ci cl_uint num_devs, cl_device_id *rd_devs, 87bf215546Sopenharmony_ci cl_uint *rnum_devs) { 88bf215546Sopenharmony_ci // There are no currently supported partitioning schemes. 89bf215546Sopenharmony_ci return CL_INVALID_VALUE; 90bf215546Sopenharmony_ci} 91bf215546Sopenharmony_ci 92bf215546Sopenharmony_ciCLOVER_API cl_int 93bf215546Sopenharmony_ciclRetainDevice(cl_device_id d_dev) try { 94bf215546Sopenharmony_ci obj(d_dev); 95bf215546Sopenharmony_ci 96bf215546Sopenharmony_ci // The reference count doesn't change for root devices. 97bf215546Sopenharmony_ci return CL_SUCCESS; 98bf215546Sopenharmony_ci 99bf215546Sopenharmony_ci} catch (error &e) { 100bf215546Sopenharmony_ci return e.get(); 101bf215546Sopenharmony_ci} 102bf215546Sopenharmony_ci 103bf215546Sopenharmony_ciCLOVER_API cl_int 104bf215546Sopenharmony_ciclReleaseDevice(cl_device_id d_dev) try { 105bf215546Sopenharmony_ci obj(d_dev); 106bf215546Sopenharmony_ci 107bf215546Sopenharmony_ci // The reference count doesn't change for root devices. 108bf215546Sopenharmony_ci return CL_SUCCESS; 109bf215546Sopenharmony_ci 110bf215546Sopenharmony_ci} catch (error &e) { 111bf215546Sopenharmony_ci return e.get(); 112bf215546Sopenharmony_ci} 113bf215546Sopenharmony_ci 114bf215546Sopenharmony_ciCLOVER_API cl_int 115bf215546Sopenharmony_ciclGetDeviceInfo(cl_device_id d_dev, cl_device_info param, 116bf215546Sopenharmony_ci size_t size, void *r_buf, size_t *r_size) try { 117bf215546Sopenharmony_ci property_buffer buf { r_buf, size, r_size }; 118bf215546Sopenharmony_ci auto &dev = obj(d_dev); 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_ci switch (param) { 121bf215546Sopenharmony_ci case CL_DEVICE_TYPE: 122bf215546Sopenharmony_ci buf.as_scalar<cl_device_type>() = dev.type(); 123bf215546Sopenharmony_ci break; 124bf215546Sopenharmony_ci 125bf215546Sopenharmony_ci case CL_DEVICE_VENDOR_ID: 126bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.vendor_id(); 127bf215546Sopenharmony_ci break; 128bf215546Sopenharmony_ci 129bf215546Sopenharmony_ci case CL_DEVICE_MAX_COMPUTE_UNITS: 130bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.max_compute_units(); 131bf215546Sopenharmony_ci break; 132bf215546Sopenharmony_ci 133bf215546Sopenharmony_ci case CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS: 134bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.max_block_size().size(); 135bf215546Sopenharmony_ci break; 136bf215546Sopenharmony_ci 137bf215546Sopenharmony_ci case CL_DEVICE_MAX_WORK_ITEM_SIZES: 138bf215546Sopenharmony_ci buf.as_vector<size_t>() = dev.max_block_size(); 139bf215546Sopenharmony_ci break; 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_ci case CL_DEVICE_MAX_WORK_GROUP_SIZE: 142bf215546Sopenharmony_ci buf.as_scalar<size_t>() = dev.max_threads_per_block(); 143bf215546Sopenharmony_ci break; 144bf215546Sopenharmony_ci 145bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR: 146bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 16; 147bf215546Sopenharmony_ci break; 148bf215546Sopenharmony_ci 149bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT: 150bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 8; 151bf215546Sopenharmony_ci break; 152bf215546Sopenharmony_ci 153bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT: 154bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 4; 155bf215546Sopenharmony_ci break; 156bf215546Sopenharmony_ci 157bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG: 158bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 2; 159bf215546Sopenharmony_ci break; 160bf215546Sopenharmony_ci 161bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT: 162bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 4; 163bf215546Sopenharmony_ci break; 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE: 166bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.has_doubles() ? 2 : 0; 167bf215546Sopenharmony_ci break; 168bf215546Sopenharmony_ci 169bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF: 170bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.has_halves() ? 8 : 0; 171bf215546Sopenharmony_ci break; 172bf215546Sopenharmony_ci 173bf215546Sopenharmony_ci case CL_DEVICE_MAX_CLOCK_FREQUENCY: 174bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.max_clock_frequency(); 175bf215546Sopenharmony_ci break; 176bf215546Sopenharmony_ci 177bf215546Sopenharmony_ci case CL_DEVICE_ADDRESS_BITS: 178bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.address_bits(); 179bf215546Sopenharmony_ci break; 180bf215546Sopenharmony_ci 181bf215546Sopenharmony_ci case CL_DEVICE_MAX_READ_IMAGE_ARGS: 182bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.max_images_read(); 183bf215546Sopenharmony_ci break; 184bf215546Sopenharmony_ci 185bf215546Sopenharmony_ci case CL_DEVICE_MAX_WRITE_IMAGE_ARGS: 186bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.max_images_write(); 187bf215546Sopenharmony_ci break; 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci case CL_DEVICE_MAX_MEM_ALLOC_SIZE: 190bf215546Sopenharmony_ci buf.as_scalar<cl_ulong>() = dev.max_mem_alloc_size(); 191bf215546Sopenharmony_ci break; 192bf215546Sopenharmony_ci 193bf215546Sopenharmony_ci case CL_DEVICE_IMAGE2D_MAX_WIDTH: 194bf215546Sopenharmony_ci case CL_DEVICE_IMAGE2D_MAX_HEIGHT: 195bf215546Sopenharmony_ci buf.as_scalar<size_t>() = dev.max_image_size(); 196bf215546Sopenharmony_ci break; 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_ci case CL_DEVICE_IMAGE3D_MAX_WIDTH: 199bf215546Sopenharmony_ci case CL_DEVICE_IMAGE3D_MAX_HEIGHT: 200bf215546Sopenharmony_ci case CL_DEVICE_IMAGE3D_MAX_DEPTH: 201bf215546Sopenharmony_ci buf.as_scalar<size_t>() = dev.max_image_size_3d(); 202bf215546Sopenharmony_ci break; 203bf215546Sopenharmony_ci 204bf215546Sopenharmony_ci case CL_DEVICE_IMAGE_MAX_BUFFER_SIZE: 205bf215546Sopenharmony_ci buf.as_scalar<size_t>() = dev.max_image_buffer_size(); 206bf215546Sopenharmony_ci break; 207bf215546Sopenharmony_ci 208bf215546Sopenharmony_ci case CL_DEVICE_IMAGE_MAX_ARRAY_SIZE: 209bf215546Sopenharmony_ci buf.as_scalar<size_t>() = dev.max_image_array_number(); 210bf215546Sopenharmony_ci break; 211bf215546Sopenharmony_ci 212bf215546Sopenharmony_ci case CL_DEVICE_IMAGE_SUPPORT: 213bf215546Sopenharmony_ci buf.as_scalar<cl_bool>() = dev.image_support(); 214bf215546Sopenharmony_ci break; 215bf215546Sopenharmony_ci 216bf215546Sopenharmony_ci case CL_DEVICE_MAX_PARAMETER_SIZE: 217bf215546Sopenharmony_ci buf.as_scalar<size_t>() = dev.max_mem_input(); 218bf215546Sopenharmony_ci break; 219bf215546Sopenharmony_ci 220bf215546Sopenharmony_ci case CL_DEVICE_MAX_SAMPLERS: 221bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.max_samplers(); 222bf215546Sopenharmony_ci break; 223bf215546Sopenharmony_ci 224bf215546Sopenharmony_ci case CL_DEVICE_MEM_BASE_ADDR_ALIGN: 225bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 8 * dev.mem_base_addr_align(); 226bf215546Sopenharmony_ci break; 227bf215546Sopenharmony_ci 228bf215546Sopenharmony_ci case CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE: 229bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 128; 230bf215546Sopenharmony_ci break; 231bf215546Sopenharmony_ci 232bf215546Sopenharmony_ci case CL_DEVICE_HALF_FP_CONFIG: 233bf215546Sopenharmony_ci // This is the "mandated minimum half precision floating-point 234bf215546Sopenharmony_ci // capability" for OpenCL 1.x. 235bf215546Sopenharmony_ci buf.as_scalar<cl_device_fp_config>() = 236bf215546Sopenharmony_ci CL_FP_INF_NAN | CL_FP_ROUND_TO_NEAREST; 237bf215546Sopenharmony_ci break; 238bf215546Sopenharmony_ci 239bf215546Sopenharmony_ci case CL_DEVICE_SINGLE_FP_CONFIG: 240bf215546Sopenharmony_ci // This is the "mandated minimum single precision floating-point 241bf215546Sopenharmony_ci // capability" for OpenCL 1.1. In OpenCL 1.2, nothing is required for 242bf215546Sopenharmony_ci // custom devices. 243bf215546Sopenharmony_ci buf.as_scalar<cl_device_fp_config>() = 244bf215546Sopenharmony_ci CL_FP_INF_NAN | CL_FP_ROUND_TO_NEAREST; 245bf215546Sopenharmony_ci break; 246bf215546Sopenharmony_ci 247bf215546Sopenharmony_ci case CL_DEVICE_DOUBLE_FP_CONFIG: 248bf215546Sopenharmony_ci if (dev.has_doubles()) 249bf215546Sopenharmony_ci // This is the "mandated minimum double precision floating-point 250bf215546Sopenharmony_ci // capability" 251bf215546Sopenharmony_ci buf.as_scalar<cl_device_fp_config>() = 252bf215546Sopenharmony_ci CL_FP_FMA 253bf215546Sopenharmony_ci | CL_FP_ROUND_TO_NEAREST 254bf215546Sopenharmony_ci | CL_FP_ROUND_TO_ZERO 255bf215546Sopenharmony_ci | CL_FP_ROUND_TO_INF 256bf215546Sopenharmony_ci | CL_FP_INF_NAN 257bf215546Sopenharmony_ci | CL_FP_DENORM; 258bf215546Sopenharmony_ci else 259bf215546Sopenharmony_ci buf.as_scalar<cl_device_fp_config>() = 0; 260bf215546Sopenharmony_ci break; 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_ci case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE: 263bf215546Sopenharmony_ci buf.as_scalar<cl_device_mem_cache_type>() = CL_NONE; 264bf215546Sopenharmony_ci break; 265bf215546Sopenharmony_ci 266bf215546Sopenharmony_ci case CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE: 267bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 0; 268bf215546Sopenharmony_ci break; 269bf215546Sopenharmony_ci 270bf215546Sopenharmony_ci case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE: 271bf215546Sopenharmony_ci buf.as_scalar<cl_ulong>() = 0; 272bf215546Sopenharmony_ci break; 273bf215546Sopenharmony_ci 274bf215546Sopenharmony_ci case CL_DEVICE_GLOBAL_MEM_SIZE: 275bf215546Sopenharmony_ci buf.as_scalar<cl_ulong>() = dev.max_mem_global(); 276bf215546Sopenharmony_ci break; 277bf215546Sopenharmony_ci 278bf215546Sopenharmony_ci case CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE: 279bf215546Sopenharmony_ci buf.as_scalar<cl_ulong>() = dev.max_const_buffer_size(); 280bf215546Sopenharmony_ci break; 281bf215546Sopenharmony_ci 282bf215546Sopenharmony_ci case CL_DEVICE_MAX_CONSTANT_ARGS: 283bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.max_const_buffers(); 284bf215546Sopenharmony_ci break; 285bf215546Sopenharmony_ci 286bf215546Sopenharmony_ci case CL_DEVICE_LOCAL_MEM_TYPE: 287bf215546Sopenharmony_ci buf.as_scalar<cl_device_local_mem_type>() = CL_LOCAL; 288bf215546Sopenharmony_ci break; 289bf215546Sopenharmony_ci 290bf215546Sopenharmony_ci case CL_DEVICE_LOCAL_MEM_SIZE: 291bf215546Sopenharmony_ci buf.as_scalar<cl_ulong>() = dev.max_mem_local(); 292bf215546Sopenharmony_ci break; 293bf215546Sopenharmony_ci 294bf215546Sopenharmony_ci case CL_DEVICE_ERROR_CORRECTION_SUPPORT: 295bf215546Sopenharmony_ci buf.as_scalar<cl_bool>() = CL_FALSE; 296bf215546Sopenharmony_ci break; 297bf215546Sopenharmony_ci 298bf215546Sopenharmony_ci case CL_DEVICE_PROFILING_TIMER_RESOLUTION: 299bf215546Sopenharmony_ci buf.as_scalar<size_t>() = 0; 300bf215546Sopenharmony_ci break; 301bf215546Sopenharmony_ci 302bf215546Sopenharmony_ci case CL_DEVICE_ENDIAN_LITTLE: 303bf215546Sopenharmony_ci buf.as_scalar<cl_bool>() = (dev.endianness() == PIPE_ENDIAN_LITTLE); 304bf215546Sopenharmony_ci break; 305bf215546Sopenharmony_ci 306bf215546Sopenharmony_ci case CL_DEVICE_AVAILABLE: 307bf215546Sopenharmony_ci case CL_DEVICE_COMPILER_AVAILABLE: 308bf215546Sopenharmony_ci case CL_DEVICE_LINKER_AVAILABLE: 309bf215546Sopenharmony_ci buf.as_scalar<cl_bool>() = CL_TRUE; 310bf215546Sopenharmony_ci break; 311bf215546Sopenharmony_ci 312bf215546Sopenharmony_ci case CL_DEVICE_EXECUTION_CAPABILITIES: 313bf215546Sopenharmony_ci buf.as_scalar<cl_device_exec_capabilities>() = CL_EXEC_KERNEL; 314bf215546Sopenharmony_ci break; 315bf215546Sopenharmony_ci 316bf215546Sopenharmony_ci case CL_DEVICE_QUEUE_PROPERTIES: 317bf215546Sopenharmony_ci buf.as_scalar<cl_command_queue_properties>() = CL_QUEUE_PROFILING_ENABLE; 318bf215546Sopenharmony_ci break; 319bf215546Sopenharmony_ci 320bf215546Sopenharmony_ci case CL_DEVICE_BUILT_IN_KERNELS: 321bf215546Sopenharmony_ci buf.as_string() = ""; 322bf215546Sopenharmony_ci break; 323bf215546Sopenharmony_ci 324bf215546Sopenharmony_ci case CL_DEVICE_NAME: 325bf215546Sopenharmony_ci buf.as_string() = dev.device_name(); 326bf215546Sopenharmony_ci break; 327bf215546Sopenharmony_ci 328bf215546Sopenharmony_ci case CL_DEVICE_VENDOR: 329bf215546Sopenharmony_ci buf.as_string() = dev.vendor_name(); 330bf215546Sopenharmony_ci break; 331bf215546Sopenharmony_ci 332bf215546Sopenharmony_ci case CL_DRIVER_VERSION: 333bf215546Sopenharmony_ci buf.as_string() = PACKAGE_VERSION; 334bf215546Sopenharmony_ci break; 335bf215546Sopenharmony_ci 336bf215546Sopenharmony_ci case CL_DEVICE_PROFILE: 337bf215546Sopenharmony_ci buf.as_string() = "FULL_PROFILE"; 338bf215546Sopenharmony_ci break; 339bf215546Sopenharmony_ci 340bf215546Sopenharmony_ci case CL_DEVICE_VERSION: 341bf215546Sopenharmony_ci buf.as_string() = "OpenCL " + dev.device_version_as_string() + " Mesa " PACKAGE_VERSION MESA_GIT_SHA1; 342bf215546Sopenharmony_ci break; 343bf215546Sopenharmony_ci 344bf215546Sopenharmony_ci case CL_DEVICE_EXTENSIONS: 345bf215546Sopenharmony_ci buf.as_string() = dev.supported_extensions_as_string(); 346bf215546Sopenharmony_ci break; 347bf215546Sopenharmony_ci 348bf215546Sopenharmony_ci case CL_DEVICE_PLATFORM: 349bf215546Sopenharmony_ci buf.as_scalar<cl_platform_id>() = desc(dev.platform); 350bf215546Sopenharmony_ci break; 351bf215546Sopenharmony_ci 352bf215546Sopenharmony_ci case CL_DEVICE_HOST_UNIFIED_MEMORY: 353bf215546Sopenharmony_ci buf.as_scalar<cl_bool>() = dev.has_unified_memory(); 354bf215546Sopenharmony_ci break; 355bf215546Sopenharmony_ci 356bf215546Sopenharmony_ci case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR: 357bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 16; 358bf215546Sopenharmony_ci break; 359bf215546Sopenharmony_ci 360bf215546Sopenharmony_ci case CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT: 361bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 8; 362bf215546Sopenharmony_ci break; 363bf215546Sopenharmony_ci 364bf215546Sopenharmony_ci case CL_DEVICE_NATIVE_VECTOR_WIDTH_INT: 365bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 4; 366bf215546Sopenharmony_ci break; 367bf215546Sopenharmony_ci 368bf215546Sopenharmony_ci case CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG: 369bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 2; 370bf215546Sopenharmony_ci break; 371bf215546Sopenharmony_ci 372bf215546Sopenharmony_ci case CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT: 373bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 4; 374bf215546Sopenharmony_ci break; 375bf215546Sopenharmony_ci 376bf215546Sopenharmony_ci case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE: 377bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.has_doubles() ? 2 : 0; 378bf215546Sopenharmony_ci break; 379bf215546Sopenharmony_ci 380bf215546Sopenharmony_ci case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF: 381bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = dev.has_halves() ? 8 : 0; 382bf215546Sopenharmony_ci break; 383bf215546Sopenharmony_ci 384bf215546Sopenharmony_ci case CL_DEVICE_OPENCL_C_VERSION: 385bf215546Sopenharmony_ci buf.as_string() = "OpenCL C " + dev.device_clc_version_as_string() + " "; 386bf215546Sopenharmony_ci break; 387bf215546Sopenharmony_ci 388bf215546Sopenharmony_ci case CL_DEVICE_PRINTF_BUFFER_SIZE: 389bf215546Sopenharmony_ci buf.as_scalar<size_t>() = dev.max_printf_buffer_size(); 390bf215546Sopenharmony_ci break; 391bf215546Sopenharmony_ci 392bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_INTEROP_USER_SYNC: 393bf215546Sopenharmony_ci buf.as_scalar<cl_bool>() = CL_TRUE; 394bf215546Sopenharmony_ci break; 395bf215546Sopenharmony_ci 396bf215546Sopenharmony_ci case CL_DEVICE_PARENT_DEVICE: 397bf215546Sopenharmony_ci buf.as_scalar<cl_device_id>() = NULL; 398bf215546Sopenharmony_ci break; 399bf215546Sopenharmony_ci 400bf215546Sopenharmony_ci case CL_DEVICE_PARTITION_MAX_SUB_DEVICES: 401bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 0; 402bf215546Sopenharmony_ci break; 403bf215546Sopenharmony_ci 404bf215546Sopenharmony_ci case CL_DEVICE_PARTITION_PROPERTIES: 405bf215546Sopenharmony_ci buf.as_vector<cl_device_partition_property>() = 406bf215546Sopenharmony_ci desc(property_list<cl_device_partition_property>()); 407bf215546Sopenharmony_ci break; 408bf215546Sopenharmony_ci 409bf215546Sopenharmony_ci case CL_DEVICE_PARTITION_AFFINITY_DOMAIN: 410bf215546Sopenharmony_ci buf.as_scalar<cl_device_affinity_domain>() = 0; 411bf215546Sopenharmony_ci break; 412bf215546Sopenharmony_ci 413bf215546Sopenharmony_ci case CL_DEVICE_PARTITION_TYPE: 414bf215546Sopenharmony_ci buf.as_vector<cl_device_partition_property>() = 415bf215546Sopenharmony_ci desc(property_list<cl_device_partition_property>()); 416bf215546Sopenharmony_ci break; 417bf215546Sopenharmony_ci 418bf215546Sopenharmony_ci case CL_DEVICE_REFERENCE_COUNT: 419bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 1; 420bf215546Sopenharmony_ci break; 421bf215546Sopenharmony_ci 422bf215546Sopenharmony_ci case CL_DEVICE_SVM_CAPABILITIES: 423bf215546Sopenharmony_ci case CL_DEVICE_SVM_CAPABILITIES_ARM: 424bf215546Sopenharmony_ci buf.as_scalar<cl_device_svm_capabilities>() = dev.svm_support(); 425bf215546Sopenharmony_ci break; 426bf215546Sopenharmony_ci 427bf215546Sopenharmony_ci case CL_DEVICE_NUMERIC_VERSION: 428bf215546Sopenharmony_ci buf.as_scalar<cl_version>() = dev.device_version(); 429bf215546Sopenharmony_ci break; 430bf215546Sopenharmony_ci 431bf215546Sopenharmony_ci case CL_DEVICE_OPENCL_C_NUMERIC_VERSION_KHR: 432bf215546Sopenharmony_ci buf.as_scalar<cl_version>() = dev.device_clc_version(true); 433bf215546Sopenharmony_ci break; 434bf215546Sopenharmony_ci 435bf215546Sopenharmony_ci case CL_DEVICE_OPENCL_C_ALL_VERSIONS: 436bf215546Sopenharmony_ci buf.as_vector<cl_name_version>() = dev.opencl_c_all_versions(); 437bf215546Sopenharmony_ci break; 438bf215546Sopenharmony_ci 439bf215546Sopenharmony_ci case CL_DEVICE_EXTENSIONS_WITH_VERSION: 440bf215546Sopenharmony_ci buf.as_vector<cl_name_version>() = dev.supported_extensions(); 441bf215546Sopenharmony_ci break; 442bf215546Sopenharmony_ci 443bf215546Sopenharmony_ci case CL_DEVICE_OPENCL_C_FEATURES: 444bf215546Sopenharmony_ci buf.as_vector<cl_name_version>() = dev.opencl_c_features(); 445bf215546Sopenharmony_ci break; 446bf215546Sopenharmony_ci 447bf215546Sopenharmony_ci case CL_DEVICE_IL_VERSION: 448bf215546Sopenharmony_ci if (dev.supported_extensions_as_string().find("cl_khr_il_program") == std::string::npos) 449bf215546Sopenharmony_ci throw error(CL_INVALID_VALUE); 450bf215546Sopenharmony_ci buf.as_string() = supported_il_versions_as_string(dev); 451bf215546Sopenharmony_ci break; 452bf215546Sopenharmony_ci 453bf215546Sopenharmony_ci case CL_DEVICE_ILS_WITH_VERSION: 454bf215546Sopenharmony_ci buf.as_vector<cl_name_version>() = dev.supported_il_versions(); 455bf215546Sopenharmony_ci break; 456bf215546Sopenharmony_ci 457bf215546Sopenharmony_ci case CL_DEVICE_BUILT_IN_KERNELS_WITH_VERSION: 458bf215546Sopenharmony_ci buf.as_vector<cl_name_version>() = std::vector<cl_name_version>{}; 459bf215546Sopenharmony_ci break; 460bf215546Sopenharmony_ci 461bf215546Sopenharmony_ci case CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS: 462bf215546Sopenharmony_ci case CL_DEVICE_IMAGE_PITCH_ALIGNMENT: 463bf215546Sopenharmony_ci case CL_DEVICE_IMAGE_BASE_ADDRESS_ALIGNMENT: 464bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT: 465bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT: 466bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT: 467bf215546Sopenharmony_ci case CL_DEVICE_MAX_NUM_SUB_GROUPS: 468bf215546Sopenharmony_ci case CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE: 469bf215546Sopenharmony_ci case CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE: 470bf215546Sopenharmony_ci case CL_DEVICE_MAX_ON_DEVICE_QUEUES: 471bf215546Sopenharmony_ci case CL_DEVICE_MAX_ON_DEVICE_EVENTS: 472bf215546Sopenharmony_ci case CL_DEVICE_MAX_PIPE_ARGS: 473bf215546Sopenharmony_ci case CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS: 474bf215546Sopenharmony_ci case CL_DEVICE_PIPE_MAX_PACKET_SIZE: 475bf215546Sopenharmony_ci buf.as_scalar<cl_uint>() = 0; 476bf215546Sopenharmony_ci break; 477bf215546Sopenharmony_ci 478bf215546Sopenharmony_ci case CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE: 479bf215546Sopenharmony_ci case CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE: 480bf215546Sopenharmony_ci buf.as_scalar<size_t>() = 0; 481bf215546Sopenharmony_ci break; 482bf215546Sopenharmony_ci 483bf215546Sopenharmony_ci case CL_DEVICE_SUB_GROUP_INDEPENDENT_FORWARD_PROGRESS: 484bf215546Sopenharmony_ci case CL_DEVICE_NON_UNIFORM_WORK_GROUP_SUPPORT: 485bf215546Sopenharmony_ci case CL_DEVICE_WORK_GROUP_COLLECTIVE_FUNCTIONS_SUPPORT: 486bf215546Sopenharmony_ci case CL_DEVICE_GENERIC_ADDRESS_SPACE_SUPPORT: 487bf215546Sopenharmony_ci case CL_DEVICE_PIPE_SUPPORT: 488bf215546Sopenharmony_ci buf.as_scalar<cl_bool>() = CL_FALSE; 489bf215546Sopenharmony_ci break; 490bf215546Sopenharmony_ci 491bf215546Sopenharmony_ci case CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES: 492bf215546Sopenharmony_ci buf.as_scalar<cl_command_queue_properties>() = 0; 493bf215546Sopenharmony_ci break; 494bf215546Sopenharmony_ci 495bf215546Sopenharmony_ci case CL_DEVICE_ATOMIC_MEMORY_CAPABILITIES: 496bf215546Sopenharmony_ci buf.as_scalar<cl_device_atomic_capabilities>() = (CL_DEVICE_ATOMIC_ORDER_RELAXED | 497bf215546Sopenharmony_ci CL_DEVICE_ATOMIC_SCOPE_WORK_GROUP); 498bf215546Sopenharmony_ci break; 499bf215546Sopenharmony_ci case CL_DEVICE_ATOMIC_FENCE_CAPABILITIES: 500bf215546Sopenharmony_ci buf.as_scalar<cl_device_atomic_capabilities>() = (CL_DEVICE_ATOMIC_ORDER_RELAXED | 501bf215546Sopenharmony_ci CL_DEVICE_ATOMIC_ORDER_ACQ_REL | 502bf215546Sopenharmony_ci CL_DEVICE_ATOMIC_SCOPE_WORK_GROUP); 503bf215546Sopenharmony_ci break; 504bf215546Sopenharmony_ci 505bf215546Sopenharmony_ci case CL_DEVICE_DEVICE_ENQUEUE_CAPABILITIES: 506bf215546Sopenharmony_ci buf.as_scalar<cl_device_device_enqueue_capabilities>() = 0; 507bf215546Sopenharmony_ci break; 508bf215546Sopenharmony_ci 509bf215546Sopenharmony_ci case CL_DEVICE_PREFERRED_WORK_GROUP_SIZE_MULTIPLE: 510bf215546Sopenharmony_ci buf.as_scalar<size_t>() = 1; 511bf215546Sopenharmony_ci break; 512bf215546Sopenharmony_ci 513bf215546Sopenharmony_ci case CL_DEVICE_LATEST_CONFORMANCE_VERSION_PASSED: 514bf215546Sopenharmony_ci buf.as_string() = ""; 515bf215546Sopenharmony_ci break; 516bf215546Sopenharmony_ci 517bf215546Sopenharmony_ci default: 518bf215546Sopenharmony_ci throw error(CL_INVALID_VALUE); 519bf215546Sopenharmony_ci } 520bf215546Sopenharmony_ci 521bf215546Sopenharmony_ci return CL_SUCCESS; 522bf215546Sopenharmony_ci 523bf215546Sopenharmony_ci} catch (error &e) { 524bf215546Sopenharmony_ci return e.get(); 525bf215546Sopenharmony_ci} 526