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

[bug] Fix infinite recursion of get_offline_cache_key_of_snode_impl() #4983

Merged
Merged
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
24 changes: 17 additions & 7 deletions taichi/analysis/offline_cache_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,16 @@ static std::vector<std::uint8_t> get_offline_cache_key_of_compile_config(

static void get_offline_cache_key_of_snode_impl(
SNode *snode,
BinaryOutputSerializer &serializer) {
BinaryOutputSerializer &serializer,
std::unordered_set<int> &visited) {
if (auto iter = visited.find(snode->id); iter != visited.end()) {
serializer(snode->id); // Use snode->id as placeholder to identify a snode
return;
}

visited.insert(snode->id);
for (auto &c : snode->ch) {
get_offline_cache_key_of_snode_impl(c.get(), serializer);
get_offline_cache_key_of_snode_impl(c.get(), serializer, visited);
}
for (int i = 0; i < taichi_max_num_indices; ++i) {
auto &extractor = snode->extractors[i];
Expand Down Expand Up @@ -106,21 +113,21 @@ static void get_offline_cache_key_of_snode_impl(
}
if (snode->grad_info && !snode->grad_info->is_primal()) {
if (auto *grad_snode = snode->grad_info->grad_snode()) {
get_offline_cache_key_of_snode_impl(grad_snode, serializer);
get_offline_cache_key_of_snode_impl(grad_snode, serializer, visited);
}
}
if (snode->exp_snode) {
get_offline_cache_key_of_snode_impl(snode->exp_snode, serializer);
get_offline_cache_key_of_snode_impl(snode->exp_snode, serializer, visited);
}
serializer(snode->bit_offset);
serializer(snode->placing_shared_exp);
serializer(snode->owns_shared_exponent);
for (auto s : snode->exponent_users) {
get_offline_cache_key_of_snode_impl(s, serializer);
get_offline_cache_key_of_snode_impl(s, serializer, visited);
}
if (snode->currently_placing_exp_snode) {
get_offline_cache_key_of_snode_impl(snode->currently_placing_exp_snode,
serializer);
serializer, visited);
}
if (snode->currently_placing_exp_snode_dtype) {
serializer(snode->currently_placing_exp_snode_dtype->to_string());
Expand All @@ -138,7 +145,10 @@ std::string get_hashed_offline_cache_key_of_snode(SNode *snode) {

BinaryOutputSerializer serializer;
serializer.initialize();
get_offline_cache_key_of_snode_impl(snode, serializer);
{
std::unordered_set<int> visited;
get_offline_cache_key_of_snode_impl(snode, serializer, visited);
}
serializer.finalize();

picosha2::hash256_one_by_one hasher;
Expand Down