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/utils.h # 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 / utils.h` 102 lines ยท 3836 bytes Raw Blame History 1 #pragma once 2 3 #include "node_context.h" 4 5 #include 6 #include 7 #include 8 #include 9 #include 10 #include 11 12 namespace ov { 13 namespace frontend { 14 namespace ggml { 15 16 std::string getCurrentTime(); 17 18 void num_inputs_check(const NodeContext & context, size_t min_inputs, size_t max_inputs); 19 20 int non_cont_dim(std::vector ne, std::vector nb); 21 22 template std::vector argsort_descend(const std::vector & v) { 23 std::vector idx(v.size()); 24 std::iota(idx.begin(), idx.end(), 0); 25 std::sort(idx.begin(), idx.end(), [&v](int i1, int i2) { return v[i1] > v[i2]; }); 26 return idx; 27 } 28 29 template std::vector sorted_descend(std::vector v) { 30 std::sort(v.begin(), v.end(), [](T a, T b) { return a > b; }); 31 return v; 32 } 33 34 template bool is_permuted(const std::vector & strides) { 35 for (size_t i = 0; i < strides.size() - 1; ++i) { 36 if (strides[i] < strides[i + 1]) { 37 return true; 38 } 39 } 40 return false; 41 } 42 43 template std::vector permute(const std::vector & x, const std::vector & perm) { 44 std::vector result; 45 result.reserve(perm.size()); 46 for (int i : perm) { 47 result.push_back(x[i]); 48 } 49 return result; 50 } 51 52 std::shared_ptr get_dimensions(const std::shared_ptr & shape, 53 const std::vector & dims); 54 std::shared_ptr get_dimensions(const std::shared_ptr & node, const std::vector & dims); 55 56 OutputVector rename_outputs_with_suffix(const OutputVector & outputs, const std::string & suffix); 57 58 std::pair, ov::Output> make_sin_cos(int32_t * rope_params, 59 std::shared_ptr inp_pos, 60 std::shared_ptr rope_freqs_weight = nullptr, 61 int mode = 0, 62 bool stateful = false, 63 int64_t head_dim = 0); 64 65 ov::Output process_view_input(const NodeContext & context, int input_index, int slice_len = 0, int axis = -1); 66 67 ov::Output process_view_input_new(const NodeContext & context, int input_index); 68 69 namespace op { 70 template OutputVector translate_1to1_match_2_inputs(const NodeContext & context) { 71 num_inputs_check(context, 2, 2); 72 auto input_0 = process_view_input_new(context, 0); 73 auto input_1 = process_view_input_new(context, 1); 74 75 auto output_type = context.get_output_type(); 76 if (input_0.get_element_type() != input_1.get_element_type()) { 77 if (input_0.get_element_type() != ov::element::f32) { 78 input_0 = std::make_shared(input_0, ov::element::f32); 79 } 80 if (input_1.get_element_type() != ov::element::f32) { 81 input_1 = std::make_shared(input_1, ov::element::f32); 82 } 83 } 84 85 ov::Output res = std::make_shared(input_0, input_1); 86 if (res.get_element_type() != output_type) { 87 res = std::make_shared(res, output_type); 88 } 89 return rename_outputs_with_suffix({res}, context.get_name()); 90 } 91 92 template OutputVector translate_1to1_match_1_input(const NodeContext & context) { 93 num_inputs_check(context, 1, 1); 94 auto input = process_view_input_new(context, 0); 95 auto res = std::make_shared(input); 96 return rename_outputs_with_suffix({res}, context.get_name()); 97 } 98 } // namespace op 99 100 } // namespace ggml 101 } // namespace frontend 102 } // namespace ov