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

Function TEST_CASE

test/split_single_dyn_dim_test.cpp:41–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39}
40
41TEST_CASE(dynamic_batch)
42{
43 // Slightly different from ref_ops_test in that the literal is copied over the submodules.
44 // A different compiler pass will pull the literals from the submodules to the main module.
45 migraphx::program p0;
46 {
47 auto* mm0 = p0.get_main_module();
48
49 // create batch submodules
50 auto create_submodule = [&](std::size_t batch_size, const std::string& module_name) {
51 auto* submod = p0.create_module(module_name);
52 migraphx::shape sm_shape{migraphx::shape::float_type, {batch_size, 4}};
53 auto sm_input = submod->add_parameter("data", sm_shape);
54 migraphx::shape lit_s{migraphx::shape{migraphx::shape::float_type, {1}}};
55 auto literal_ins = submod->add_literal(migraphx::literal{lit_s, {6}});
56 auto broadcast_lit =
57 submod->add_instruction(migraphx::make_op("multibroadcast"), literal_ins, sm_input);
58 auto add_ins =
59 submod->add_instruction(migraphx::make_op("add"), sm_input, broadcast_lit);
60 submod->add_return({add_ins});
61 return submod;
62 };
63 auto* dim1 = create_submodule(1, "dim_1");
64 auto* dim2 = create_submodule(2, "dim_2");
65 auto* dim3 = create_submodule(3, "dim_3");
66 auto* dim4 = create_submodule(4, "dim_4");
67
68 migraphx::shape s{migraphx::shape::float_type, {{1, 4}, {4, 4}}};
69 auto input0 = mm0->add_parameter("data", s);
70 std::vector<migraphx::shape> sub_shapes = {};
71 sub_shapes.push_back(migraphx::shape{migraphx::shape::float_type, {{1, 4}, {4, 4}}});
72 migraphx::shape out_attr = migraphx::shape{sub_shapes};
73 auto sm_ins = mm0->add_instruction(
74 migraphx::make_op("select_module",
75 {{"output_dyn_shapes", migraphx::to_value(out_attr)}}),
76 {input0},
77 {dim1, dim2, dim3, dim4});
78 auto ret =
79 mm0->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), sm_ins);
80 mm0->add_return({ret});
81 }
82
83 migraphx::program p1;
84 {
85 auto* mm1 = p1.get_main_module();
86 migraphx::shape s{migraphx::shape::float_type, {{1, 4}, {4, 4}}};
87 auto input1 = mm1->add_parameter("data", s);
88 migraphx::shape lit_s{migraphx::shape{migraphx::shape::float_type, {1}}};
89 auto literal_ins = mm1->add_literal(migraphx::literal{lit_s, {6}});
90 auto broadcast_lit =
91 mm1->add_instruction(migraphx::make_op("multibroadcast"), literal_ins, input1);
92 auto add_ins = mm1->add_instruction(migraphx::make_op("add"), input1, broadcast_lit);
93 mm1->add_return({add_ins});
94 }
95 run_pass(p1);
96
97 EXPECT(p0 == p1);
98}

Callers

nothing calls this directly

Calls 15

get_main_moduleMethod · 0.80
add_parameterMethod · 0.80
run_passFunction · 0.70
is_sortedFunction · 0.70
make_opFunction · 0.50
to_valueFunction · 0.50
find_ifFunction · 0.50
create_moduleMethod · 0.45
add_literalMethod · 0.45
add_instructionMethod · 0.45
add_returnMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected