| 92 | } |
| 93 | |
| 94 | TEST_CASE(calc_implict_deps) |
| 95 | { |
| 96 | migraphx::program p; |
| 97 | auto* mm = p.get_main_module(); |
| 98 | migraphx::shape cond_s{migraphx::shape::bool_type}; |
| 99 | migraphx::shape xs{migraphx::shape::float_type, {2, 3}}; |
| 100 | migraphx::shape ys{migraphx::shape::float_type, {3, 3}}; |
| 101 | std::vector<float> datax = {1, 2, 3, 4, 5, 6}; |
| 102 | std::vector<float> datay = {8, 7, 6, 5, 4, 3, 2, 1, 0}; |
| 103 | |
| 104 | auto lx = mm->add_literal(migraphx::literal(xs, datax)); |
| 105 | auto ly = mm->add_literal(migraphx::literal(ys, datay)); |
| 106 | auto cond = mm->add_parameter("cond", cond_s); |
| 107 | auto x1 = mm->add_parameter("x1", xs); |
| 108 | auto x2 = mm->add_parameter("x2", xs); |
| 109 | auto y2 = mm->add_parameter("y2", ys); |
| 110 | |
| 111 | auto* then_mod = p.create_module("If_5_if"); |
| 112 | auto l1 = then_mod->add_literal(migraphx::literal(ys, datay)); |
| 113 | auto a1 = then_mod->add_instruction(migraphx::make_op("add"), x1, lx); |
| 114 | then_mod->add_return({a1, l1}); |
| 115 | |
| 116 | auto* then_mod1 = p.create_module("If_6_if"); |
| 117 | auto l11 = then_mod1->add_literal(migraphx::literal(ys, datay)); |
| 118 | auto a11 = then_mod1->add_instruction(migraphx::make_op("add"), x2, lx); |
| 119 | then_mod1->add_return({a11, l11}); |
| 120 | |
| 121 | auto* else_mod1 = p.create_module("If_6_else"); |
| 122 | auto l21 = else_mod1->add_literal(migraphx::literal(xs, datax)); |
| 123 | auto a21 = else_mod1->add_instruction(migraphx::make_op("mul"), y2, ly); |
| 124 | else_mod1->add_return({l21, a21}); |
| 125 | |
| 126 | auto* else_mod = p.create_module("If_5_else"); |
| 127 | auto l2 = else_mod->add_literal(migraphx::literal(ys, datay)); |
| 128 | auto a2 = else_mod->add_instruction(migraphx::make_op("if"), {cond}, {then_mod1, else_mod1}); |
| 129 | auto a3 = else_mod->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), a2); |
| 130 | else_mod->add_return({a3, l2}); |
| 131 | |
| 132 | auto ret = mm->add_instruction(migraphx::make_op("if"), {cond}, {then_mod, else_mod}); |
| 133 | auto r = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), ret); |
| 134 | mm->add_return({r}); |
| 135 | |
| 136 | auto implicit_deps = mm->calc_implicit_deps(); |
| 137 | EXPECT(migraphx::contains(implicit_deps, ret)); |
| 138 | EXPECT(migraphx::contains(implicit_deps.at(ret), x1)); |
| 139 | EXPECT(migraphx::contains(implicit_deps.at(ret), x2)); |
| 140 | EXPECT(migraphx::contains(implicit_deps.at(ret), y2)); |
| 141 | EXPECT(migraphx::contains(implicit_deps.at(ret), lx)); |
| 142 | EXPECT(migraphx::contains(implicit_deps.at(ret), ly)); |
| 143 | // test for sorting |
| 144 | p.sort(); |
| 145 | auto ret_inputs = ret->inputs(); |
| 146 | ret_inputs.insert(ret_inputs.end(), implicit_deps.at(ret).begin(), implicit_deps.at(ret).end()); |
| 147 | EXPECT(std::all_of(ret_inputs.begin(), ret_inputs.end(), [&](const auto i) { |
| 148 | return std::distance(mm->begin(), i) < std::distance(mm->begin(), ret); |
| 149 | })); |
| 150 | } |
| 151 |
nothing calls this directly
no test coverage detected