OSDN Git Service

Add FusedActivationFunc enum and renamed certain operations.
[android-x86/hardware-interfaces.git] / neuralnetworks / 1.0 / types.hal
1 /*
2  * Copyright (C) 2017 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 /* This HAL is a work in progress */
18
19 package android.hardware.neuralnetworks@1.0;
20
21 // The types an operand can have.
22 // These values are the same as found in the NeuralNetworks.h file.
23 // When modifying, be sure to update HAL_NUM_OPERAND_TYPES in HalIntefaces.h.
24 enum OperandType : uint32_t {
25     FLOAT16                   = 0,
26     FLOAT32                   = 1,
27     INT8                      = 2,
28     UINT8                     = 3,
29     INT16                     = 4,
30     UINT16                    = 5,
31     INT32                     = 6,
32     UINT32                    = 7,
33     TENSOR_FLOAT16            = 8,
34     TENSOR_FLOAT32            = 9,
35     TENSOR_INT32              = 10,
36     TENSOR_QUANT8_ASYMM       = 11,
37 };
38
39 // The type of operations.  Unlike the operation types found in
40 // NeuralNetworks.h file, these specify the data type they operate on.
41 // This is done to simplify the work of drivers.
42 // TODO: Currently they are the same.  Add a conversion when finalizing the model.
43 // When modifying, be sure to update HAL_NUM_OPERATION_TYPES in HalIntefaces.h.
44 enum OperationType : uint32_t {
45     OEM_OPERATION                = 0,
46     ADD                          = 1,
47     AVERAGE_POOL_2D              = 2,
48     CONCATENATION                = 3,
49     CONV_2D                      = 4,
50     DEPTHWISE_CONV_2D            = 5,
51     DEPTH_TO_SPACE               = 6,
52     DEQUANTIZE                   = 7,
53     EMBEDDING_LOOKUP             = 8,
54     FAKE_QUANT                   = 9,
55     FLOOR                        = 10,
56     FULLY_CONNECTED              = 11,
57     HASHTABLE_LOOKUP             = 12,
58     L2_NORMALIZATION             = 13,
59     L2_POOL_2D                   = 14,
60     LOCAL_RESPONSE_NORMALIZATION = 15,
61     LOGISTIC                     = 16,
62     LSH_PROJECTION               = 17,
63     LSTM                         = 18,
64     MAX_POOL_2D                  = 19,
65     MUL                          = 20,
66     RELU                         = 21,
67     RELU1                        = 22,
68     RELU6                        = 23,
69     RESHAPE                      = 24,
70     RESIZE_BILINEAR              = 25,
71     RNN                          = 26,
72     SOFTMAX                      = 27,
73     SPACE_TO_DEPTH               = 28,
74     SVDF                         = 29,
75     TANH                         = 30,
76 };
77
78 // Fused activation functions
79 enum FusedActivationFunc : int32_t {
80     NONE  = 0,
81     RELU  = 1,
82     RELU1 = 2,
83     RELU6 = 3,
84 };
85
86 // Two special values that can be used instead of a regular poolIndex.
87 enum LocationValues : uint32_t {
88     // The location will be specified at runtime. It's either a temporary
89     // variable, an input, or an output.
90     LOCATION_AT_RUN_TIME = 0xFFFFFFFF,
91     // The operand's value is stored in the
92     // TODO: Only for old
93     LOCATION_SAME_BLOCK = 0xFFFFFFFE
94 };
95
96 // Status of a device.
97 enum DeviceStatus : uint32_t {
98     AVAILABLE,
99     BUSY,
100     OFFLINE,
101     UNKNOWN  // Do we need this?
102 };
103
104 // For the reference workload
105 // Used by a driver to report its performance characteristics.
106 // TODO revisit the data types and scales.
107 struct PerformanceInfo {
108     float execTime;    // in nanoseconds
109     float powerUsage;  // in picoJoules
110 };
111
112 struct OperationTuple {
113     // The type of operation.
114     OperationType operationType;
115     // The input data type of operation.
116     OperandType operandType;
117 };
118
119 // The capabilities of a driver.
120 struct Capabilities {
121     vec<OperationTuple> supportedOperationTuples;
122     // TODO Do the same for baseline model IDs
123     bool cachesCompilation;
124     // TODO revisit the data types and scales.
125     float bootupTime;  // in nanoseconds
126     PerformanceInfo float16Performance;
127     PerformanceInfo float32Performance;
128     PerformanceInfo quantized8Performance;
129 };
130
131 // Describes the location of a data object.
132 struct DataLocation {
133     // The index of the memory pool where this location is found.
134     // Two special values can also be used.  See the LOCATION_* constants above.
135     uint32_t poolIndex;
136     // Offset in bytes from the start of the pool.
137     uint32_t offset;
138     // The length of the data, in bytes.
139     uint32_t length;
140 };
141
142 struct Operand {
143     OperandType type;
144     vec<uint32_t> dimensions;
145
146     // The number of operations that uses this operand as input.
147     // TODO It would be nice to track the actual consumers, e.g. vec<uint32_t> consumers;
148     uint32_t numberOfConsumers;
149
150     float scale;
151     int32_t zeroPoint;
152
153     // Where to find the data for this operand.
154     DataLocation location;
155 };
156
157 // Describes one operation of the graph.
158 struct Operation {
159     // The tuple describing the operation type and input type.
160     OperationTuple opTuple;
161     // Describes the table that contains the indexes of the inputs of the
162     // operation. The offset is the index in the operandIndexes table.
163     vec<uint32_t> inputs;
164     // Describes the table that contains the indexes of the outputs of the
165     // operation. The offset is the index in the operandIndexes table.
166     vec<uint32_t> outputs;
167 };
168
169 struct InputOutputInfo {
170     DataLocation location;
171     // If dimensions.size() > 0, we have updated dimensions.
172     vec<uint32_t> dimensions;
173 };
174
175 struct Model {
176     vec<Operand> operands;
177     vec<Operation> operations;
178     vec<uint32_t> inputIndexes;
179     vec<uint32_t> outputIndexes;
180     vec<uint8_t> operandValues;
181     vec<memory> pools;
182 };
183
184 struct Request {
185     vec<InputOutputInfo> inputs;
186     vec<InputOutputInfo> outputs;
187     vec<memory> pools;
188 };
189
190 enum Status : uint32_t {
191     SUCCESS,
192     ERROR,
193 };