Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
903c87bd
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看板
未验证
提交
903c87bd
编写于
9月 15, 2022
作者:
W
WangZhen
提交者:
GitHub
9月 15, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support 0 shapes input Tensor for MKL slice (#45930) (#46072)
Support 0 shapes input Tensor for MKL slice kernel
上级
07933116
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
42 addition
and
3 deletion
+42
-3
paddle/fluid/framework/data_layout_transform.cc
paddle/fluid/framework/data_layout_transform.cc
+3
-1
paddle/fluid/operators/mkldnn/slice_mkldnn_op.cc
paddle/fluid/operators/mkldnn/slice_mkldnn_op.cc
+9
-1
paddle/phi/kernels/funcs/data_layout_transform.cc
paddle/phi/kernels/funcs/data_layout_transform.cc
+3
-1
python/paddle/fluid/tests/unittests/test_slice_op.py
python/paddle/fluid/tests/unittests/test_slice_op.py
+27
-0
未找到文件。
paddle/fluid/framework/data_layout_transform.cc
浏览文件 @
903c87bd
...
...
@@ -171,7 +171,9 @@ void innerTransDataLayoutFromMKLDNN(DataLayout in_layout,
out
->
set_mem_desc
(
out_mem_desc
);
out
->
Resize
(
in
.
dims
());
if
((
in
.
mem_desc
()
!=
out
->
mem_desc
())
||
always_copy
)
{
// Note(0x45f): Using initialized() to support slice Tensors
// with shapes like [0, 0, 0].
if
(
in
.
initialized
()
&&
((
in
.
mem_desc
()
!=
out
->
mem_desc
())
||
always_copy
))
{
void
*
in_data
=
GetDataFromTensor
(
in
,
in_type
);
platform
::
ReorderMKLDNNHandler
handler
(
...
...
paddle/fluid/operators/mkldnn/slice_mkldnn_op.cc
浏览文件 @
903c87bd
...
...
@@ -72,11 +72,19 @@ class SliceMKLDNNKernel : public framework::OpKernel<T> {
ends
[
i
]
=
ends
[
i
]
<
0
?
x_vec_dims
[
axes
[
i
]]
+
ends
[
i
]
:
std
::
min
(
ends
[
i
],
x_vec_dims
[
axes
[
i
]]);
offsets
[
axes
[
i
]]
=
starts
[
i
];
slice_dims
[
axes
[
i
]]
=
ends
[
i
]
-
starts
[
i
];
slice_dims
[
axes
[
i
]]
=
std
::
max
(
static_cast
<
int64_t
>
(
0
),
ends
[
i
]
-
starts
[
i
]);
}
out
->
Resize
(
phi
::
make_ddim
(
slice_dims
));
// Note(0x45f): To support slice Tensors with shapes like [0, 0, 0].
if
(
!
x
->
initialized
())
{
out
->
mutable_data
(
x
->
place
(),
x
->
dtype
());
out
->
set_layout
(
experimental
::
DataLayout
::
kMKLDNN
);
return
;
}
dnnl
::
memory
::
data_type
x_type
=
framework
::
ToMKLDNNDataType
(
framework
::
TransToProtoVarType
(
x
->
dtype
()));
...
...
paddle/phi/kernels/funcs/data_layout_transform.cc
浏览文件 @
903c87bd
...
...
@@ -83,7 +83,9 @@ void innerTransDataLayoutFromOneDNN(DataLayout in_layout,
out
->
set_mem_desc
(
out_mem_desc
);
out
->
Resize
(
in
.
dims
());
if
((
in
.
mem_desc
()
!=
out
->
mem_desc
())
||
always_copy
)
{
// Note(0x45f): Using initialized() to support slice Tensors
// with shapes like [0, 0, 0].
if
(
in
.
initialized
()
&&
((
in
.
mem_desc
()
!=
out
->
mem_desc
())
||
always_copy
))
{
void
*
in_data
=
GetDataFromTensor
(
in
,
in_type
);
ReorderOneDNNHandler
handler
(
in_tz
,
in
.
dtype
(),
in_type
,
cpu_engine
);
...
...
python/paddle/fluid/tests/unittests/test_slice_op.py
浏览文件 @
903c87bd
...
...
@@ -79,6 +79,33 @@ class TestCase2(TestSliceOp):
self
.
out
=
self
.
input
[
-
3
:
3
,
0
:
100
,
:,
2
:
-
1
]
class
TestSliceZerosShapeTensor
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
"slice"
self
.
config
()
self
.
inputs
=
{
'Input'
:
self
.
input
}
self
.
outputs
=
{
'Out'
:
self
.
out
}
self
.
attrs
=
{
'axes'
:
self
.
axes
,
'starts'
:
self
.
starts
,
'ends'
:
self
.
ends
,
'infer_flags'
:
self
.
infer_flags
,
'use_mkldnn'
:
True
}
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
0
,
0
,
0
]).
astype
(
"float32"
)
self
.
starts
=
[
1
]
self
.
ends
=
[
2
]
self
.
axes
=
[
0
]
self
.
infer_flags
=
[]
self
.
out
=
self
.
input
[
1
:
2
]
def
test_check_output
(
self
):
self
.
check_output_with_place
(
paddle
.
CPUPlace
())
# 1.2 with attr(decrease)
class
TestSliceOp_decs_dim
(
OpTest
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录