From aa2dcad7dcf18a98d55a33ea896665208908b89b Mon Sep 17 00:00:00 2001 From: PGZXB <420254146@qq.com> Date: Sun, 15 May 2022 10:23:40 +0800 Subject: [PATCH 1/4] Fix infinite recursion of get_offline_cache_key_of_snode_impl --- taichi/analysis/offline_cache_util.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/taichi/analysis/offline_cache_util.cpp b/taichi/analysis/offline_cache_util.cpp index 140a3915df67a..6dfe4e48ac44e 100644 --- a/taichi/analysis/offline_cache_util.cpp +++ b/taichi/analysis/offline_cache_util.cpp @@ -71,9 +71,16 @@ static std::vector 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 &visited) { + if (auto iter = visited.find(snode->id); iter != visited.end()) { + serializer(snode->id); // Node: Use snode-id as placeholder + return; + } else { + 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]; @@ -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()); @@ -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 visited; // Node: snode-id + get_offline_cache_key_of_snode_impl(snode, serializer, visited); + } serializer.finalize(); picosha2::hash256_one_by_one hasher; From 222205ee3351f18a6892d43725c674f0969ddf8a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 May 2022 02:29:30 +0000 Subject: [PATCH 2/4] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- taichi/analysis/offline_cache_util.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taichi/analysis/offline_cache_util.cpp b/taichi/analysis/offline_cache_util.cpp index 6dfe4e48ac44e..b813e015bbb7d 100644 --- a/taichi/analysis/offline_cache_util.cpp +++ b/taichi/analysis/offline_cache_util.cpp @@ -74,7 +74,7 @@ static void get_offline_cache_key_of_snode_impl( BinaryOutputSerializer &serializer, std::unordered_set &visited) { if (auto iter = visited.find(snode->id); iter != visited.end()) { - serializer(snode->id); // Node: Use snode-id as placeholder + serializer(snode->id); // Node: Use snode-id as placeholder return; } else { visited.insert(snode->id); @@ -146,7 +146,7 @@ std::string get_hashed_offline_cache_key_of_snode(SNode *snode) { BinaryOutputSerializer serializer; serializer.initialize(); { - std::unordered_set visited; // Node: snode-id + std::unordered_set visited; // Node: snode-id get_offline_cache_key_of_snode_impl(snode, serializer, visited); } serializer.finalize(); From 048b010a86d9f46fc7bef710bf54d1a6db85a3e7 Mon Sep 17 00:00:00 2001 From: PGZXB <420254146@qq.com> Date: Sun, 15 May 2022 10:32:55 +0800 Subject: [PATCH 3/4] Fix some comments --- taichi/analysis/offline_cache_util.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taichi/analysis/offline_cache_util.cpp b/taichi/analysis/offline_cache_util.cpp index b813e015bbb7d..531662d93455a 100644 --- a/taichi/analysis/offline_cache_util.cpp +++ b/taichi/analysis/offline_cache_util.cpp @@ -74,7 +74,7 @@ static void get_offline_cache_key_of_snode_impl( BinaryOutputSerializer &serializer, std::unordered_set &visited) { if (auto iter = visited.find(snode->id); iter != visited.end()) { - serializer(snode->id); // Node: Use snode-id as placeholder + serializer(snode->id); // Use snode->id as placeholder to identify a snode return; } else { visited.insert(snode->id); @@ -146,7 +146,7 @@ std::string get_hashed_offline_cache_key_of_snode(SNode *snode) { BinaryOutputSerializer serializer; serializer.initialize(); { - std::unordered_set visited; // Node: snode-id + std::unordered_set visited; get_offline_cache_key_of_snode_impl(snode, serializer, visited); } serializer.finalize(); From e68bf552ae3313c36ead2ae85b4ff425298e04aa Mon Sep 17 00:00:00 2001 From: PGZXB <420254146@qq.com> Date: Sun, 15 May 2022 10:40:07 +0800 Subject: [PATCH 4/4] Fix --- taichi/analysis/offline_cache_util.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/taichi/analysis/offline_cache_util.cpp b/taichi/analysis/offline_cache_util.cpp index 531662d93455a..bcffd829f3940 100644 --- a/taichi/analysis/offline_cache_util.cpp +++ b/taichi/analysis/offline_cache_util.cpp @@ -76,9 +76,9 @@ static void get_offline_cache_key_of_snode_impl( if (auto iter = visited.find(snode->id); iter != visited.end()) { serializer(snode->id); // Use snode->id as placeholder to identify a snode return; - } else { - visited.insert(snode->id); } + + visited.insert(snode->id); for (auto &c : snode->ch) { get_offline_cache_key_of_snode_impl(c.get(), serializer, visited); }