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

[refactor] Add ASTSerializer and use it to generate offline-cache-key #4863

Merged
merged 2 commits into from
Apr 28, 2022
Merged
Show file tree
Hide file tree
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
441 changes: 441 additions & 0 deletions taichi/analysis/gen_offline_cache_key.cpp

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions taichi/analysis/offline_cache_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ std::string get_hashed_offline_cache_key(CompileConfig *config,
Kernel *kernel) {
std::string kernel_ast_string;
if (kernel) {
irpass::gen_offline_cache_key(kernel->program, kernel->ir.get(),
&kernel_ast_string);
std::ostringstream oss;
gen_offline_cache_key(kernel->program, kernel->ir.get(), &oss);
kernel_ast_string = oss.str();
}

std::vector<std::uint8_t> compile_config_key;
Expand Down
5 changes: 4 additions & 1 deletion taichi/analysis/offline_cache_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ namespace taichi {
namespace lang {

struct CompileConfig;
class Kernel;
class Program;
class IRNode;
class SNode;
class Kernel;

std::string get_hashed_offline_cache_key_of_snode(SNode *snode);
std::string get_hashed_offline_cache_key(CompileConfig *config, Kernel *kernel);
void gen_offline_cache_key(Program *prog, IRNode *ast, std::ostream *os);

} // namespace lang
} // namespace taichi
15 changes: 15 additions & 0 deletions taichi/inc/frontend_statements.inc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
PER_STATEMENT(FrontendExternalFuncStmt)
PER_STATEMENT(FrontendExprStmt)
PER_STATEMENT(FrontendIfStmt)
PER_STATEMENT(FrontendForStmt)
PER_STATEMENT(FrontendPrintStmt)
PER_STATEMENT(FrontendWhileStmt)
PER_STATEMENT(FrontendBreakStmt)
PER_STATEMENT(FrontendContinueStmt)
PER_STATEMENT(FrontendAllocaStmt)
PER_STATEMENT(FrontendAssignStmt)
PER_STATEMENT(FrontendEvalStmt)
PER_STATEMENT(FrontendSNodeOpStmt) // activate, deactivate, append, clear
PER_STATEMENT(FrontendAssertStmt)
PER_STATEMENT(FrontendFuncDefStmt)
PER_STATEMENT(FrontendReturnStmt)
16 changes: 1 addition & 15 deletions taichi/inc/statements.inc.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
// Frontend statements
PER_STATEMENT(FrontendExternalFuncStmt)
PER_STATEMENT(FrontendExprStmt)
PER_STATEMENT(FrontendIfStmt)
PER_STATEMENT(FrontendForStmt)
PER_STATEMENT(FrontendPrintStmt)
PER_STATEMENT(FrontendWhileStmt)
PER_STATEMENT(FrontendBreakStmt)
PER_STATEMENT(FrontendContinueStmt)
PER_STATEMENT(FrontendAllocaStmt)
PER_STATEMENT(FrontendAssignStmt)
PER_STATEMENT(FrontendEvalStmt)
PER_STATEMENT(FrontendSNodeOpStmt) // activate, deactivate, append, clear
PER_STATEMENT(FrontendAssertStmt)
PER_STATEMENT(FrontendFuncDefStmt)
PER_STATEMENT(FrontendReturnStmt)
#include "frontend_statements.inc.h"

// Middle-end statement

Expand Down
8 changes: 4 additions & 4 deletions taichi/ir/expression_printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ class ExpressionPrinter : public ExpressionVisitor {
os_ = os;
}

std::ostream &get_ostream() {
TI_ASSERT(os_);
return *os_;
std::ostream *get_ostream() {
return os_;
}

private:
Expand Down Expand Up @@ -227,7 +226,8 @@ class ExpressionHumanFriendlyPrinter : public ExpressionPrinter {
protected:
template <typename... Args>
void emit(Args &&...args) {
(this->get_ostream() << ... << std::forward<Args>(args));
TI_ASSERT(this->get_ostream());
(*this->get_ostream() << ... << std::forward<Args>(args));
}

template <typename T>
Expand Down
1 change: 0 additions & 1 deletion taichi/ir/transforms.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ void full_simplify(IRNode *root,
const CompileConfig &config,
const FullSimplifyPass::Args &args);
void print(IRNode *root, std::string *output = nullptr);
void gen_offline_cache_key(Program *program, IRNode *root, std::string *output);
void frontend_type_check(IRNode *root);
void lower_ast(IRNode *root);
void type_check(IRNode *root, const CompileConfig &config);
Expand Down
6 changes: 0 additions & 6 deletions taichi/transforms/ir_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -805,12 +805,6 @@ void print(IRNode *root, std::string *output) {
return IRPrinter::run(&expr_printer, root, output);
}

void gen_offline_cache_key(Program *prog, IRNode *root, std::string *output) {
irpass::re_id(root);
ExpressionOfflineCacheKeyGenerator cache_key_generator(prog);
return IRPrinter::run(&cache_key_generator, root, output);
}

} // namespace irpass

TLANG_NAMESPACE_END