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

Function create_program

test/run_loop_test.cpp:163–201  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

161};
162
163static auto create_program(int64_t max_loop_iterations = 10)
164{
165 migraphx::program p;
166 auto* mm = p.get_main_module();
167 migraphx::shape si{migraphx::shape::int64_type};
168 migraphx::shape s{migraphx::shape::int64_type, {1}};
169 migraphx::shape sc{migraphx::shape::bool_type};
170
171 auto in_iter = mm->add_parameter("iter_num", si);
172 auto in_cond = mm->add_parameter("ccond", sc);
173 auto in_val = mm->add_parameter("val", s);
174
175 auto* body = p.create_module("loop_module");
176 auto iter = body->add_parameter("#loop_module_in_0", si);
177 body->add_parameter("#loop_module_in_1", sc);
178 auto in_v = body->add_parameter("#loop_module_in_2", s);
179 std::vector<int64_t> vd = {3};
180 auto l = body->add_literal(migraphx::literal(si, vd));
181 auto ad = body->add_instruction(migraphx::make_op("add"), iter, l);
182 auto val = body->add_instruction(migraphx::make_op("add"), in_v, ad);
183 auto eq = body->add_instruction(migraphx::make_op("equal"), iter, l);
184 auto beq = body->add_instruction(
185 migraphx::make_op("convert", {{"target_type", migraphx::shape::bool_type}}), eq);
186 auto neq = body->add_instruction(migraphx::make_op("not"), beq);
187 std::string out_param_prefix = "loop_module:#output_";
188 auto out0 = body->add_parameter(out_param_prefix + std::to_string(0), neq->get_shape());
189 auto r_neq = body->add_instruction(copy_op{}, neq, out0);
190 auto out2 = body->add_parameter(out_param_prefix + std::to_string(2), val->get_shape());
191 auto r_val = body->add_instruction(copy_op{}, val, out2);
192 body->add_return({r_neq, r_val, r_val});
193
194 auto rl =
195 mm->add_instruction(test_loop_op{max_loop_iterations}, {in_iter, in_cond, in_val}, {body});
196 auto r0 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), rl);
197 auto r1 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 1}}), rl);
198 mm->add_return({r0, r1});
199
200 return p;
201};
202
203static auto run_prog(migraphx::program p, int64_t iter_num, bool cond, int64_t ini_val)
204{

Callers 1

TEST_CASEFunction · 0.70

Calls 10

get_main_moduleMethod · 0.80
add_parameterMethod · 0.80
literalClass · 0.50
make_opFunction · 0.50
to_stringFunction · 0.50
create_moduleMethod · 0.45
add_literalMethod · 0.45
add_instructionMethod · 0.45
get_shapeMethod · 0.45
add_returnMethod · 0.45

Tested by

no test coverage detected