Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
babc63b8
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
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看板
提交
babc63b8
编写于
1年前
作者:
Z
zhangbo9674
提交者:
GitHub
1年前
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert "[NewIR]New ir support vector type place transfer (#56328)"
This reverts commit
2a378ff5
.
上级
dcfe2f1a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
116 deletion
+25
-116
paddle/fluid/ir/transforms/pd_op_to_kernel_pass.cc
paddle/fluid/ir/transforms/pd_op_to_kernel_pass.cc
+25
-99
test/ir/new_ir/test_standalone_new_ir.py
test/ir/new_ir/test_standalone_new_ir.py
+0
-17
未找到文件。
paddle/fluid/ir/transforms/pd_op_to_kernel_pass.cc
浏览文件 @
babc63b8
...
...
@@ -23,7 +23,6 @@
#include "paddle/fluid/ir/dialect/op_yaml_info_util.h"
#include "paddle/fluid/ir/dialect/pd_attribute.h"
#include "paddle/fluid/ir/dialect/pd_dialect.h"
#include "paddle/fluid/ir/dialect/pd_type.h"
#include "paddle/fluid/ir/dialect/utils.h"
#include "paddle/fluid/ir/interface/op_yaml_info.h"
#include "paddle/fluid/ir/interface/op_yaml_info_parser.h"
...
...
@@ -107,37 +106,6 @@ bool NeedFallBackFromGPUDNN2GPU(ir::Operation* op,
return
false
;
}
std
::
vector
<
phi
::
DenseTensor
>
GetFakeTensorList
(
ir
::
Value
new_input_tmp
)
{
std
::
vector
<
phi
::
DenseTensor
>
vec_res
;
auto
input_type
=
new_input_tmp
.
type
();
std
::
vector
<
dialect
::
AllocatedDenseTensorType
>
types
;
if
(
input_type
.
isa
<
dialect
::
AllocatedDenseTensorType
>
())
{
types
.
push_back
(
input_type
.
dyn_cast
<
dialect
::
AllocatedDenseTensorType
>
());
}
else
if
(
input_type
.
isa
<
ir
::
VectorType
>
())
{
auto
vec_inner_types
=
input_type
.
dyn_cast
<
ir
::
VectorType
>
().
data
();
for
(
size_t
i
=
0
;
i
<
vec_inner_types
.
size
();
++
i
)
{
types
.
push_back
(
vec_inner_types
[
0
].
dyn_cast
<
dialect
::
AllocatedDenseTensorType
>
());
}
}
for
(
auto
&
type
:
types
)
{
auto
ptr
=
new
phi
::
Allocation
(
nullptr
,
0
,
type
.
place
());
std
::
shared_ptr
<
phi
::
Allocation
>
holder
(
ptr
);
auto
dtype
=
TransToPhiDataType
(
type
.
dtype
());
phi
::
DenseTensorMeta
meta
(
dtype
,
type
.
dims
(),
type
.
data_layout
(),
type
.
lod
(),
type
.
offset
());
phi
::
DenseTensor
fake_tensor
(
holder
,
meta
);
vec_res
.
push_back
(
fake_tensor
);
}
return
vec_res
;
}
ir
::
OpResult
AddPlaceTransferOp
(
ir
::
OpResult
in
,
ir
::
Type
out_type
,
const
phi
::
Place
&
src_place
,
...
...
@@ -332,10 +300,32 @@ phi::KernelKey GetKernelKey(
}
auto
new_input_tmp
=
map_value_pair
.
at
(
input_tmp
);
auto
fake_tensors
=
GetFakeTensorList
(
new_input_tmp
);
for
(
auto
&
fake_tensor
:
fake_tensors
)
{
kernel_key_parser
.
AssignKernelKeySet
(
fake_tensor
);
auto
input_type
=
new_input_tmp
.
type
();
dialect
::
AllocatedDenseTensorType
type
;
if
(
input_type
.
isa
<
dialect
::
AllocatedDenseTensorType
>
())
{
type
=
input_type
.
dyn_cast
<
dialect
::
AllocatedDenseTensorType
>
();
}
else
if
(
input_type
.
isa
<
ir
::
VectorType
>
())
{
if
(
!
input_type
.
dyn_cast
<
ir
::
VectorType
>
().
empty
())
{
type
=
input_type
.
dyn_cast
<
ir
::
VectorType
>
()[
0
]
.
dyn_cast
<
dialect
::
AllocatedDenseTensorType
>
();
}
else
{
continue
;
}
}
// fake tensor here
auto
ptr
=
new
phi
::
Allocation
(
nullptr
,
0
,
type
.
place
());
std
::
shared_ptr
<
phi
::
Allocation
>
holder
(
ptr
);
auto
dtype
=
TransToPhiDataType
(
type
.
dtype
());
phi
::
DenseTensorMeta
meta
(
dtype
,
type
.
dims
(),
type
.
data_layout
(),
type
.
lod
(),
type
.
offset
());
phi
::
DenseTensor
fake_tensor
(
holder
,
meta
);
kernel_key_parser
.
AssignKernelKeySet
(
fake_tensor
);
}
auto
kernel_key_set
=
kernel_key_parser
.
key_set
;
...
...
@@ -713,70 +703,6 @@ std::unique_ptr<ir::Program> PdOpLowerToKernelPass(ir::Program* prog,
}
}
else
if
(
new_in_type
.
isa
<
ir
::
VectorType
>
())
{
// [ todo need update here, support combine data transfomer]
// deal with pre combine op
auto
pre_define_op
=
cur_in
.
GetDefiningOp
();
if
(
pre_define_op
->
name
()
==
"builtin.combine"
)
{
std
::
vector
<
ir
::
OpResult
>
inner_inputs
;
std
::
vector
<
ir
::
Type
>
types_in_vec
;
bool
is_trans
=
false
;
for
(
size_t
j
=
0
;
j
<
pre_define_op
->
num_operands
();
++
j
)
{
auto
in_i
=
map_value_pair
.
at
(
pre_define_op
->
operand_source
(
j
));
auto
in_i_type
=
in_i
.
type
();
auto
place
=
in_i_type
.
dyn_cast
<
dialect
::
AllocatedDenseTensorType
>
()
.
place
();
// get input args def type
auto
args_def
=
kernel
.
args_def
();
auto
input_defs
=
args_def
.
input_defs
();
bool
need_trans
=
(
place
.
GetType
()
!=
phi
::
AllocationType
::
UNDEFINED
)
&&
(
op_info_parser
!=
nullptr
&&
!
op_info_parser
->
IsTensorAttribute
(
i
))
&&
(
paddle
::
experimental
::
NeedTransformPlace
(
place
,
kernel
.
InputAt
(
i
).
backend
,
{}));
if
(
need_trans
)
{
VLOG
(
6
)
<<
"need trans from "
<<
place
<<
" to "
<<
kernel_key
.
backend
();
// build memcopy op
auto
out_place
=
phi
::
TransToPhiPlace
(
kernel
.
InputAt
(
i
).
backend
);
auto
out_type
=
dialect
::
AllocatedDenseTensorType
::
get
(
ctx
,
out_place
,
pre_define_op
->
operand_source
(
j
)
.
type
()
.
dyn_cast
<
dialect
::
DenseTensorType
>
());
in_i
=
AddPlaceTransferOp
(
in_i
,
out_type
,
place
,
out_place
,
kernel_key
,
program
.
get
());
is_trans
=
true
;
}
inner_inputs
.
push_back
(
in_i
);
types_in_vec
.
push_back
(
in_i
.
type
());
}
if
(
is_trans
)
{
// Add combine op
std
::
string
combine_op_name
(
ir
::
CombineOp
::
name
());
ir
::
OpInfo
op_info
=
ctx
->
GetRegisteredOpInfo
(
combine_op_name
);
ir
::
Type
target_vec_type
=
ir
::
VectorType
::
get
(
ctx
,
types_in_vec
);
ir
::
Operation
*
operation
=
ir
::
Operation
::
Create
(
inner_inputs
,
{},
{
target_vec_type
},
op_info
);
new_in
=
operation
->
result
(
0
);
program
->
block
()
->
push_back
(
operation
);
}
}
}
else
if
(
new_in_type
.
isa
<
dialect
::
AllocatedSelectedRowsType
>
())
{
// do nothing here
}
else
{
...
...
This diff is collapsed.
Click to expand it.
test/ir/new_ir/test_standalone_new_ir.py
浏览文件 @
babc63b8
...
...
@@ -328,23 +328,6 @@ class TestJitSaveOp(unittest.TestCase):
)
class
TestNewIrConcatDygraph
(
unittest
.
TestCase
):
def
test_with_new_ir
(
self
):
paddle
.
disable_static
()
@
paddle
.
jit
.
to_static
def
func
(
x
,
y
):
return
paddle
.
concat
([
paddle
.
shape
(
x
),
y
],
-
1
)
x
=
paddle
.
ones
([
2
,
2
],
dtype
=
'float32'
)
y
=
paddle
.
ones
([
2
],
dtype
=
'int32'
)
*
2
z
=
func
(
x
,
y
)
gold_res
=
np
.
ones
([
4
],
dtype
=
"float32"
)
*
2
np
.
testing
.
assert_array_equal
(
z
.
numpy
(),
gold_res
)
if
__name__
==
"__main__"
:
paddle
.
enable_static
()
unittest
.
main
()
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
新手
引导
客服
返回
顶部