Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
cc7d1f34
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
cc7d1f34
编写于
7月 02, 2023
作者:
W
Wilber
提交者:
GitHub
7月 02, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[IR] Support TypeAttribute. (#54984)
上级
89feae07
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
53 addition
and
7 deletion
+53
-7
paddle/ir/core/builtin_attribute.cc
paddle/ir/core/builtin_attribute.cc
+3
-0
paddle/ir/core/builtin_attribute.h
paddle/ir/core/builtin_attribute.h
+10
-0
paddle/ir/core/builtin_attribute_storage.h
paddle/ir/core/builtin_attribute_storage.h
+22
-0
paddle/ir/core/builtin_dialect.cc
paddle/ir/core/builtin_dialect.cc
+2
-1
paddle/ir/core/ir_printer.cc
paddle/ir/core/ir_printer.cc
+2
-0
paddle/ir/transforms/dce.cc
paddle/ir/transforms/dce.cc
+5
-4
paddle/ir/transforms/dce.h
paddle/ir/transforms/dce.h
+1
-1
test/cpp/ir/core/ir_attribute_test.cc
test/cpp/ir/core/ir_attribute_test.cc
+7
-0
test/cpp/ir/pattern_rewrite/pattern_rewrite_test.cc
test/cpp/ir/pattern_rewrite/pattern_rewrite_test.cc
+1
-1
未找到文件。
paddle/ir/core/builtin_attribute.cc
浏览文件 @
cc7d1f34
...
...
@@ -35,6 +35,8 @@ std::vector<Attribute> ArrayAttribute::data() const {
void
*
PointerAttribute
::
data
()
const
{
return
storage
()
->
GetAsKey
();
}
Type
TypeAttribute
::
data
()
const
{
return
storage
()
->
GetAsKey
();
}
}
// namespace ir
IR_DEFINE_EXPLICIT_TYPE_ID
(
ir
::
StrAttribute
)
...
...
@@ -45,3 +47,4 @@ IR_DEFINE_EXPLICIT_TYPE_ID(ir::Int32Attribute)
IR_DEFINE_EXPLICIT_TYPE_ID
(
ir
::
Int64Attribute
)
IR_DEFINE_EXPLICIT_TYPE_ID
(
ir
::
ArrayAttribute
)
IR_DEFINE_EXPLICIT_TYPE_ID
(
ir
::
PointerAttribute
)
IR_DEFINE_EXPLICIT_TYPE_ID
(
ir
::
TypeAttribute
)
paddle/ir/core/builtin_attribute.h
浏览文件 @
cc7d1f34
...
...
@@ -103,6 +103,15 @@ class IR_API PointerAttribute : public Attribute {
void
*
data
()
const
;
};
class
IR_API
TypeAttribute
:
public
Attribute
{
public:
using
Attribute
::
Attribute
;
DECLARE_ATTRIBUTE_UTILITY_FUNCTOR
(
TypeAttribute
,
TypeAttributeStorage
);
Type
data
()
const
;
};
}
// namespace ir
IR_EXPORT_DECLARE_EXPLICIT_TYPE_ID
(
ir
::
StrAttribute
)
...
...
@@ -113,3 +122,4 @@ IR_EXPORT_DECLARE_EXPLICIT_TYPE_ID(ir::Int32Attribute)
IR_EXPORT_DECLARE_EXPLICIT_TYPE_ID
(
ir
::
Int64Attribute
)
IR_EXPORT_DECLARE_EXPLICIT_TYPE_ID
(
ir
::
ArrayAttribute
)
IR_EXPORT_DECLARE_EXPLICIT_TYPE_ID
(
ir
::
PointerAttribute
)
IR_EXPORT_DECLARE_EXPLICIT_TYPE_ID
(
ir
::
TypeAttribute
)
paddle/ir/core/builtin_attribute_storage.h
浏览文件 @
cc7d1f34
...
...
@@ -20,6 +20,7 @@
#include "paddle/ir/core/attribute.h"
#include "paddle/ir/core/attribute_base.h"
#include "paddle/ir/core/type.h"
#include "paddle/ir/core/utils.h"
namespace
ir
{
...
...
@@ -131,4 +132,25 @@ struct ArrayAttributeStorage : public AttributeStorage {
size_t
length_
=
0
;
};
struct
TypeAttributeStorage
:
public
AttributeStorage
{
using
ParamKey
=
Type
;
explicit
TypeAttributeStorage
(
const
ParamKey
&
key
)
:
value_
(
key
)
{}
static
TypeAttributeStorage
*
Construct
(
ParamKey
key
)
{
return
new
TypeAttributeStorage
(
key
);
}
static
std
::
size_t
HashValue
(
const
ParamKey
&
key
)
{
return
std
::
hash
<
Type
>
()(
key
);
}
bool
operator
==
(
const
ParamKey
&
key
)
const
{
return
value_
==
key
;
}
ParamKey
GetAsKey
()
const
{
return
value_
;
}
private:
Type
value_
;
};
}
// namespace ir
paddle/ir/core/builtin_dialect.cc
浏览文件 @
cc7d1f34
...
...
@@ -46,7 +46,8 @@ void BuiltinDialect::initialize() {
PointerAttribute
,
Int32Attribute
,
Int64Attribute
,
ArrayAttribute
>
();
ArrayAttribute
,
TypeAttribute
>
();
RegisterOps
<
ModuleOp
,
GetParameterOp
,
...
...
paddle/ir/core/ir_printer.cc
浏览文件 @
cc7d1f34
...
...
@@ -107,6 +107,8 @@ void BasicIrPrinter::PrintAttribute(const Attribute& attr) {
[
this
](
Attribute
v
)
{
this
->
PrintAttribute
(
v
);
},
[
this
]()
{
this
->
os
<<
","
;
});
os
<<
"]"
;
}
else
if
(
auto
type
=
attr
.
dyn_cast
<
TypeAttribute
>
())
{
os
<<
type
.
data
();
}
else
{
auto
&
dialect
=
attr
.
dialect
();
dialect
.
PrintAttribute
(
attr
,
os
);
...
...
paddle/ir/transforms/dce.cc
浏览文件 @
cc7d1f34
...
...
@@ -22,13 +22,13 @@ namespace {
// TODO(wilber): After support SideEffectTrait, Only NoSideEffectTrait op can be
// removed by dce pass.
// Now just a naive implementation.
class
D
CE
Pass
:
public
ir
::
Pass
{
class
D
ce
Pass
:
public
ir
::
Pass
{
public:
D
CEPass
()
:
ir
::
Pass
(
"DCE
Pass"
,
0
)
{}
D
cePass
()
:
ir
::
Pass
(
"Dce
Pass"
,
0
)
{}
void
Run
(
ir
::
Operation
*
op
)
override
{
auto
module_op
=
op
->
dyn_cast
<
ir
::
ModuleOp
>
();
IR_ENFORCE
(
module_op
,
"D
CE
Pass should run on module op."
);
IR_ENFORCE
(
module_op
,
"D
ce
Pass should run on module op."
);
auto
*
block
=
module_op
.
block
();
std
::
vector
<
ir
::
Operation
>
erased_op
;
for
(
auto
it
=
block
->
begin
();
it
!=
block
->
end
();
++
it
)
{
...
...
@@ -39,6 +39,7 @@ class DCEPass : public ir::Pass {
for
(
uint32_t
i
=
0
;
i
<
(
*
it
)
->
num_results
();
++
i
)
{
use_empty
&=
(
*
it
)
->
result
(
i
).
use_empty
();
}
// TODO(wilber): Support Terminator trait.
if
(
use_empty
&&
(
*
it
)
->
name
()
!=
"pd.fetch"
)
{
erased_op
.
push_back
(
**
it
);
}
...
...
@@ -56,6 +57,6 @@ class DCEPass : public ir::Pass {
namespace
ir
{
std
::
unique_ptr
<
Pass
>
CreateD
CEPass
()
{
return
std
::
make_unique
<
DCE
Pass
>
();
}
std
::
unique_ptr
<
Pass
>
CreateD
cePass
()
{
return
std
::
make_unique
<
Dce
Pass
>
();
}
}
// namespace ir
paddle/ir/transforms/dce.h
浏览文件 @
cc7d1f34
...
...
@@ -20,6 +20,6 @@
namespace
ir
{
class
Pass
;
IR_API
std
::
unique_ptr
<
Pass
>
CreateD
CE
Pass
();
IR_API
std
::
unique_ptr
<
Pass
>
CreateD
ce
Pass
();
}
// namespace ir
test/cpp/ir/core/ir_attribute_test.cc
浏览文件 @
cc7d1f34
...
...
@@ -19,6 +19,7 @@
#include "paddle/ir/core/attribute_base.h"
#include "paddle/ir/core/builtin_attribute.h"
#include "paddle/ir/core/builtin_dialect.h"
#include "paddle/ir/core/builtin_type.h"
#include "paddle/ir/core/dialect.h"
#include "paddle/ir/core/ir_context.h"
...
...
@@ -63,4 +64,10 @@ TEST(attribute_test, built_in_attribute) {
string_attr_1
.
dyn_cast
<
ir
::
StrAttribute
>
();
EXPECT_EQ
(
string_attr_cast_1
.
isa
<
ir
::
StrAttribute
>
(),
true
);
EXPECT_EQ
(
string_attr_cast_1
.
size
()
==
8
,
1
);
ir
::
Int32Type
i32_type
=
ir
::
Int32Type
::
get
(
ctx
);
ir
::
Attribute
type_attr
=
ir
::
TypeAttribute
::
get
(
ctx
,
i32_type
);
EXPECT_TRUE
(
type_attr
.
isa
<
ir
::
TypeAttribute
>
());
EXPECT_EQ
(
type_attr
.
dyn_cast
<
ir
::
TypeAttribute
>
().
data
().
type_id
(),
i32_type
.
type_id
());
}
test/cpp/ir/pattern_rewrite/pattern_rewrite_test.cc
浏览文件 @
cc7d1f34
...
...
@@ -429,7 +429,7 @@ TEST(pattern_rewrite, Patterns) {
ir
::
PassManager
pm
(
ctx
);
pm
.
AddPass
(
std
::
make_unique
<
TestPass
>
());
pm
.
AddPass
(
ir
::
CreateD
CE
Pass
());
pm
.
AddPass
(
ir
::
CreateD
ce
Pass
());
program
.
Print
(
std
::
cout
);
std
::
cout
<<
std
::
endl
;
pm
.
Run
(
&
program
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录