ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-openvino / openvino / op / transpose.cpp
| 1 | #include "../node_context.h" |
| 2 | #include "../op_table.h" |
| 3 | #include "../utils.h" |
| 4 | |
| 5 | #include <openvino/op/transpose.hpp> |
| 6 | |
| 7 | namespace ov { |
| 8 | namespace frontend { |
| 9 | namespace ggml { |
| 10 | namespace op { |
| 11 | |
| 12 | OutputVector translate_transpose(const NodeContext & context) { |
| 13 | num_inputs_check(context, 1, 1); |
| 14 | |
| 15 | // Compute permute order from input/output shape and stride information |
| 16 | // so it adapts to different input and output layouts. |
| 17 | auto input_stride = context.get_input_stride(0); |
| 18 | auto output_stride = context.get_output_stride(); |
| 19 | |
| 20 | // Compute permute order by matching output and input stride rankings. |
| 21 | // Build <stride, dim_index> pairs. |
| 22 | std::vector<std::pair<size_t, int>> output_stride_dims; |
| 23 | std::vector<std::pair<size_t, int>> input_stride_dims; |
| 24 | |
| 25 | for (int i = 0; i < 4; ++i) { |
| 26 | output_stride_dims.push_back({output_stride[i], i}); |
| 27 | input_stride_dims.push_back({input_stride[i], i}); |
| 28 | } |
| 29 | |
| 30 | // Sort by stride in descending order. |
| 31 | std::sort(output_stride_dims.rbegin(), output_stride_dims.rend()); |
| 32 | std::sort(input_stride_dims.rbegin(), input_stride_dims.rend()); |
| 33 | |
| 34 | // Build permute order. |
| 35 | std::vector<int64_t> permute_order(4); |
| 36 | for (int i = 0; i < 4; ++i) { |
| 37 | int output_dim = output_stride_dims[i].second; |
| 38 | int input_dim = input_stride_dims[i].second; |
| 39 | permute_order[output_dim] = input_dim; |
| 40 | } |
| 41 | |
| 42 | auto input = process_view_input_new(context, 0); |
| 43 | |
| 44 | auto res = std::make_shared<ov::op::v1::Transpose>( |
| 45 | input, ov::op::v0::Constant::create(ov::element::i64, {4}, permute_order)); |
| 46 | return rename_outputs_with_suffix({res}, context.get_name()); |
| 47 | } |
| 48 | |
| 49 | } // namespace op |
| 50 | } // namespace ggml |
| 51 | } // namespace frontend |
| 52 | } // namespace ov |