forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevaluates_map.cpp
116 lines (103 loc) · 3.42 KB
/
evaluates_map.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Copyright (C) 2018-2024 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#include "evaluates_map.hpp"
#include "ops/ops_evaluates.hpp"
std::vector<float> get_floats(const ov::Tensor& input, const ov::Shape& shape) {
size_t input_size = ov::shape_size(shape);
std::vector<float> result(input_size);
switch (input.get_element_type()) {
case ov::element::bf16: {
ov::bfloat16* p = input.data<ov::bfloat16>();
for (size_t i = 0; i < input_size; ++i) {
result[i] = float(p[i]);
}
} break;
case ov::element::f16: {
ov::float16* p = input.data<ov::float16>();
for (size_t i = 0; i < input_size; ++i) {
result[i] = float(p[i]);
}
} break;
case ov::element::f32: {
float* p = input.data<float>();
memcpy(result.data(), p, input_size * sizeof(float));
} break;
default:
throw std::runtime_error("Unsupported data type.");
break;
}
return result;
}
std::vector<int64_t> get_integers(const ov::Tensor& input, const ov::Shape& shape) {
size_t input_size = ov::shape_size(shape);
std::vector<int64_t> result(input_size);
switch (input.get_element_type()) {
case ov::element::Type_t::i8: {
auto p = input.data<int8_t>();
for (size_t i = 0; i < input_size; ++i) {
result[i] = int64_t(p[i]);
}
} break;
case ov::element::Type_t::i16: {
auto p = input.data<int16_t>();
for (size_t i = 0; i < input_size; ++i) {
result[i] = int64_t(p[i]);
}
} break;
case ov::element::Type_t::i32: {
auto p = input.data<int32_t>();
for (size_t i = 0; i < input_size; ++i) {
result[i] = int64_t(p[i]);
}
} break;
case ov::element::Type_t::i64: {
auto p = input.data<int64_t>();
for (size_t i = 0; i < input_size; ++i) {
result[i] = int64_t(p[i]);
}
} break;
case ov::element::Type_t::u8: {
auto p = input.data<uint8_t>();
for (size_t i = 0; i < input_size; ++i) {
result[i] = int64_t(p[i]);
}
} break;
case ov::element::Type_t::u16: {
auto p = input.data<uint16_t>();
for (size_t i = 0; i < input_size; ++i) {
result[i] = int64_t(p[i]);
}
} break;
case ov::element::Type_t::u32: {
auto p = input.data<uint32_t>();
for (size_t i = 0; i < input_size; ++i) {
result[i] = int64_t(p[i]);
}
} break;
case ov::element::Type_t::u64: {
auto p = input.data<uint64_t>();
for (size_t i = 0; i < input_size; ++i) {
result[i] = int64_t(p[i]);
}
} break;
default:
throw std::runtime_error("Unsupported data type in op NonMaxSuppression-5");
break;
}
return result;
}
std::vector<int64_t> get_signal_size(const ov::TensorVector& inputs, size_t num_of_axes) {
if (inputs.size() == 3) {
return get_integers(inputs[2], inputs[2].get_shape());
}
return std::vector<int64_t>(num_of_axes, static_cast<int64_t>(-1));
}
ov::runtime::interpreter::EvaluatorsMap& ov::runtime::interpreter::get_evaluators_map() {
static runtime::interpreter::EvaluatorsMap evaluatorsMap{
#define _OPENVINO_OP_REG(NAME, NAMESPACE) {NAMESPACE::NAME::get_type_info_static(), evaluate_node<NAMESPACE::NAME>},
#include "opset_int_tbl.hpp"
#undef _OPENVINO_OP_REG
};
return evaluatorsMap;
}