forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathie_ngraph_utils.hpp
157 lines (148 loc) · 6.66 KB
/
ie_ngraph_utils.hpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright (C) 2018-2023 Intel Corporation
// SPDX-License-Identifier: Apache-2.0
//
#pragma once
#include <algorithm>
#include <string>
#include "cpp/ie_cnn_network.h"
#include "ie_precision.hpp"
#include "ngraph/type/element_type.hpp"
#include "openvino/core/type/element_type.hpp"
#include "openvino/runtime/common.hpp"
namespace InferenceEngine {
namespace details {
inline ::ngraph::element::Type convertPrecision(const Precision& precision) {
Precision::ePrecision pType = precision;
switch (pType) {
case Precision::UNSPECIFIED:
return ::ngraph::element::Type(::ngraph::element::Type_t::undefined);
case Precision::FP32:
return ::ngraph::element::Type(::ngraph::element::Type_t::f32);
case Precision::FP64:
return ::ngraph::element::Type(::ngraph::element::Type_t::f64);
case Precision::FP16:
return ::ngraph::element::Type(::ngraph::element::Type_t::f16);
case Precision::BF16:
return ::ngraph::element::Type(::ngraph::element::Type_t::bf16);
case Precision::U4:
return ::ngraph::element::Type(::ngraph::element::Type_t::u4);
case Precision::U8:
return ::ngraph::element::Type(::ngraph::element::Type_t::u8);
case Precision::I4:
return ::ngraph::element::Type(::ngraph::element::Type_t::i4);
case Precision::I8:
return ::ngraph::element::Type(::ngraph::element::Type_t::i8);
case Precision::U16:
return ::ngraph::element::Type(::ngraph::element::Type_t::u16);
case Precision::I16:
return ::ngraph::element::Type(::ngraph::element::Type_t::i16);
case Precision::I32:
return ::ngraph::element::Type(::ngraph::element::Type_t::i32);
case Precision::U32:
return ::ngraph::element::Type(::ngraph::element::Type_t::u32);
case Precision::I64:
return ::ngraph::element::Type(::ngraph::element::Type_t::i64);
case Precision::U64:
return ::ngraph::element::Type(::ngraph::element::Type_t::u64);
case Precision::BOOL:
return ::ngraph::element::Type(::ngraph::element::Type_t::boolean);
case Precision::BIN:
return ::ngraph::element::Type(::ngraph::element::Type_t::u1);
case Precision::Q78:
case Precision::MIXED:
case Precision::CUSTOM:
default:
IE_THROW() << "Incorrect precision!";
}
}
inline ::ngraph::element::Type convertPrecision(const std::string& precision) {
if (precision == "f16" || precision == "FP16") {
return ::ngraph::element::Type(::ngraph::element::Type_t::f16);
} else if (precision == "f32" || precision == "FP32") {
return ::ngraph::element::Type(::ngraph::element::Type_t::f32);
} else if (precision == "bf16" || precision == "BF16") {
return ::ngraph::element::Type(::ngraph::element::Type_t::bf16);
} else if (precision == "f64" || precision == "FP64") {
return ::ngraph::element::Type(::ngraph::element::Type_t::f64);
} else if (precision == "i4" || precision == "I4") {
return ::ngraph::element::Type(::ngraph::element::Type_t::i4);
} else if (precision == "i8" || precision == "I8") {
return ::ngraph::element::Type(::ngraph::element::Type_t::i8);
} else if (precision == "i16" || precision == "I16") {
return ::ngraph::element::Type(::ngraph::element::Type_t::i16);
} else if (precision == "i32" || precision == "I32") {
return ::ngraph::element::Type(::ngraph::element::Type_t::i32);
} else if (precision == "i64" || precision == "I64") {
return ::ngraph::element::Type(::ngraph::element::Type_t::i64);
} else if (precision == "u1" || precision == "U1" || precision == "BIN" || precision == "bin") {
return ::ngraph::element::Type(::ngraph::element::Type_t::u1);
} else if (precision == "u4" || precision == "U4") {
return ::ngraph::element::Type(::ngraph::element::Type_t::u4);
} else if (precision == "u8" || precision == "U8") {
return ::ngraph::element::Type(::ngraph::element::Type_t::u8);
} else if (precision == "u16" || precision == "U16") {
return ::ngraph::element::Type(::ngraph::element::Type_t::u16);
} else if (precision == "u32" || precision == "U32") {
return ::ngraph::element::Type(::ngraph::element::Type_t::u32);
} else if (precision == "u64" || precision == "U64") {
return ::ngraph::element::Type(::ngraph::element::Type_t::u64);
} else if (precision == "boolean" || precision == "BOOL") {
return ::ngraph::element::Type(::ngraph::element::Type_t::boolean);
} else if (precision == "undefined") {
return ::ngraph::element::Type(::ngraph::element::Type_t::undefined);
} else {
IE_THROW() << "Incorrect precision: " << precision;
}
}
inline Precision convertPrecision(const ::ngraph::element::Type& precision) {
switch (precision) {
case ::ngraph::element::Type_t::undefined:
return Precision(Precision::UNSPECIFIED);
case ::ngraph::element::Type_t::f16:
return Precision(Precision::FP16);
case ::ngraph::element::Type_t::f32:
return Precision(Precision::FP32);
case ::ngraph::element::Type_t::f64:
return Precision(Precision::FP64);
case ::ngraph::element::Type_t::bf16:
return Precision(Precision::BF16);
case ::ngraph::element::Type_t::i4:
return Precision(Precision::I4);
case ::ngraph::element::Type_t::i8:
return Precision(Precision::I8);
case ::ngraph::element::Type_t::i16:
return Precision(Precision::I16);
case ::ngraph::element::Type_t::i32:
return Precision(Precision::I32);
case ::ngraph::element::Type_t::i64:
return Precision(Precision::I64);
case ::ngraph::element::Type_t::u4:
return Precision(Precision::U4);
case ::ngraph::element::Type_t::u8:
return Precision(Precision::U8);
case ::ngraph::element::Type_t::u16:
return Precision(Precision::U16);
case ::ngraph::element::Type_t::u32:
return Precision(Precision::U32);
case ::ngraph::element::Type_t::u64:
return Precision(Precision::U64);
case ::ngraph::element::Type_t::u1:
return Precision(Precision::BIN);
case ::ngraph::element::Type_t::boolean:
return Precision(Precision::BOOL);
case ::ngraph::element::Type_t::dynamic:
return Precision(Precision::UNSPECIFIED);
default:
IE_THROW() << "Incorrect precision " << precision.get_type_name() << "!";
return {};
}
}
/**
* @brief Clones input network including all layers and internal data objects
* @note Blobs inside layers are reused
* @param network A network to clone
* @return A cloned object
*/
INFERENCE_ENGINE_API_CPP(CNNNetwork) cloneNetwork(const CNNNetwork& network);
} // namespace details
} // namespace InferenceEngine