| 38 | } |
| 39 | |
| 40 | TEST_CASE(layernorm_pointwise) |
| 41 | { |
| 42 | migraphx::shape s{migraphx::shape::float_type, {2, 3, 4}}; |
| 43 | auto create_program = [=](bool first_arg_layernorm) { |
| 44 | migraphx::program p; |
| 45 | auto* mm = p.get_main_module(); |
| 46 | auto x = mm->add_parameter("x", s); |
| 47 | auto y = mm->add_parameter("y", s); |
| 48 | auto z = mm->add_parameter("z", s); |
| 49 | auto alloc = migraphx::make_op("allocate", {{"shape", to_value(s)}}); |
| 50 | auto alloc_ins = mm->add_instruction(alloc); |
| 51 | auto* pw_add1 = |
| 52 | create_pointwise_module(p, "main:pointwise0", {x, y}, single_pointwise("add")); |
| 53 | auto add1 = |
| 54 | mm->add_instruction(make_precompile_op("pointwise"), {x, y, alloc_ins}, {pw_add1}); |
| 55 | auto alloc_ins2 = mm->add_instruction(alloc); |
| 56 | auto layernorm_ins = |
| 57 | mm->add_instruction(make_precompile_op("gpu::prelayernorm"), add1, alloc_ins2); |
| 58 | std::vector<migraphx::instruction_ref> pw_inputs = {layernorm_ins, z}; |
| 59 | if(not first_arg_layernorm) |
| 60 | { |
| 61 | pw_inputs = {z, layernorm_ins}; |
| 62 | } |
| 63 | auto* pw_add2 = |
| 64 | create_pointwise_module(p, "main:pointwise1", pw_inputs, single_pointwise("add")); |
| 65 | auto alloc_ins3 = mm->add_instruction(alloc); |
| 66 | pw_inputs.push_back(alloc_ins3); |
| 67 | auto add2 = mm->add_instruction(make_precompile_op("pointwise"), pw_inputs, {pw_add2}); |
| 68 | mm->add_return({add2}); |
| 69 | return p; |
| 70 | }; |
| 71 | |
| 72 | auto create_fused_program = [=]() { |
| 73 | migraphx::program p; |
| 74 | auto* mm = p.get_main_module(); |
| 75 | auto x = mm->add_parameter("x", s); |
| 76 | auto y = mm->add_parameter("y", s); |
| 77 | auto z = mm->add_parameter("z", s); |
| 78 | auto alloc = migraphx::make_op("allocate", {{"shape", to_value(s)}}); |
| 79 | auto alloc_ins = mm->add_instruction(alloc); |
| 80 | auto* pw_add1 = |
| 81 | create_pointwise_module(p, "main:pointwise0", {x, y}, single_pointwise("add")); |
| 82 | auto add1 = |
| 83 | mm->add_instruction(make_precompile_op("pointwise"), {x, y, alloc_ins}, {pw_add1}); |
| 84 | auto alloc_ins2 = mm->add_instruction(alloc); |
| 85 | auto* pw_add2 = |
| 86 | create_pointwise_module(p, "main:pointwise1", {x, z}, single_pointwise("add")); |
| 87 | auto layernorm_op = migraphx::make_op("gpu::prelayernorm"); |
| 88 | auto pre_comp_op = migraphx::make_op( |
| 89 | "gpu::precompile_op", |
| 90 | {{"op", migraphx::to_value(layernorm_op)}, {"output_shape", migraphx::to_value(s)}}); |
| 91 | |
| 92 | auto layernorm_ins = mm->add_instruction(pre_comp_op, {add1, z, alloc_ins2}, {pw_add2}); |
| 93 | mm->add_return({layernorm_ins}); |
| 94 | return p; |
| 95 | }; |
| 96 | |
| 97 | { |
nothing calls this directly
no test coverage detected