| 38 | std::vector<op_desc> operators() const { return {{"DepthwiseConv2dNative"}}; } |
| 39 | |
| 40 | instruction_ref parse(const op_desc& /*opd*/, |
| 41 | const tf_parser& parser, |
| 42 | tf_parser::node_info info, |
| 43 | std::vector<instruction_ref> args) const |
| 44 | { |
| 45 | op::convolution op; |
| 46 | size_t num_channels = args[0]->get_shape().lens()[1]; |
| 47 | op.group = num_channels; |
| 48 | |
| 49 | if(contains(info.attributes, "strides")) |
| 50 | { |
| 51 | std::vector<size_t> stride; |
| 52 | copy(info.attributes.at("strides").list().i(), std::back_inserter(stride)); |
| 53 | parser.reorder_data(stride); |
| 54 | if(stride.size() != 4) |
| 55 | { |
| 56 | MIGRAPHX_THROW("strides should have 4 values"); |
| 57 | } |
| 58 | op.stride[0] = stride[2]; |
| 59 | op.stride[1] = stride[3]; |
| 60 | } |
| 61 | |
| 62 | auto weights = parser.to_kcxy(args[1]); |
| 63 | if(contains(info.attributes, "dilations")) |
| 64 | { |
| 65 | std::vector<size_t> dilation; |
| 66 | copy(info.attributes.at("dilations").list().i(), std::back_inserter(dilation)); |
| 67 | parser.reorder_data(dilation); |
| 68 | if(dilation.size() != 4) |
| 69 | { |
| 70 | MIGRAPHX_THROW("dilation should have 4 values"); |
| 71 | } |
| 72 | op.dilation[0] = dilation[2]; |
| 73 | op.dilation[1] = dilation[3]; |
| 74 | } |
| 75 | |
| 76 | auto l0 = args[0]; |
| 77 | if(contains(info.attributes, "padding")) |
| 78 | { |
| 79 | const std::string& pad_mode = info.attributes.at("padding").s(); |
| 80 | |
| 81 | if(pad_mode.find("SAME") != std::string::npos) |
| 82 | { |
| 83 | std::vector<size_t> weight_dims = weights->get_shape().lens(); |
| 84 | size_t weight_h = weight_dims[2]; |
| 85 | size_t weight_w = weight_dims[3]; |
| 86 | |
| 87 | auto input_dims = l0->get_shape().lens(); |
| 88 | std::vector<int64_t> pads(input_dims.size()); |
| 89 | calculate_padding(0, pads, input_dims[2], op.stride[0], op.dilation[0], weight_h); |
| 90 | calculate_padding(1, pads, input_dims[3], op.stride[1], op.dilation[1], weight_w); |
| 91 | |
| 92 | if(pads[0] != pads[2] or pads[1] != pads[3]) |
| 93 | { |
| 94 | std::vector<int64_t> padding = {0, 0, pads[0], pads[1], 0, 0, pads[2], pads[3]}; |
| 95 | l0 = info.add_instruction(migraphx::make_op("pad", {{"pads", padding}}), l0); |
| 96 | } |
| 97 | else |
nothing calls this directly
no test coverage detected