-
Notifications
You must be signed in to change notification settings - Fork 75
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
||
float scale_h; | ||
float scale_w; | ||
std::vector<float> scales = {1.0f, 1.0f, 1.0f, 1.0f}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
}); | ||
} | ||
|
There was a problem hiding this comment.
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.