CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
【CINN】Add func of div and mod for IterExpr. #68624
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
@@ -71,5 +71,41 @@ inline std::optional<ir::Expr> TryConstFold<ir::Mul>(ir::Expr a, ir::Expr b) { | |||
return std::nullopt; | |||
} | |||
|
|||
template <> | |||
inline std::optional<ir::Expr> TryConstFold<ir::Div>(ir::Expr a, ir::Expr b) { |
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.
这些ir::Expr
会替换成ir::IndexExpr
吗?
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.
这里不会替换为ir::IndexExpr
,ir::IndexExpr
重载运算符实现了常量折叠。这里目的是对ir::Expr
进行折叠,可以在对ir::Expr
操作时当做工具函数使用
static Expr Make(const std::vector<Expr>& args, const IndexExpr& base); | ||
Type type() const { return base.type(); } | ||
std::vector<Expr> args; | ||
Expr base; | ||
IndexExpr base; |
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.
哪些成员是Expr, 哪些是IndexExpr类型目前有约定吗?
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.
由于将IterExpr
从indexExpr
中摘除,因此,IterMark::source
,IterSplit::source
,IterSum::args
变更为Expr
,其余成员为IndexExpr
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.
后续是否可以做到让Expr完全从下标表示中彻底去掉?
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.
这个Expr
出现的位置是在IterMark, IterSplit, IterSum
结构中,当前该三个辅助结构从IndexExpr
中摘除并继承自于Expr
,除非让IterMark, IterSplit, IterSum
包含在IndexExpr
中,才可完全去除Expr
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.
不是让IterMark, IterSplit, IterSum这些直接用IndexExpr吗,为什么是包含在IndexExpr?
bool IsOne(const Expr& expr) { | ||
if (expr.is_constant() && expr.get_constant() == 1) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
bool IsZero(const Expr& expr) { | ||
if (expr.is_constant() && expr.get_constant() == 0) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
bool ProveDivisible(const Expr& lhs, | ||
const Expr& rhs, | ||
const common::SymbolicExprAnalyzer& analyzer) { | ||
if (auto rhs_imm = rhs.As<ir::IntImm>()) { | ||
return GetLargestMutiplyPart(lhs) % rhs_imm->value == 0; | ||
} else if (rhs.is_var()) { | ||
return analyzer.ProveDivisible(lhs, rhs).value_or(false); | ||
} else { | ||
return false; | ||
} | ||
} | ||
|
||
bool ProveEQ(const Expr& lhs, | ||
const Expr& rhs, | ||
const common::SymbolicExprAnalyzer& analyzer) { | ||
if (lhs == rhs) return true; | ||
return analyzer.ProveEQ(lhs, rhs).value_or(false); | ||
} | ||
|
||
bool ProveLE(const Expr& lhs, | ||
const Expr& rhs, | ||
const common::SymbolicExprAnalyzer& analyzer) { | ||
if (lhs == rhs) return true; | ||
return analyzer.ProveLE(lhs, rhs).value_or(false); | ||
} |
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.
这些是不都后续都需要换成IndexExpr?
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.
后续会更替为ir::IndexExpr
|
||
bool ProveEQ(const Expr& lhs, | ||
const Expr& rhs, | ||
const common::SymbolicExprAnalyzer& analyzer) { |
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.
这个analyzer是哪里来的?
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.
是由外部传入的,用来支撑动态shape下化简。详见integer_set_test.cc
和iter_simplify_test.cc::TestIterSimplify::analyzer
static Expr Make(const std::vector<Expr>& args, const IndexExpr& base); | ||
Type type() const { return base.type(); } | ||
std::vector<Expr> args; | ||
Expr base; | ||
IndexExpr base; |
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.
后续是否可以做到让Expr完全从下标表示中彻底去掉?
PR Category
CINN
PR Types
New features
Description
Add div and mod for IterSplit、IterSum、Constant.
Pcard-67164