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

Method insert

src/op/builder/gemm.cpp:53–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51 }
52
53 std::vector<instruction_ref>
54 insert(module& m, instruction_ref ins, const std::vector<instruction_ref>& args) const
55 {
56 auto a_arg = args[0];
57 auto b_arg = args[1];
58 if(a_arg->get_shape().ndim() != 2 or b_arg->get_shape().ndim() != 2)
59 {
60 MIGRAPHX_THROW("gemm op_builder: A and B should be rank 2, A is rank " +
61 std::to_string(a_arg->get_shape().ndim()) + ", B is rank " +
62 std::to_string(b_arg->get_shape().ndim()));
63 }
64
65 std::vector<int64_t> perm = {1, 0};
66 auto dot_type = a_arg->get_shape().type();
67 if(alpha != 1.0f)
68 {
69 auto alpha_literal = m.add_literal(alpha);
70 a_arg = insert_common_op(m, ins, "mul", alpha_literal, a_arg);
71
72 if(a_arg->get_shape().type() != dot_type)
73 {
74 a_arg = m.insert_instruction(
75 ins, make_op("convert", {{"target_type", dot_type}}), a_arg);
76 }
77 }
78
79 a_arg =
80 (trans_a)
81 ? m.insert_instruction(ins, make_op("transpose", {{"permutation", perm}}), a_arg)
82 : a_arg;
83 b_arg =
84 (trans_b)
85 ? m.insert_instruction(ins, make_op("transpose", {{"permutation", perm}}), args[1])
86 : args[1];
87
88 auto dot_ins = m.insert_instruction(ins, make_op("dot"), a_arg, b_arg);
89
90 if(args.size() == 3)
91 {
92 if(not float_equal(beta, 0.0f))
93 {
94 auto c_arg = args[2];
95 if(dot_ins->get_shape().dynamic())
96 {
97 c_arg = m.insert_instruction(ins, make_op("multibroadcast"), args[2], dot_ins);
98 }
99 else
100 {
101 auto out_lens = a_arg->get_shape().lens();
102 out_lens.back() = b_arg->get_shape().lens().back();
103 auto c_lens = c_arg->get_shape().lens();
104 if(not std::equal(
105 out_lens.begin(), out_lens.end(), c_lens.begin(), c_lens.end()))
106 {
107 c_arg = m.insert_instruction(
108 ins, make_op("multibroadcast", {{"out_lens", out_lens}}), args[2]);
109 }
110 }

Callers 9

invoke_builderFunction · 0.45
applyMethod · 0.45
get_argument_usagesMethod · 0.45
show_helpMethod · 0.45
parseMethod · 0.45
capture_argFunction · 0.45
trim_moduleFunction · 0.45
add_op_nameFunction · 0.45

Calls 15

ndimMethod · 0.80
insert_instructionMethod · 0.80
dynamicMethod · 0.80
lensMethod · 0.80
backMethod · 0.80
to_stringFunction · 0.50
insert_common_opFunction · 0.50
make_opFunction · 0.50
float_equalFunction · 0.50
equalFunction · 0.50
get_shapeMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected