From f2ee059b21697820b9f567a8b1d8becde6f885e0 Mon Sep 17 00:00:00 2001 From: PGZXB Date: Tue, 4 Apr 2023 18:46:11 +0800 Subject: [PATCH 1/3] [bug] Avoid re-loading offline-cached-kernel --- .../kernel_compilation_manager.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/taichi/compilation_manager/kernel_compilation_manager.cpp b/taichi/compilation_manager/kernel_compilation_manager.cpp index 46fb29a10cf7b..e28a65599504d 100644 --- a/taichi/compilation_manager/kernel_compilation_manager.cpp +++ b/taichi/compilation_manager/kernel_compilation_manager.cpp @@ -216,14 +216,16 @@ const CompiledKernelData *KernelCompilationManager::try_load_cached_kernel( auto iter = kernels.find(kernel_key); if (iter != kernels.end()) { auto &k = iter->second; - if (auto loaded = load_ckd(kernel_key, arch)) { - TI_DEBUG("Create kernel '{}' from cache (key='{}')", - kernel_def.get_name(), kernel_key); - TI_ASSERT(loaded->arch() == arch); - k.last_used_at = std::time(nullptr); - k.compiled_kernel_data = std::move(loaded); - updated_data_.push_back(&k); - return k.compiled_kernel_data.get(); + if (!k.compiled_kernel_data) { + if (auto loaded = load_ckd(kernel_key, arch)) { + TI_DEBUG("Create kernel '{}' from cache (key='{}')", + kernel_def.get_name(), kernel_key); + TI_ASSERT(loaded->arch() == arch); + k.last_used_at = std::time(nullptr); + k.compiled_kernel_data = std::move(loaded); + updated_data_.push_back(&k); + return k.compiled_kernel_data.get(); + } } } } From 10f05d5b38889071329ed5e8e9982d388347ab8f Mon Sep 17 00:00:00 2001 From: PGZXB Date: Tue, 4 Apr 2023 21:13:01 +0800 Subject: [PATCH 2/3] Fix --- .../kernel_compilation_manager.cpp | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/taichi/compilation_manager/kernel_compilation_manager.cpp b/taichi/compilation_manager/kernel_compilation_manager.cpp index e28a65599504d..2b91d7af30b88 100644 --- a/taichi/compilation_manager/kernel_compilation_manager.cpp +++ b/taichi/compilation_manager/kernel_compilation_manager.cpp @@ -216,16 +216,16 @@ const CompiledKernelData *KernelCompilationManager::try_load_cached_kernel( auto iter = kernels.find(kernel_key); if (iter != kernels.end()) { auto &k = iter->second; - if (!k.compiled_kernel_data) { - if (auto loaded = load_ckd(kernel_key, arch)) { - TI_DEBUG("Create kernel '{}' from cache (key='{}')", - kernel_def.get_name(), kernel_key); - TI_ASSERT(loaded->arch() == arch); - k.last_used_at = std::time(nullptr); - k.compiled_kernel_data = std::move(loaded); - updated_data_.push_back(&k); - return k.compiled_kernel_data.get(); - } + if (k.compiled_kernel_data) { + return k.compiled_kernel_data.get(); + } else if (auto loaded = load_ckd(kernel_key, arch)) { + TI_DEBUG("Create kernel '{}' from cache (key='{}')", + kernel_def.get_name(), kernel_key); + TI_ASSERT(loaded->arch() == arch); + k.last_used_at = std::time(nullptr); + k.compiled_kernel_data = std::move(loaded); + updated_data_.push_back(&k); + return k.compiled_kernel_data.get(); } } } From bfea899046edc776486009c5d7457845cb929733 Mon Sep 17 00:00:00 2001 From: PGZXB Date: Tue, 4 Apr 2023 21:19:38 +0800 Subject: [PATCH 3/3] Add logging --- taichi/compilation_manager/kernel_compilation_manager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/taichi/compilation_manager/kernel_compilation_manager.cpp b/taichi/compilation_manager/kernel_compilation_manager.cpp index 2b91d7af30b88..b9c3f5e631fad 100644 --- a/taichi/compilation_manager/kernel_compilation_manager.cpp +++ b/taichi/compilation_manager/kernel_compilation_manager.cpp @@ -217,6 +217,8 @@ const CompiledKernelData *KernelCompilationManager::try_load_cached_kernel( if (iter != kernels.end()) { auto &k = iter->second; if (k.compiled_kernel_data) { + TI_DEBUG("Create kernel '{}' from cache (key='{}')", + kernel_def.get_name(), kernel_key); return k.compiled_kernel_data.get(); } else if (auto loaded = load_ckd(kernel_key, arch)) { TI_DEBUG("Create kernel '{}' from cache (key='{}')",