From a554d7e03d23e2689b1af60b6c8e18859b6cad12 Mon Sep 17 00:00:00 2001 From: jorgep31415 Date: Wed, 20 Nov 2024 17:45:59 -0800 Subject: [PATCH 1/2] [ET-VK] Remove unneeded `Runtime` move Pull Request resolved: https://github.com/pytorch/executorch/pull/6964 TSIA ghstack-source-id: 254701487 @exported-using-ghexport Differential Revision: [D66174493](https://our.internmc.facebook.com/intern/diff/D66174493/) --- backends/vulkan/runtime/vk_api/Runtime.cpp | 12 +----------- backends/vulkan/runtime/vk_api/Runtime.h | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/backends/vulkan/runtime/vk_api/Runtime.cpp b/backends/vulkan/runtime/vk_api/Runtime.cpp index e82f631ddb4..da03c4e86d7 100644 --- a/backends/vulkan/runtime/vk_api/Runtime.cpp +++ b/backends/vulkan/runtime/vk_api/Runtime.cpp @@ -265,7 +265,7 @@ std::unique_ptr init_global_vulkan_runtime() { }; try { - return std::make_unique(Runtime(default_config)); + return std::make_unique(default_config); } catch (...) { } @@ -323,16 +323,6 @@ Runtime::~Runtime() { instance_ = VK_NULL_HANDLE; } -Runtime::Runtime(Runtime&& other) noexcept - : config_(other.config_), - instance_(other.instance_), - adapters_(std::move(other.adapters_)), - default_adapter_i_(other.default_adapter_i_), - debug_report_callback_(other.debug_report_callback_) { - other.instance_ = VK_NULL_HANDLE; - other.debug_report_callback_ = {}; -} - uint32_t Runtime::create_adapter(const Selector& selector) { VK_CHECK_COND( !device_mappings_.empty(), diff --git a/backends/vulkan/runtime/vk_api/Runtime.h b/backends/vulkan/runtime/vk_api/Runtime.h index 14e6bd57dcb..16f1400021c 100644 --- a/backends/vulkan/runtime/vk_api/Runtime.h +++ b/backends/vulkan/runtime/vk_api/Runtime.h @@ -51,7 +51,7 @@ class Runtime final { Runtime(const Runtime&) = delete; Runtime& operator=(const Runtime&) = delete; - Runtime(Runtime&&) noexcept; + Runtime(Runtime&&) = delete; Runtime& operator=(Runtime&&) = delete; ~Runtime(); From ee709a4499ce625d3171db49777bce264030dd2b Mon Sep 17 00:00:00 2001 From: jorgep31415 Date: Wed, 20 Nov 2024 17:46:00 -0800 Subject: [PATCH 2/2] [ET-VK] Only `save_cache` the first time Pull Request resolved: https://github.com/pytorch/executorch/pull/6966 Add a check in `save_cache` to return early if the cache file already exists. Currently we append the same cache data to that file which makes no difference to model-load time. ghstack-source-id: 254701486 @exported-using-ghexport Differential Revision: [D66179919](https://our.internmc.facebook.com/intern/diff/D66179919/) --- backends/vulkan/runtime/vk_api/Pipeline.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/backends/vulkan/runtime/vk_api/Pipeline.cpp b/backends/vulkan/runtime/vk_api/Pipeline.cpp index 5cc5a76c358..07fc313984a 100644 --- a/backends/vulkan/runtime/vk_api/Pipeline.cpp +++ b/backends/vulkan/runtime/vk_api/Pipeline.cpp @@ -433,12 +433,12 @@ void ComputePipelineCache::purge() { } std::vector ComputePipelineCache::load_cache() { - // Return if path is not specified; this means the optimization is disabled + // No optimization if path is unspecified if (cache_data_path_.empty()) { return {}; } - // Return if file doesn't exist; this is expected on the first model-load + // Return if file doesn't exist; this is expected on first model-load std::ifstream file(cache_data_path_, std::ios::binary | std::ios::ate); if (file.fail()) { return {}; @@ -454,6 +454,17 @@ std::vector ComputePipelineCache::load_cache() { } void ComputePipelineCache::save_cache() { + // No optimization if path is unspecified + if (cache_data_path_.empty()) { + return; + } + + // Return if file exists; the cache is already saved + std::ifstream ifile(cache_data_path_); + if (ifile.good()) { + return; + } + size_t size{}; vkGetPipelineCacheData(device_, pipeline_cache_, &size, nullptr);