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

[CINN] Add Div to replace Recipical in DimExpr #70376

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from

Conversation

gongshaotian
Copy link
Contributor

@gongshaotian gongshaotian commented Dec 20, 2024

PR Category

CINN

PR Types

New features

Description

Pcard-67164

Copy link

paddle-bot bot commented Dec 20, 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.

Comment on lines +382 to +385
Call(lhs, DoEach, depth + 1, is_inversed);
Call(rhs, DoEach, depth + 1, !is_inversed);
} else {
DoEach(expr, depth, is_inversed);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

什么情况下 is_inversed 为true

Copy link
Contributor

Choose a reason for hiding this comment

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

如图

image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

删除VisitEachOperandStruct

/*
* Simplify Example:
* Mul(2, Reciprocal(2)) => 1
* Mul(2, Div(1, 2)) => 1
Copy link
Contributor Author

@gongshaotian gongshaotian Dec 25, 2024

Choose a reason for hiding this comment

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

Mul(S0, Div(S1, S0)) => S1 现在不成立了
更新为
Mul(Div(1, S0), S0) => S0
Mul(S0, Div(1, S0) => S0

Copy link
Contributor Author

@gongshaotian gongshaotian Dec 25, 2024

Choose a reason for hiding this comment

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

这里需要论证下,能不能做为一个通用化简

Comment on lines +748 to +772
if (lhs.Has<Div<DimExpr>>()) {
auto div_expr = lhs.Get<Div<DimExpr>>();
if (!div_expr->lhs.Has<std::int64_t>()) {
return false;
}
const auto& [lhs_num, lhs_dem] = GetConstRational(div_expr->lhs);
if (lhs_dem != 1) {
return false;
}
if (div_expr->rhs == rhs) {
return true;
}
}
if (rhs.Has<Reciprocal<DimExpr>>()) {
const auto& rhs_operand = rhs.Get<Reciprocal<DimExpr>>()->data;
return rhs_operand == lhs;
if (rhs.Has<Div<DimExpr>>()) {
auto div_expr = rhs.Get<Div<DimExpr>>();
if (!div_expr->lhs.Has<std::int64_t>()) {
return false;
}
const auto& [rhs_num, rhs_dem] = GetConstRational(div_expr->lhs);
if (rhs_dem != 1) {
return false;
}
if (div_expr->rhs == lhs) {
return true;
}
Copy link
Contributor Author

@gongshaotian gongshaotian Dec 25, 2024

Choose a reason for hiding this comment

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

Mul(Div(1, S0), S0) -> S0
Mul(S0, Div(1, S0) -> S0
下同

static const_value_type MakeUnit() { return ConstRational{1, 1}; }
static void Accumulate(const_value_type* value, const DimExpr& expr) {
*value = MulConstRational(
*value, GetConstRational(expr)); // The expr are in the denominator.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

expr在分母上有什么特殊之处吗

Copy link
Contributor

Choose a reason for hiding this comment

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

这个地方应该删掉,或者是DeadCode,因为Div修改为二元运算了

Copy link
Contributor Author

Choose a reason for hiding this comment

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

删除Accumulate

@@ -1033,6 +1124,62 @@ struct SimplifyBroadcast {
}
};

struct SimplifyDiv {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

需要补充一下 Simplify Example

@gongshaotian gongshaotian changed the title Expr div [CINN] Add Div to replace Recipient in DimExpr Dec 25, 2024
@gongshaotian gongshaotian changed the title [CINN] Add Div to replace Recipient in DimExpr [CINN] Add Div to replace Recipical in DimExpr Dec 27, 2024
Copy link

paddle-ci-bot bot commented Jan 6, 2025

Sorry to inform you that 4b4a22b's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually.

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