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] [ir] IR system refactorings #1058

Merged
merged 16 commits into from
May 26, 2020

Conversation

TH3CHARLie
Copy link
Collaborator

@TH3CHARLie
Copy link
Collaborator Author

TH3CHARLie commented May 25, 2020

This PR literally follows guidelines from #988, with minimal modifications to backend code(namely adding get() to match argument types).

However, it has not yet implemented the last point on removing CompileConfig.

Try to remove dependency on get_current_program in irpasses
Use X.get_kernel().program instead

Regarding this, there are plenty of get_current_program I left untouched, they are backends and ir/frontend, FrontendForStmt, SNode.

The remaining get_current_programs in irpass are in ConstantFold::get_jit_evaluator_kernel, where no IRNode is provided

@yuanming-hu yuanming-hu requested a review from xumingkuan May 25, 2020 17:22
taichi/analysis/clone.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@xumingkuan xumingkuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

taichi/transforms/type_check.cpp Outdated Show resolved Hide resolved
@@ -113,13 +113,14 @@ class ConstantFold : public BasicStmtVisitor {
rhs.dt,
true};
auto *ker = get_jit_evaluator_kernel(id);
auto &ctx = get_current_program().get_context();
auto &current_program = stmt->get_kernel()->program;
auto &ctx = current_program.get_context();
Copy link
Collaborator Author

@TH3CHARLie TH3CHARLie May 26, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This segment has some issues with it. Please see comment below

@TH3CHARLie
Copy link
Collaborator Author

TH3CHARLie commented May 26, 2020

The current build has failed due to segfault in C++ tests (all broken tests are due to the same reason, you can simply take alg_simp/simplify_add_zero as an example).

The source of segfault lies in the above segment in constant_fold.cpp, because stmt->get_kernel() would be nullptr and therefore accessing program causes segfault.

However, I find this is rare for taichi program written in python, because in such cases, IRNode's kernel would be set. However, in C++ tests like alg_simp, I find that the IR block is constructed manually, and I suspect that some process is missing or different from construction via python AST, therefore leading to IRNode's kernel unset(nullptr).

To pass the C++ tests, one way is to fallback the above code segment to using get_current_program again. But personally I think it contradicts the idea of this PR. I'd like to know your thoughts on it @yuanming-hu @xumingkuan

updates:
I comment out the new approach to pass CI for now.

updates 2:
The similar situation happens when we change alg_simp(IRNode*, const CompileConfig &) to alg_simp(IRNode*). For taichi programs this would be fine since we can get config through IRNode::kernel->program.config. But for C++ tests, currently CompileConfigs are constructed ad-hoc and have no connection to kernels.

@xumingkuan
Copy link
Contributor

xumingkuan commented May 26, 2020

For C++ tests, Program was constructed in this PR: #839 (comment)

Maybe we also need a Kernel for C++ tests now?

@TH3CHARLie
Copy link
Collaborator Author

For C++ tests, Program was constructed in this PR: #839 (comment)

Maybe we also need a Kernel for C++ tests now?

Yes, I find that program is constructed with kernel set properly. But the kernel itself is not connected to IRNode.

@TH3CHARLie
Copy link
Collaborator Author

TH3CHARLie commented May 26, 2020

Maybe we also need a Kernel for C++ tests now?

I am thinking modifying tests hugely are adding too much in this PR. Maybe we can do a hack by adding block->kernel = get_current_program().get_current_kernel only in test case. And in a later, separate PR, we make the test more reasonable

@yuanming-hu
Copy link
Member

To pass the C++ tests, one way is to fallback the above code segment to using get_current_program again. But personally I think it contradicts the idea of this PR. I'd like to know your thoughts on it @yuanming-hu @xumingkuan

Let's use get_current_program for now to make the tests pass. I don't think usages of this global function can be removed in just one PR anyway :-)

@TH3CHARLie
Copy link
Collaborator Author

TH3CHARLie commented May 26, 2020

Let's use get_current_program for now to make the tests pass. I don't think usages of this global function can be removed in just one PR anyway :-)

Then it would involve changing plenty of places in C++ test code, but I assume most of them would be insignificant, especially no one would affect the check semantics itself. If that's OK for you, then I'll have a try right away

@yuanming-hu
Copy link
Member

Let's use get_current_program for now to make the tests pass. I don't think usages of this global function can be removed in just one PR anyway :-)

Then it would involve changing plenty of places in C++ test code, but I assume most of them would be insignificant, especially no one would affect the check semantics itself. If that's OK for you, then I'll have a try right away

I see. Feel free to pick the most convenient solution then.

Maybe we can do a hack by adding block->kernel = get_current_program().get_current_kernel only in test case.

This sounds like the easiest way given the current situation.

@xumingkuan
Copy link
Contributor

Yeah, since C++ tests are manually constructing Blocks, it sounds reasonable to manually set a member variable of the Block.

@TH3CHARLie
Copy link
Collaborator Author

Summary:

  • Implement all refactor TODOs listed in [refactor] [ir] IR system refactorings #988: for the last one, alg_simp and full_simplify are modified. The remaining one is compile_to_offloads, changing it would change some backend code. My personal opinion is to keep things in the IR level in this PR and address this later.

  • Change(or hack) C++ tests with fake kernels. After this is merged, I'd love to open an issue for better C++ tests, then we will remove these code for sure.

Copy link
Contributor

@xumingkuan xumingkuan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the hard work! Just a nit.

taichi/transforms/alg_simp.cpp Outdated Show resolved Hide resolved
Co-authored-by: xumingkuan <xumingkuan0721@126.com>
Copy link
Member

@yuanming-hu yuanming-hu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks! @xumingkuan Please merge when everything's good on your part :-)

@xumingkuan xumingkuan merged commit 2bf0bee into taichi-dev:master May 26, 2020
@TH3CHARLie
Copy link
Collaborator Author

Thanks for the review!

@TH3CHARLie TH3CHARLie deleted the ir-refactor branch May 26, 2020 18:13
@yuanming-hu yuanming-hu mentioned this pull request May 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants