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

Function TEST_CASE

test/rewrite_gelu_test.cpp:41–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39#include <migraphx/verify.hpp>
40
41TEST_CASE(bias_gelu)
42{
43 migraphx::shape s1{migraphx::shape::half_type, {2, 4, 8}};
44 migraphx::shape s2{migraphx::shape::half_type};
45 migraphx::module m1;
46 {
47 auto a = m1.add_parameter("a", s1);
48 auto b = m1.add_parameter("b", s1);
49 auto add1 = m1.add_instruction(migraphx::make_op("add"), a, b);
50 auto l1 = m1.add_literal(migraphx::literal{s2, {1.4140625f}});
51 auto div = add_common_op(m1, migraphx::make_op("div"), {add1, l1});
52 auto erf = m1.add_instruction(migraphx::make_op("erf"), div);
53 auto l2 = m1.add_literal(migraphx::literal{s2, {1.0f}});
54 auto add2 = add_common_op(m1, migraphx::make_op("add"), {erf, l2});
55 auto mul = m1.add_instruction(migraphx::make_op("mul"), add1, add2);
56 auto l3 = m1.add_literal(migraphx::literal{s2, {0.5f}});
57 mul = add_common_op(m1, migraphx::make_op("mul"), {mul, l3});
58 m1.add_return({mul});
59 }
60 migraphx::rewrite_gelu pass;
61 pass.apply(m1);
62 migraphx::dead_code_elimination dce;
63 dce.apply(m1);
64
65 migraphx::module m2;
66 {
67 using migraphx::literal;
68 using migraphx::make_op;
69 using migraphx::shape;
70 auto x_param = m2.add_parameter("a", s1);
71 auto bias_param = m2.add_parameter("b", s1);
72 auto bias_add = m2.add_instruction(migraphx::make_op("add"), x_param, bias_param);
73 double const0 = -2. * sqrt(M_2_PI);
74 double const1 = 0.044715 * const0;
75 auto lit0 = m2.add_literal(literal{shape{s2.type()}, {const0}});
76 auto lit1 = m2.add_literal(literal{shape{s2.type()}, {const1}});
77 auto one = m2.add_literal(literal{shape{s2.type()}, {1.0}});
78 auto xb = add_common_op(m2, make_op("mul"), {bias_add, lit1});
79 auto a = m2.add_instruction(make_op("mul"), bias_add, xb);
80 auto b = add_common_op(m2, make_op("add"), {a, lit0});
81 auto u = m2.add_instruction(make_op("mul"), bias_add, b);
82 auto emu = m2.add_instruction(make_op("exp"), u);
83 auto c = add_common_op(m2, make_op("add"), {one, emu});
84 auto y = m2.add_instruction(make_op("div"), bias_add, c);
85 m2.add_return({y});
86 }
87
88 EXPECT(m1 == m2);
89}
90
91TEST_CASE(non_bias_gelu)
92{

Callers

nothing calls this directly

Calls 9

add_common_opFunction · 0.85
sqrtClass · 0.85
add_parameterMethod · 0.80
make_opFunction · 0.50
add_instructionMethod · 0.45
add_literalMethod · 0.45
add_returnMethod · 0.45
applyMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected