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

Function run_program

test/ref/topk.cpp:33–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31#include <test.hpp>
32
33static auto run_program(const migraphx::value& op, bool custom_idx = false, bool fill1 = false)
34{
35 migraphx::program p;
36 auto* mm = p.get_main_module();
37 migraphx::shape s{migraphx::shape::float_type, {3, 5}};
38 auto data = mm->add_parameter("data", s);
39 std::vector<migraphx::instruction_ref> topk_inputs = {data};
40 if(custom_idx)
41 {
42 migraphx::shape is{migraphx::shape::uint16_type, {3, 5}};
43 std::vector<int16_t> indices(is.elements());
44 std::iota(indices.rbegin(), indices.rend(), 1);
45 topk_inputs.push_back(mm->add_literal(migraphx::literal{is, indices}));
46 }
47 auto r = mm->add_instruction(migraphx::make_op("topk", op), topk_inputs);
48 auto r0 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), r);
49 auto r1 = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 1}}), r);
50 mm->add_return({r0, r1});
51
52 p.compile(migraphx::make_target("ref"));
53
54 std::vector<float> input_data = {
55 2.1,
56 2.3,
57 2.0,
58 2.5,
59 1.9,
60 3.3,
61 0.2,
62 4.5,
63 0.1,
64 0.8,
65 1.0,
66 4.5,
67 2.1,
68 0.8,
69 1.5,
70 };
71 if(fill1)
72 input_data.assign(input_data.size(), 1);
73 migraphx::parameter_map pp;
74 pp["data"] = migraphx::argument(s, input_data.data());
75 auto rets = p.eval(pp);
76 std::vector<float> ret_val;
77 rets.front().visit([&](auto v) { ret_val.assign(v.begin(), v.end()); });
78 std::vector<int64_t> ret_ind;
79 rets.back().visit([&](auto v) { ret_ind.assign(v.begin(), v.end()); });
80
81 return std::make_pair(ret_val, ret_ind);
82}
83
84TEST_CASE(topk_largest0)
85{

Callers 1

TEST_CASEFunction · 0.70

Calls 15

iotaFunction · 0.85
make_targetFunction · 0.85
get_main_moduleMethod · 0.80
add_parameterMethod · 0.80
frontMethod · 0.80
backMethod · 0.80
make_opFunction · 0.50
argumentClass · 0.50
elementsMethod · 0.45
push_backMethod · 0.45
add_literalMethod · 0.45
add_instructionMethod · 0.45

Tested by

no test coverage detected