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

Function TEST_CASE

test/ref/if.cpp:33–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31#include <test.hpp>
32
33TEST_CASE(if_literal_test)
34{
35 auto create_program = [] {
36 migraphx::program p;
37 auto* mm = p.get_main_module();
38 migraphx::shape cond_s{migraphx::shape::bool_type};
39 auto cond = mm->add_parameter("cond", cond_s);
40
41 migraphx::shape s{migraphx::shape::float_type, {5}};
42
43 auto* then_mod = p.create_module("If_0_if");
44 std::vector<float> data1 = {1, 2, 3, 4, 5};
45 auto l1 = then_mod->add_literal(migraphx::literal(s, data1));
46 then_mod->add_return({l1});
47
48 auto* else_mod = p.create_module("If_0_else");
49 std::vector<float> data2 = {5, 4, 3, 2, 1};
50 auto l2 = else_mod->add_literal(migraphx::literal(s, data2));
51 else_mod->add_return({l2});
52
53 auto ret = mm->add_instruction(migraphx::make_op("if"), {cond}, {then_mod, else_mod});
54 auto r = mm->add_instruction(migraphx::make_op("get_tuple_elem", {{"index", 0}}), ret);
55 mm->add_return({r});
56
57 return p;
58 };
59
60 auto run_prog = [&](bool cond) {
61 auto p = create_program();
62 p.compile(migraphx::make_target("ref"));
63 std::vector<char> c_data = {static_cast<char>(cond)};
64 migraphx::shape cs{migraphx::shape::bool_type};
65 migraphx::parameter_map m;
66 m["cond"] = migraphx::argument(cs, c_data.data());
67
68 auto res = p.eval(m).back();
69 std::vector<float> ret;
70 res.visit([&](auto v) { ret.assign(v.begin(), v.end()); });
71
72 return ret;
73 };
74
75 // then branch
76 {
77 std::vector<float> gold_ret = {1.0f, 2.0f, 3.0f, 4.0f, 5.0f};
78 auto ret = run_prog(true);
79 EXPECT(gold_ret == ret);
80 }
81
82 // else branch
83 {
84 std::vector<float> gold_ret = {5.0f, 4.0f, 3.0f, 2.0f, 1.0f};
85 auto ret = run_prog(false);
86 EXPECT(gold_ret == ret);
87 }
88}
89
90TEST_CASE(if_param_test)

Callers

nothing calls this directly

Calls 15

make_targetFunction · 0.85
get_main_moduleMethod · 0.80
add_parameterMethod · 0.80
backMethod · 0.80
add_outlineMethod · 0.80
create_programFunction · 0.70
run_progFunction · 0.70
literalClass · 0.50
make_opFunction · 0.50
argumentClass · 0.50
create_moduleMethod · 0.45
add_literalMethod · 0.45

Tested by

no test coverage detected