| 179 | } |
| 180 | |
| 181 | void apply(module& m, const match::matcher_result& mr) const |
| 182 | { |
| 183 | auto ins = mr.result; |
| 184 | |
| 185 | std::vector<operation> ops; |
| 186 | auto x = ins; |
| 187 | while(contains(shape_transform_ops(), x->get_operator().name()) or |
| 188 | x->get_operator().name() == "contiguous") |
| 189 | { |
| 190 | ops.push_back(x->get_operator()); |
| 191 | x = x->inputs().front(); |
| 192 | } |
| 193 | if(x->get_shape().scalar()) |
| 194 | { |
| 195 | m.replace_instruction( |
| 196 | ins, make_op("multibroadcast", {{"out_lens", ins->get_shape().lens()}}), x); |
| 197 | } |
| 198 | else if(x->get_shape().elements() == 1 and ins->get_shape().elements() == 1) |
| 199 | { |
| 200 | // TODO: Use squeeze or unsqueeze |
| 201 | m.replace_instruction(ins, make_op("reshape", {{"dims", ins->get_shape().lens()}}), x); |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | std::reverse(ops.begin(), ops.end()); |
| 206 | auto opt_ops = optimize_shape_transforms(x->get_shape().lens(), ops); |
| 207 | if(ops == opt_ops) |
| 208 | return; |
| 209 | auto y = insert_ops(m, ins, opt_ops, x); |
| 210 | m.replace_instruction(ins, y); |
| 211 | } |
| 212 | } |
| 213 | }; |
| 214 | |
| 215 | struct find_op_shape_transform_op |
nothing calls this directly
no test coverage detected