Skip to content

Commit c179f0d

Browse files
authored
[ET-VK][ez] Store physical device identity metadata (#10361)
## 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/)
1 parent e2630d3 commit c179f0d

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

backends/vulkan/runtime/vk_api/Device.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
#include <executorch/backends/vulkan/runtime/vk_api/Exception.h>
1414

15+
#include <algorithm>
1516
#include <bitset>
17+
#include <cctype>
1618
#include <cstring>
1719

1820
namespace vkcompute {
@@ -40,7 +42,9 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle)
4042
has_unified_memory(false),
4143
has_timestamps(false),
4244
timestamp_period(0),
43-
min_ubo_alignment(0) {
45+
min_ubo_alignment(0),
46+
device_name{},
47+
device_type{DeviceType::UNKNOWN} {
4448
// Extract physical device properties
4549
vkGetPhysicalDeviceProperties(handle, &properties);
4650

@@ -107,6 +111,24 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle)
107111
num_compute_queues += p.queueCount;
108112
}
109113
}
114+
115+
// Obtain device identity metadata
116+
device_name = std::string(properties.deviceName);
117+
std::transform(
118+
device_name.begin(),
119+
device_name.end(),
120+
device_name.begin(),
121+
[](unsigned char c) { return std::tolower(c); });
122+
123+
if (device_name.find("adreno") != std::string::npos) {
124+
device_type = DeviceType::ADRENO;
125+
} else if (device_name.find("swiftshader") != std::string::npos) {
126+
device_type = DeviceType::SWIFTSHADER;
127+
} else if (device_name.find("nvidia") != std::string::npos) {
128+
device_type = DeviceType::NVIDIA;
129+
} else if (device_name.find("mali") != std::string::npos) {
130+
device_type = DeviceType::MALI;
131+
}
110132
}
111133

112134
//

backends/vulkan/runtime/vk_api/Device.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
namespace vkcompute {
1919
namespace vkapi {
2020

21+
enum class DeviceType : uint32_t {
22+
UNKNOWN,
23+
NVIDIA,
24+
MALI,
25+
ADRENO,
26+
SWIFTSHADER,
27+
};
28+
2129
struct PhysicalDevice final {
2230
// Handle
2331
VkPhysicalDevice handle;
@@ -48,6 +56,10 @@ struct PhysicalDevice final {
4856
float timestamp_period;
4957
size_t min_ubo_alignment;
5058

59+
// Device identity
60+
std::string device_name;
61+
DeviceType device_type;
62+
5163
explicit PhysicalDevice(VkPhysicalDevice);
5264
};
5365

0 commit comments

Comments
 (0)