| 38 | std::vector<op_desc> operators() const { return {{"AvgPool"}, {"MaxPool"}}; } |
| 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 | if(not starts_with(opd.tf_name, "Max") and not starts_with(opd.tf_name, "Av")) |
| 46 | { |
| 47 | MIGRAPHX_THROW("tf pooling mode must be Max or Average"); |
| 48 | } |
| 49 | op::pooling op{starts_with(opd.tf_name, "Max") ? op::pooling_mode::max |
| 50 | : op::pooling_mode::average}; |
| 51 | |
| 52 | if(contains(info.attributes, "strides")) |
| 53 | { |
| 54 | std::vector<size_t> stride; |
| 55 | copy(info.attributes.at("strides").list().i(), std::back_inserter(stride)); |
| 56 | parser.reorder_data(stride); |
| 57 | if(stride.size() != 4) |
| 58 | { |
| 59 | MIGRAPHX_THROW("strides should have 4 values"); |
| 60 | } |
| 61 | op.stride[0] = stride[2]; |
| 62 | op.stride[1] = stride[3]; |
| 63 | } |
| 64 | if(contains(info.attributes, "ksize")) |
| 65 | { |
| 66 | std::vector<size_t> ksize; |
| 67 | copy(info.attributes.at("ksize").list().i(), std::back_inserter(ksize)); |
| 68 | parser.reorder_data(ksize); |
| 69 | if(ksize.size() != 4) |
| 70 | { |
| 71 | MIGRAPHX_THROW("ksize should have 4 values"); |
| 72 | } |
| 73 | op.lengths[0] = ksize[2]; |
| 74 | op.lengths[1] = ksize[3]; |
| 75 | } |
| 76 | |
| 77 | auto l0 = args[0]; |
| 78 | if(contains(info.attributes, "padding")) |
| 79 | { |
| 80 | const std::string& pad_mode = info.attributes.at("padding").s(); |
| 81 | if(pad_mode.find("SAME") != std::string::npos) |
| 82 | { |
| 83 | auto input_dims = l0->get_shape().lens(); |
| 84 | std::vector<int64_t> pads(input_dims.size()); |
| 85 | calculate_padding(0, pads, input_dims[2], op.stride[0], 1, op.lengths[0]); |
| 86 | calculate_padding(1, pads, input_dims[3], op.stride[1], 1, op.lengths[1]); |
| 87 | |
| 88 | op.padding = std::vector<size_t>(pads.begin(), pads.end()); |
| 89 | } |
| 90 | } |
| 91 | return info.add_instruction(op, l0); |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | } // namespace tf |
nothing calls this directly
no test coverage detected