Skip to content

Commit

Permalink
add compile config
Browse files Browse the repository at this point in the history
  • Loading branch information
lin-hitonami committed Sep 20, 2022
1 parent 347a373 commit 18b0747
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions taichi/program/compile_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct CompileConfig {
bool lower_access;
bool simplify_after_lower_access;
bool move_loop_invariant_outside_if;
bool cache_loop_invariant_global_vars{false};
bool demote_dense_struct_fors;
bool advanced_optimization;
bool constant_folding;
Expand Down
1 change: 1 addition & 0 deletions taichi/python/export_lang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ void export_lang(py::module &m) {
.def_readwrite("lower_access", &CompileConfig::lower_access)
.def_readwrite("move_loop_invariant_outside_if",
&CompileConfig::move_loop_invariant_outside_if)
.def_readwrite("cache_loop_invariant_global_vars", &CompileConfig::cache_loop_invariant_global_vars)
.def_readwrite("default_cpu_block_dim",
&CompileConfig::default_cpu_block_dim)
.def_readwrite("cpu_block_dim_adaptive",
Expand Down
7 changes: 5 additions & 2 deletions taichi/transforms/compile_to_offloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,11 @@ void offload_to_executable(IRNode *ir,
irpass::demote_atomics(ir, config);
print("Atomics demoted I");
irpass::analysis::verify(ir);
irpass::cache_loop_invariant_global_vars(ir, config);
print("Cache loop-invariant global vars");
if (config.cache_loop_invariant_global_vars) {
irpass::cache_loop_invariant_global_vars(ir, config);
print("Cache loop-invariant global vars");
}

if (config.demote_dense_struct_fors) {
irpass::demote_dense_struct_fors(ir, config.packed);
irpass::type_check(ir, config);
Expand Down
6 changes: 3 additions & 3 deletions taichi/transforms/loop_invariant_code_motion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class LoopInvariantCodeMotion : public LoopInvariantDetector {
}

void visit(GlobalPtrStmt *stmt) override {
if (is_loop_invariant(stmt, stmt->parent)) {
if (config.cache_loop_invariant_global_vars && is_loop_invariant(stmt, stmt->parent)) {
auto replacement = stmt->clone();
stmt->replace_usages_with(replacement.get());

Expand All @@ -43,7 +43,7 @@ class LoopInvariantCodeMotion : public LoopInvariantDetector {
}

void visit(ExternalPtrStmt *stmt) override {
if (is_loop_invariant(stmt, stmt->parent)) {
if (config.cache_loop_invariant_global_vars && is_loop_invariant(stmt, stmt->parent)) {
auto replacement = stmt->clone();
stmt->replace_usages_with(replacement.get());

Expand All @@ -53,7 +53,7 @@ class LoopInvariantCodeMotion : public LoopInvariantDetector {
}

void visit(ArgLoadStmt *stmt) override {
if (is_loop_invariant(stmt, stmt->parent)) {
if (config.cache_loop_invariant_global_vars && is_loop_invariant(stmt, stmt->parent)) {
auto replacement = stmt->clone();
stmt->replace_usages_with(replacement.get());

Expand Down

0 comments on commit 18b0747

Please sign in to comment.