| 217 | } |
| 218 | |
| 219 | void rewrite_pooling::apply(module& m) const |
| 220 | { |
| 221 | for(auto ins : iterator_for(m)) |
| 222 | { |
| 223 | if(ins->inputs().empty()) |
| 224 | continue; |
| 225 | if(rewrite_lrn and ins->name() == "lrn") |
| 226 | { |
| 227 | lower_lrn_to_pooling(m, ins); |
| 228 | continue; |
| 229 | } |
| 230 | if(ins->name() != "pooling") |
| 231 | continue; |
| 232 | |
| 233 | auto&& s = ins->inputs().front()->get_shape(); |
| 234 | auto&& op = any_cast<op::pooling>(ins->get_operator()); |
| 235 | bool same_kernel_as_shape = std::equal( |
| 236 | s.lens().cbegin() + 2, s.lens().cend(), op.lengths.cbegin(), op.lengths.cend()); |
| 237 | bool default_strides = |
| 238 | std::all_of(op.stride.cbegin(), op.stride.cend(), [](auto i) { return i == 1; }); |
| 239 | bool default_padding = |
| 240 | std::all_of(op.padding.cbegin(), op.padding.cend(), [](auto i) { return i == 0; }); |
| 241 | bool default_dilations = |
| 242 | std::all_of(op.dilations.cbegin(), op.dilations.cend(), [](auto i) { return i == 1; }); |
| 243 | if(same_kernel_as_shape and default_strides and default_padding and default_dilations) |
| 244 | { |
| 245 | replace_with_reduce(m, ins); |
| 246 | } |
| 247 | else if(not default_dilations) |
| 248 | { |
| 249 | // Dilated AvgPool with padding is not supported |
| 250 | if(not default_padding and op.mode == op::pooling_mode::average) |
| 251 | { |
| 252 | continue; |
| 253 | } |
| 254 | auto size = |
| 255 | std::accumulate(s.lens().cbegin(), s.lens().cend(), 1, std::multiplies<size_t>()); |
| 256 | // Can't handle too much size because of literal size |
| 257 | if(size > 100000) |
| 258 | { |
| 259 | continue; |
| 260 | } |
| 261 | |
| 262 | replace_dilations_with_gather_pooling(m, ins); |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | |
| 267 | } // namespace MIGRAPHX_INLINE_NS |
| 268 | } // namespace migraphx |
nothing calls this directly
no test coverage detected