-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Lower linearized
into a series of adds and muls.
#509
Conversation
One tip: |
linearized
into a series of adds and muls.linearized
into a series of adds and muls.
Just to confirm that the product of |
Good question! Yes, you can assume it fits in |
taichi/transforms/simplify.cpp
Outdated
@@ -691,7 +688,32 @@ class BasicBlockSimplify : public IRVisitor { | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CSE here
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();
}
}
}
}
can be removed now.
taichi/transforms/simplify.cpp
Outdated
stmt->insert_before_me(std::move(sum)); | ||
} | ||
stmt->replace_with(sumptr); | ||
stmt->parent->erase(stmt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do irpass::typecheck(stmt->parent)
if necessary.
taichi/transforms/simplify.cpp
Outdated
|
||
// Lower into a series of adds and muls. | ||
// Need typecheck afterwards. | ||
if (stmt->inputs.empty()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, no need to specialize when you have empty inputs. Empty inputs should simply be treated as inputs
with zero lengths. Then you can merge two clauses of this if
stmt. The extra 0 + i
can be optimized by your alg_simp
pass.
tests/cpp/test_alg_simp.cpp
Outdated
@@ -121,4 +121,39 @@ TI_TEST("simplify_multiply_zero_fast_math") { | |||
TI_CHECK((*block)[0]->is<GlobalTemporaryStmt>()); | |||
} | |||
|
|||
TI_TEST("simplify_linearized_with_trivial_inputs") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe create a test_simplify.cpp
file for this test?
Looks good in general! Just some small changes are needed. |
Changes finished :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!!!
Related issue id = #464
I'm confused with those
Stmt*
's andstd::unique_ptr
's. The code cannot pass the test now and I'm not sure if I'm writing bugs.