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