MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / TEST_CASE

Function TEST_CASE

test/tf/tests/batchnorm_test.cpp:28–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26#include <tf_test.hpp>
27
28TEST_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}

Callers

nothing calls this directly

Calls 10

add_common_opFunction · 0.85
optimize_tfFunction · 0.85
get_main_moduleMethod · 0.80
add_parameterMethod · 0.80
lensMethod · 0.80
make_opFunction · 0.50
add_literalMethod · 0.45
add_instructionMethod · 0.45
get_shapeMethod · 0.45
sortMethod · 0.45

Tested by

no test coverage detected