| 34 | struct test_shrink : verify_program<test_shrink<T>> |
| 35 | { |
| 36 | migraphx::program create_program() const |
| 37 | { |
| 38 | migraphx::program p; |
| 39 | float bias = 1.5; |
| 40 | float lambd = 1.5; |
| 41 | auto* mm = p.get_main_module(); |
| 42 | migraphx::shape is{T, {2, 3}}; |
| 43 | std::vector<float> data; |
| 44 | migraphx::shape::visit(T, [&](auto as) { |
| 45 | as.is_signed() ? data.assign({-3.0, -2.0, -1.0, 0.0, 1.0, 2.0}) |
| 46 | : data.assign({3.0, 2.0, 1.0, 0.0, 1.0, 2.0}); |
| 47 | }); |
| 48 | auto x = mm->add_literal(migraphx::literal{is, data}); |
| 49 | auto lit_bias = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {bias}}); |
| 50 | auto lit_neg_lambd = |
| 51 | mm->add_literal(migraphx::literal{migraphx::shape::float_type, {-lambd}}); |
| 52 | auto lit_lambd = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {lambd}}); |
| 53 | |
| 54 | auto x_plus_bias = add_common_op(*mm, migraphx::make_op("add"), {x, lit_bias}); |
| 55 | auto x_min_bias = add_common_op(*mm, migraphx::make_op("sub"), {x, lit_bias}); |
| 56 | |
| 57 | auto cond1 = add_common_op(*mm, migraphx::make_op("less"), {x, lit_neg_lambd}); |
| 58 | auto cond2_a = add_common_op(*mm, migraphx::make_op("not"), {cond1}); |
| 59 | auto cond2_b = add_common_op(*mm, migraphx::make_op("greater"), {x, lit_lambd}); |
| 60 | auto cond2 = add_common_op(*mm, migraphx::make_op("logical_and"), {cond2_a, cond2_b}); |
| 61 | |
| 62 | auto mul1 = mm->add_instruction(migraphx::make_op("convert", {{"target_type", T}}), cond1); |
| 63 | auto mul2 = mm->add_instruction(migraphx::make_op("convert", {{"target_type", T}}), cond2); |
| 64 | |
| 65 | auto first = add_common_op(*mm, migraphx::make_op("mul"), {mul1, x_plus_bias}); |
| 66 | auto second = add_common_op(*mm, migraphx::make_op("mul"), {mul2, x_min_bias}); |
| 67 | auto ret = add_common_op(*mm, migraphx::make_op("add"), {first, second}); |
| 68 | if(ret->get_shape().type() != T) |
| 69 | { |
| 70 | mm->add_instruction(migraphx::make_op("convert", {{"target_type", T}}), ret); |
| 71 | } |
| 72 | return p; |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | template struct test_shrink<migraphx::shape::double_type>; |
nothing calls this directly
no test coverage detected