blob: ba163342b8cca03603cec82cf671a9890af48a9b [file] [log] [blame]
Xusong Wang1a06e772018-10-31 08:43:12 -07001/*
2 * Copyright (C) 2018 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
17package android.hardware.neuralnetworks@1.2;
18
19import @1.0::ErrorStatus;
20import @1.0::IPreparedModel;
21import @1.0::Request;
Michael Butlera06e2612019-01-15 10:52:41 -080022import IBurstCallback;
23import IBurstContext;
Xusong Wang1a06e772018-10-31 08:43:12 -070024import IExecutionCallback;
25
26/**
27 * IPreparedModel describes a model that has been prepared for execution and
28 * is used to launch executions.
29 */
30interface IPreparedModel extends @1.0::IPreparedModel {
31 /**
32 * Launches an asynchronous execution on a prepared model.
33 *
34 * The execution is performed asynchronously with respect to the caller.
35 * execute_1_2 must verify the inputs to the function are correct. If there is
36 * an error, execute_1_2 must immediately invoke the callback with the
37 * appropriate ErrorStatus value, then return with the same ErrorStatus. If
38 * the inputs to the function are valid and there is no error, execute_1_2 must
39 * launch an asynchronous task to perform the execution in the background,
40 * and immediately return with ErrorStatus::NONE. If the asynchronous task
41 * fails to launch, execute_1_2 must immediately invoke the callback with
42 * ErrorStatus::GENERAL_FAILURE, then return with
43 * ErrorStatus::GENERAL_FAILURE.
44 *
45 * When the asynchronous task has finished its execution, it must
46 * immediately invoke the callback object provided as an input to the
47 * execute_1_2 function. This callback must be provided with the ErrorStatus of
48 * the execution.
49 *
David Grossf406bf92019-06-20 13:30:54 -070050 * If the launch is successful, the caller must not change the content of
51 * any data object referenced by 'request' (described by the
52 * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}) until the
53 * asynchronous task has invoked the callback object. The asynchronous task
54 * must not change the content of any of the data objects corresponding to
55 * 'request' inputs.
56 *
Xusong Wang1a06e772018-10-31 08:43:12 -070057 * If the prepared model was prepared from a model wherein all
58 * tensor operands have fully specified dimensions, and the inputs
59 * to the function are valid, then the execution should launch
60 * and complete successfully (ErrorStatus::NONE). There must be
61 * no failure unless the device itself is in a bad state.
62 *
David Gross4592ed12018-12-21 11:20:26 -080063 * Any number of calls to the execute, execute_1_2, and executeSynchronously
64 * functions, in any combination, may be made concurrently, even on the same
65 * IPreparedModel object.
Xusong Wang1a06e772018-10-31 08:43:12 -070066 *
67 * @param request The input and output information on which the prepared
68 * model is to be executed.
David Gross55a3d322019-01-23 14:01:52 -080069 * @param measure Specifies whether or not to measure duration of the execution.
70 * The duration runs from the time the driver sees the call
71 * to the execute_1_2 function to the time the driver invokes
72 * the callback.
Xusong Wang1a06e772018-10-31 08:43:12 -070073 * @param callback A callback object used to return the error status of
74 * the execution. The callback object's notify function must
75 * be called exactly once, even if the execution was
76 * unsuccessful.
77 * @return status Error status of the call, must be:
78 * - NONE if task is successfully launched
79 * - DEVICE_UNAVAILABLE if driver is offline or busy
80 * - GENERAL_FAILURE if there is an unspecified error
81 * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is
82 * not large enough to store the resultant values
83 * - INVALID_ARGUMENT if one of the input arguments is
84 * invalid
85 */
David Gross55a3d322019-01-23 14:01:52 -080086 execute_1_2(Request request, MeasureTiming measure, IExecutionCallback callback)
Xusong Wang1a06e772018-10-31 08:43:12 -070087 generates (ErrorStatus status);
David Gross4592ed12018-12-21 11:20:26 -080088
89 /**
90 * Performs a synchronous execution on a prepared model.
91 *
92 * The execution is performed synchronously with respect to the caller.
93 * executeSynchronously must verify the inputs to the function are
94 * correct. If there is an error, executeSynchronously must immediately
95 * return with the appropriate ErrorStatus value. If the inputs to the
96 * function are valid and there is no error, executeSynchronously must
97 * perform the execution, and must not return until the execution is
98 * complete.
99 *
David Grossf406bf92019-06-20 13:30:54 -0700100 * The caller must not change the content of any data object referenced by
101 * 'request' (described by the {@link @1.0::DataLocation} of a
102 * {@link @1.0::RequestArgument}) until executeSynchronously
103 * returns. executeSynchronously must not change the content of any of the
104 * data objects corresponding to 'request' inputs.
105 *
David Gross4592ed12018-12-21 11:20:26 -0800106 * If the prepared model was prepared from a model wherein all tensor
107 * operands have fully specified dimensions, and the inputs to the function
108 * are valid, then the execution should complete successfully
109 * (ErrorStatus::NONE). There must be no failure unless the device itself is
110 * in a bad state.
111 *
112 * Any number of calls to the execute, execute_1_2, and executeSynchronously
113 * functions, in any combination, may be made concurrently, even on the same
114 * IPreparedModel object.
115 *
116 * @param request The input and output information on which the prepared
117 * model is to be executed.
David Gross55a3d322019-01-23 14:01:52 -0800118 * @param measure Specifies whether or not to measure duration of the execution.
119 * The duration runs from the time the driver sees the call
120 * to the executeSynchronously function to the time the driver
121 * returns from the function.
David Gross4592ed12018-12-21 11:20:26 -0800122 * @return status Error status of the execution, must be:
123 * - NONE if execution is performed successfully
124 * - DEVICE_UNAVAILABLE if driver is offline or busy
125 * - GENERAL_FAILURE if there is an unspecified error
Michael Butlera06e2612019-01-15 10:52:41 -0800126 * - OUTPUT_INSUFFICIENT_SIZE if at least one output
127 * operand buffer is not large enough to store the
128 * corresponding output
David Gross4592ed12018-12-21 11:20:26 -0800129 * - INVALID_ARGUMENT if one of the input arguments is
130 * invalid
Michael Butlera06e2612019-01-15 10:52:41 -0800131 * @return outputShapes A list of shape information of model output operands.
132 * The index into "outputShapes" corresponds to the index
133 * of the output operand in the Request outputs vector.
134 * outputShapes must be empty unless the status is either
135 * NONE or OUTPUT_INSUFFICIENT_SIZE.
David Gross55a3d322019-01-23 14:01:52 -0800136 * @return Timing Duration of execution. Unless measure is YES and status is
137 * NONE, all times must be reported as UINT64_MAX. A driver may
138 * choose to report any time as UINT64_MAX, indicating that
139 * measurement is not available.
David Gross4592ed12018-12-21 11:20:26 -0800140 */
David Gross55a3d322019-01-23 14:01:52 -0800141 executeSynchronously(Request request, MeasureTiming measure)
142 generates (ErrorStatus status, vec<OutputShape> outputShapes, Timing timing);
Michael Butlera06e2612019-01-15 10:52:41 -0800143
144 /**
145 * Configure a Burst object used to execute multiple inferences on a
146 * prepared model in rapid succession.
147 *
148 * @param callback A callback object used to retrieve memory resources
149 * corresponding to a unique identifiers ("slots").
150 * @param requestChannel Used by the client to send a serialized Request to
David Grossf406bf92019-06-20 13:30:54 -0700151 * the Burst for execution. The client must not change
152 * the content of any data object referenced by the
153 * Request (described by the {@link @1.0::DataLocation}
154 * of an {@link OperandInformation}) until a result
155 * has been received from resultChannel. Execution
156 * must not change the content of any of the data
157 * objects corresponding to Request inputs. requestChannel
158 * must not be used to pass a second Request object
159 * until a result has been received from resultChannel.
Michael Butlera06e2612019-01-15 10:52:41 -0800160 * @param resultChannel Used by the service to return the results of an
161 * execution to the client: the status of the execution
162 * and OutputShape of all output tensors. resultChannel
163 * must be used to return the results if a Request was
164 * sent through the requestChannel.
165 * @return status Error status of configuring the execution burst, must be:
166 * - NONE if the burst is successfully configured
167 * - DEVICE_UNAVAILABLE if driver is offline or busy
168 * - GENERAL_FAILURE if there is an unspecified error
169 * - INVALID_ARGUMENT if one of the input arguments is
170 * invalid
171 * @return context Object containing all resources (such as cached
172 * hidl_memory) related to a Burst if successful, otherwise
173 * nullptr.
174 */
175 configureExecutionBurst(IBurstCallback callback,
176 fmq_sync<FmqRequestDatum> requestChannel,
177 fmq_sync<FmqResultDatum> resultChannel)
178 generates (ErrorStatus status, IBurstContext context);
Xusong Wang1a06e772018-10-31 08:43:12 -0700179};