-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AutoDiff] Automatically determine AdStack's size (#2438)
* [AutoDiff] Automatically determine AdStack's size * Auto Format * revert auto format * revert auto format * update comment * fix format * oops * Update taichi/ir/statements.h Co-authored-by: Ye Kuang <k-ye@users.noreply.github.com> * Update taichi/ir/control_flow_graph.cpp Co-authored-by: Yuanming Hu <yuanming-hu@users.noreply.github.com> * Apply review * Add a documentation * Add a basic C++ test * Add 3 more tests * Add comments * Update taichi/ir/control_flow_graph.cpp Co-authored-by: Ye Kuang <k-ye@users.noreply.github.com> * Apply review, use parameterized tests, fix typo and code format * Apply review * Use the Bellman-Ford algorithm * Update taichi/ir/control_flow_graph.cpp * Run Bellman-Ford on each stack separately, fix a bug, add a test Co-authored-by: Taichi Gardener <taichigardener@gmail.com> Co-authored-by: Ye Kuang <k-ye@users.noreply.github.com> Co-authored-by: Yuanming Hu <yuanming-hu@users.noreply.github.com>
- Loading branch information
1 parent
a7d9dc2
commit 7fe1cf2
Showing
15 changed files
with
455 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "taichi/ir/analysis.h" | ||
#include "taichi/ir/control_flow_graph.h" | ||
#include "taichi/ir/ir.h" | ||
#include "taichi/ir/statements.h" | ||
#include "taichi/ir/transforms.h" | ||
|
||
#include <queue> | ||
#include <unordered_map> | ||
|
||
namespace taichi { | ||
namespace lang { | ||
|
||
namespace irpass { | ||
|
||
bool determine_ad_stack_size(IRNode *root, const CompileConfig &config) { | ||
if (irpass::analysis::gather_statements(root, [&](Stmt *s) { | ||
if (auto ad_stack = s->cast<AdStackAllocaStmt>()) { | ||
return ad_stack->max_size == 0; // adaptive | ||
} | ||
return false; | ||
}).empty()) { | ||
return false; // no AD-stacks with adaptive size | ||
} | ||
auto cfg = analysis::build_cfg(root); | ||
cfg->simplify_graph(); | ||
cfg->determine_ad_stack_size(config.default_ad_stack_size); | ||
return true; | ||
} | ||
|
||
} // namespace irpass | ||
|
||
} // namespace lang | ||
} // namespace taichi |
Oops, something went wrong.