Skip to content

Commit 81cf3ab

Browse files
jorgep31415facebook-github-bot
authored andcommitted
Convert DeviceHandle into a struct (#4186)
Summary: Pull Request resolved: #4186 We already expose the only private member `VkDevice` from Adapter's public function `device_handle()` so nothing's really private. This change also makes it consistent with the layout of `PhysicalDevice` and allows decoupling from Adapter in the next change. ghstack-source-id: 233085716 exported-using-ghexport bypass-github-export-checks bypass-github-pytorch-ci-checks bypass-github-executorch-ci-checks Reviewed By: SS-JIA Differential Revision: D59540129 fbshipit-source-id: ced3cd5f6e40546caabfcd024a2d3225753ebf71
1 parent 073a96d commit 81cf3ab

File tree

2 files changed

+14
-30
lines changed

2 files changed

+14
-30
lines changed

backends/vulkan/runtime/vk_api/Adapter.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -271,18 +271,13 @@ std::string get_queue_family_properties_str(const VkQueueFlags flags) {
271271
// DeviceHandle
272272
//
273273

274-
DeviceHandle::DeviceHandle(VkDevice device) : handle_(device) {}
275-
276-
DeviceHandle::DeviceHandle(DeviceHandle&& other) noexcept
277-
: handle_(other.handle_) {
278-
other.handle_ = VK_NULL_HANDLE;
279-
}
274+
DeviceHandle::DeviceHandle(VkDevice device) : handle(device) {}
280275

281276
DeviceHandle::~DeviceHandle() {
282-
if (VK_NULL_HANDLE == handle_) {
277+
if (VK_NULL_HANDLE == handle) {
283278
return;
284279
}
285-
vkDestroyDevice(handle_, nullptr);
280+
vkDestroyDevice(handle, nullptr);
286281
}
287282

288283
//
@@ -305,12 +300,12 @@ Adapter::Adapter(
305300
num_queues,
306301
queues_,
307302
queue_usage_)),
308-
shader_layout_cache_(device_.handle_),
309-
shader_cache_(device_.handle_),
310-
pipeline_layout_cache_(device_.handle_),
311-
compute_pipeline_cache_(device_.handle_, cache_data_path),
312-
sampler_cache_(device_.handle_),
313-
vma_(instance_, physical_device_.handle, device_.handle_) {}
303+
shader_layout_cache_(device_.handle),
304+
shader_cache_(device_.handle),
305+
pipeline_layout_cache_(device_.handle),
306+
compute_pipeline_cache_(device_.handle, cache_data_path),
307+
sampler_cache_(device_.handle),
308+
vma_(instance_, physical_device_.handle, device_.handle) {}
314309

315310
Adapter::Queue Adapter::request_queue() {
316311
// Lock the mutex as multiple threads can request a queue at the same time
@@ -448,7 +443,7 @@ std::string Adapter::stringize() const {
448443
<< std::endl;
449444
}
450445
ss << " }" << std::endl;
451-
ss << " VkDevice: " << device_.handle_ << std::endl;
446+
ss << " VkDevice: " << device_.handle << std::endl;
452447
ss << " Compute Queues [" << std::endl;
453448
for (const Adapter::Queue& compute_queue : queues_) {
454449
ss << " Family " << compute_queue.family_index << ", Queue "

backends/vulkan/runtime/vk_api/Adapter.h

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,22 +53,11 @@ struct PhysicalDevice final {
5353
explicit PhysicalDevice(VkPhysicalDevice);
5454
};
5555

56-
class DeviceHandle final {
57-
public:
58-
explicit DeviceHandle(VkDevice device);
59-
60-
DeviceHandle(const DeviceHandle&) = delete;
61-
DeviceHandle& operator=(const DeviceHandle&) = delete;
62-
63-
DeviceHandle(DeviceHandle&&) noexcept;
64-
DeviceHandle& operator=(DeviceHandle&&) = delete;
56+
struct DeviceHandle final {
57+
VkDevice handle;
6558

59+
explicit DeviceHandle(VkDevice);
6660
~DeviceHandle();
67-
68-
private:
69-
VkDevice handle_;
70-
71-
friend class Adapter;
7261
};
7362

7463
//
@@ -150,7 +139,7 @@ class Adapter final {
150139
}
151140

152141
inline VkDevice device_handle() const {
153-
return device_.handle_;
142+
return device_.handle;
154143
}
155144

156145
inline bool has_unified_memory() const {

0 commit comments

Comments
 (0)