Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c6bd9fb8
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看板
未验证
提交
c6bd9fb8
编写于
7月 03, 2023
作者:
Z
zhangbo9674
提交者:
GitHub
7月 03, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[IR] Support SelectRowsType (#55041)
* add selectrows * fix bug * add ut * refine code * refien code
上级
af96d1e8
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
174 addition
and
0 deletion
+174
-0
paddle/fluid/ir/dialect/op_generator/op_gen.py
paddle/fluid/ir/dialect/op_generator/op_gen.py
+1
-0
paddle/fluid/ir/dialect/pd_dialect.cc
paddle/fluid/ir/dialect/pd_dialect.cc
+1
-0
paddle/fluid/ir/dialect/pd_op.yaml
paddle/fluid/ir/dialect/pd_op.yaml
+42
-0
paddle/fluid/ir/dialect/pd_type.cc
paddle/fluid/ir/dialect/pd_type.cc
+13
-0
paddle/fluid/ir/dialect/pd_type.h
paddle/fluid/ir/dialect/pd_type.h
+18
-0
paddle/fluid/ir/dialect/pd_type_storage.h
paddle/fluid/ir/dialect/pd_type_storage.h
+81
-0
test/cpp/ir/core/type_test.cc
test/cpp/ir/core/type_test.cc
+18
-0
未找到文件。
paddle/fluid/ir/dialect/op_generator/op_gen.py
浏览文件 @
c6bd9fb8
...
@@ -483,6 +483,7 @@ class OpInfoParser:
...
@@ -483,6 +483,7 @@ class OpInfoParser:
output_type_map
=
{
output_type_map
=
{
'Tensor'
:
'paddle::dialect::DenseTensorType'
,
'Tensor'
:
'paddle::dialect::DenseTensorType'
,
'Tensor[]'
:
'ir::VectorType<paddle::dialect::DenseTensorType>'
,
'Tensor[]'
:
'ir::VectorType<paddle::dialect::DenseTensorType>'
,
'SelectedRows'
:
'paddle::dialect::SelectedRowsType'
,
}
}
type_list
=
[]
type_list
=
[]
for
output_info
in
self
.
op_yaml_item
[
'outputs'
]:
for
output_info
in
self
.
op_yaml_item
[
'outputs'
]:
...
...
paddle/fluid/ir/dialect/pd_dialect.cc
浏览文件 @
c6bd9fb8
...
@@ -92,6 +92,7 @@ PaddleDialect::PaddleDialect(ir::IrContext *context)
...
@@ -92,6 +92,7 @@ PaddleDialect::PaddleDialect(ir::IrContext *context)
void
PaddleDialect
::
initialize
()
{
void
PaddleDialect
::
initialize
()
{
RegisterTypes
<
paddle
::
dialect
::
DenseTensorType
>
();
RegisterTypes
<
paddle
::
dialect
::
DenseTensorType
>
();
RegisterTypes
<
paddle
::
dialect
::
SelectedRowsType
>
();
RegisterAttributes
<
paddle
::
dialect
::
IntArrayAttribute
,
RegisterAttributes
<
paddle
::
dialect
::
IntArrayAttribute
,
paddle
::
dialect
::
DataTypeAttribute
,
paddle
::
dialect
::
DataTypeAttribute
,
...
...
paddle/fluid/ir/dialect/pd_op.yaml
浏览文件 @
c6bd9fb8
...
@@ -161,3 +161,45 @@
...
@@ -161,3 +161,45 @@
-
{
typename
:
'
Tensor'
,
name
:
out
,
optional
:
false
,
intermediate
:
false
}
-
{
typename
:
'
Tensor'
,
name
:
out
,
optional
:
false
,
intermediate
:
false
}
no_need_buffer
:
null
no_need_buffer
:
null
data_transform
:
null
data_transform
:
null
-
name
:
embedding_grad_sparse
inputs
:
-
typename
:
Tensor
name
:
x
optional
:
false
no_need_buffer
:
false
data_transform
:
{}
-
typename
:
Tensor
name
:
weight
optional
:
false
no_need_buffer
:
false
data_transform
:
{}
-
typename
:
Tensor
name
:
out_grad
optional
:
false
no_need_buffer
:
false
data_transform
:
{}
attrs
:
-
{
typename
:
int64_t
,
name
:
padding_idx
,
default_value
:
'
-1'
}
-
{
typename
:
bool
,
name
:
sparse
,
default_value
:
'
false'
}
outputs
:
-
{
typename
:
SelectedRows
,
name
:
weight_grad
,
optional
:
false
,
intermediate
:
false
}
no_need_buffer
:
null
data_transform
:
null
infer_meta
:
func
:
UnchangedInferMeta
param
:
[
weight
]
kernel
:
func
:
[
embedding_grad_sparse
]
param
:
[
x
,
weight
,
out_grad
,
padding_idx
,
sparse
]
backend
:
null
layout
:
null
data_type
:
ordered
:
false
candidates
:
[
weight
]
to_complex_flag
:
[
false
]
dispatch
:
{
embedding_grad_sparse
:
null
}
force_backend
:
null
inplace
:
null
view
:
null
backward
:
null
paddle/fluid/ir/dialect/pd_type.cc
浏览文件 @
c6bd9fb8
...
@@ -28,7 +28,20 @@ const phi::LoD& DenseTensorType::lod() const { return storage()->lod_; }
...
@@ -28,7 +28,20 @@ const phi::LoD& DenseTensorType::lod() const { return storage()->lod_; }
const
size_t
&
DenseTensorType
::
offset
()
const
{
return
storage
()
->
offset_
;
}
const
size_t
&
DenseTensorType
::
offset
()
const
{
return
storage
()
->
offset_
;
}
const
ir
::
Type
&
SelectedRowsType
::
dtype
()
const
{
return
storage
()
->
dtype_
;
}
const
phi
::
DDim
&
SelectedRowsType
::
dims
()
const
{
return
storage
()
->
dims_
;
}
const
phi
::
DataLayout
&
SelectedRowsType
::
data_layout
()
const
{
return
storage
()
->
layout_
;
}
const
phi
::
LoD
&
SelectedRowsType
::
lod
()
const
{
return
storage
()
->
lod_
;
}
const
size_t
&
SelectedRowsType
::
offset
()
const
{
return
storage
()
->
offset_
;
}
}
// namespace dialect
}
// namespace dialect
}
// namespace paddle
}
// namespace paddle
IR_DEFINE_EXPLICIT_TYPE_ID
(
paddle
::
dialect
::
DenseTensorType
)
IR_DEFINE_EXPLICIT_TYPE_ID
(
paddle
::
dialect
::
DenseTensorType
)
IR_DEFINE_EXPLICIT_TYPE_ID
(
paddle
::
dialect
::
SelectedRowsType
)
paddle/fluid/ir/dialect/pd_type.h
浏览文件 @
c6bd9fb8
...
@@ -39,7 +39,25 @@ class DenseTensorType : public ir::Type {
...
@@ -39,7 +39,25 @@ class DenseTensorType : public ir::Type {
const
size_t
&
offset
()
const
;
const
size_t
&
offset
()
const
;
};
};
class
SelectedRowsType
:
public
ir
::
Type
{
public:
using
Type
::
Type
;
DECLARE_TYPE_UTILITY_FUNCTOR
(
SelectedRowsType
,
SelectedRowsTypeStorage
);
const
ir
::
Type
&
dtype
()
const
;
const
phi
::
DDim
&
dims
()
const
;
const
phi
::
DataLayout
&
data_layout
()
const
;
const
phi
::
LoD
&
lod
()
const
;
const
size_t
&
offset
()
const
;
};
}
// namespace dialect
}
// namespace dialect
}
// namespace paddle
}
// namespace paddle
IR_DECLARE_EXPLICIT_TYPE_ID
(
paddle
::
dialect
::
DenseTensorType
)
IR_DECLARE_EXPLICIT_TYPE_ID
(
paddle
::
dialect
::
DenseTensorType
)
IR_DECLARE_EXPLICIT_TYPE_ID
(
paddle
::
dialect
::
SelectedRowsType
)
paddle/fluid/ir/dialect/pd_type_storage.h
浏览文件 @
c6bd9fb8
...
@@ -128,5 +128,86 @@ struct DenseTensorTypeStorage : public ir::TypeStorage {
...
@@ -128,5 +128,86 @@ struct DenseTensorTypeStorage : public ir::TypeStorage {
size_t
offset_
;
size_t
offset_
;
};
};
struct
SelectedRowsTypeStorage
:
public
ir
::
TypeStorage
{
using
DataLayout
=
phi
::
DataLayout
;
using
Dim
=
phi
::
DDim
;
using
LoD
=
std
::
vector
<
std
::
vector
<
size_t
>>
;
///
/// \brief Declare ParamKey according to parameter type.
///
using
ParamKey
=
std
::
tuple
<
ir
::
Type
,
phi
::
DDim
,
phi
::
DataLayout
,
phi
::
LoD
,
size_t
>
;
SelectedRowsTypeStorage
(
const
ir
::
Type
&
dtype
,
const
phi
::
DDim
&
dims
,
const
phi
::
DataLayout
&
layout
,
const
phi
::
LoD
&
lod
,
size_t
offset
)
:
dtype_
(
dtype
),
dims_
(
dims
),
layout_
(
layout
),
lod_
(
lod
),
offset_
(
offset
)
{}
///
/// \brief Each derived TypeStorage must define a Construct method, which
/// StorageManager uses to construct a derived TypeStorage.
///
static
SelectedRowsTypeStorage
*
Construct
(
const
ParamKey
&
key
)
{
return
new
SelectedRowsTypeStorage
(
std
::
get
<
0
>
(
key
),
std
::
get
<
1
>
(
key
),
std
::
get
<
2
>
(
key
),
std
::
get
<
3
>
(
key
),
std
::
get
<
4
>
(
key
));
}
///
/// \brief Each derived TypeStorage must provide a HashValue method.
///
static
std
::
size_t
HashValue
(
const
ParamKey
&
key
)
{
std
::
size_t
hash_value
=
317
;
// hash dtype
hash_value
=
ir
::
hash_combine
(
hash_value
,
std
::
hash
<
ir
::
Type
>
()(
std
::
get
<
0
>
(
key
)));
// hash dims
hash_value
=
ir
::
hash_combine
(
hash_value
,
std
::
hash
<
phi
::
DDim
>
()(
std
::
get
<
1
>
(
key
)));
// hash layout
hash_value
=
ir
::
hash_combine
(
hash_value
,
std
::
hash
<
std
::
underlying_type
<
phi
::
DataLayout
>::
type
>
()(
static_cast
<
std
::
underlying_type
<
phi
::
DataLayout
>::
type
>
(
std
::
get
<
2
>
(
key
))));
// hash lod
hash_value
=
ir
::
hash_combine
(
hash_value
,
std
::
hash
<
phi
::
LoD
>
()(
std
::
get
<
3
>
(
key
)));
// hash offset
hash_value
=
ir
::
hash_combine
(
hash_value
,
std
::
hash
<
size_t
>
()(
std
::
get
<
4
>
(
key
)));
return
hash_value
;
}
///
/// \brief Each derived TypeStorage needs to overload operator==.
///
bool
operator
==
(
const
ParamKey
&
key
)
const
{
return
ParamKey
(
dtype_
,
dims_
,
layout_
,
lod_
,
offset_
)
==
key
;
}
ParamKey
GetAsKey
()
const
{
return
ParamKey
(
dtype_
,
dims_
,
layout_
,
lod_
,
offset_
);
}
///
/// \brief DenseTensorTypeStorage include five parameters: dims, dtype,
/// layout, lod, offset.
///
ir
::
Type
dtype_
;
phi
::
DDim
dims_
;
phi
::
DataLayout
layout_
;
phi
::
LoD
lod_
;
size_t
offset_
;
};
}
// namespace dialect
}
// namespace dialect
}
// namespace paddle
}
// namespace paddle
test/cpp/ir/core/type_test.cc
浏览文件 @
c6bd9fb8
...
@@ -15,6 +15,7 @@
...
@@ -15,6 +15,7 @@
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include <unordered_map>
#include <unordered_map>
#include "paddle/fluid/ir/dialect/pd_type.h"
#include "paddle/ir/core/builtin_dialect.h"
#include "paddle/ir/core/builtin_dialect.h"
#include "paddle/ir/core/builtin_type.h"
#include "paddle/ir/core/builtin_type.h"
#include "paddle/ir/core/dialect.h"
#include "paddle/ir/core/dialect.h"
...
@@ -229,6 +230,23 @@ TEST(type_test, custom_type_dialect) {
...
@@ -229,6 +230,23 @@ TEST(type_test, custom_type_dialect) {
EXPECT_EQ
(
dialect_integer1
,
dialect_integer2
);
EXPECT_EQ
(
dialect_integer1
,
dialect_integer2
);
}
}
TEST
(
type_test
,
pd_dialect
)
{
ir
::
IrContext
*
ctx
=
ir
::
IrContext
::
Instance
();
ir
::
Type
fp32_dtype
=
ir
::
Float32Type
::
get
(
ctx
);
phi
::
DDim
dims
=
{
2
,
2
};
phi
::
DataLayout
data_layout
=
phi
::
DataLayout
::
NCHW
;
phi
::
LoD
lod
=
{{
0
,
1
,
2
}};
size_t
offset
=
0
;
paddle
::
dialect
::
SelectedRowsType
select_rows_dtype
=
paddle
::
dialect
::
SelectedRowsType
::
get
(
ctx
,
fp32_dtype
,
dims
,
data_layout
,
lod
,
offset
);
EXPECT_EQ
(
select_rows_dtype
.
dtype
().
isa
<
ir
::
Float32Type
>
(),
true
);
EXPECT_EQ
(
select_rows_dtype
.
dims
(),
dims
);
EXPECT_EQ
(
select_rows_dtype
.
data_layout
(),
data_layout
);
EXPECT_EQ
(
select_rows_dtype
.
lod
(),
lod
);
EXPECT_EQ
(
select_rows_dtype
.
offset
(),
offset
);
}
namespace
TestNamespace
{
namespace
TestNamespace
{
class
TestClass
{};
class
TestClass
{};
}
// namespace TestNamespace
}
// namespace TestNamespace
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录