| 89 | } |
| 90 | |
| 91 | static void create_pointwise_modules(module_pass_manager& mpm) |
| 92 | { |
| 93 | std::size_t n = 0; |
| 94 | for(auto ins : iterator_for(mpm.get_module())) |
| 95 | { |
| 96 | if(not ins->get_operator().attributes().get("pointwise", false)) |
| 97 | continue; |
| 98 | if(ins->get_operator().name() == "layout") |
| 99 | continue; |
| 100 | auto* pm = mpm.create_module(mpm.get_module().name() + ":pointwise" + std::to_string(n++)); |
| 101 | pm->set_bypass(); |
| 102 | |
| 103 | std::unordered_map<instruction_ref, instruction_ref> param_map; |
| 104 | std::vector<instruction_ref> pointwise_inputs; |
| 105 | std::size_t i = 0; |
| 106 | |
| 107 | for(auto input : ins->inputs()) |
| 108 | { |
| 109 | if(contains(param_map, input)) |
| 110 | continue; |
| 111 | auto scalar = get_scalar(input); |
| 112 | if(scalar.empty()) |
| 113 | { |
| 114 | pointwise_inputs.push_back(input); |
| 115 | param_map[input] = |
| 116 | pm->add_parameter(param_name(i), shape{input->get_shape().type()}); |
| 117 | i++; |
| 118 | } |
| 119 | else |
| 120 | { |
| 121 | param_map[input] = pm->add_literal(scalar); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | // Don't create pointwise module if no inputs are detected |
| 126 | if(pointwise_inputs.empty()) |
| 127 | continue; |
| 128 | |
| 129 | std::vector<instruction_ref> inputs; |
| 130 | std::transform(ins->inputs().begin(), |
| 131 | ins->inputs().end(), |
| 132 | std::back_inserter(inputs), |
| 133 | [&](auto input) { return param_map[input]; }); |
| 134 | auto r = pm->add_instruction(ins->get_operator(), inputs); |
| 135 | pm->add_return({r}); |
| 136 | |
| 137 | mpm.get_module().replace_instruction(ins, make_op("pointwise"), pointwise_inputs, {pm}); |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | static module::with_inputs append_pointwise_module(instruction_ref ins, instruction_ref output) |
| 142 | { |
no test coverage detected