Skip to content

Commit

Permalink
[metal] Enable offline cache by default on Metal (#6307)
Browse files Browse the repository at this point in the history
Issue: #6263, #4401

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
PGZXB and pre-commit-ci[bot] authored Oct 13, 2022
1 parent b8fffd6 commit 7c6f910
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 16 deletions.
5 changes: 1 addition & 4 deletions taichi/runtime/program_impls/metal/metal_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,7 @@ const std::unique_ptr<metal::CacheManager>
TI_ASSERT(compiled_runtime_module_.has_value());
using Mgr = metal::CacheManager;
Mgr::Params params;
params.mode =
offline_cache::enabled_wip_offline_cache(config->offline_cache)
? Mgr::MemAndDiskCache
: Mgr::MemCache;
params.mode = config->offline_cache ? Mgr::MemAndDiskCache : Mgr::MemCache;
params.cache_path = offline_cache::get_cache_path_by_arch(
config->offline_cache_file_path, Arch::metal);
params.compiled_runtime_module_ = &(*compiled_runtime_module_);
Expand Down
8 changes: 0 additions & 8 deletions taichi/util/offline_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ std::string get_cache_path_by_arch(const std::string &base_path, Arch arch) {
return taichi::join_path(base_path, subdir);
}

bool enabled_wip_offline_cache(bool enable_hint) {
// CompileConfig::offline_cache is a global option to enable offline cache on
// all backends To disable WIP offline cache by default & enable when
// developing/testing:
const char *enable_env = std::getenv("TI_WIP_OFFLINE_CACHE");
return enable_hint && enable_env && std::strncmp("1", enable_env, 1) == 0;
}

std::string mangle_name(const std::string &primal_name,
const std::string &key) {
// Result: {primal_name}{key: char[65]}_{(checksum(primal_name)) ^
Expand Down
1 change: 0 additions & 1 deletion taichi/util/offline_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,6 @@ class CacheCleaner {

void disable_offline_cache_if_needed(CompileConfig *config);
std::string get_cache_path_by_arch(const std::string &base_path, Arch arch);
bool enabled_wip_offline_cache(bool enable_hint);
std::string mangle_name(const std::string &primal_name, const std::string &key);
bool try_demangle_name(const std::string &mangled_name,
std::string &primal_name,
Expand Down
9 changes: 6 additions & 3 deletions tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,15 @@ def size_of_dir(dir):
])
return size

n = len(os.listdir(tmp_cache_file_path))
size = size_of_dir(tmp_cache_file_path)
stat = {}
for subdir in os.listdir(tmp_cache_file_path):
stat[subdir] = len(
os.listdir(os.path.join(tmp_cache_file_path, subdir)))
shutil.rmtree(tmp_cache_file_path)
print('Summary of testing the offline cache:')
print(f' The number of cache files: {n}')
print(f' Size of cache files: {size / 1024:.2f} KB')
print(f' Simple statistics: {stat}')
print(f' Size of cache files: {size / 1024:.2f} KB')

atexit.register(print_and_remove)
else: # Default: disable offline cache
Expand Down

0 comments on commit 7c6f910

Please sign in to comment.