diff --git a/backends/vulkan/runtime/VulkanBackend.cpp b/backends/vulkan/runtime/VulkanBackend.cpp index 14cc7df02a1..5093d61d2f7 100644 --- a/backends/vulkan/runtime/VulkanBackend.cpp +++ b/backends/vulkan/runtime/VulkanBackend.cpp @@ -621,6 +621,10 @@ class VulkanBackend final : public ::executorch::runtime::BackendInterface { void destroy(DelegateHandle* handle) const override { if (handle != nullptr) { ComputeGraph* compute_graph = static_cast(handle); + compute_graph->context() + ->adapter_ptr() + ->compute_pipeline_cache() + .save_cache(); // ComputeGraph is not trivially destructible. Since // this was constructed manually in init(), we must destroy it manually // here. diff --git a/backends/vulkan/runtime/vk_api/Pipeline.cpp b/backends/vulkan/runtime/vk_api/Pipeline.cpp index 07fc313984a..49bbf083359 100644 --- a/backends/vulkan/runtime/vk_api/Pipeline.cpp +++ b/backends/vulkan/runtime/vk_api/Pipeline.cpp @@ -406,8 +406,6 @@ ComputePipelineCache::~ComputePipelineCache() { return; } - save_cache(); - vkDestroyPipelineCache(device_, pipeline_cache_, nullptr); pipeline_cache_ = VK_NULL_HANDLE; } diff --git a/backends/vulkan/runtime/vk_api/Pipeline.h b/backends/vulkan/runtime/vk_api/Pipeline.h index 8765156deb2..4f42a9bf6bb 100644 --- a/backends/vulkan/runtime/vk_api/Pipeline.h +++ b/backends/vulkan/runtime/vk_api/Pipeline.h @@ -269,9 +269,10 @@ class ComputePipelineCache final { } }; + void save_cache(); + private: std::vector load_cache(); - void save_cache(); // Multiple threads could potentially be adding entries into the cache, so use // a mutex to manage access