• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ANDROID_FRAMEWORKS_ML_NN_COMMON_NNAPI_OPERAND_TYPES_H
18 #define ANDROID_FRAMEWORKS_ML_NN_COMMON_NNAPI_OPERAND_TYPES_H
19 
20 namespace android::nn {
21 
22 /**
23  * Operand types.
24  *
25  * The type of an operand in a model.
26  *
27  * Types prefaced with TENSOR_* must be used for tensor data (i.e., tensors
28  * with at least one dimension). Types not prefaced by TENSOR_* represent
29  * scalar values and must have no dimensions.
30  *
31  * Although we define many types, most operators accept just a few
32  * types. Most used are {@link OperandType::TENSOR_FLOAT32},
33  * {@link OperandType::TENSOR_QUANT8_ASYMM},
34  * and {@link OperandType::INT32}.
35  */
36 enum class OperandType {
37     /** A 32 bit floating point scalar value. */
38     FLOAT32 = 0,
39 
40     /** A signed 32 bit integer scalar value. */
41     INT32 = 1,
42 
43     /** An unsigned 32 bit integer scalar value. */
44     UINT32 = 2,
45 
46     /** A tensor of 32 bit floating point values. */
47     TENSOR_FLOAT32 = 3,
48 
49     /** A tensor of 32 bit integer values. */
50     TENSOR_INT32 = 4,
51 
52     /**
53      * A tensor of 8 bit unsigned integers that represent real numbers.
54      *
55      * Attached to this tensor are two numbers that can be used to convert the
56      * 8 bit integer to the real value and vice versa. These two numbers are:
57      * - scale: a 32 bit floating point value greater than zero.
58      * - zeroPoint: a 32 bit integer, in range [0, 255].
59      *
60      * The formula is:
61      *   real_value = (integer_value - zeroPoint) * scale.
62      */
63     TENSOR_QUANT8_ASYMM = 5,
64 
65     /**
66      * An 8 bit boolean scalar value.
67      *
68      * Values of this operand type are either true or false. A zero value
69      * represents false; any other value represents true.
70      */
71     BOOL = 6,
72 
73     /**
74      * A tensor of 16 bit signed integers that represent real numbers.
75      *
76      * Attached to this tensor is a number representing real value scale that is
77      * used to convert the 16 bit number to a real value in the following way:
78      * realValue = integerValue * scale.
79      *
80      * scale is a 32 bit floating point with value greater than zero.
81      */
82     TENSOR_QUANT16_SYMM = 7,
83 
84     /**
85      * A tensor of IEEE 754 16 bit floating point values.
86      */
87     TENSOR_FLOAT16 = 8,
88 
89     /**
90      * A tensor of 8 bit boolean values.
91      *
92      * Values of this operand type are either true or false. A zero value
93      * represents false; any other value represents true.
94      */
95     TENSOR_BOOL8 = 9,
96 
97     /**
98      * An IEEE 754 16 bit floating point scalar value.
99      */
100     FLOAT16 = 10,
101 
102     /**
103      * A tensor of 8 bit signed integers that represent real numbers.
104      *
105      * This tensor is associated with additional fields that can
106      * be used to convert the 8 bit signed integer to the real value and vice versa.
107      * These fields are:
108      * - channelDim: a 32 bit unsigned integer indicating channel dimension.
109      * - scales: an array of positive 32 bit floating point values.
110      * The size of the scales array must be equal to dimensions[channelDim].
111      *
112      *{@link SymmPerChannelQuantParams} must hold the parameters for an Operand of this type.
113      * The channel dimension of this tensor must not be unknown (dimensions[channelDim] != 0).
114      *
115      * The formula is:
116      * realValue[..., C, ...] =
117      *     integerValue[..., C, ...] * scales[C]
118      * where C is an index in the Channel dimension.
119      */
120     TENSOR_QUANT8_SYMM_PER_CHANNEL = 11,
121 
122     /**
123      * A tensor of 16 bit unsigned integers that represent real numbers.
124      *
125      * Attached to this tensor are two numbers that can be used to convert the
126      * 16 bit integer to the real value and vice versa. These two numbers are:
127      * - scale: a 32 bit floating point value greater than zero.
128      * - zeroPoint: a 32 bit integer, in range [0, 65535].
129      *
130      * The formula is:
131      * real_value = (integer_value - zeroPoint) * scale.
132      */
133     TENSOR_QUANT16_ASYMM = 12,
134 
135     /**
136      * A tensor of 8 bit signed integers that represent real numbers.
137      *
138      * Attached to this tensor is a number representing real value scale that is
139      * used to convert the 8 bit number to a real value in the following way:
140      * realValue = integerValue * scale.
141      *
142      * scale is a 32 bit floating point with value greater than zero.
143      */
144     TENSOR_QUANT8_SYMM = 13,
145 
146     /**
147      * A tensor of 8 bit signed integers that represent real numbers.
148      *
149      * Attached to this tensor are two numbers that can be used to convert the
150      * 8 bit integer to the real value and vice versa. These two numbers are:
151      * - scale: a 32 bit floating point value greater than zero.
152      * - zeroPoint: a 32 bit integer, in range [-128, 127].
153      *
154      * The formula is:
155      * real_value = (integer_value - zeroPoint) * scale.
156      */
157     TENSOR_QUANT8_ASYMM_SIGNED = 14,
158 
159     /**
160      * A reference to a subgraph.
161      *
162      * Must have the lifetime {@link Operand::LifeTime::SUBGRAPH}.
163      */
164     SUBGRAPH = 15,
165 
166     /**
167      * DEPRECATED. Since HAL version 1.2, extensions are the preferred
168      * alternative to OEM operation and data types.
169      *
170      * OEM specific scalar value.
171      */
172     OEM = 10000,
173 
174     /**
175      * DEPRECATED. Since HAL version 1.2, extensions are the preferred
176      * alternative to OEM operation and data types.
177      *
178      * A tensor of OEM specific values.
179      */
180     TENSOR_OEM_BYTE = 10001,
181 };
182 
183 }  // namespace android::nn
184 
185 #endif  // ANDROID_FRAMEWORKS_ML_NN_COMMON_NNAPI_OPERAND_TYPES_H
186