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

Function TEST_CASE

test/fuse_attention.cpp:48–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48TEST_CASE(gemm_softmax_gemm)
49{
50 migraphx::shape s1{migraphx::shape::half_type, {1, 12, 256, 256}};
51
52 migraphx::program p1;
53 {
54 auto* mm = p1.get_main_module();
55 auto a = mm->add_parameter("1", s1);
56 auto b = mm->add_parameter("2", s1);
57 auto b1 = mm->add_parameter("3", s1);
58 b = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 1, 3, 2}}}), b);
59 b1 = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 1, 3, 2}}}),
60 b1);
61 auto gemm1 = mm->add_instruction(migraphx::make_op("dot"), a, b);
62 auto rmax = mm->add_instruction(migraphx::make_op("reduce_max", {{"axes", {3}}}), gemm1);
63 rmax = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", s1.lens()}}),
64 rmax);
65 auto sub = mm->add_instruction(migraphx::make_op("sub"), gemm1, rmax);
66 auto exp = mm->add_instruction(migraphx::make_op("exp"), sub);
67 auto rsum = mm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {3}}}), exp);
68 rsum = mm->add_instruction(migraphx::make_op("multibroadcast", {{"out_lens", s1.lens()}}),
69 rsum);
70 auto div = mm->add_instruction(migraphx::make_op("div"), exp, rsum);
71 auto gemm2 = mm->add_instruction(migraphx::make_op("dot"), div, b1);
72 mm->add_return({gemm2});
73 }
74 run_pass(p1, {.attn_enabled = true});
75
76 migraphx::program p2;
77 {
78 auto* mm = p2.get_main_module();
79 auto a = mm->add_parameter("1", s1);
80 auto b = mm->add_parameter("2", s1);
81 auto b1 = mm->add_parameter("3", s1);
82 b = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 1, 3, 2}}}), b);
83 b1 = mm->add_instruction(migraphx::make_op("transpose", {{"permutation", {0, 1, 3, 2}}}),
84 b1);
85 auto group = add_group(
86 p2,
87 "attn0",
88 "attention",
89 {a, b, b1},
90 {"x0", "x1", "x2"},
91 [=](auto* gm, const auto& inputs) {
92 auto gemm1 = gm->add_instruction(migraphx::make_op("dot"), inputs[0], inputs[1]);
93 auto rmax =
94 gm->add_instruction(migraphx::make_op("reduce_max", {{"axes", {3}}}), gemm1);
95 rmax = gm->add_instruction(
96 migraphx::make_op("multibroadcast", {{"out_lens", s1.lens()}}), rmax);
97 auto sub = gm->add_instruction(migraphx::make_op("sub"), gemm1, rmax);
98 auto exp = gm->add_instruction(migraphx::make_op("exp"), sub);
99 auto rsum =
100 gm->add_instruction(migraphx::make_op("reduce_sum", {{"axes", {3}}}), exp);
101 rsum = gm->add_instruction(
102 migraphx::make_op("multibroadcast", {{"out_lens", s1.lens()}}), rsum);
103 auto div = gm->add_instruction(migraphx::make_op("div"), exp, rsum);
104 auto gemm2 = gm->add_instruction(migraphx::make_op("dot"), div, inputs[2]);
105 return std::vector<migraphx::instruction_ref>{gemm2};

Callers

nothing calls this directly

Calls 14

add_groupFunction · 0.85
get_main_moduleMethod · 0.80
add_parameterMethod · 0.80
lensMethod · 0.80
atMethod · 0.80
run_passFunction · 0.70
make_opFunction · 0.50
literalClass · 0.50
add_instructionMethod · 0.45
add_returnMethod · 0.45
sortMethod · 0.45
elementsMethod · 0.45

Tested by

no test coverage detected