diff --git a/src/api.cpp b/src/api.cpp index bad7e8b8..ec114074 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -378,11 +378,16 @@ cl_int CLVK_API_CALL clGetDeviceIDs(cl_platform_id platform, cl_uint num = 0; for (auto dev : icd_downcast(platform)->devices()) { - if (dev->type() & device_type) { + if ((dev->type() & device_type) || + (device_type == CL_DEVICE_TYPE_DEFAULT && num == 0) || + (device_type == CL_DEVICE_TYPE_ALL)) { if ((devices != nullptr) && (num < num_entries)) { devices[num] = dev; } num++; + if (device_type == CL_DEVICE_TYPE_DEFAULT) { + break; + } } } @@ -620,19 +625,23 @@ cl_int CLVK_API_CALL clGetDeviceInfo(cl_device_id dev, case CL_DEVICE_PREFERRED_VECTOR_WIDTH_INT: case CL_DEVICE_PREFERRED_VECTOR_WIDTH_LONG: case CL_DEVICE_PREFERRED_VECTOR_WIDTH_FLOAT: - case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE: case CL_DEVICE_PREFERRED_VECTOR_WIDTH_HALF: case CL_DEVICE_NATIVE_VECTOR_WIDTH_CHAR: case CL_DEVICE_NATIVE_VECTOR_WIDTH_SHORT: case CL_DEVICE_NATIVE_VECTOR_WIDTH_INT: case CL_DEVICE_NATIVE_VECTOR_WIDTH_LONG: case CL_DEVICE_NATIVE_VECTOR_WIDTH_FLOAT: - case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE: case CL_DEVICE_NATIVE_VECTOR_WIDTH_HALF: val_uint = 1; // FIXME can we do better? copy_ptr = &val_uint; size_ret = sizeof(val_uint); break; + case CL_DEVICE_PREFERRED_VECTOR_WIDTH_DOUBLE: + case CL_DEVICE_NATIVE_VECTOR_WIDTH_DOUBLE: + val_uint = 0; + copy_ptr = &val_uint; + size_ret = sizeof(val_uint); + break; case CL_DEVICE_PROFILING_TIMER_RESOLUTION: val_sizet = 1; copy_ptr = &val_sizet; diff --git a/src/device.cpp b/src/device.cpp index 7d71742f..12dc7e33 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -28,8 +28,8 @@ constexpr VkMemoryPropertyFlags cvk_device::buffer_supported_memory_types[]; constexpr VkMemoryPropertyFlags cvk_device::image_supported_memory_types[]; cvk_device* cvk_device::create(cvk_platform* platform, VkInstance instance, - VkPhysicalDevice pdev, bool is_default) { - cvk_device* device = new cvk_device(platform, pdev, is_default); + VkPhysicalDevice pdev) { + cvk_device* device = new cvk_device(platform, pdev); if (!device->init(instance)) { delete device; diff --git a/src/device.hpp b/src/device.hpp index 4753d200..a4dff861 100644 --- a/src/device.hpp +++ b/src/device.hpp @@ -48,26 +48,23 @@ struct cvk_platform; struct cvk_device : public _cl_device_id, object_magic_header { - cvk_device(cvk_platform* platform, VkPhysicalDevice pd, bool is_default) + cvk_device(cvk_platform* platform, VkPhysicalDevice pd) : m_platform(platform), m_pdev(pd) { vkGetPhysicalDeviceProperties(m_pdev, &m_properties); vkGetPhysicalDeviceMemoryProperties(m_pdev, &m_mem_properties); - if (is_default) { - m_type = CL_DEVICE_TYPE_DEFAULT; - } switch (m_properties.deviceType) { case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: - m_type |= CL_DEVICE_TYPE_GPU; + m_type = CL_DEVICE_TYPE_GPU; break; case VK_PHYSICAL_DEVICE_TYPE_CPU: - m_type |= CL_DEVICE_TYPE_CPU; + m_type = CL_DEVICE_TYPE_CPU; break; case VK_PHYSICAL_DEVICE_TYPE_OTHER: default: - m_type |= CL_DEVICE_TYPE_ACCELERATOR; + m_type = CL_DEVICE_TYPE_ACCELERATOR; break; } @@ -77,7 +74,7 @@ struct cvk_device : public _cl_device_id, } static cvk_device* create(cvk_platform* platform, VkInstance instance, - VkPhysicalDevice pdev, bool is_default); + VkPhysicalDevice pdev); virtual ~cvk_device() { for (auto entry : m_pipeline_caches) { @@ -844,7 +841,7 @@ struct cvk_platform : public _cl_platform_id, CHECK_RETURN bool create_device(VkInstance instance, VkPhysicalDevice pdev) { - auto dev = cvk_device::create(this, instance, pdev, m_devices.empty()); + auto dev = cvk_device::create(this, instance, pdev); if (dev != nullptr) { m_devices.push_back(dev); return true; diff --git a/tests/api/platform.cpp b/tests/api/platform.cpp index 1c973712..47dd4dfb 100644 --- a/tests/api/platform.cpp +++ b/tests/api/platform.cpp @@ -16,35 +16,6 @@ #include -TEST(Platform, HasOneDefaultDevice) { - cl_int err; - cl_uint num_devices; - err = - clGetDeviceIDs(gPlatform, CL_DEVICE_TYPE_ALL, 0, nullptr, &num_devices); - ASSERT_EQ(err, CL_SUCCESS); - - std::vector devices(num_devices); - - err = clGetDeviceIDs(gPlatform, CL_DEVICE_TYPE_ALL, num_devices, - devices.data(), nullptr); - ASSERT_EQ(err, CL_SUCCESS); - - unsigned num_default = 0; - - for (auto dev : devices) { - cl_device_type dtype; - err = clGetDeviceInfo(dev, CL_DEVICE_TYPE, sizeof(dtype), &dtype, - nullptr); - ASSERT_EQ(err, CL_SUCCESS); - - if (dtype & CL_DEVICE_TYPE_DEFAULT) { - num_default++; - } - } - - ASSERT_EQ(num_default, 1); -} - TEST(Platform, DeviceQueryWithMultipleTypes) { cl_int err; @@ -55,7 +26,6 @@ TEST(Platform, DeviceQueryWithMultipleTypes) { ASSERT_EQ(err, CL_SUCCESS); // Check its type is one of the expected values - dtype &= ~CL_DEVICE_TYPE_DEFAULT; ASSERT_TRUE(dtype == CL_DEVICE_TYPE_GPU || dtype == CL_DEVICE_TYPE_CPU || dtype == CL_DEVICE_TYPE_ACCELERATOR);