Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
36cdb6e2
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
36cdb6e2
编写于
9月 07, 2021
作者:
J
jakpiase
提交者:
GitHub
9月 07, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix for reshape2 oneDNN op (#35455)
* fix for reshape2 * added reviewers sugestions
上级
ed97be09
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
55 addition
and
9 deletion
+55
-9
paddle/fluid/operators/mkldnn/reshape_mkldnn_op.cc
paddle/fluid/operators/mkldnn/reshape_mkldnn_op.cc
+24
-1
python/paddle/fluid/tests/unittests/mkldnn/test_reshape_mkldnn_op.py
...le/fluid/tests/unittests/mkldnn/test_reshape_mkldnn_op.py
+31
-8
未找到文件。
paddle/fluid/operators/mkldnn/reshape_mkldnn_op.cc
浏览文件 @
36cdb6e2
...
@@ -22,6 +22,25 @@ using paddle::framework::LoDTensor;
...
@@ -22,6 +22,25 @@ using paddle::framework::LoDTensor;
using
platform
::
to_void_cast
;
using
platform
::
to_void_cast
;
using
platform
::
GetMKLDNNFormat
;
using
platform
::
GetMKLDNNFormat
;
static
std
::
vector
<
int
>
extract_shape
(
const
std
::
vector
<
const
Tensor
*>&
list_new_shape_tensor
)
{
std
::
vector
<
int
>
vec_new_shape
;
vec_new_shape
.
reserve
(
list_new_shape_tensor
.
size
());
for
(
const
auto
&
tensor
:
list_new_shape_tensor
)
{
PADDLE_ENFORCE_EQ
(
tensor
->
dims
(),
framework
::
make_ddim
({
1
}),
platform
::
errors
::
InvalidArgument
(
"If the element type of 'shape' in ReshapeOp is Tensor, "
"the element's shape must be [1]. But received the element's shape "
"is [%s]"
,
tensor
->
dims
()));
vec_new_shape
.
emplace_back
(
*
tensor
->
data
<
int32_t
>
());
}
return
vec_new_shape
;
}
template
<
typename
T
>
template
<
typename
T
>
class
ReshapeMKLDNNKernel
:
public
framework
::
OpKernel
<
T
>
{
class
ReshapeMKLDNNKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
...
@@ -59,7 +78,11 @@ class ReshapeMKLDNNKernel : public framework::OpKernel<T> {
...
@@ -59,7 +78,11 @@ class ReshapeMKLDNNKernel : public framework::OpKernel<T> {
}
}
if
(
ctx
.
Type
().
find
(
"reshape"
)
!=
std
::
string
::
npos
)
{
if
(
ctx
.
Type
().
find
(
"reshape"
)
!=
std
::
string
::
npos
)
{
if
(
ctx
.
HasInput
(
"Shape"
))
{
auto
list_new_shape_tensor
=
ctx
.
MultiInput
<
Tensor
>
(
"ShapeTensor"
);
if
(
list_new_shape_tensor
.
size
()
>
0
)
{
auto
new_shape
=
extract_shape
(
list_new_shape_tensor
);
out_dims
=
ValidateShape
(
new_shape
,
x_dims
);
}
else
if
(
ctx
.
HasInput
(
"Shape"
))
{
auto
*
shape_tensor
=
ctx
.
Input
<
framework
::
LoDTensor
>
(
"Shape"
);
auto
*
shape_tensor
=
ctx
.
Input
<
framework
::
LoDTensor
>
(
"Shape"
);
auto
*
shape_data
=
shape_tensor
->
data
<
int
>
();
auto
*
shape_data
=
shape_tensor
->
data
<
int
>
();
...
...
python/paddle/fluid/tests/unittests/mkldnn/test_reshape_mkldnn_op.py
浏览文件 @
36cdb6e2
...
@@ -72,9 +72,9 @@ class TestReshape2OneDNNOpDimInfer1(TestReshape2OneDNNOp):
...
@@ -72,9 +72,9 @@ class TestReshape2OneDNNOpDimInfer1(TestReshape2OneDNNOp):
class
TestReshape2OneDNNOpDimInfer2
(
TestReshape2OneDNNOp
):
class
TestReshape2OneDNNOpDimInfer2
(
TestReshape2OneDNNOp
):
def
init_data
(
self
):
def
init_data
(
self
):
self
.
ori_shape
=
(
10
,
2
,
6
)
self
.
ori_shape
=
(
6
,
20
)
self
.
new_shape
=
(
10
,
0
,
3
,
-
1
)
self
.
new_shape
=
(
0
,
-
1
,
20
)
self
.
infered_shape
=
(
10
,
2
,
3
,
-
1
)
self
.
actual_shape
=
(
2
,
3
,
20
)
def
set_additional_inputs
(
self
):
def
set_additional_inputs
(
self
):
self
.
inputs
[
"Shape"
]
=
np
.
array
(
self
.
actual_shape
,
dtype
=
"int32"
)
self
.
inputs
[
"Shape"
]
=
np
.
array
(
self
.
actual_shape
,
dtype
=
"int32"
)
...
@@ -85,11 +85,6 @@ class TestReshape2OneDNNOpDimInfer2(TestReshape2OneDNNOp):
...
@@ -85,11 +85,6 @@ class TestReshape2OneDNNOpDimInfer2(TestReshape2OneDNNOp):
'XShape'
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float32"
)
'XShape'
:
np
.
random
.
random
(
self
.
ori_shape
).
astype
(
"float32"
)
}
}
def
init_data1
(
self
):
self
.
ori_shape
=
(
6
,
20
)
self
.
new_shape
=
(
0
,
-
1
,
20
)
self
.
actual_shape
=
(
2
,
3
,
20
)
class
TestReshape2OneDNNOp_attr_OnlyShape
(
TestReshape2OneDNNOp
):
class
TestReshape2OneDNNOp_attr_OnlyShape
(
TestReshape2OneDNNOp
):
def
set_additional_inputs
(
self
):
def
set_additional_inputs
(
self
):
...
@@ -119,6 +114,34 @@ class TestReshape2OneDNNOpDimInfer1_attr_OnlyShape(
...
@@ -119,6 +114,34 @@ class TestReshape2OneDNNOpDimInfer1_attr_OnlyShape(
self
.
shape
=
(
5
,
-
1
,
-
1
)
self
.
shape
=
(
5
,
-
1
,
-
1
)
class
TestReshape2OneDNNOpDimInfer1_attr_ShapeTensor
(
TestReshape2OneDNNOp
):
def
set_additional_inputs
(
self
):
shape_tensor
=
[]
for
index
,
ele
in
enumerate
(
self
.
new_shape
):
shape_tensor
.
append
((
"x"
+
str
(
index
),
np
.
ones
(
(
1
)).
astype
(
'int32'
)
*
ele
))
self
.
inputs
[
"ShapeTensor"
]
=
shape_tensor
def
init_data
(
self
):
self
.
ori_shape
=
(
5
,
20
)
self
.
new_shape
=
(
5
,
-
1
,
10
)
self
.
infered_shape
=
(
5
,
-
1
,
10
)
self
.
shape
=
(
5
,
-
1
,
-
1
)
class
TestReshape2OneDNNOpDimInfer1_attr_ShapeTensorAndShape
(
TestReshape2OneDNNOpDimInfer1_attr_ShapeTensor
):
def
set_additional_inputs
(
self
):
shape_tensor
=
[]
for
index
,
ele
in
enumerate
(
self
.
new_shape
):
shape_tensor
.
append
((
"x"
+
str
(
index
),
np
.
ones
(
(
1
)).
astype
(
'int32'
)
*
ele
))
self
.
inputs
[
"Shape"
]
=
np
.
array
((
1
,
2
,
3
,
4
),
dtype
=
"int32"
)
self
.
inputs
[
"ShapeTensor"
]
=
shape_tensor
class
TestReshapeOneDNNOp
(
TestReshape2OneDNNOp
):
class
TestReshapeOneDNNOp
(
TestReshape2OneDNNOp
):
def
set_op_type
(
self
):
def
set_op_type
(
self
):
self
.
op_type
=
"reshape"
self
.
op_type
=
"reshape"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录