Skip to content

Commit 0dc25e5

Browse files
pytorchbotjorgep31415
andauthored
[ET-VK] Only save_cache the first time (#7001)
Pull Request resolved: #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/) --------- Co-authored-by: jorgep31415 <[email protected]>
1 parent 6b0bb56 commit 0dc25e5

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

backends/vulkan/runtime/vk_api/Pipeline.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,12 +433,12 @@ void ComputePipelineCache::purge() {
433433
}
434434

435435
std::vector<char> ComputePipelineCache::load_cache() {
436-
// Return if path is not specified; this means the optimization is disabled
436+
// No optimization if path is unspecified
437437
if (cache_data_path_.empty()) {
438438
return {};
439439
}
440440

441-
// Return if file doesn't exist; this is expected on the first model-load
441+
// Return if file doesn't exist; this is expected on first model-load
442442
std::ifstream file(cache_data_path_, std::ios::binary | std::ios::ate);
443443
if (file.fail()) {
444444
return {};
@@ -454,6 +454,17 @@ std::vector<char> ComputePipelineCache::load_cache() {
454454
}
455455

456456
void ComputePipelineCache::save_cache() {
457+
// No optimization if path is unspecified
458+
if (cache_data_path_.empty()) {
459+
return;
460+
}
461+
462+
// Return if file exists; the cache is already saved
463+
std::ifstream ifile(cache_data_path_);
464+
if (ifile.good()) {
465+
return;
466+
}
467+
457468
size_t size{};
458469
vkGetPipelineCacheData(device_, pipeline_cache_, &size, nullptr);
459470

0 commit comments

Comments
 (0)