Skip to content

【CINN】Enrich ability of index expr #68986

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

Merged
merged 3 commits into from
Oct 28, 2024

Conversation

liuruyan
Copy link
Contributor

@liuruyan liuruyan commented Oct 27, 2024

PR Category

CINN

PR Types

New features

Description

  1. Upgrade ProveDivisible without AutoSimplify and analyzer.
  2. Enrich the ability of IndexExpr, constant must be at the rhs operand in Add and Mul. e.g.
3 + S0 ===> S0 + 3 
(S0 + 2) + S1 ===> S0 + S1 + 2
  1. Constant should be fold in Add and Mul now . e.g.
2 + 3 ===> 5
(S0 + 2) + 3 ===> S0 + 5
  1. Implemented the associative law of Add for constants. e.g.
S0 * 3 + S0 * 4 ===> S0 * 7
  1. Implemented IsSumPartialBySymbol func for Add and IsDivisiblieBySymbol func for Div, It can judge whether the expression can be simplified. if return true, then will apply SimplifySymbolicAdd and SimplifySymbolicDivide to simplify.
  2. Implement Normalize func for IndexExpr, Its function is to explicitly reconstruct an IndexExpr and simplify it at the same time. It usually use when an unsimplified Expr is converted to an IndexExpr using as_index(), e.g.
Expr e = (S0 + 2) + 3
e.as_index() ===> (S0 + 2) + 3
e.as_index().Normalize() ===> S0 + 5

Pcard-67164

Copy link

paddle-bot bot commented Oct 27, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@liuruyan liuruyan changed the title Enrich index expr 【CINN】Enrich ability of index expr Oct 28, 2024
Comment on lines +191 to +211
// TODO(liuruyan): canby simplify into IndexExpr multiply.
ir::IndexExpr MulAndNormalize(const ir::IndexExpr &lhs,
const ir::IndexExpr &rhs);

int32_t CalculateExprComplexity(const Expr &expr, int count = 0);

// True means don't change sequence
bool IsCorrectPriority(const Expr &lhs, const Expr &rhs);

bool IsSumPartialBySymbol(const ir::IndexExpr &expr,
const ir::IndexExpr &symbol);

// If true is returned, the operation will be attempted on each subpart in
// outter `simplify` function. Note: this func dont deal the corner case, e.g.
// `IsDivisiblieBySymbol(f % S0 - f, S0)` is `false`. please use
// `ProveDivisible` for exact result.
bool IsDivisiblieBySymbol(const ir::IndexExpr &expr,
const ir::IndexExpr &symbol,
const ir::IrNodeTy &ty);

bool ProveDivisible(const ir::IndexExpr &lhs, const ir::IndexExpr &rhs);
Copy link
Contributor

Choose a reason for hiding this comment

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

这几个接口再补充一些注释说明,能给出示例的尽量用例子说明一下

Copy link
Contributor Author

Choose a reason for hiding this comment

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

下一个PR中进行添加

@@ -501,5 +502,140 @@ Expr min(Expr a, Expr b) {
return ir::Min::Make(a, b);
}

int32_t CalculateExprComplexity(const Expr &expr, int count) {
Copy link
Contributor

Choose a reason for hiding this comment

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

这里用Complexity是否准确?看着只是做节点数量的统计

Copy link
Contributor Author

Choose a reason for hiding this comment

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

下一个PR中进行更改

}
}

bool IsCorrectPriority(const Expr &lhs, const Expr &rhs) {
Copy link
Contributor

@zyfncg zyfncg Oct 28, 2024

Choose a reason for hiding this comment

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

这个看上去是做两个Expr的比较,CorrectPriority在语义上看不太出来返回true是左边Priority高还是右边Priority高

Copy link
Contributor Author

Choose a reason for hiding this comment

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

下一个PR中进行更改

@zyfncg zyfncg merged commit a919b05 into PaddlePaddle:develop Oct 28, 2024
27 checks passed
@liuruyan liuruyan deleted the enrichIndexExpr branch October 28, 2024 07:57
fxfxfxfxfxfxfxfx pushed a commit to fxfxfxfxfxfxfxfx/Paddle that referenced this pull request Oct 29, 2024
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.

2 participants