HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
to_tensor_proto_element_type.h
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License.
3 
4 #pragma once
5 
6 #include <cstdint>
7 #include <string>
8 
9 #ifndef SHARED_PROVIDER
10 #include "core/graph/onnx_protobuf.h"
11 #endif
12 
13 #include "core/framework/float8.h"
14 #include "core/framework/float16.h"
15 #include "core/framework/int4.h"
16 
17 namespace onnxruntime {
18 namespace utils {
19 /** Gets the TensorProto_DataType corresponding to the template type `T`. */
20 template <typename T>
21 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType() {
22  return ONNX_NAMESPACE::TensorProto_DataType_UNDEFINED;
23 }
24 template <>
25 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<float>() {
26  return ONNX_NAMESPACE::TensorProto_DataType_FLOAT;
27 }
28 template <>
29 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<uint8_t>() {
30  return ONNX_NAMESPACE::TensorProto_DataType_UINT8;
31 }
32 template <>
33 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<int8_t>() {
34  return ONNX_NAMESPACE::TensorProto_DataType_INT8;
35 }
36 template <>
37 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<uint16_t>() {
38  return ONNX_NAMESPACE::TensorProto_DataType_UINT16;
39 }
40 template <>
41 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<int16_t>() {
42  return ONNX_NAMESPACE::TensorProto_DataType_INT16;
43 }
44 template <>
45 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<int32_t>() {
46  return ONNX_NAMESPACE::TensorProto_DataType_INT32;
47 }
48 template <>
49 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<int64_t>() {
50  return ONNX_NAMESPACE::TensorProto_DataType_INT64;
51 }
52 template <>
53 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<std::string>() {
54  return ONNX_NAMESPACE::TensorProto_DataType_STRING;
55 }
56 template <>
57 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<bool>() {
58  return ONNX_NAMESPACE::TensorProto_DataType_BOOL;
59 }
60 template <>
61 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<MLFloat16>() {
62  return ONNX_NAMESPACE::TensorProto_DataType_FLOAT16;
63 }
64 template <>
65 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<double>() {
66  return ONNX_NAMESPACE::TensorProto_DataType_DOUBLE;
67 }
68 template <>
69 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<uint32_t>() {
70  return ONNX_NAMESPACE::TensorProto_DataType_UINT32;
71 }
72 template <>
73 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<uint64_t>() {
74  return ONNX_NAMESPACE::TensorProto_DataType_UINT64;
75 }
76 template <>
77 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<BFloat16>() {
78  return ONNX_NAMESPACE::TensorProto_DataType_BFLOAT16;
79 }
80 
81 #if !defined(DISABLE_FLOAT8_TYPES)
82 
83 template <>
84 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<Float8E4M3FN>() {
85  return ONNX_NAMESPACE::TensorProto_DataType_FLOAT8E4M3FN;
86 }
87 template <>
88 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<Float8E4M3FNUZ>() {
89  return ONNX_NAMESPACE::TensorProto_DataType_FLOAT8E4M3FNUZ;
90 }
91 template <>
92 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<Float8E5M2>() {
93  return ONNX_NAMESPACE::TensorProto_DataType_FLOAT8E5M2;
94 }
95 template <>
96 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<Float8E5M2FNUZ>() {
97  return ONNX_NAMESPACE::TensorProto_DataType_FLOAT8E5M2FNUZ;
98 }
99 
100 #endif
101 template <>
102 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<Int4x2>() {
103  return ONNX_NAMESPACE::TensorProto_DataType_INT4;
104 }
105 template <>
106 constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType<UInt4x2>() {
107  return ONNX_NAMESPACE::TensorProto_DataType_UINT4;
108 }
109 
110 } // namespace utils
111 } // namespace onnxruntime
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< uint8_t >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< Float8E4M3FN >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< Float8E4M3FNUZ >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< uint32_t >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< Int4x2 >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< Float8E5M2FNUZ >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< bool >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< int32_t >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< uint16_t >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< uint64_t >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< int8_t >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< MLFloat16 >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< Float8E5M2 >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< int64_t >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< int16_t >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< BFloat16 >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< double >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< float >()
constexpr ONNX_NAMESPACE::TensorProto_DataType ToTensorProtoElementType< UInt4x2 >()