func (d *Device) Property(prop DeviceProperty) interface{} { if value, ok := d.properties[prop]; ok { return value } var data interface{} var length C.size_t var ret C.cl_int switch prop { case DEVICE_AVAILABLE, DEVICE_COMPILER_AVAILABLE, DEVICE_ENDIAN_LITTLE, DEVICE_ERROR_CORRECTION_SUPPORT, DEVICE_HOST_UNIFIED_MEMORY, DEVICE_IMAGE_SUPPORT: //DEVICE_LINKER_AVAILABLE, //DEVICE_PREFERRED_INTEROP_USER_SYNC: var val C.cl_bool ret = C.clGetDeviceInfo(d.id, C.cl_device_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length) data = val == C.CL_TRUE case DEVICE_ADDRESS_BITS, DEVICE_MAX_CLOCK_FREQUENCY, DEVICE_MAX_COMPUTE_UNITS, DEVICE_MAX_CONSTANT_ARGS, DEVICE_MAX_READ_IMAGE_ARGS, DEVICE_MAX_SAMPLERS, DEVICE_MAX_WORK_ITEM_DIMENSIONS, DEVICE_MAX_WRITE_IMAGE_ARGS, DEVICE_MEM_BASE_ADDR_ALIGN, DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, DEVICE_NATIVE_VECTOR_WIDTH_CHAR, DEVICE_NATIVE_VECTOR_WIDTH_SHORT, DEVICE_NATIVE_VECTOR_WIDTH_INT, DEVICE_NATIVE_VECTOR_WIDTH_LONG, DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, DEVICE_NATIVE_VECTOR_WIDTH_HALF, //DEVICE_PARTITION_MAX_SUB_DEVICES, DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, DEVICE_PREFERRED_VECTOR_WIDTH_INT, DEVICE_PREFERRED_VECTOR_WIDTH_LONG, DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, DEVICE_PREFERRED_VECTOR_WIDTH_HALF, //DEVICE_REFERENCE_COUNT, DEVICE_VENDOR_ID: var val C.cl_uint ret = C.clGetDeviceInfo(d.id, C.cl_device_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length) data = val case DEVICE_IMAGE2D_MAX_HEIGHT, DEVICE_IMAGE2D_MAX_WIDTH, DEVICE_IMAGE3D_MAX_DEPTH, DEVICE_IMAGE3D_MAX_HEIGHT, DEVICE_IMAGE3D_MAX_WIDTH, //DEVICE_IMAGE_MAX_BUFFER_SIZE, //DEVICE_IMAGE_MAX_ARRAY_SIZE, DEVICE_MAX_PARAMETER_SIZE, DEVICE_MAX_WORK_GROUP_SIZE, //DEVICE_PRINTF_BUFFER_SIZE, DEVICE_PROFILING_TIMER_RESOLUTION: var val C.size_t ret = C.clGetDeviceInfo(d.id, C.cl_device_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length) data = val case DEVICE_GLOBAL_MEM_CACHE_SIZE, DEVICE_GLOBAL_MEM_SIZE, DEVICE_LOCAL_MEM_SIZE, DEVICE_MAX_CONSTANT_BUFFER_SIZE, DEVICE_MAX_MEM_ALLOC_SIZE: var val C.cl_ulong ret = C.clGetDeviceInfo(d.id, C.cl_device_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length) data = val /*case DEVICE_PLATFORM: var val C.cl_platform_id ret = C.clGetDeviceInfo(d.id, C.cl_device_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length) data = Platform{id: val}*/ /*case DEVICE_PARENT_DEVICE: var val C.cl_device_id ret = C.clGetDeviceInfo(d.id, C.cl_device_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length) data = Device{id: val}*/ case DEVICE_TYPE: var val C.cl_device_type ret = C.clGetDeviceInfo(d.id, C.cl_device_info(prop), C.size_t(unsafe.Sizeof(val)), unsafe.Pointer(&val), &length) data = DeviceType(val) case //DEVICE_BUILT_IN_KERNELS, DEVICE_EXTENSIONS, DEVICE_NAME, DEVICE_OPENCL_C_VERSION, DEVICE_PROFILE, DEVICE_VENDOR, DEVICE_VERSION, DRIVER_VERSION: if ret = C.clGetDeviceInfo(d.id, C.cl_device_info(prop), 0, nil, &length); ret != C.CL_SUCCESS || length < 1 { data = "" break } buf := make([]C.char, length) if ret = C.clGetDeviceInfo(d.id, C.cl_device_info(prop), length, unsafe.Pointer(&buf[0]), &length); ret != C.CL_SUCCESS || length < 1 { data = "" break } data = C.GoStringN(&buf[0], C.int(length-1)) default: return nil } if ret != C.CL_SUCCESS { return nil } d.properties[prop] = data return d.properties[prop] }
// see https://www.khronos.org/registry/cl/sdk/1.1/docs/man/xhtml/clGetDeviceInfo.html func GetDeviceInfo(did DeviceId, paramName DeviceInfo, paramValueSize uint64, data unsafe.Pointer, paramValueSizeRet *uint64) ErrorCode { return ErrorCode(C.clGetDeviceInfo(did, C.cl_device_info(paramName), C.size_t(paramValueSize), data, (*C.size_t)(paramValueSizeRet))) }
func CLGetDeviceInfo(device CL_device_id, param_name CL_device_info, param_value_size CL_size_t, param_value *interface{}, param_value_size_ret *CL_size_t) CL_int { if (param_value_size == 0 || param_value == nil) && param_value_size_ret == nil { return CL_INVALID_VALUE } else { var c_param_value_size_ret C.size_t var c_errcode_ret C.cl_int if param_value_size == 0 || param_value == nil { c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), nil, &c_param_value_size_ret) } else { switch param_name { case CL_DEVICE_AVAILABLE, CL_DEVICE_COMPILER_AVAILABLE, CL_DEVICE_ENDIAN_LITTLE, CL_DEVICE_ERROR_CORRECTION_SUPPORT, CL_DEVICE_HOST_UNIFIED_MEMORY, CL_DEVICE_IMAGE_SUPPORT, CL_DEVICE_LINKER_AVAILABLE, CL_DEVICE_PREFERRED_INTEROP_USER_SYNC: var value C.cl_bool c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = value == C.CL_TRUE case CL_DEVICE_ADDRESS_BITS, CL_DEVICE_MAX_CLOCK_FREQUENCY, CL_DEVICE_MAX_COMPUTE_UNITS, CL_DEVICE_MAX_CONSTANT_ARGS, CL_DEVICE_MAX_READ_IMAGE_ARGS, CL_DEVICE_MAX_SAMPLERS, CL_DEVICE_MAX_WORK_ITEM_DIMENSIONS, CL_DEVICE_MAX_WRITE_IMAGE_ARGS, CL_DEVICE_MEM_BASE_ADDR_ALIGN, CL_DEVICE_MIN_DATA_TYPE_ALIGN_SIZE, CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR, CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT, CL_DEVICE_NATIVE_VECTOR_WIDTH_INT, CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG, CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT, CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE, CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF, CL_DEVICE_PREFERRED_VECTOR_WIDTH_CHAR, CL_DEVICE_PREFERRED_VECTOR_WIDTH_SHORT, CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT, CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG, CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT, CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE, CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF, CL_DEVICE_VENDOR_ID, CL_DEVICE_GLOBAL_MEM_CACHELINE_SIZE, CL_DEVICE_PARTITION_MAX_SUB_DEVICES, CL_DEVICE_REFERENCE_COUNT, CL_DEVICE_MAX_READ_WRITE_IMAGE_ARGS, CL_DEVICE_QUEUE_ON_DEVICE_PREFERRED_SIZE, CL_DEVICE_QUEUE_ON_DEVICE_MAX_SIZE, CL_DEVICE_MAX_ON_DEVICE_QUEUES, CL_DEVICE_MAX_ON_DEVICE_EVENTS, CL_DEVICE_MAX_PIPE_ARGS, CL_DEVICE_PIPE_MAX_ACTIVE_RESERVATIONS, CL_DEVICE_PIPE_MAX_PACKET_SIZE, CL_DEVICE_PREFERRED_PLATFORM_ATOMIC_ALIGNMENT, CL_DEVICE_PREFERRED_GLOBAL_ATOMIC_ALIGNMENT, CL_DEVICE_PREFERRED_LOCAL_ATOMIC_ALIGNMENT: var value C.cl_uint c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_uint(value) case CL_DEVICE_IMAGE2D_MAX_HEIGHT, CL_DEVICE_IMAGE2D_MAX_WIDTH, CL_DEVICE_IMAGE3D_MAX_DEPTH, CL_DEVICE_IMAGE3D_MAX_HEIGHT, CL_DEVICE_IMAGE3D_MAX_WIDTH, CL_DEVICE_MAX_PARAMETER_SIZE, CL_DEVICE_MAX_WORK_GROUP_SIZE, CL_DEVICE_PROFILING_TIMER_RESOLUTION, CL_DEVICE_IMAGE_MAX_BUFFER_SIZE, CL_DEVICE_IMAGE_MAX_ARRAY_SIZE, CL_DEVICE_PRINTF_BUFFER_SIZE, CL_DEVICE_MAX_GLOBAL_VARIABLE_SIZE, CL_DEVICE_GLOBAL_VARIABLE_PREFERRED_TOTAL_SIZE: var value C.size_t c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_size_t(value) case CL_DEVICE_GLOBAL_MEM_CACHE_SIZE, CL_DEVICE_GLOBAL_MEM_SIZE, CL_DEVICE_LOCAL_MEM_SIZE, CL_DEVICE_MAX_CONSTANT_BUFFER_SIZE, CL_DEVICE_MAX_MEM_ALLOC_SIZE: var value C.cl_ulong c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_ulong(value) case CL_DEVICE_PLATFORM: var value C.cl_platform_id c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_platform_id{value} case CL_DEVICE_PARENT_DEVICE: var value C.cl_device_id c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_device_id{value} case CL_DEVICE_TYPE: var value C.cl_device_type c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_device_type(value) case CL_DEVICE_EXTENSIONS, CL_DEVICE_NAME, CL_DEVICE_OPENCL_C_VERSION, CL_DEVICE_PROFILE, CL_DEVICE_VENDOR, CL_DEVICE_VERSION, CL_DRIVER_VERSION, CL_DEVICE_BUILT_IN_KERNELS: value := make([]C.char, param_value_size) c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value[0]), &c_param_value_size_ret) *param_value = C.GoStringN(&value[0], C.int(c_param_value_size_ret-1)) case CL_DEVICE_SINGLE_FP_CONFIG, CL_DEVICE_DOUBLE_FP_CONFIG: var value C.cl_device_fp_config c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_device_fp_config(value) case CL_DEVICE_GLOBAL_MEM_CACHE_TYPE: var value C.cl_device_mem_cache_type c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_device_mem_cache_type(value) case CL_DEVICE_LOCAL_MEM_TYPE: var value C.cl_device_local_mem_type c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_device_local_mem_type(value) case CL_DEVICE_EXECUTION_CAPABILITIES: var value C.cl_device_exec_capabilities c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_device_exec_capabilities(value) //case CL_DEVICE_QUEUE_PROPERTIES,//deprecated case CL_DEVICE_QUEUE_ON_HOST_PROPERTIES, CL_DEVICE_QUEUE_ON_DEVICE_PROPERTIES: var value C.cl_command_queue_properties c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_command_queue_properties(value) case CL_DEVICE_PARTITION_PROPERTIES, CL_DEVICE_PARTITION_TYPE: var param C.cl_device_partition_property length := int(C.size_t(param_value_size) / C.size_t(unsafe.Sizeof(param))) value1 := make([]C.cl_device_partition_property, length) value2 := make([]CL_device_partition_property, length) c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value1[0]), &c_param_value_size_ret) for i := 0; i < length; i++ { value2[i] = CL_device_partition_property(value1[i]) } *param_value = value2 case CL_DEVICE_MAX_WORK_ITEM_SIZES: var param C.size_t length := int(C.size_t(param_value_size) / C.size_t(unsafe.Sizeof(param))) value1 := make([]C.size_t, length) value2 := make([]CL_size_t, length) c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value1[0]), &c_param_value_size_ret) for i := 0; i < length; i++ { value2[i] = CL_size_t(value1[i]) } *param_value = value2 case CL_DEVICE_PARTITION_AFFINITY_DOMAIN: var value C.cl_device_affinity_domain c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_device_affinity_domain(value) case CL_DEVICE_SVM_CAPABILITIES: var value C.cl_bitfield //C.cl_device_svm_capabilities //use cl_bitfield to make darwin pass c_errcode_ret = C.clGetDeviceInfo(device.cl_device_id, C.cl_device_info(param_name), C.size_t(param_value_size), unsafe.Pointer(&value), &c_param_value_size_ret) *param_value = CL_device_svm_capabilities(value) default: return CL_INVALID_VALUE } } if param_value_size_ret != nil { *param_value_size_ret = CL_size_t(c_param_value_size_ret) } return CL_int(c_errcode_ret) } }