| 161 | }; |
| 162 | |
| 163 | static auto create_program(int64_t max_loop_iterations = 10) |
| 164 | { |
| 165 | migraphx::program p; |
| 166 | auto* mm = p.get_main_module(); |
| 167 | migraphx::shape si{migraphx::shape::int64_type}; |
| 168 | migraphx::shape s{migraphx::shape::int64_type, {1}}; |
| 169 | migraphx::shape sc{migraphx::shape::bool_type}; |
| 170 | |
| 171 | auto in_iter = mm->add_parameter("iter_num", si); |
| 172 | auto in_cond = mm->add_parameter("ccond", sc); |
| 173 | auto in_val = mm->add_parameter("val", s); |
| 174 | |
| 175 | auto* body = p.create_module("loop_module"); |
| 176 | auto iter = body->add_parameter("#loop_module_in_0", si); |
| 177 | body->add_parameter("#loop_module_in_1", sc); |
| 178 | auto in_v = body->add_parameter("#loop_module_in_2", s); |
| 179 | std::vector<int64_t> vd = {3}; |
| 180 | auto l = body->add_literal(migraphx::literal(si, vd)); |
| 181 | auto ad = body->add_instruction(migraphx::make_op("add"), iter, l); |
| 182 | auto val = body->add_instruction(migraphx::make_op("add"), in_v, ad); |
| 183 | auto eq = body->add_instruction(migraphx::make_op("equal"), iter, l); |
| 184 | auto beq = body->add_instruction( |
| 185 | migraphx::make_op("convert", {{"target_type", migraphx::shape::bool_type}}), eq); |
| 186 | auto neq = body->add_instruction(migraphx::make_op("not"), beq); |
| 187 | std::string out_param_prefix = "loop_module:#output_"; |
| 188 | auto out0 = body->add_parameter(out_param_prefix + std::to_string(0), neq->get_shape()); |
| 189 | auto r_neq = body->add_instruction(copy_op{}, neq, out0); |
| 190 | auto out2 = body->add_parameter(out_param_prefix + std::to_string(2), val->get_shape()); |
| 191 | auto r_val = body->add_instruction(copy_op{}, val, out2); |
| 192 | body->add_return({r_neq, r_val, r_val}); |
| 193 | |
| 194 | auto rl = |
| 195 | mm->add_instruction(test_loop_op{max_loop_iterations}, {in_iter, in_cond, in_val}, {body}); |
| 196 | auto r0 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), rl); |
| 197 | auto r1 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 1}}), rl); |
| 198 | mm->add_return({r0, r1}); |
| 199 | |
| 200 | return p; |
| 201 | }; |
| 202 | |
| 203 | static auto run_prog(migraphx::program p, int64_t iter_num, bool cond, int64_t ini_val) |
| 204 | { |
no test coverage detected