Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm] (Decomp of #5251 7/n) Change the way to record the time of offline cache #5373

Merged
merged 2 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion taichi/runtime/llvm/llvm_aot_module_builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ void LlvmAotModuleBuilder::add_per_backend(const std::string &identifier,
kcache.owned_module = std::move(compiled.module);
kcache.args = infer_launch_args(kernel);
kcache.offloaded_task_list = std::move(compiled.tasks);
kcache.last_used_at = std::time(nullptr);
kcache.created_at = std::time(nullptr);
cache_.kernels[identifier] = std::move(kcache);
}

Expand Down Expand Up @@ -64,7 +66,10 @@ void LlvmAotModuleBuilder::add_field_per_backend(const std::string &identifier,
void LlvmAotModuleBuilder::add_compiled_kernel(aot::Kernel *kernel) {
auto *kernel_impl = dynamic_cast<llvm_aot::KernelImpl *>(kernel);
TI_ASSERT(kernel_impl);

if (!kernel_impl->kernel_data_.created_at) {
kernel_impl->kernel_data_.last_used_at = std::time(nullptr);
kernel_impl->kernel_data_.created_at = std::time(nullptr);
}
const std::string &kernel_name = kernel_impl->kernel_name_;
if (cache_.kernels.find(kernel_name) == cache_.kernels.end()) {
cache_.kernels[kernel_name] = std::move(kernel_impl->kernel_data_);
Expand Down
9 changes: 6 additions & 3 deletions taichi/runtime/llvm/llvm_offline_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ bool LlvmOfflineCacheFileReader::get_kernel_cache(
kernel_data.module = kernel_data.owned_module.get();
}

kernel_data.last_used_at = std::time(nullptr);

res.created_at = kernel_data.created_at;
res.last_used_at = kernel_data.last_used_at;
res.kernel_key = key;
res.args = kernel_data.args;
res.offloaded_task_list = kernel_data.offloaded_task_list;
Expand Down Expand Up @@ -146,7 +150,6 @@ void LlvmOfflineCacheFileWriter::dump(const std::string &path,
LlvmOfflineCache::Format format,
bool merge_with_old) {
taichi::create_directories(path);
std::time_t now = std::time(nullptr);
std::size_t new_kernels_size = 0; // bytes

for (auto &[k, v] : data_.kernels) {
Expand Down Expand Up @@ -185,8 +188,8 @@ void LlvmOfflineCacheFileWriter::dump(const std::string &path,
}

// Set meta info
v.created_at = now;
v.last_used_at = now;
TI_ASSERT(v.created_at);
TI_ASSERT(v.last_used_at);
v.size = size;
TI_ASSERT(v.size > 0);
new_kernels_size += v.size;
Expand Down
2 changes: 2 additions & 0 deletions taichi/runtime/program_impls/llvm/llvm_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ void LlvmProgramImpl::cache_kernel(
return;
}
auto &kernel_cache = cache_data_->kernels[kernel_key];
kernel_cache.created_at = std::time(nullptr);
kernel_cache.last_used_at = std::time(nullptr);
kernel_cache.kernel_key = kernel_key;
kernel_cache.owned_module = llvm::CloneModule(*module);
kernel_cache.args = std::move(args);
Expand Down
2 changes: 2 additions & 0 deletions tests/cpp/llvm/llvm_offline_cache_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ TEST_P(LlvmOfflineCacheTest, ReadWrite) {

LlvmOfflineCacheFileWriter writer;
LlvmOfflineCache::KernelCacheData kcache;
kcache.created_at = 1;
kcache.last_used_at = 1;
kcache.kernel_key = kKernelName;
kcache.owned_module = make_module(*llvm_ctx);
kcache.module = kcache.owned_module.get();
Expand Down