diff --git a/backends/vulkan/runtime/vk_api/Adapter.cpp b/backends/vulkan/runtime/vk_api/Adapter.cpp index db6fdc2909a..5b698096bb5 100644 --- a/backends/vulkan/runtime/vk_api/Adapter.cpp +++ b/backends/vulkan/runtime/vk_api/Adapter.cpp @@ -107,7 +107,33 @@ VkDevice create_logical_device( nullptr, // pEnabledFeatures }; - device_create_info.pNext = physical_device.extension_features; + void* extension_list_top = nullptr; + +#ifdef VK_KHR_16bit_storage + VkPhysicalDevice16BitStorageFeatures shader_16bit_storage{ + physical_device.shader_16bit_storage}; + + shader_16bit_storage.pNext = extension_list_top; + extension_list_top = &shader_16bit_storage; +#endif /* VK_KHR_16bit_storage */ + +#ifdef VK_KHR_8bit_storage + VkPhysicalDevice8BitStorageFeatures shader_8bit_storage{ + physical_device.shader_8bit_storage}; + + shader_8bit_storage.pNext = extension_list_top; + extension_list_top = &shader_8bit_storage; +#endif /* VK_KHR_8bit_storage */ + +#ifdef VK_KHR_shader_float16_int8 + VkPhysicalDeviceShaderFloat16Int8Features shader_float16_int8_types{ + physical_device.shader_float16_int8_types}; + + shader_float16_int8_types.pNext = extension_list_top; + extension_list_top = &shader_float16_int8_types; +#endif /* VK_KHR_shader_float16_int8 */ + + device_create_info.pNext = extension_list_top; VkDevice handle = nullptr; VK_CHECK(vkCreateDevice( diff --git a/backends/vulkan/runtime/vk_api/Device.cpp b/backends/vulkan/runtime/vk_api/Device.cpp index c4119e04b78..b9e3b444db2 100644 --- a/backends/vulkan/runtime/vk_api/Device.cpp +++ b/backends/vulkan/runtime/vk_api/Device.cpp @@ -12,7 +12,9 @@ #include +#include #include +#include #include namespace vkcompute { @@ -34,14 +36,15 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle) shader_float16_int8_types{ VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR}, #endif /* VK_KHR_shader_float16_int8 */ - extension_features{nullptr}, queue_families{}, num_compute_queues(0), supports_int16_shader_types(false), has_unified_memory(false), has_timestamps(false), timestamp_period(0), - min_ubo_alignment(0) { + min_ubo_alignment(0), + device_name{}, + device_type{DeviceType::UNKNOWN} { // Extract physical device properties vkGetPhysicalDeviceProperties(handle, &properties); @@ -57,34 +60,24 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle) // Create linked list to query availability of extensions + void* extension_list_top = nullptr; + #ifdef VK_KHR_16bit_storage - extension_features = &shader_16bit_storage; - features2.pNext = &shader_16bit_storage; -#elif defined(VK_KHR_8bit_storage) - extension_features = &shader_8bit_storage; - features2.pNext = &shader_8bit_storage; -#elif defined(VK_KHR_shader_float16_int8) - extension_features = &shader_float16_int8_types; - features2.pNext = &shader_float16_int8_types; + shader_16bit_storage.pNext = extension_list_top; + extension_list_top = &shader_16bit_storage; #endif /* VK_KHR_16bit_storage */ -#if defined(VK_KHR_16bit_storage) && defined(VK_KHR_8bit_storage) - shader_16bit_storage.pNext = &shader_8bit_storage; -#elif defined(VK_KHR_16bit_storage) && defined(VK_KHR_shader_float16_int8) - shader_16bit_storage.pNext = &shader_float16_int8_types; -#elif defined(VK_KHR_16bit_storage) - shader_16bit_storage.pNext = nullptr; -#endif - -#if defined(VK_KHR_8bit_storage) && defined(VK_KHR_shader_float16_int8) - shader_8bit_storage.pNext = &shader_float16_int8_types; -#elif defined(VK_KHR_8bit_storage) - shader_8bit_storage.pNext = nullptr; -#endif +#ifdef VK_KHR_8bit_storage + shader_8bit_storage.pNext = extension_list_top; + extension_list_top = &shader_8bit_storage; +#endif /* VK_KHR_8bit_storage */ #ifdef VK_KHR_shader_float16_int8 - shader_float16_int8_types.pNext = nullptr; -#endif + shader_float16_int8_types.pNext = extension_list_top; + extension_list_top = &shader_float16_int8_types; +#endif /* VK_KHR_shader_float16_int8 */ + + features2.pNext = extension_list_top; vkGetPhysicalDeviceFeatures2(handle, &features2); @@ -118,6 +111,24 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle) num_compute_queues += p.queueCount; } } + + // Obtain device identity metadata + device_name = std::string(properties.deviceName); + std::transform( + device_name.begin(), + device_name.end(), + device_name.begin(), + [](unsigned char c) { return std::tolower(c); }); + + if (device_name.find("adreno") != std::string::npos) { + device_type = DeviceType::ADRENO; + } else if (device_name.find("swiftshader") != std::string::npos) { + device_type = DeviceType::SWIFTSHADER; + } else if (device_name.find("nvidia") != std::string::npos) { + device_type = DeviceType::NVIDIA; + } else if (device_name.find("mali") != std::string::npos) { + device_type = DeviceType::MALI; + } } // diff --git a/backends/vulkan/runtime/vk_api/Device.h b/backends/vulkan/runtime/vk_api/Device.h index 70d5b1db5af..3fdfcc04a49 100644 --- a/backends/vulkan/runtime/vk_api/Device.h +++ b/backends/vulkan/runtime/vk_api/Device.h @@ -18,6 +18,14 @@ namespace vkcompute { namespace vkapi { +enum class DeviceType : uint32_t { + UNKNOWN, + NVIDIA, + MALI, + ADRENO, + SWIFTSHADER, +}; + struct PhysicalDevice final { // Handle VkPhysicalDevice handle; @@ -37,9 +45,6 @@ struct PhysicalDevice final { VkPhysicalDeviceShaderFloat16Int8Features shader_float16_int8_types; #endif /* VK_KHR_shader_float16_int8 */ - // Head of the linked list of extensions to be requested - void* extension_features; - // Available GPU queues std::vector queue_families; @@ -51,6 +56,10 @@ struct PhysicalDevice final { float timestamp_period; size_t min_ubo_alignment; + // Device identity + std::string device_name; + DeviceType device_type; + explicit PhysicalDevice(VkPhysicalDevice); };