-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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] Type system stage4: Add some built-in types and type conversion methods #51112
[IR] Type system stage4: Add some built-in types and type conversion methods #51112
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
paddle/ir/builtin_type_storage.h
Outdated
/// \brief Enable hashing std::vector<std::vector<T> instances. | ||
/// | ||
template <typename T> | ||
struct hash<std::vector<std::vector<T>>> { |
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.
这个有必要吗?我理解 vector<vector>也是vector的一种实例化吧
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.
没有必要,已删除多余的特化。
paddle/ir/builtin_type_storage.h
Outdated
enum class DataLayout : unsigned int { | ||
UNDEFINED = 0, | ||
// TODO(chenweihang): keep ANY for compatibility, remove it later | ||
ANY = UNDEFINED, |
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.
既然这儿说ANY是为了兼容性,后续需要移动。可否现在就移除?
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 DataLayout 中 ANY 删除。
paddle/ir/tests/type_test.cc
Outdated
|
||
ir::Type int64_1 = ir::Int64Type::get(ctx); | ||
ir::Type int64_2 = ir::Int64Type::get(ctx); | ||
EXPECT_EQ(int64_1 == int64_2, 1); |
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.
EXPECT_EQ(int64_1 == int64_2, 1); | |
EXPECT_EQ(int64_1, int64_2); |
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.
Done, tks!
template <class To, class From> | ||
inline typename cast_type_deduction<To, From>::return_type dyn_cast_impl( | ||
From &Val) { // NOLINT | ||
if (!isa<To>(Val)) { |
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.
commonly, return nullptr is better?
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.
Done, tks!
paddle/ir/cast_utils.h
Outdated
From *Val) { | ||
return dyn_cast_impl<To>(Val); | ||
template <typename To, typename From> | ||
inline typename DeriveRetty<To, From *>::return_type dyn_cast(From *Val) { |
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.
DeriveRetty -> ReturnTypeDuduction
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.
Done, tks!
paddle/ir/cast_utils.h
Outdated
template <class To, class From> | ||
struct cast_type_deduction { | ||
template <typename To, typename From> | ||
struct DeriveRettyWrap { | ||
typedef To &return_type; |
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.
return_type -> type
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.
Done, tks!
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.
LGTM
PR types
New features
PR changes
APIs
Describe
Pcard-67160
1、PR 主要内容
1.1 内置类型添加
新增 5 种内置类型:
DenseTensorType
、Float16Type
、Float64Type
、Int16Type
、Int64Type
。至此,内置 Dialect 拥有的内置类型包括 7 种:详见:builtin_type.h。内置类型的创建及使用方法如下:
1.2 丰富Type接口
新增
ir::Type::isa
及ir::Type::dyn_cast
方法:isa
: 判断Type对象是否为某个类型dyn_cast
: 类型转换,将Type对象cast为另一种类型对象使用示例如下: