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

[IR] Init GlobalTensorElementExpression and PtrOffsetStmt #2543

Merged
merged 36 commits into from
Jul 31, 2021

Conversation

squarefk
Copy link
Contributor

@squarefk squarefk commented Jul 19, 2021

Related Issue = #2590

Below is the design overview and some concerns to resolve before moving on to accomplish all related components like type-check, ir-printer...

  1. From Python AST, it generates GlobalTensorElementExpression(GlobalPtrExpression, Expr).
  2. In lower_ast pass, it will be lowered into GlobalTensorElementStmt(GlobalPtrStmt, Stmt)
  3. In lower_access pass, the lower process of GlobalPtrStmt has been moved into visit(GlobalTensorElementStmt*)
  4. With codegen_llvm, GlobalTensorElementStmt will emit function calls (acces_with_offset_*) predefined in llvm/runtime.cpp

Concerns:

  • Line 1. shall we have GlobalTensorElementExpression inherited from GlobalPtrExpression or directly from Expression?
  • Line 3. why do we not have something like visit(GlobalPtrStmt*)?
  • Line 4. is there any better solution?

@ljcc0930 ljcc0930 changed the title [IR] init GlobalTensorElementExpression and GlobalTensorElementExpr [IR] Init GlobalTensorElementExpression and GlobalTensorElementExpr Jul 19, 2021
@k-ye
Copy link
Member

k-ye commented Jul 19, 2021

From Python AST, it generates GlobalTensorElementExpression(GlobalPtrExpression, Expr).

I think it should be (GlobalPtrExpression, ExprGroup)? Otherwise we cannot support dynamic indexing for a ti.Matrix?

@CLAassistant
Copy link

CLAassistant commented Jul 20, 2021

CLA assistant check
All committers have signed the CLA.

@squarefk
Copy link
Contributor Author

/format

Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

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

Awesome work! A few code style suggestions

taichi/ir/expr.cpp Outdated Show resolved Hide resolved
python/taichi/lang/matrix.py Outdated Show resolved Hide resolved
taichi/ir/frontend_ir.cpp Outdated Show resolved Hide resolved
taichi/ir/frontend_ir.h Outdated Show resolved Hide resolved
taichi/ir/statements.h Outdated Show resolved Hide resolved
taichi/ir/statements.h Outdated Show resolved Hide resolved
taichi/ir/frontend_ir.h Outdated Show resolved Hide resolved
taichi/transforms/lower_access.cpp Outdated Show resolved Hide resolved
@k-ye k-ye requested a review from strongoier July 23, 2021 12:01
taichi/ir/expr.cpp Outdated Show resolved Hide resolved
squarefk and others added 3 commits July 27, 2021 10:04
Co-authored-by: xumingkuan <xumingkuan0721@126.com>
@squarefk
Copy link
Contributor Author

/format

Copy link
Contributor

@strongoier strongoier left a comment

Choose a reason for hiding this comment

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

Maybe we can rename GlobalTensorElementStmt to something like GlobalPtrWithOffsetStmt?

tests/python/test_matrix.py Outdated Show resolved Hide resolved
python/taichi/lang/matrix.py Outdated Show resolved Hide resolved
tests/python/test_matrix.py Outdated Show resolved Hide resolved
taichi/ir/statements.h Show resolved Hide resolved
taichi/transforms/type_check.cpp Show resolved Hide resolved
Copy link
Contributor

@strongoier strongoier left a comment

Choose a reason for hiding this comment

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

LGTM!

@strongoier
Copy link
Contributor

/format

@squarefk squarefk changed the title [IR] Init GlobalTensorElementExpression and GlobalTensorElementExpr [IR] Init GlobalTensorElementExpression and ShiftGlobalPtrStmt Jul 29, 2021
@squarefk
Copy link
Contributor Author

/format

@squarefk
Copy link
Contributor Author

/format

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.

I believe alias_analysis.cpp should be modified. Currently any two ShiftGlobalPtrStmts will result in AliasResult::uncertain, which is too conservative. (Feel free to use value_diff_ptr_index or same_value to implement alias_analysis)

taichi/ir/statements.h Show resolved Hide resolved
Copy link
Member

@k-ye k-ye left a comment

Choose a reason for hiding this comment

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

Great work!

taichi/codegen/codegen_llvm.cpp Outdated Show resolved Hide resolved
taichi/ir/statements.h Show resolved Hide resolved
@squarefk
Copy link
Contributor Author

/format

@squarefk
Copy link
Contributor Author

I believe alias_analysis.cpp should be modified. Currently any two ShiftGlobalPtrStmts will result in AliasResult::uncertain, which is too conservative. (Feel free to use value_diff_ptr_index or same_value to implement alias_analysis)

I believe you are right. I will open another pull request about this after I get more familiar with CFG optimization passes.

@squarefk squarefk changed the title [IR] Init GlobalTensorElementExpression and ShiftGlobalPtrStmt [IR] Init GlobalTensorElementExpression and PtrOffsetStmt Jul 30, 2021
@k-ye k-ye merged commit e71f2eb into taichi-dev:master Jul 31, 2021
@Leonz5288 Leonz5288 mentioned this pull request Aug 3, 2021
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.

6 participants