#include #include #include #include #include #include #include #include #include namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { void eliminate_pad::apply(program& p) const { for(auto ins : iterator_for(p)) { const std::string& op_name = ins->name(); if(op_name != "convolution" and op_name != "im2col" and op_name != "pooling") continue; auto input = ins->inputs().front(); if(input->name() != "pad") continue; if(op_name == "convolution") update_op(op::convolution{}, input, ins, p); else if(op_name == "im2col") update_op(op::im2col{}, input, ins, p); else if(op_name == "pooling") update_op(op::pooling{}, input, ins, p); } } template void eliminate_pad::update_op(T, const instruction_ref& input, const instruction_ref& ins, program& p) const { auto pad_op = any_cast(input->get_operator()); if(!pad_op.symmetric()) return; std::vector pads = pad_op.pads; std::array new_pads{static_cast(pads[2]), static_cast(pads[3])}; T op = any_cast(ins->get_operator()); op.padding = new_pads; std::vector new_inputs{ins->inputs()}; new_inputs.front() = input->inputs().front(); p.replace_instruction(ins, op, new_inputs); } } // namespace MIGRAPHX_INLINE_NS } // namespace migraphx