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

Method create_program

test/verify/test_conv_bn.cpp:35–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

33struct test_conv_bn : verify_program<test_conv_bn<DType>>
34{
35 migraphx::program create_program() const
36 {
37 migraphx::program p;
38 auto* mm = p.get_main_module();
39
40 migraphx::shape xs{DType, {1, 3, 224, 224}};
41 migraphx::shape ws{DType, {64, 3, 7, 7}};
42 migraphx::shape vars{DType, {64}};
43 auto x = mm->add_parameter("x", xs);
44 auto w = mm->add_parameter("w", ws);
45 // non-symmetrical tiling
46 auto conv = mm->add_instruction(
47 migraphx::make_op("convolution",
48 {{"padding", {3, 3}}, {"stride", {2, 2}}, {"dilation", {1, 1}}}),
49 x,
50 w);
51
52 auto scale = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 1)));
53 auto bias = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 2)));
54 auto mean = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 3)));
55 auto variance = mm->add_literal(migraphx::abs(migraphx::generate_literal(vars, 4)));
56
57 auto rt = mm->add_literal(migraphx::literal{DType, {0.5}});
58
59 auto eps = mm->add_literal(migraphx::literal{DType, {1e-5f}});
60 if constexpr(DType == migraphx::shape::fp8e4m3fnuz_type or
61 DType == migraphx::shape::fp8e4m3fn_type or
62 DType == migraphx::shape::fp8e5m2_type)
63 {
64 // use 0.250 for fp8
65 eps = mm->add_literal(migraphx::literal{DType, {0.250}});
66 }
67
68 auto usq_scale =
69 mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), scale);
70 auto usq_bias =
71 mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), bias);
72 auto usq_mean =
73 mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), mean);
74 auto usq_var =
75 mm->add_instruction(migraphx::make_op("unsqueeze", {{"axes", {1, 2}}}), variance);
76
77 auto numer = add_common_op(*mm, migraphx::make_op("sub"), {conv, usq_mean});
78 auto var_eps = add_common_op(*mm, migraphx::make_op("add"), {usq_var, eps});
79 auto denom = add_common_op(*mm, migraphx::make_op("pow"), {var_eps, rt});
80 auto div0 = add_common_op(*mm, migraphx::make_op("div"), {numer, denom});
81 auto r0 = add_common_op(*mm, migraphx::make_op("mul"), {div0, usq_scale});
82 add_common_op(*mm, migraphx::make_op("add"), {r0, usq_bias});
83 return p;
84 }
85 std::string section() const { return "conv"; }
86};
87

Callers

nothing calls this directly

Calls 8

generate_literalFunction · 0.85
add_common_opFunction · 0.85
get_main_moduleMethod · 0.80
add_parameterMethod · 0.80
make_opFunction · 0.50
absFunction · 0.50
add_instructionMethod · 0.45
add_literalMethod · 0.45

Tested by

no test coverage detected