Skip to content

Commit 6f008a7

Browse files
committed
[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-source-id: 279540367 Pull Request resolved: #10353
1 parent 2b14c01 commit 6f008a7

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

backends/vulkan/runtime/vk_api/Device.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <executorch/backends/vulkan/runtime/vk_api/Exception.h>
1414

1515
#include <bitset>
16+
#include <cctype>
1617
#include <cstring>
1718

1819
namespace vkcompute {
@@ -40,7 +41,9 @@ PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle)
4041
has_unified_memory(false),
4142
has_timestamps(false),
4243
timestamp_period(0),
43-
min_ubo_alignment(0) {
44+
min_ubo_alignment(0),
45+
device_name{},
46+
device_type{DeviceType::UNKNOWN} {
4447
// Extract physical device properties
4548
vkGetPhysicalDeviceProperties(handle, &properties);
4649

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

112133
//

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)