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

[ODLA/DNNL]resize support nhwc #241

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions ODLA/platforms/dnnl/odla_dnnl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1348,11 +1348,28 @@ odla_value odla_Resize(odla_value input, odla_interpolation_mode interpolation,
auto input_md = input->mem.get_desc();
auto dt = input->mem.get_desc().data_type();

auto ret_md = dnnl::memory::desc(getDims(output_dims), dt,
dnnl::memory::format_tag::nchw);
auto format_tag = dnnl::memory::format_tag::nchw;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ret_md should be the same format_tag as input_md.


float scale_h;
float scale_w;
std::vector<float> scales = {1.0f, 1.0f, 1.0f, 1.0f};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here it can check each bit of axes_mask. if I-th bit is 0, scales[I] = 1
we don't need to worry about nhwc/nchw.

if (axes_mask == -1) {
scale_h = 1.0f * output_dims.dims[1] / input_md.dims()[1];
scale_w = 1.0f * output_dims.dims[2] / input_md.dims()[2];
scales[1] = scale_h;
scales[2] = scale_w;
format_tag = dnnl::memory::format_tag::nhwc;
} else {
scale_h = 1.0f * output_dims.dims[2] / input_md.dims()[2];
scale_w = 1.0f * output_dims.dims[3] / input_md.dims()[3];
scales[2] = scale_h;
scales[3] = scale_w;
}

auto ret_md = dnnl::memory::desc(getDims(output_dims), dt, format_tag);

auto op_desc = dnnl::resampling_forward::desc(
dnnl::prop_kind::forward_inference, algo, input_md, ret_md);
dnnl::prop_kind::forward_inference, algo, scales, input_md);
auto pd = dnnl::resampling_forward::primitive_desc(op_desc, g_comp->eng);
auto prim = dnnl::resampling_forward(pd);

Expand Down
2 changes: 1 addition & 1 deletion lib/transforms/inst_simplify.cc
Original file line number Diff line number Diff line change
Expand Up @@ -709,12 +709,12 @@ std::pair<Def, Def> InstSimplify::RunOnInstruction(ResizeInst* inst) {
}

new_shape->SetName(inst->GetName() + "_resize_shape");

return SinkTranspose(
*inst, [new_shape, inst](IRBuilder& builder, const std::string& name,
const Def& op) {
auto new_inst = builder.CreateResize(name, {op, *new_shape});
new_inst->CopyAttrsFrom(*inst);
new_inst->SetAxesMask(-1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For NCHW, the masks are (0011), for NHWC, the masks are (0110). So there it should permute the bits for axe mask

return new_inst;
});
}
Expand Down