-
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
[IR][refactor] Convert loop_var into LoopIndexStmt #953
Conversation
The If we put this pass before I think ideally we should put this pass right after |
taichi/ir/statements.h
Outdated
@@ -217,19 +217,20 @@ class OffloadedStmt : public Stmt { | |||
|
|||
class LoopIndexStmt : public Stmt { | |||
public: | |||
Stmt *loop; | |||
int index; | |||
bool is_struct_for; |
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.
I think the field is_struct_for
would be unnecessary.
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.
Yes, please feel free to remove that.
You mean moving |
Oh, I mean moving |
Oh, I see. That sounds good. Actually, let's make it part of taichi/taichi/transforms/lower_ast.cpp Lines 446 to 449 in f78f387
|
# Conflicts: # taichi/ir/ir.h
Why is this? Lines 243 to 246 in e0ef399
I think I need
to not throw exceptions. I'm changing the above line to |
I have no idea on this. |
Very probably... |
# Conflicts: # taichi/transforms/statement_replace.cpp
I wonder in which case this is
Since there are no loop_var s after this PR, I'm afraid that the information on data type will be lost.
|
Thanks for pointing that out. Shall we simply add a rule to enforce the data type of loop variables to be |
I think in LLVM and CUDA backends, the loop variables are |
Sounds good. |
TI_ASSERT(total_bits <= 31); | ||
TI_ASSERT(total_bits <= 30); | ||
|
||
auto upper_bound = 1 << total_bits; |
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.
1 << 31
looks dangerous. So I suppose not supporting tensors of size 2^31 for now.
TODO: Remove |
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.
Looks great! Thank you so much for refactoring this. The LLVM backend modifications look good to me. (I didn't look at the OpenGL and Metal backends.)
Btw, would it be possible to remove Sorry I missed your last message. Great work!RangeForStmt::loop_var
and StructForStmt::loop_vars
in the future? How easy/hard is that?
My feeling is that this is doable, but probably something in |
I would prefer not touching Currently, for this IR,
after
Shall we modify taichi/taichi/ir/frontend_ir.h Lines 448 to 452 in e0ef399
and Stmt *Block::lookup_var(const Identifier &ident) to treat loop vars specifically?
|
Sounds good. Feel free to pick the most convenient solution for now (keep in mind the presence of #925)... |
Shall I do it in this PR or the next?
I think even if |
Next PR sounds good.
That's true. Testing if a variable is a loop variable is easier in AST than in transformer.py. |
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.
OpenGL is OK, thank you!
|
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.
Great! I can confirm that the change works for Metal as well, thx!
taichi/codegen/codegen_llvm.h
Outdated
@@ -72,8 +72,7 @@ class CodeGenLLVM : public IRVisitor, public LLVMModuleBuilder { | |||
std::vector<OffloadedTask> offloaded_tasks; | |||
BasicBlock *func_body_bb; | |||
|
|||
std::unordered_map<OffloadedStmt *, std::vector<llvm::Value *>> | |||
offloaded_loop_vars_llvm; | |||
std::unordered_map<Stmt *, std::vector<llvm::Value *>> loop_vars_llvm; |
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.
nit: is it possible to use const Stmt*
here? i don't think the key is modified?
I think maybe we're encountering this issue #656 (comment), that is, some tests are mismatched, so there are some |
Related PR = #932 (comment)
There are more places than I thought that need to be refactored...
[Click here for the format server]