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/pad.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 / pad.cpp` 94 lines ยท 3631 bytes Raw Blame History 1 #include "../op_table.h" 2 #include "../utils.h" 3 4 #include 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 #include 12 #include 13 14 namespace ov { 15 namespace frontend { 16 namespace ggml { 17 namespace op { 18 19 namespace { 20 21 ov::Output translate_circular_pad(ov::Output input, 22 const std::array & pads, 23 const ov::Shape & input_shape) { 24 ov::Output result = std::move(input); 25 26 const std::array pads_begin = {pads[6], pads[4], pads[2], pads[0]}; 27 const std::array pads_end = {pads[7], pads[5], pads[3], pads[1]}; 28 29 for (size_t axis = 0; axis < input_shape.size(); ++axis) { 30 const int64_t input_dim = static_cast(input_shape[axis]); 31 const int64_t pad_begin = pads_begin[axis]; 32 const int64_t pad_end = pads_end[axis]; 33 34 if (pad_begin == 0 && pad_end == 0) { 35 continue; 36 } 37 38 FRONT_END_CHECK_IMPLEMENTED(input_dim > 0, "Circular PAD requires static non-zero input dimensions"); 39 40 std::vector indices(static_cast(input_dim + pad_begin + pad_end)); 41 for (int64_t index = 0; index < static_cast(indices.size()); ++index) { 42 int64_t wrapped = (index - pad_begin) % input_dim; 43 if (wrapped < 0) { 44 wrapped += input_dim; 45 } 46 indices[static_cast(index)] = wrapped; 47 } 48 49 auto gather_indices = ov::op::v0::Constant::create(ov::element::i64, {indices.size()}, indices); 50 auto gather_axis = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {axis}); 51 result = std::make_shared(result, gather_indices, gather_axis); 52 } 53 54 return result; 55 } 56 57 } // namespace 58 59 OutputVector translate_pad(const NodeContext & context) { 60 num_inputs_check(context, 1, 1); 61 62 auto input = process_view_input_new(context, 0); 63 if (context.get_input_shape(0) == context.get_output_shape()) { 64 return rename_outputs_with_suffix({input}, context.get_name()); 65 } 66 67 const int32_t * op_params = context.get_output_op_params(); 68 FRONT_END_CHECK_IMPLEMENTED(op_params != nullptr, "PAD requires output op params"); 69 70 const std::array pads = {op_params[0], op_params[1], op_params[2], op_params[3], 71 op_params[4], op_params[5], op_params[6], op_params[7]}; 72 const bool circular = op_params[8] != 0; 73 74 if (circular) { 75 auto res = translate_circular_pad(input, pads, context.get_input_shape(0).to_shape()); 76 return rename_outputs_with_suffix({res}, context.get_name()); 77 } 78 79 const std::vector pads_begin = {pads[6], pads[4], pads[2], pads[0]}; 80 const std::vector pads_end = {pads[7], pads[5], pads[3], pads[1]}; 81 82 auto pads_begin_node = ov::op::v0::Constant::create(ov::element::i64, {pads_begin.size()}, pads_begin); 83 auto pads_end_node = ov::op::v0::Constant::create(ov::element::i64, {pads_end.size()}, pads_end); 84 auto pad_value = ov::op::v0::Constant::create(context.get_input_type(0), ov::Shape{}, {0}); 85 auto res = 86 std::make_shared(input, pads_begin_node, pads_end_node, pad_value, ov::op::PadMode::CONSTANT); 87 88 return rename_outputs_with_suffix({res}, context.get_name()); 89 } 90 91 } // namespace op 92 } // namespace ggml 93 } // namespace frontend 94 } // namespace ov