Skip to content

Commit 9942c00

Browse files
author
jorgep31415
committed
[ET-VK] Move save_cache from Runtime dtor to model destroy
## Issue `Runtime` is a local static variable. Hence we'd expect the Runtime dtor to be called on program exit. But on Android devices it's not being invoked. This behavior is different than that seen 6 months ago (D57085281). It's unclear what changed. This means the cache is not saved due to the following chain never being invoked. `~Runtime()` > `~Adapter()` > `~ComputePipelineCache()` > `save_cache()`.\ ## Solution Move cache saving to `VulkanBackend.cpp`'s model destroy. This makes sense since the cache is tied to the model and not the runtime. ## Resources https://medium.com/@martin00001313/mastering-static-objects-in-c-initialization-destruction-and-best-practices-760b17734195 Differential Revision: [D66179917](https://our.internmc.facebook.com/intern/diff/D66179917/) [ghstack-poisoned]
1 parent 29399e5 commit 9942c00

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

backends/vulkan/runtime/VulkanBackend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ class VulkanBackend final : public ::executorch::runtime::BackendInterface {
626626
// here.
627627
compute_graph->~ComputeGraph();
628628
}
629+
api::context()->adapter_ptr()->compute_pipeline_cache().save_cache();
629630
}
630631
};
631632

backends/vulkan/runtime/vk_api/Pipeline.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,8 +406,6 @@ ComputePipelineCache::~ComputePipelineCache() {
406406
return;
407407
}
408408

409-
save_cache();
410-
411409
vkDestroyPipelineCache(device_, pipeline_cache_, nullptr);
412410
pipeline_cache_ = VK_NULL_HANDLE;
413411
}

backends/vulkan/runtime/vk_api/Pipeline.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ class ComputePipelineCache final {
269269
}
270270
};
271271

272+
void save_cache();
273+
272274
private:
273275
std::vector<char> load_cache();
274-
void save_cache();
275276

276277
// Multiple threads could potentially be adding entries into the cache, so use
277278
// a mutex to manage access

0 commit comments

Comments
 (0)