From 541a14fc7c8dc7238d0eb560cfcfeb4239d34d34 Mon Sep 17 00:00:00 2001 From: Stephen Jia Date: Tue, 22 Apr 2025 08:12:21 -0700 Subject: [PATCH] [ET-VK][ez] Store physical device identity metadata ## Context Lay the groundwork for storing device identity metadata. This will allow operator implementations to select and/or configure compute shaders based on the GPU that is being used. Differential Revision: [D73438723](https://our.internmc.facebook.com/intern/diff/D73438723/) [ghstack-poisoned] --- backends/vulkan/runtime/vk_api/Device.cpp | 23 ++++++++++++++++++++++- backends/vulkan/runtime/vk_api/Device.h | 12 ++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/backends/vulkan/runtime/vk_api/Device.cpp b/backends/vulkan/runtime/vk_api/Device.cpp index e87510cd9f8..373bea41154 100644 --- a/backends/vulkan/runtime/vk_api/Device.cpp +++ b/backends/vulkan/runtime/vk_api/Device.cpp @@ -13,6 +13,7 @@ #include #include +#include #include namespace vkcompute { @@ -40,7 +41,9 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle) 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); @@ -107,6 +110,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 6bb17b01223..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; @@ -48,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); };