xref: /aosp_15_r20/external/executorch/backends/vulkan/runtime/vk_api/Device.h (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 // @lint-ignore-every CLANGTIDY facebook-hte-BadMemberName
12 
13 #include <executorch/backends/vulkan/runtime/vk_api/vk_api.h>
14 
15 #include <sstream>
16 #include <vector>
17 
18 namespace vkcompute {
19 namespace vkapi {
20 
21 struct PhysicalDevice final {
22   // Handle
23   VkPhysicalDevice handle;
24 
25   // Properties obtained from Vulkan
26   VkPhysicalDeviceProperties properties;
27   VkPhysicalDeviceMemoryProperties memory_properties;
28 
29   // Additional features available from extensions
30 #ifdef VK_KHR_16bit_storage
31   VkPhysicalDevice16BitStorageFeatures shader_16bit_storage;
32 #endif /* VK_KHR_16bit_storage */
33 #ifdef VK_KHR_8bit_storage
34   VkPhysicalDevice8BitStorageFeatures shader_8bit_storage;
35 #endif /* VK_KHR_8bit_storage */
36 #ifdef VK_KHR_shader_float16_int8
37   VkPhysicalDeviceShaderFloat16Int8Features shader_float16_int8_types;
38 #endif /* VK_KHR_shader_float16_int8 */
39 
40   // Head of the linked list of extensions to be requested
41   void* extension_features;
42 
43   // Available GPU queues
44   std::vector<VkQueueFamilyProperties> queue_families;
45 
46   // Metadata
47   uint32_t num_compute_queues;
48   bool supports_int16_shader_types;
49   bool has_unified_memory;
50   bool has_timestamps;
51   float timestamp_period;
52 
53   explicit PhysicalDevice(VkPhysicalDevice);
54 };
55 
56 struct DeviceHandle final {
57   VkDevice handle;
58 
59   explicit DeviceHandle(VkDevice);
60   ~DeviceHandle();
61 };
62 
63 void find_requested_device_extensions(
64     VkPhysicalDevice physical_device,
65     std::vector<const char*>& enabled_extensions,
66     const std::vector<const char*>& requested_extensions);
67 
68 std::string get_device_type_str(const VkPhysicalDeviceType type);
69 
70 std::string get_memory_properties_str(const VkMemoryPropertyFlags flags);
71 
72 std::string get_queue_family_properties_str(const VkQueueFlags flags);
73 
74 } // namespace vkapi
75 } // namespace vkcompute
76