| 26 | #include <tf_test.hpp> |
| 27 | |
| 28 | TEST_CASE(batchnorm_test) |
| 29 | { |
| 30 | migraphx::program p; |
| 31 | auto* mm = p.get_main_module(); |
| 32 | |
| 33 | auto x = mm->add_parameter("x", {migraphx::shape::float_type, {1, 32, 16, 16}}); |
| 34 | auto bias = mm->add_parameter("bias", {migraphx::shape::float_type, {32}}); |
| 35 | auto mean = mm->add_parameter("mean", {migraphx::shape::float_type, {32}}); |
| 36 | auto var = mm->add_parameter("variance", {migraphx::shape::float_type, {32}}); |
| 37 | |
| 38 | std::vector<float> scale_data(32, 1.0); |
| 39 | auto scale = mm->add_literal(migraphx::shape{migraphx::shape::float_type, {32}}, scale_data); |
| 40 | auto eps = mm->add_literal(migraphx::literal{migraphx::shape::float_type, {1e-4f}}); |
| 41 | |
| 42 | auto usq_scale = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), scale); |
| 43 | auto usq_bias = mm->add_instruction( |
| 44 | migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", x->get_shape().lens()}}), bias); |
| 45 | auto usq_mean = mm->add_instruction( |
| 46 | migraphx::make_op("broadcast", {{"axis", 1}, {"out_lens", x->get_shape().lens()}}), mean); |
| 47 | auto usq_var = mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), var); |
| 48 | |
| 49 | auto x_sub_mean = add_common_op(*mm, migraphx::make_op("sub"), {x, usq_mean}); |
| 50 | auto var_eps = add_common_op(*mm, migraphx::make_op("add"), {usq_var, eps}); |
| 51 | auto rsqrt = mm->add_instruction(migraphx::make_op("rsqrt"), var_eps); |
| 52 | auto mul0 = add_common_op(*mm, migraphx::make_op("mul"), {usq_scale, rsqrt}); |
| 53 | auto r0 = add_common_op(*mm, migraphx::make_op("mul"), {x_sub_mean, mul0}); |
| 54 | add_common_op(*mm, migraphx::make_op("add"), {r0, usq_bias}); |
| 55 | |
| 56 | auto prog = optimize_tf("batchnorm_test.pb", true); |
| 57 | EXPECT(p.sort() == prog.sort()); |
| 58 | } |
nothing calls this directly
no test coverage detected