Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-openvino/openvino/op/mulmat.cpp # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-openvino / openvino / op / mulmat.cpp` 92 lines ยท 3569 bytes Raw Blame History 1 #include "../node_context.h" 2 #include "../op_table.h" 3 #include "../utils.h" 4 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 #include 14 #include 15 #include 16 #include 17 #include 18 #include 19 #include 20 #include 21 22 namespace ov { 23 namespace frontend { 24 namespace ggml { 25 namespace op { 26 27 OutputVector translate_mulmat(const NodeContext & context) { 28 num_inputs_check(context, 2, 2); 29 30 int op_case = context.get_op_case(); 31 32 ov::Output B = process_view_input_new(context, 0); 33 ov::Output A = process_view_input_new(context, 1); 34 35 if (A.get_element_type() != B.get_element_type()) { 36 B = std::make_shared(B, context.get_input_type(1)); 37 } 38 39 auto B_shape = context.get_input_shape(0).to_shape(); 40 auto A_shape = context.get_input_shape(1).to_shape(); 41 int64_t A_batch = A_shape[1]; 42 int64_t B_batch = B_shape[1]; 43 44 auto A_batch_larger = A_batch > B_batch; 45 auto batch_large = A_batch_larger ? A_batch : B_batch; 46 auto batch_small = A_batch_larger ? B_batch : A_batch; 47 48 Output Z = A_batch_larger ? B : A; 49 auto Z_shape = A_batch_larger ? B_shape : A_shape; 50 int64_t factor = batch_large / batch_small; 51 if (factor > 1 && batch_small > 1) { 52 auto batch_large_node = ov::op::v0::Constant::create(ov::element::i64, {1}, std::vector{batch_large}); 53 auto batch_small_node = ov::op::v0::Constant::create(ov::element::i64, {1}, std::vector{batch_small}); 54 auto factor_node = ov::op::v0::Constant::create(ov::element::i64, {1}, std::vector{factor}); 55 56 auto unsqueeze_axes = ov::op::v0::Constant::create(ov::element::i64, Shape{}, {2}); 57 auto Z_unsqueezed = std::make_shared(Z, unsqueeze_axes); 58 59 auto broadcast_shape = ov::op::v0::Constant::create( 60 ov::element::i64, {5}, {(int64_t) 1, (int64_t) 1, factor, (int64_t) 1, (int64_t) 1}); 61 auto new_Z_shape = ov::op::v0::Constant::create(ov::element::i64, {4}, 62 {(int64_t) 0, batch_large, (int64_t) -1, (int64_t) Z_shape[3]}); 63 if (op_case == 2) { 64 new_Z_shape = ov::op::v0::Constant::create(ov::element::i64, {4}, 65 {(int64_t) 0, batch_large, (int64_t) Z_shape[2], (int64_t) -1}); 66 } 67 68 auto Z_broadcasted = std::make_shared(Z_unsqueezed, broadcast_shape, 69 ov::op::BroadcastType::BIDIRECTIONAL); 70 Z = std::make_shared(Z_broadcasted, new_Z_shape, true); 71 } 72 if (A_batch_larger) { 73 B = Z; 74 } else { 75 A = Z; 76 } 77 78 bool transpose_b = true; 79 ov::Output res = std::make_shared(A, B, false, transpose_b); 80 81 const auto output_type = context.get_output_type(); 82 if (res.get_element_type() != output_type) { 83 res = std::make_shared(res, output_type); 84 } 85 86 return rename_outputs_with_suffix({res}, context.get_name()); 87 } 88 89 } // namespace op 90 } // namespace ggml 91 } // namespace frontend 92 } // namespace ov