Skip to content

Commit

Permalink
[misc] Introduced a temporary boolean constant for benchmarking advan…
Browse files Browse the repository at this point in the history
…ced optimizations (#657)

* Introduce a temporary boolean constant for benchmarking

* [skip ci] enforce code format

Co-authored-by: Taichi Gardener <taichigardener@gmail.com>
  • Loading branch information
xumingkuan and taichi-gardener authored Mar 25, 2020
1 parent 2d1c023 commit 068af03
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<img width="500px" src="https://github.com/yuanming-hu/taichi/raw/master/misc/logo.png">
<h3> <a href="https://taichi.readthedocs.io/en/latest/"> Docs </a> | <a href="https://taichi.readthedocs.io/en/latest/hello.html"> Tutorial </a> | <a href="https://github.com/yuanming-hu/difftaichi"> DiffTaichi </a> | <a href="https://github.com/yuanming-hu/taichi/tree/master/examples"> Examples </a> | <a href="https://taichi.readthedocs.io/en/latest/contributor_guide.html"> Contribute </a> | <a href="https://forum.taichi.graphics/"> Forum </a> </h3>
</div>
</div>

| **Documentations** | **Chat** | taichi-nightly | taichi-nightly-cuda-10-0 | taichi-nightly-cuda-10-1 |
|:-----|:-----|:----|:----|:----|
Expand Down Expand Up @@ -46,7 +46,7 @@ python3 -m pip install taichi-nightly-cuda-10-1
- Experimental support for automatically differentiating through conditional global load/stores (by **Yuanming Hu**)
- **Bug fixes**
- Fixed stack traceback printing on OS X (#610) (by **Yuanming Hu**)
- **CLI**
- **CLI**
- `ti format` now cover all files from upstream/master to the working tree (#629) (by **Ye Kuang**)
- `ti test` now uses `argparse` for better customizability (#601) (by **彭于斌**)
- **OpenGL backend**
Expand Down
13 changes: 6 additions & 7 deletions examples/mgpcg_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@ def __init__(self):
shape=(self.N_gui, self.N_gui)) # image buffer

indices = ti.ijk if self.dim == 3 else ti.ij
self.grid = ti.root.pointer(indices,
[self.N_tot // 4]).dense(indices, 4).place(
self.x, self.p, self.Ap)
self.grid = ti.root.pointer(indices, [self.N_tot // 4]).dense(
indices, 4).place(self.x, self.p, self.Ap)

for l in range(self.n_mg_levels):
self.grid = ti.root.pointer(indices,
[self.N_tot // (4 * 2**l)]).dense(
indices, 4).place(
self.r[l], self.z[l])
indices,
4).place(self.r[l], self.z[l])

ti.root.place(self.alpha, self.beta, self.sum)

Expand All @@ -55,8 +54,8 @@ def init(self):
(self.N_ext, self.N_tot - self.N_ext), ) * self.dim)):
self.r[0][I] = 1.0
for k in ti.static(range(self.dim)):
self.r[0][I] *= ti.sin(2.0 * np.pi *
(I[k] - self.N_ext) * 2.0 / self.N_tot)
self.r[0][I] *= ti.sin(2.0 * np.pi * (I[k] - self.N_ext) *
2.0 / self.N_tot)
self.z[0][I] = 0.0
self.Ap[I] = 0.0
self.p[I] = 0.0
Expand Down
2 changes: 2 additions & 0 deletions taichi/program/compile_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

TLANG_NAMESPACE_BEGIN

const bool advanced_optimization = true;

CompileConfig::CompileConfig() {
arch = host_arch();
simd_width = default_simd_width(arch);
Expand Down
4 changes: 4 additions & 0 deletions taichi/program/compile_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

TLANG_NAMESPACE_BEGIN

// TODO(xumingkuan): Temporary variable for benchmarking.
// TODO(xumingkuan): Will be removed in the future.
extern const bool advanced_optimization;

struct CompileConfig {
Arch arch;
bool debug;
Expand Down
29 changes: 25 additions & 4 deletions taichi/transforms/simplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -667,8 +667,10 @@ class BasicBlockSimplify : public IRVisitor {
}

void visit(LinearizeStmt *stmt) override {
// if (is_done(stmt))
// return;
if (!advanced_optimization) {
if (is_done(stmt))
return;
}

if (stmt->inputs.size() && stmt->inputs.back()->is<IntegerOffsetStmt>()) {
auto previous_offset = stmt->inputs.back()->as<IntegerOffsetStmt>();
Expand All @@ -681,7 +683,25 @@ class BasicBlockSimplify : public IRVisitor {
offset_stmt->as<IntegerOffsetStmt>()->input = stmt;
throw IRModified();
}
// set_done(stmt);
if (!advanced_optimization) {
for (int i = 0; i < current_stmt_id; i++) {
auto &bstmt = block->statements[i];
if (stmt->ret_type == bstmt->ret_type) {
auto &bstmt_data = *bstmt;
if (typeid(bstmt_data) == typeid(*stmt)) {
auto bstmt_ = bstmt->as<LinearizeStmt>();
if (identical_vectors(bstmt_->inputs, stmt->inputs) &&
identical_vectors(bstmt_->strides, stmt->strides)) {
stmt->replace_with(bstmt.get());
stmt->parent->erase(current_stmt_id);
throw IRModified();
}
}
}
}
set_done(stmt);
return;
}

// Lower into a series of adds and muls.
auto sum = Stmt::make<ConstStmt>(LaneAttribute<TypedConstant>(0));
Expand Down Expand Up @@ -1014,7 +1034,8 @@ void simplify(IRNode *root) {

void full_simplify(IRNode *root, const CompileConfig &config) {
constant_fold(root);
alg_simp(root, config);
if (advanced_optimization)
alg_simp(root, config);
die(root);
simplify(root);
}
Expand Down

0 comments on commit 068af03

Please sign in to comment.