From 4a1321562d827e26899633761cf17822c2eeb2ff Mon Sep 17 00:00:00 2001 From: jorgep31415 Date: Tue, 19 Nov 2024 10:58:06 -0800 Subject: [PATCH 1/2] [ET-VK] Only save_cache the first time 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. Differential Revision: [D66179919](https://our.internmc.facebook.com/intern/diff/D66179919/) [ghstack-poisoned] --- 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..edf3d876668 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); From 29399e5b4ddc47b5a3ef3d757b8d20ac7224c0a4 Mon Sep 17 00:00:00 2001 From: jorgep31415 Date: Tue, 19 Nov 2024 12:48:58 -0800 Subject: [PATCH 2/2] Update on "[ET-VK] Only save_cache the first time" 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. Differential Revision: [D66179919](https://our.internmc.facebook.com/intern/diff/D66179919/) [ghstack-poisoned] --- backends/vulkan/runtime/vk_api/Pipeline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backends/vulkan/runtime/vk_api/Pipeline.cpp b/backends/vulkan/runtime/vk_api/Pipeline.cpp index edf3d876668..07fc313984a 100644 --- a/backends/vulkan/runtime/vk_api/Pipeline.cpp +++ b/backends/vulkan/runtime/vk_api/Pipeline.cpp @@ -458,7 +458,7 @@ void ComputePipelineCache::save_cache() { if (cache_data_path_.empty()) { return; } - + // Return if file exists; the cache is already saved std::ifstream ifile(cache_data_path_); if (ifile.good()) {