1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
7 #include "ie_precision.hpp"
9 namespace InferenceEngine {
12 * @brief reverse trait for getting some precision from it's underlined memory type
13 * this might not work for certain precisions : for Q78, U16
17 struct precision_from_media {
18 static const Precision::ePrecision type = Precision::CUSTOM;
22 struct precision_from_media<float> {
23 static const Precision::ePrecision type = Precision::FP32;
27 struct precision_from_media<uint16_t> {
28 static const Precision::ePrecision type = Precision::FP16;
32 struct precision_from_media<int16_t> {
33 static const Precision::ePrecision type = Precision::I16;
37 struct precision_from_media<uint8_t> {
38 static const Precision::ePrecision type = Precision::U8;
42 struct precision_from_media<int8_t> {
43 static const Precision::ePrecision type = Precision::I8;
47 struct precision_from_media<int32_t> {
48 static const Precision::ePrecision type = Precision::I32;
52 * @brief container for storing both precision and it's underlined media type
55 template <class TMedia>
56 class TPrecision : public Precision {
58 typedef TMedia MediaType;
59 TPrecision() : Precision(precision_from_media<TMedia>::type) {}
60 explicit TPrecision(const Precision & that) : Precision(that) {}
61 TPrecision & operator = (const Precision & that) {
62 Precision::operator=(that);
65 explicit TPrecision(const Precision::ePrecision value) : Precision(value) {}
68 template <class T> TPrecision<T> createTPrecision() {
69 TPrecision<T> cnt(InferenceEngine::Precision::fromType<T>());
73 template <InferenceEngine::Precision::ePrecision T>
74 TPrecision<typename InferenceEngine::PrecisionTrait<T>::value_type> createTPrecision() {
75 TPrecision<typename InferenceEngine::PrecisionTrait<T>::value_type> cnt(T);
80 // special case for Mixed, or undefined precisions
82 class TPrecision<void> : public Precision {
84 typedef void MediaType;
85 TPrecision() = default;
86 explicit TPrecision(const Precision & that) : Precision(that) {}
87 TPrecision & operator = (const Precision & that) {
88 Precision::operator=(that);
91 explicit TPrecision(const Precision::ePrecision value) : Precision(value) {}
95 } // namespace InferenceEngine