xref: /aosp_15_r20/hardware/interfaces/neuralnetworks/1.2/types.t (revision 4d7e907c777eeecc4c5bd7cf640a754fac206ff7)
1%% template file for generating types.hal.
2%% see frameworks/ml/nn/tools/api/README.md.
3/*
4 * Copyright (C) 2018 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *      http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package [email protected];
20
21import @1.0::DataLocation;
22import @1.0::ErrorStatus;
23import @1.0::OperandLifeTime;
24import @1.0::OperandType;
25import @1.0::PerformanceInfo;
26import @1.1::OperationType;
27
28import [email protected]::Monostate;
29
30enum Constant : uint32_t {
31    /**
32     * The byte size of the cache token.
33     */
34    BYTE_SIZE_OF_CACHE_TOKEN = 32,
35
36    /**
37     * The maximum number of files for each type of cache in compilation caching.
38     */
39    MAX_NUMBER_OF_CACHE_FILES = 32,
40};
41
42enum OperandType : @1.0::OperandType {
43%insert Operand_1.2
44%insert OEMDeprecationAndOperandTypeRangeMaxComment
45};
46
47/**
48 * The range of operand values in the OperandType enum.
49 */
50enum OperandTypeRange : uint32_t {
51    BASE_MIN        = 0,
52    FUNDAMENTAL_MIN = 0,
53%insert Operand_1.2_MAX
54    OEM_MIN         = 10000,
55    OEM_MAX         = 10001,
56    BASE_MAX        = 0xFFFF,
57};
58
59/**
60 * Operation types.
61 *
62 * The type of an operation in a model.
63 */
64enum OperationType : int32_t {
65
66%insert Operation_1.0
67
68%insert Operation_1.1
69
70%insert Operation_1.2
71
72    /**
73     * DEPRECATED. Since NNAPI 1.2, extensions are the preferred alternative to
74     * OEM operation and data types.
75     *
76     * This operation is OEM specific. It should only be used for OEM
77     * applications.
78     */
79    OEM_OPERATION = @1.1::OperationType:OEM_OPERATION,
80    /* ADDING A NEW FUNDAMENTAL OPERATION REQUIRES UPDATING THE VALUE OF
81     * OperationTypeRange::FUNDAMENTAL_MAX.
82     */
83    /* ADDING A NEW OEM OPERATION REQUIRES UPDATING THE VALUE OF
84     * OperationTypeRange::OEM_MAX.
85     */
86};
87
88/**
89 * The range of values in the OperationType enum.
90 */
91enum OperationTypeRange : uint32_t {
92    BASE_MIN        = 0,
93    FUNDAMENTAL_MIN = 0,
94%insert Operation_1.2_MAX
95    OEM_MIN         = 10000,
96    OEM_MAX         = 10000,
97    BASE_MAX        = 0xFFFF,
98};
99
100%insert DeviceType
101
102%insert Capabilities
103
104%insert Operation
105
106%insert SymmPerChannelQuantParams
107
108%insert Operand
109
110%insert Model
111
112%insert OutputShape
113
114%insert MeasureTiming
115
116%insert Timing
117
118/**
119 * FmqRequestDatum is a single element of a serialized representation of an
120 * execution request (a {@link @1.0::Request} object and a {@link MeasureTiming}
121 * value) which is sent across FastMessageQueue.
122 *
123 * The serialized representation for a particular execution is referred to later
124 * in these descriptions as a 'packet'.
125 *
126 * FastMessageQueue can only pass HIDL-defined types that do not involve nested
127 * buffers, handles, or interfaces.
128 *
129 * The request is serialized as follows:
130 * 1) 'packetInformation'
131 * 2) For each input operand:
132 *    2.1) 'inputOperandInformation'
133 *    2.2) For each dimension element of the operand:
134 *         2.2.1) 'inputOperandDimensionValue'
135 * 3) For each output operand:
136 *    3.1) 'outputOperandInformation'
137 *    3.2) For each dimension element of the operand:
138 *         3.2.1) 'outputOperandDimensionValue'
139 * 4) For each pool:
140 *    4.1) 'poolIdentifier'
141 * 5) 'measureTiming'
142 */
143safe_union FmqRequestDatum {
144    /**
145     * Type to describe the high-level layout of the packet.
146     */
147    struct PacketInformation {
148        /**
149         * How many elements the packet contains, including the
150         * "packetInformation" datum.
151         */
152        uint32_t packetSize;
153
154        /**
155         * Number of input operands.
156         */
157        uint32_t numberOfInputOperands;
158
159        /**
160         * Number of output operands.
161         */
162        uint32_t numberOfOutputOperands;
163
164        /**
165         * Number of pool identifiers.
166         */
167        uint32_t numberOfPools;
168    };
169
170    /**
171     * Type representing the information for each operand.
172     */
173    struct OperandInformation {
174        /**
175         * If true, the argument does not have a value. This can be used for
176         * operations that take optional arguments. If true, the fields of
177         * 'location' are set to 0, 'numberOfDimensions' is set to 0,  and the
178         * dimensions information is omitted from the serialization.
179         */
180        bool hasNoValue;
181
182        /**
183         * The location within one of the memory pools passed in the Request.
184         */
185        DataLocation location;
186
187        /**
188         * Number of subsequent elements that belong to the dimensions vector.
189         */
190        uint32_t numberOfDimensions;
191    };
192
193    /**
194     * packetInformation is the first element of the packet and describes the
195     * remainder of the packet.
196     */
197    PacketInformation packetInformation;
198
199    /**
200     * Information for each input operand.
201     */
202    OperandInformation inputOperandInformation;
203
204    /**
205     * Element of the dimensions vector.
206     */
207    uint32_t inputOperandDimensionValue;
208
209    /**
210     * Information for each output operand.
211     */
212    OperandInformation outputOperandInformation;
213
214    /**
215     * Element of the dimensions vector.
216     */
217    uint32_t outputOperandDimensionValue;
218
219    /**
220     * Unique identifier for a pool.
221     *
222     * A {@link @1.0::Request} passes across one or more pools of shared memory
223     * for the inputs and outputs of an execution. However, these memory pools
224     * are not able to be sent across FastMessageQueue directly. Instead, the
225     * producing side of the FMQ represents each different pool with a unique
226     * identifier, and sends this identifier across the FMQ. Whenever the
227     * consuming side of the FMQ needs the memory corresponding to this unique
228     * identifier, it can pass the identifier to
229     * {@link IBurstCallback::getMemories} to retreive the memory. Although this
230     * HIDL Binder call is expensive compared to communication across FMQ, it is
231     * only needed in the cases when the consumer does not recognize the unique
232     * identifier.
233     */
234    int32_t poolIdentifier;
235
236    /**
237     * Specifies whether or not to measure duration of the execution. The
238     * duration runs from the time the driver dequeues the request from a
239     * FastMessageQueue to the time the driver enqueues results to a
240     * FastMessageQueue.
241     */
242    MeasureTiming measureTiming;
243};
244
245/**
246 * FmqResultDatum is a single element of a serialized representation of the
247 * values returned from an execution ({@link @1.0::ErrorStatus},
248 * vec<{@link OutputShape}>, and {@link Timing}) which is returned via
249 * FastMessageQueue.
250 *
251 * The serialized representation for a particular execution is referred to later
252 * in these descriptions as a 'packet'.
253 *
254 * FastMessageQueue can only pass HIDL-defined types that do not involve nested
255 * buffers, handles, or interfaces.
256 *
257 * The execution return values ({@link @1.0::ErrorStatus} and
258 * vec<{@link OutputShape}>) are serialized as follows:
259 * 1) 'packetInformation'
260 * 2) For each returned operand:
261 *    2.1) 'operandInformation'
262 *    2.2) For each dimension element of the operand:
263 *         2.2.1) 'operandDimensionValue'
264 * 3) 'executionTiming'
265 */
266safe_union FmqResultDatum {
267    /**
268     * Type to describe the high-level layout of the packet.
269     */
270    struct PacketInformation {
271        /**
272         * How many elements the packet contains, including the
273         * "packetInformation" datum.
274         */
275        uint32_t packetSize;
276
277        /**
278         * Status of the execution.
279         */
280        ErrorStatus errorStatus;
281
282        /**
283         * Number of returned operands.
284         */
285        uint32_t numberOfOperands;
286    };
287
288    /**
289     * Type representing the information for each operand.
290     */
291    struct OperandInformation {
292        /**
293         * Indicates whether the operand's output buffer is large enough to
294         * store the operand's result data.
295         */
296        bool isSufficient;
297
298        /**
299         * Number of subsequent elements that belong to the dimensions vector.
300         */
301        uint32_t numberOfDimensions;
302    };
303
304    /**
305     * packetInformation is the first element of the packet and describes the
306     * remainder of the packet. It additionally includes the status of the
307     * execution.
308     */
309    PacketInformation packetInformation;
310
311    /**
312     * Information for each returned operand.
313     */
314    OperandInformation operandInformation;
315
316    /**
317     * Element of the dimensions vector.
318     */
319    uint32_t operandDimensionValue;
320
321    /**
322     * Duration of execution. Unless measurement was requested and execution
323     * succeeds, all times must be reported as UINT64_MAX. A driver may choose
324     * to report any time as UINT64_MAX, indicating that measurement is not
325     * available.
326     */
327    Timing executionTiming;
328};
329
330%insert Extension
331