Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slice bugs in MKLDNN when input dims are zeros #46671

Merged
merged 5 commits into from Oct 11, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions paddle/fluid/operators/slice_op.cc
Expand Up @@ -155,7 +155,14 @@ class SliceOp : public framework::OperatorWithKernel {
#ifdef PADDLE_WITH_MKLDNN
auto input_data_type =
framework::OperatorWithKernel::IndicateVarDataType(ctx, "Input");

auto vec_dims = phi::vectorize(in_tensor.dims());
bool all_zeros = true;
for (auto &dim : vec_dims) {
if (dim != 0) {
all_zeros = false;
break;
}
}
yeliang2258 marked this conversation as resolved.
Show resolved Hide resolved
if (this->CanMKLDNNBeUsed(ctx, input_data_type)) {
yeliang2258 marked this conversation as resolved.
Show resolved Hide resolved
// OneDNN uses blocking format, which cannot be always supported with
// reorders, because if blocked dimension is not divisible by 8 or
Expand All @@ -165,7 +172,7 @@ class SliceOp : public framework::OperatorWithKernel {
phi::vectorize(ctx.Input<phi::DenseTensor>("Input")->dims()),
dnnl::memory::data_type::f32,
ctx.Input<phi::DenseTensor>("Input")->format());
if (tmp_md.data.format_desc.blocking.inner_nblks == 0)
if (tmp_md.data.format_desc.blocking.inner_nblks == 0 && !all_zeros)
return framework::OpKernelType(input_data_type,
ctx.GetPlace(),
framework::DataLayout::kMKLDNN,
Expand Down