Skip to content

Commit

Permalink
[bug] add test case and clean debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
erizmr committed Apr 19, 2024
1 parent 097dca8 commit cbcd0b0
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 26 deletions.
3 changes: 0 additions & 3 deletions taichi/analysis/gen_offline_cache_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ class ASTSerializer : public IRVisitor, public ExpressionVisitor {
emit(static_cast<std::size_t>(snode->get_snode_tree_id()));
emit(static_cast<std::size_t>(snode->id));
const auto *root = snode->get_root();
// snode_tree_roots_.insert(root);
snode_tree_roots_.push_back(root);
} else {
emit(std::numeric_limits<std::size_t>::max());
Expand Down Expand Up @@ -655,8 +654,6 @@ class ASTSerializer : public IRVisitor, public ExpressionVisitor {
#undef DEFINE_EMIT_ENUM

std::ostream *os_{nullptr};
// std::unordered_set<const SNode *> snode_tree_roots_;
// std::unordered_map<Function *, std::size_t> real_funcs_;
std::vector<const SNode *> snode_tree_roots_;
std::map<Function *, std::size_t> real_funcs_;
std::vector<char> string_pool_;
Expand Down
21 changes: 0 additions & 21 deletions taichi/analysis/offline_cache_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,27 +184,6 @@ std::string get_hashed_offline_cache_key(const CompileConfig &config,
auto device_caps_key = get_offline_cache_key_of_device_caps(caps);
std::string autodiff_mode =
std::to_string(static_cast<std::size_t>(kernel->autodiff_mode));
// std::cout << "=============== kernel name " << kernel->name <<
// "==================="<< std::endl; for (auto elem : kernel->parameter_list)
// {
// std::cout << "kernel->parameter_list "<< elem << std::endl;
// }
// for (auto elem : kernel_rets_string) {
// std::cout << "kernel_rets_string "<< elem << std::endl;
// }
// for (auto elem : compile_config_key) {
// std::cout << "compile_config_key "<< elem << std::endl;
// }
// for (auto elem : device_caps_key) {
// std::cout << "device_caps_key "<< elem << std::endl;
// }
// for (auto elem : kernel_params_string) {
// std::cout << "kernel_params_string "<< elem << std::endl;
// }
// for (auto elem : kernel_rets_string) {
// std::cout << "kernel_rets_string "<< elem << std::endl;
// }
// std::cout << "kernel_body_string "<< kernel_body_string << std::endl;
picosha2::hash256_one_by_one hasher;
hasher.process(compile_config_key.begin(), compile_config_key.end());
hasher.process(device_caps_key.begin(), device_caps_key.end());
Expand Down
2 changes: 0 additions & 2 deletions taichi/compilation_manager/kernel_compilation_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,6 @@ const CompiledKernelData *KernelCompilationManager::try_load_cached_kernel(
auto &kernels = cached_data_.kernels;
auto iter = kernels.find(kernel_key);

TI_INFO("!!!!!KERNEL KEY {}, in kernels, is exist {}", kernel_key,
iter != kernels.end());
if (iter != kernels.end()) {
auto &k = iter->second;
if (k.compiled_kernel_data) {
Expand Down
64 changes: 64 additions & 0 deletions tests/python/test_offline_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,70 @@ def helper():
assert added_files() == expected_num_cache_files(len(simple_kernels_to_test))


@pytest.mark.parametrize("curr_arch", supported_archs_offline_cache)
@_test_offline_cache_dec
def test_offline_cache_with_different_snode_trees(curr_arch):
count_of_cache_file = cache_files_cnt()

def added_files():
return cache_files_cnt() - count_of_cache_file

def helper():
x = ti.field(float, shape=5)
@ti.kernel
def trigger_compile():
x[0] += 1

# This case is used for testing SNodeTree storeing order matters (i.e., use a ordered container such as vector instead of unordered_map or unordered_set) when generating kernel offline cache key
# The multiple `trigger_compile` equalivant to allocate each field to a different SNodeTree
# i.e.,
# x = ti.field(float)
# fb.dense(ti.i, 5).place(x)
# fb.finalize()

trigger_compile()
a = ti.field(float, shape=5)
trigger_compile()
b = ti.field(float, shape=10)
trigger_compile()
c = ti.field(float, shape=5)
trigger_compile()
d = ti.field(float, shape=10)
trigger_compile()
e = ti.field(float, shape=5)
trigger_compile()
f = ti.field(float, shape=10)
trigger_compile()
g = ti.field(float, shape=5)
trigger_compile()
h = ti.field(float, shape=10)


@ti.kernel
def kernel_forward():
for i in range(5):
a[i] += i
b[i] += i
c[i] += i
d[i] += i
e[i] += i
f[i] += i
g[i] += i
h[i] += i

kernel_forward()

ti.init(arch=curr_arch, enable_fallback=False, **current_thread_ext_options())
helper()
assert added_files() == expected_num_cache_files(2)

# The number of cache file should not change
for _ in range(5):
ti.init(arch=curr_arch, enable_fallback=False, **current_thread_ext_options())
helper()
assert added_files() == expected_num_cache_files(2)


@pytest.mark.parametrize("curr_arch", supported_archs_offline_cache)
@_test_offline_cache_dec
def test_offline_cache_with_changing_compile_config(curr_arch):
Expand Down

0 comments on commit cbcd0b0

Please sign in to comment.