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

Method parse

src/onnx/parse_matmul.cpp:340–486  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338 }
339
340 instruction_ref parse(const op_desc& opd,
341 const onnx_parser& /*parser*/,
342 const onnx_parser::node_info& info,
343 std::vector<instruction_ref> args) const
344 {
345 std::string op_name{opd.op_name};
346 auto a0 = args[0];
347 auto a1 = args[1];
348 auto s0 = a0->get_shape();
349 auto s1 = a1->get_shape();
350
351 instruction_ref dot_res;
352 bool is_a_prepended = false;
353 bool is_b_appended = false;
354 if(s0.ndim() == 1)
355 {
356 is_a_prepended = true;
357 a0 = info.add_instruction(make_op("unsqueeze", {{"axes", {0}}}), args[0]);
358 }
359 if(s1.ndim() == 1)
360 {
361 is_b_appended = true;
362 a1 = info.add_instruction(make_op("unsqueeze", {{"axes", {1}}}), args[1]);
363 }
364
365 auto is_quant_dot = opd.op_name == "quant_dot";
366 auto is_quant_dot_scaled = opd.op_name == "quant_dot_scaled";
367 auto is_dot = opd.op_name == "dot";
368
369 if(s0.dynamic() or s1.dynamic())
370 {
371 if(is_quant_dot or is_quant_dot_scaled)
372 {
373 MIGRAPHX_THROW(op_name + ": dynamic inputs not supported");
374 }
375
376 auto s0_dds = a0->get_shape().to_dynamic().dyn_dims();
377 auto s1_dds = a1->get_shape().to_dynamic().dyn_dims();
378
379 if(not std::equal(
380 s0_dds.rbegin() + 2, s0_dds.rend(), s1_dds.rbegin() + 2, s1_dds.rend()))
381 {
382 auto broadcasted_a0 = info.add_instruction(make_op("broadcast_for_dot"), a0, a1);
383 auto broadcasted_a1 = info.add_instruction(make_op("broadcast_for_dot"), a1, a0);
384 dot_res =
385 info.add_instruction(make_op(opd.op_name), broadcasted_a0, broadcasted_a1);
386 }
387 else
388 {
389 dot_res = info.add_instruction(make_op(opd.op_name), a0, a1);
390 }
391 }
392 else
393 {
394 auto s0_lens = a0->get_shape().lens();
395 auto s1_lens = a1->get_shape().lens();
396
397 if(is_dot and args.size() > 2)

Callers

nothing calls this directly

Calls 12

containsFunction · 0.85
ndimMethod · 0.80
dynamicMethod · 0.80
to_dynamicMethod · 0.80
lensMethod · 0.80
make_opFunction · 0.50
equalFunction · 0.50
get_shapeMethod · 0.45
add_instructionMethod · 0.45
sizeMethod · 0.45
typeMethod · 0.45
add_literalMethod · 0.45

Tested by

no test coverage detected