Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
0cc5eddb
P
Paddle
项目概览
机器未来
/
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看板
提交
0cc5eddb
编写于
9月 17, 2020
作者:
J
Jacek Czaja
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- condidate fix to issue
#25537
test=develop
上级
da583edf
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
36 addition
and
1 deletion
+36
-1
paddle/fluid/framework/data_layout_transform.cc
paddle/fluid/framework/data_layout_transform.cc
+1
-1
paddle/fluid/operators/transpose_op.cc
paddle/fluid/operators/transpose_op.cc
+13
-0
paddle/fluid/platform/mkldnn_helper.h
paddle/fluid/platform/mkldnn_helper.h
+22
-0
未找到文件。
paddle/fluid/framework/data_layout_transform.cc
浏览文件 @
0cc5eddb
...
@@ -203,7 +203,7 @@ void innerTransDataLayoutFromMKLDNN(DataLayout in_layout, DataLayout out_layout,
...
@@ -203,7 +203,7 @@ void innerTransDataLayoutFromMKLDNN(DataLayout in_layout, DataLayout out_layout,
// As MKL-DNN description was in NCHW and paddle is expecting NHWC
// As MKL-DNN description was in NCHW and paddle is expecting NHWC
platform
::
MatchShapeToLayout
(
out
,
in_layout
,
out_layout
);
platform
::
MatchShapeToLayout
(
out
,
in_layout
,
out_layout
);
out
->
set_layout
(
out_layout
);
out
->
set_layout
(
DataLayout
::
kNCHW
);
// reset format since the out tensor will be feed to non-MKLDNN OPkernel
// reset format since the out tensor will be feed to non-MKLDNN OPkernel
out
->
set_format
(
MKLDNNMemoryFormat
::
undef
);
out
->
set_format
(
MKLDNNMemoryFormat
::
undef
);
}
}
...
...
paddle/fluid/operators/transpose_op.cc
浏览文件 @
0cc5eddb
...
@@ -61,6 +61,19 @@ class TransposeOp : public framework::OperatorWithKernel {
...
@@ -61,6 +61,19 @@ class TransposeOp : public framework::OperatorWithKernel {
}
}
framework
::
DDim
out_dims
(
x_dims
);
framework
::
DDim
out_dims
(
x_dims
);
#ifdef PADDLE_WITH_MKLDNN
// Here we need to match dims to paddle layout
// as we are producing non-oneDNN result
if
((
x_dims
.
size
()
>=
3
)
&&
(
paddle
::
platform
::
MKLDNNDeviceContext
::
tls
()
.
get_cur_paddle_data_layout
()
==
framework
::
DataLayout
::
kNHWC
))
{
auto
dims
=
framework
::
vectorize
<
int
>
(
x_dims
);
std
::
rotate
(
dims
.
begin
()
+
1
,
dims
.
begin
()
+
2
,
dims
.
end
());
x_dims
=
x_dims
.
reshape
(
dims
);
VLOG
(
3
)
<<
"Rotating Shape in Transpose from: kMKLDNN to: kNHWC output_shape"
;
}
#endif
for
(
size_t
i
=
0
;
i
<
axis_size
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
axis_size
;
i
++
)
{
out_dims
[
i
]
=
x_dims
[
axis
[
i
]];
out_dims
[
i
]
=
x_dims
[
axis
[
i
]];
}
}
...
...
paddle/fluid/platform/mkldnn_helper.h
浏览文件 @
0cc5eddb
...
@@ -14,7 +14,9 @@ limitations under the License. */
...
@@ -14,7 +14,9 @@ limitations under the License. */
#pragma once
#pragma once
#include <algorithm>
#include <algorithm>
#include <iostream>
#include <memory>
#include <memory>
#include <sstream>
#include <string>
#include <string>
#include <utility>
#include <utility>
#include <vector>
#include <vector>
...
@@ -81,12 +83,30 @@ inline void MatchShapeToLayout(framework::Tensor* tensor_in,
...
@@ -81,12 +83,30 @@ inline void MatchShapeToLayout(framework::Tensor* tensor_in,
return
;
return
;
}
}
auto
print_dims
=
[](
const
std
::
vector
<
int
>&
dims
)
{
std
::
ostringstream
oss
;
if
(
!
dims
.
empty
())
{
oss
<<
"["
;
// Convert all but the last element to avoid a trailing ","
std
::
copy
(
dims
.
begin
(),
dims
.
end
()
-
1
,
std
::
ostream_iterator
<
int
>
(
oss
,
","
));
// Now add the last element with no delimiter
oss
<<
dims
.
back
()
<<
"]"
;
}
return
oss
.
str
();
};
switch
(
from
)
{
switch
(
from
)
{
case
framework
:
:
DataLayout
::
kMKLDNN
:
case
framework
:
:
DataLayout
::
kMKLDNN
:
if
(
to
==
framework
::
DataLayout
::
kNHWC
)
{
if
(
to
==
framework
::
DataLayout
::
kNHWC
)
{
auto
dims
=
framework
::
vectorize
<
int
>
(
tensor_in
->
dims
());
auto
dims
=
framework
::
vectorize
<
int
>
(
tensor_in
->
dims
());
std
::
rotate
(
dims
.
begin
()
+
1
,
dims
.
begin
()
+
2
,
dims
.
end
());
std
::
rotate
(
dims
.
begin
()
+
1
,
dims
.
begin
()
+
2
,
dims
.
end
());
tensor_in
->
Resize
(
framework
::
make_ddim
(
dims
));
tensor_in
->
Resize
(
framework
::
make_ddim
(
dims
));
VLOG
(
3
)
<<
"Rotating Shape from: kMKLDNN to: kNHWC output_shape"
<<
print_dims
(
dims
);
}
}
break
;
break
;
case
framework
:
:
DataLayout
::
kNHWC
:
case
framework
:
:
DataLayout
::
kNHWC
:
...
@@ -94,6 +114,8 @@ inline void MatchShapeToLayout(framework::Tensor* tensor_in,
...
@@ -94,6 +114,8 @@ inline void MatchShapeToLayout(framework::Tensor* tensor_in,
auto
dims
=
framework
::
vectorize
<
int
>
(
tensor_in
->
dims
());
auto
dims
=
framework
::
vectorize
<
int
>
(
tensor_in
->
dims
());
std
::
rotate
(
dims
.
begin
()
+
1
,
dims
.
end
()
-
1
,
dims
.
end
());
std
::
rotate
(
dims
.
begin
()
+
1
,
dims
.
end
()
-
1
,
dims
.
end
());
tensor_in
->
Resize
(
framework
::
make_ddim
(
dims
));
tensor_in
->
Resize
(
framework
::
make_ddim
(
dims
));
VLOG
(
3
)
<<
"Rotating Shape from: kNHWC to: kMKLDNN output_shape"
<<
print_dims
(
dims
);
}
}
break
;
break
;
default:
default:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录