|
10 | 10 |
|
11 | 11 | #include <executorch/backends/vulkan/runtime/vk_api/Adapter.h>
|
12 | 12 |
|
13 |
| -#include <bitset> |
14 |
| -#include <cstring> |
15 | 13 | #include <iomanip>
|
16 |
| -#include <sstream> |
17 |
| -#include <utility> |
18 | 14 |
|
19 | 15 | namespace vkcompute {
|
20 | 16 | namespace vkapi {
|
21 | 17 |
|
22 |
| -PhysicalDevice::PhysicalDevice(VkPhysicalDevice physical_device_handle) |
23 |
| - : handle(physical_device_handle), |
24 |
| - properties{}, |
25 |
| - memory_properties{}, |
26 |
| - shader_16bit_storage{ |
27 |
| - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES}, |
28 |
| - shader_8bit_storage{ |
29 |
| - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES}, |
30 |
| - shader_float16_int8_types{ |
31 |
| - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_FLOAT16_INT8_FEATURES_KHR}, |
32 |
| - queue_families{}, |
33 |
| - num_compute_queues(0), |
34 |
| - has_unified_memory(false), |
35 |
| - has_timestamps(properties.limits.timestampComputeAndGraphics), |
36 |
| - timestamp_period(properties.limits.timestampPeriod), |
37 |
| - extension_features(&shader_16bit_storage) { |
38 |
| - // Extract physical device properties |
39 |
| - vkGetPhysicalDeviceProperties(handle, &properties); |
40 |
| - vkGetPhysicalDeviceMemoryProperties(handle, &memory_properties); |
41 |
| - |
42 |
| - VkPhysicalDeviceFeatures2 features2{ |
43 |
| - VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2}; |
44 |
| - |
45 |
| - // Create linked list to query availability of extensions |
46 |
| - features2.pNext = &shader_16bit_storage; |
47 |
| - shader_16bit_storage.pNext = &shader_8bit_storage; |
48 |
| - shader_8bit_storage.pNext = &shader_float16_int8_types; |
49 |
| - shader_float16_int8_types.pNext = nullptr; |
50 |
| - |
51 |
| - vkGetPhysicalDeviceFeatures2(handle, &features2); |
52 |
| - |
53 |
| - // Check if there are any memory types have both the HOST_VISIBLE and the |
54 |
| - // DEVICE_LOCAL property flags |
55 |
| - const VkMemoryPropertyFlags unified_memory_flags = |
56 |
| - VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; |
57 |
| - for (size_t i = 0; i < memory_properties.memoryTypeCount; ++i) { |
58 |
| - if (memory_properties.memoryTypes[i].propertyFlags | unified_memory_flags) { |
59 |
| - has_unified_memory = true; |
60 |
| - break; |
61 |
| - } |
62 |
| - } |
63 |
| - |
64 |
| - uint32_t queue_family_count = 0; |
65 |
| - vkGetPhysicalDeviceQueueFamilyProperties( |
66 |
| - handle, &queue_family_count, nullptr); |
67 |
| - |
68 |
| - queue_families.resize(queue_family_count); |
69 |
| - vkGetPhysicalDeviceQueueFamilyProperties( |
70 |
| - handle, &queue_family_count, queue_families.data()); |
71 |
| - |
72 |
| - // Find the total number of compute queues |
73 |
| - for (const VkQueueFamilyProperties& p : queue_families) { |
74 |
| - // Check if this family has compute capability |
75 |
| - if (p.queueFlags & VK_QUEUE_COMPUTE_BIT) { |
76 |
| - num_compute_queues += p.queueCount; |
77 |
| - } |
78 |
| - } |
79 |
| -} |
80 |
| - |
81 | 18 | namespace {
|
82 | 19 |
|
83 |
| -void find_requested_device_extensions( |
84 |
| - VkPhysicalDevice physical_device, |
85 |
| - std::vector<const char*>& enabled_extensions, |
86 |
| - const std::vector<const char*>& requested_extensions) { |
87 |
| - uint32_t device_extension_properties_count = 0; |
88 |
| - VK_CHECK(vkEnumerateDeviceExtensionProperties( |
89 |
| - physical_device, nullptr, &device_extension_properties_count, nullptr)); |
90 |
| - std::vector<VkExtensionProperties> device_extension_properties( |
91 |
| - device_extension_properties_count); |
92 |
| - VK_CHECK(vkEnumerateDeviceExtensionProperties( |
93 |
| - physical_device, |
94 |
| - nullptr, |
95 |
| - &device_extension_properties_count, |
96 |
| - device_extension_properties.data())); |
97 |
| - |
98 |
| - std::vector<const char*> enabled_device_extensions; |
99 |
| - |
100 |
| - for (const auto& requested_extension : requested_extensions) { |
101 |
| - for (const auto& extension : device_extension_properties) { |
102 |
| - if (strcmp(requested_extension, extension.extensionName) == 0) { |
103 |
| - enabled_extensions.push_back(requested_extension); |
104 |
| - break; |
105 |
| - } |
106 |
| - } |
107 |
| - } |
108 |
| -} |
109 |
| - |
110 | 20 | VkDevice create_logical_device(
|
111 | 21 | const PhysicalDevice& physical_device,
|
112 | 22 | const uint32_t num_queues_to_create,
|
@@ -210,76 +120,8 @@ VkDevice create_logical_device(
|
210 | 120 | return handle;
|
211 | 121 | }
|
212 | 122 |
|
213 |
| -// Print utils |
214 |
| - |
215 |
| -std::string get_device_type_str(const VkPhysicalDeviceType type) { |
216 |
| - switch (type) { |
217 |
| - case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU: |
218 |
| - return "INTEGRATED_GPU"; |
219 |
| - case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU: |
220 |
| - return "DISCRETE_GPU"; |
221 |
| - case VK_PHYSICAL_DEVICE_TYPE_VIRTUAL_GPU: |
222 |
| - return "VIRTUAL_GPU"; |
223 |
| - case VK_PHYSICAL_DEVICE_TYPE_CPU: |
224 |
| - return "CPU"; |
225 |
| - default: |
226 |
| - return "UNKNOWN"; |
227 |
| - } |
228 |
| -} |
229 |
| - |
230 |
| -std::string get_memory_properties_str(const VkMemoryPropertyFlags flags) { |
231 |
| - std::bitset<10> values(flags); |
232 |
| - std::stringstream ss("|"); |
233 |
| - if (values[0]) { |
234 |
| - ss << " DEVICE_LOCAL |"; |
235 |
| - } |
236 |
| - if (values[1]) { |
237 |
| - ss << " HOST_VISIBLE |"; |
238 |
| - } |
239 |
| - if (values[2]) { |
240 |
| - ss << " HOST_COHERENT |"; |
241 |
| - } |
242 |
| - if (values[3]) { |
243 |
| - ss << " HOST_CACHED |"; |
244 |
| - } |
245 |
| - if (values[4]) { |
246 |
| - ss << " LAZILY_ALLOCATED |"; |
247 |
| - } |
248 |
| - |
249 |
| - return ss.str(); |
250 |
| -} |
251 |
| - |
252 |
| -std::string get_queue_family_properties_str(const VkQueueFlags flags) { |
253 |
| - std::bitset<10> values(flags); |
254 |
| - std::stringstream ss("|"); |
255 |
| - if (values[0]) { |
256 |
| - ss << " GRAPHICS |"; |
257 |
| - } |
258 |
| - if (values[1]) { |
259 |
| - ss << " COMPUTE |"; |
260 |
| - } |
261 |
| - if (values[2]) { |
262 |
| - ss << " TRANSFER |"; |
263 |
| - } |
264 |
| - |
265 |
| - return ss.str(); |
266 |
| -} |
267 |
| - |
268 | 123 | } // namespace
|
269 | 124 |
|
270 |
| -// |
271 |
| -// DeviceHandle |
272 |
| -// |
273 |
| - |
274 |
| -DeviceHandle::DeviceHandle(VkDevice device) : handle(device) {} |
275 |
| - |
276 |
| -DeviceHandle::~DeviceHandle() { |
277 |
| - if (VK_NULL_HANDLE == handle) { |
278 |
| - return; |
279 |
| - } |
280 |
| - vkDestroyDevice(handle, nullptr); |
281 |
| -} |
282 |
| - |
283 | 125 | //
|
284 | 126 | // Adapter
|
285 | 127 | //
|
|
0 commit comments