blob: 4ce3691d147cf673829e30cba46617109189c7ff [file] [log] [blame]
Xusong Wang62a760c2019-10-25 12:07:17 -07001/*
2 * Copyright (C) 2019 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.3;
18
Xusong Wang62a760c2019-10-25 12:07:17 -070019import @1.2::IPreparedModel;
Xusong Wangebd88ba2019-10-28 11:11:19 -070020import @1.2::MeasureTiming;
21import @1.2::OutputShape;
22import @1.2::Timing;
Michael Butlerc2499ec2019-12-11 18:31:12 -080023import ErrorStatus;
Miao Wang3fd70b02020-01-21 13:15:09 -080024import OptionalTimeoutDuration;
Michael Butlerc2499ec2019-12-11 18:31:12 -080025import OptionalTimePoint;
Xusong Wang931d5a12019-11-27 12:46:48 -080026import Request;
Michael Butlerc2499ec2019-12-11 18:31:12 -080027import IExecutionCallback;
Miao Wang90cf3dd2019-11-12 14:02:16 -080028import IFencedExecutionCallback;
Xusong Wang62a760c2019-10-25 12:07:17 -070029
30/**
31 * IPreparedModel describes a model that has been prepared for execution and
32 * is used to launch executions.
33 */
34interface IPreparedModel extends @1.2::IPreparedModel {
35 /**
36 * Launches an asynchronous execution on a prepared model.
37 *
38 * The execution is performed asynchronously with respect to the caller.
Xusong Wang931d5a12019-11-27 12:46:48 -080039 * execute_1_3 must verify the inputs to the function are correct, and the usages
40 * of memory pools allocated by IDevice::allocate are valid. If there is
Xusong Wang62a760c2019-10-25 12:07:17 -070041 * an error, execute_1_3 must immediately invoke the callback with the
42 * appropriate ErrorStatus value, then return with the same ErrorStatus. If
43 * the inputs to the function are valid and there is no error, execute_1_3 must
44 * launch an asynchronous task to perform the execution in the background,
45 * and immediately return with ErrorStatus::NONE. If the asynchronous task
46 * fails to launch, execute_1_3 must immediately invoke the callback with
47 * ErrorStatus::GENERAL_FAILURE, then return with
48 * ErrorStatus::GENERAL_FAILURE.
49 *
50 * When the asynchronous task has finished its execution, it must
51 * immediately invoke the callback object provided as an input to the
52 * execute_1_3 function. This callback must be provided with the ErrorStatus of
53 * the execution.
54 *
55 * If the launch is successful, the caller must not change the content of
56 * any data object referenced by 'request' (described by the
57 * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}) until the
58 * asynchronous task has invoked the callback object. The asynchronous task
59 * must not change the content of any of the data objects corresponding to
60 * 'request' inputs.
61 *
62 * If the prepared model was prepared from a model wherein all tensor
63 * operands have fully specified dimensions, and the inputs to the function
64 * are valid, then:
65 * - the execution should launch successfully (ErrorStatus::NONE): There
66 * must be no failure unless the device itself is in a bad state.
67 * - if at execution time every operation's input operands have legal
68 * values, the execution should complete successfully (ErrorStatus::NONE):
69 * There must be no failure unless the device itself is in a bad state.
70 *
Michael Butlerc2499ec2019-12-11 18:31:12 -080071 * execute_1_3 can be called with an optional deadline. If the execution
Miao Wang3fd70b02020-01-21 13:15:09 -080072 * is not able to be completed before the provided deadline, the execution
Michael Butlerc2499ec2019-12-11 18:31:12 -080073 * must be aborted, and either {@link
74 * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
75 * ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
76 * to an abort must be sent the same way as other errors, described above.
77 * If the service reports that it does not support execution deadlines via
78 * IDevice::supportsDeadlines, and execute_1_3 is called with a deadline,
79 * then the argument is invalid, and {@link ErrorStatus::INVALID_ARGUMENT}
80 * must be returned.
81 *
Xusong Wangebd88ba2019-10-28 11:11:19 -070082 * Any number of calls to the execute* and executeSynchronously* functions,
83 * in any combination, may be made concurrently, even on the same
Xusong Wang62a760c2019-10-25 12:07:17 -070084 * IPreparedModel object.
85 *
86 * @param request The input and output information on which the prepared
87 * model is to be executed.
88 * @param measure Specifies whether or not to measure duration of the execution.
89 * The duration runs from the time the driver sees the call
90 * to the execute_1_3 function to the time the driver invokes
91 * the callback.
Miao Wang3fd70b02020-01-21 13:15:09 -080092 * @param deadline The time by which the execution must complete. If the
Michael Butlerc2499ec2019-12-11 18:31:12 -080093 * execution cannot be finished by the deadline, the
94 * execution must be aborted.
Slava Shklyaevf034bf92020-02-11 14:27:02 +000095 * @param loopTimeoutDuration The maximum amount of time that should be spent
96 * executing a {@link OperationType::WHILE}
97 * operation. If a loop condition model does not
98 * output false within this duration, the
99 * execution must be aborted. If the model
100 * contains a {@link OperationType::WHILE}
101 * operation and no loop timeout duration is
102 * provided, the maximum amount of time is {@link
103 * LoopTimeoutDurationNs::DEFAULT}. When
104 * provided, the duration must not exceed {@link
105 * LoopTimeoutDurationNs::MAXIMUM}.
Xusong Wang62a760c2019-10-25 12:07:17 -0700106 * @param callback A callback object used to return the error status of
Miao Wang90cf3dd2019-11-12 14:02:16 -0800107 * the execution, shape information of model output operands, and
108 * duration of execution. The callback object's notify function must
Xusong Wang62a760c2019-10-25 12:07:17 -0700109 * be called exactly once, even if the execution was
110 * unsuccessful.
111 * @return status Error status of the call, must be:
112 * - NONE if task is successfully launched
113 * - DEVICE_UNAVAILABLE if driver is offline or busy
114 * - GENERAL_FAILURE if there is an unspecified error
115 * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is
116 * not large enough to store the resultant values
117 * - INVALID_ARGUMENT if one of the input arguments is
118 * invalid
Michael Butlerc2499ec2019-12-11 18:31:12 -0800119 * - MISSED_DEADLINE_* if the deadline for executing a model
120 * cannot be met
121 * - RESOURCE_EXHAUSTED_* if the task was aborted by the
122 * driver
Xusong Wang62a760c2019-10-25 12:07:17 -0700123 */
Michael Butlerc2499ec2019-12-11 18:31:12 -0800124 execute_1_3(Request request, MeasureTiming measure, OptionalTimePoint deadline,
Slava Shklyaevf034bf92020-02-11 14:27:02 +0000125 OptionalTimeoutDuration loopTimeoutDuration, IExecutionCallback callback)
Xusong Wang62a760c2019-10-25 12:07:17 -0700126 generates (ErrorStatus status);
Xusong Wangebd88ba2019-10-28 11:11:19 -0700127
128 /**
129 * Performs a synchronous execution on a prepared model.
130 *
131 * The execution is performed synchronously with respect to the caller.
132 * executeSynchronously_1_3 must verify the inputs to the function are
Xusong Wang931d5a12019-11-27 12:46:48 -0800133 * correct, and the usages of memory pools allocated by IDevice::allocate
134 * are valid. If there is an error, executeSynchronously_1_3 must immediately
Xusong Wangebd88ba2019-10-28 11:11:19 -0700135 * return with the appropriate ErrorStatus value. If the inputs to the
136 * function are valid and there is no error, executeSynchronously_1_3 must
137 * perform the execution, and must not return until the execution is
138 * complete.
139 *
140 * The caller must not change the content of any data object referenced by
141 * 'request' (described by the {@link @1.0::DataLocation} of a
142 * {@link @1.0::RequestArgument}) until executeSynchronously_1_3
143 * returns. executeSynchronously_1_3 must not change the content of any of the
144 * data objects corresponding to 'request' inputs.
145 *
146 * If the prepared model was prepared from a model wherein all tensor
147 * operands have fully specified dimensions, and the inputs to the function
148 * are valid, and at execution time every operation's input operands have
149 * legal values, then the execution should complete successfully
150 * (ErrorStatus::NONE): There must be no failure unless the device itself is
151 * in a bad state.
152 *
Michael Butlerc2499ec2019-12-11 18:31:12 -0800153 * executeSynchronously_1_3 can be called with an optional deadline. If the
Miao Wang3fd70b02020-01-21 13:15:09 -0800154 * execution is not able to be completed before the provided deadline, the
Michael Butlerc2499ec2019-12-11 18:31:12 -0800155 * execution must be aborted, and either {@link
156 * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
157 * ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
158 * to an abort must be sent the same way as other errors, described above.
159 * If the service reports that it does not support execution deadlines via
160 * IDevice::supportsDeadlines, and executeSynchronously_1_3 is called with a
161 * deadline, then the argument is invalid, and
162 * {@link ErrorStatus::INVALID_ARGUMENT} must be returned.
163 *
Xusong Wangebd88ba2019-10-28 11:11:19 -0700164 * Any number of calls to the execute* and executeSynchronously* functions,
165 * in any combination, may be made concurrently, even on the same
166 * IPreparedModel object.
167 *
168 * @param request The input and output information on which the prepared
169 * model is to be executed.
170 * @param measure Specifies whether or not to measure duration of the execution.
171 * The duration runs from the time the driver sees the call
172 * to the executeSynchronously_1_3 function to the time the driver
173 * returns from the function.
Miao Wang3fd70b02020-01-21 13:15:09 -0800174 * @param deadline The time by which the execution must complete. If the
Michael Butlerc2499ec2019-12-11 18:31:12 -0800175 * execution cannot be finished by the deadline, the
176 * execution must be aborted.
Slava Shklyaevf034bf92020-02-11 14:27:02 +0000177 * @param loopTimeoutDuration The maximum amount of time that should be spent
178 * executing a {@link OperationType::WHILE}
179 * operation. If a loop condition model does not
180 * output false within this duration, the
181 * execution must be aborted. If the model
182 * contains a {@link OperationType::WHILE}
183 * operation and no loop timeout duration is
184 * provided, the maximum amount of time is {@link
185 * LoopTimeoutDurationNs::DEFAULT}. When
186 * provided, the duration must not exceed {@link
187 * LoopTimeoutDurationNs::MAXIMUM}.
Xusong Wangebd88ba2019-10-28 11:11:19 -0700188 * @return status Error status of the execution, must be:
189 * - NONE if execution is performed successfully
190 * - DEVICE_UNAVAILABLE if driver is offline or busy
191 * - GENERAL_FAILURE if there is an unspecified error
192 * - OUTPUT_INSUFFICIENT_SIZE if at least one output
193 * operand buffer is not large enough to store the
194 * corresponding output
195 * - INVALID_ARGUMENT if one of the input arguments is
196 * invalid
Michael Butlerc2499ec2019-12-11 18:31:12 -0800197 * - MISSED_DEADLINE_* if the deadline for executing a model
198 * cannot be met
199 * - RESOURCE_EXHAUSTED_* if the task was aborted by the
200 * driver
Xusong Wangebd88ba2019-10-28 11:11:19 -0700201 * @return outputShapes A list of shape information of model output operands.
202 * The index into "outputShapes" corresponds to the index
203 * of the output operand in the Request outputs vector.
204 * outputShapes must be empty unless the status is either
205 * NONE or OUTPUT_INSUFFICIENT_SIZE.
Michael Butlerc2499ec2019-12-11 18:31:12 -0800206 * @return timing Duration of execution. Unless measure is YES and status is
Xusong Wangebd88ba2019-10-28 11:11:19 -0700207 * NONE, all times must be reported as UINT64_MAX. A driver may
208 * choose to report any time as UINT64_MAX, indicating that
209 * measurement is not available.
210 */
Michael Butlerc2499ec2019-12-11 18:31:12 -0800211 executeSynchronously_1_3(Request request, MeasureTiming measure,
Slava Shklyaevf034bf92020-02-11 14:27:02 +0000212 OptionalTimePoint deadline,
213 OptionalTimeoutDuration loopTimeoutDuration)
Michael Butlerc2499ec2019-12-11 18:31:12 -0800214 generates (ErrorStatus status, vec<OutputShape> outputShapes,
215 Timing timing);
Miao Wang90cf3dd2019-11-12 14:02:16 -0800216
217 /**
218 * Launch a fenced asynchronous execution on a prepared model.
219 *
220 * The execution is performed asynchronously with respect to the caller.
Miao Wang3fd70b02020-01-21 13:15:09 -0800221 * executeFenced must verify the inputs to the function are correct, and the usages
222 * of memory pools allocated by IDevice::allocate are valid. If there is an error,
223 * executeFenced must immediately return with the corresponding ErrorStatus, an empty
224 * handle for syncFence, and nullptr for callback. If the inputs to the function
225 * are valid and there is no error, executeFenced must dispatch an asynchronous task
226 * to perform the execution in the background, and immediately return with
227 * ErrorStatus::NONE, a sync fence that will be signaled once the execution is completed,
228 * and a callback that can be used by the client to query the duration and runtime error
229 * status. If the task has finished before the call returns, an empty handle may be returned
230 * for syncFence. The execution must wait for all the sync fences (if any) in waitFor
231 * to be signaled before starting the actual execution.
Miao Wang90cf3dd2019-11-12 14:02:16 -0800232 *
233 * When the asynchronous task has finished its execution, it must
Miao Wang3fd70b02020-01-21 13:15:09 -0800234 * immediately signal the syncFence returned from the executeFenced call. After
235 * the syncFence is signaled, the task must not modify the content of
Miao Wang90cf3dd2019-11-12 14:02:16 -0800236 * any data object referenced by 'request' (described by the
237 * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}).
238 *
Miao Wang3fd70b02020-01-21 13:15:09 -0800239 * executeFenced can be called with an optional deadline and an optional duration.
240 * If the execution is not able to be completed before the provided deadline or
241 * within the timeout duration (measured from when all sync fences in waitFor are
242 * signaled), whichever comes earlier, the execution must be aborted, and either
243 * {@link ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
244 * ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
245 * to an abort must be sent the same way as other errors, described above.
246 * If the service reports that it does not support execution deadlines via
247 * IDevice::supportsDeadlines, and executeFenced is called with a
248 * deadline or duration, then the argument is invalid, and
249 * {@link ErrorStatus::INVALID_ARGUMENT} must be returned.
250 *
251 * If any of the sync fences in waitFor changes to error status after the executeFenced
252 * call succeeds, or the execution is aborted because it cannot finish before the deadline
253 * has been reached or the duration has elapsed, the driver must immediately set the returned
254 * syncFence to error status.
255 *
Miao Wang90cf3dd2019-11-12 14:02:16 -0800256 * Any number of calls to the executeFenced, execute* and executeSynchronously*
257 * functions, in any combination, may be made concurrently, even on the same
258 * IPreparedModel object.
259 *
260 * @param request The input and output information on which the prepared
Miao Wang3fd70b02020-01-21 13:15:09 -0800261 * model is to be executed. The outputs in the request must have
262 * fully specified dimensions.
Miao Wang90cf3dd2019-11-12 14:02:16 -0800263 * @param waitFor A vector of sync fence file descriptors.
264 * Execution must not start until all sync fences have been signaled.
265 * @param measure Specifies whether or not to measure duration of the execution.
Miao Wang3fd70b02020-01-21 13:15:09 -0800266 * @param deadline The time by which the execution must complete. If the
267 * execution cannot be finished by the deadline, the
268 * execution must be aborted.
Slava Shklyaevf034bf92020-02-11 14:27:02 +0000269 * @param loopTimeoutDuration The maximum amount of time that should be spent
270 * executing a {@link OperationType::WHILE}
271 * operation. If a loop condition model does not
272 * output false within this duration, the
273 * execution must be aborted. If the model
274 * contains a {@link OperationType::WHILE}
275 * operation and no loop timeout duration is
276 * provided, the maximum amount of time is {@link
277 * LoopTimeoutDurationNs::DEFAULT}. When
278 * provided, the duration must not exceed {@link
279 * LoopTimeoutDurationNs::MAXIMUM}.
Miao Wang3fd70b02020-01-21 13:15:09 -0800280 * @param duration The length of time within which the execution must
281 * complete after all sync fences in waitFor are signaled. If the
282 * execution cannot be finished within the duration, the execution
283 * must be aborted.
Miao Wang90cf3dd2019-11-12 14:02:16 -0800284 * @return status Error status of the call, must be:
285 * - NONE if task is successfully launched
286 * - DEVICE_UNAVAILABLE if driver is offline or busy
287 * - GENERAL_FAILURE if there is an unspecified error
288 * - INVALID_ARGUMENT if one of the input arguments is invalid, including
289 * fences in error states.
Miao Wang3fd70b02020-01-21 13:15:09 -0800290 * - MISSED_DEADLINE_* if the deadline for executing a model
291 * cannot be met
292 * - RESOURCE_EXHAUSTED_* if the task was aborted by the
293 * driver
294 * @return syncFence The sync fence that will be signaled when the task is completed.
Miao Wang90cf3dd2019-11-12 14:02:16 -0800295 * The sync fence will be set to error if a critical error,
296 * e.g. hardware failure or kernel panic, occurs when doing execution.
297 * @return callback The IFencedExecutionCallback can be used to query information like duration
298 * and error status when the execution is completed.
299 */
Miao Wang3fd70b02020-01-21 13:15:09 -0800300 executeFenced(Request request, vec<handle> waitFor, MeasureTiming measure,
Slava Shklyaevf034bf92020-02-11 14:27:02 +0000301 OptionalTimePoint deadline, OptionalTimeoutDuration loopTimeoutDuration,
302 OptionalTimeoutDuration duration)
Miao Wang90cf3dd2019-11-12 14:02:16 -0800303 generates (ErrorStatus status, handle syncFence, IFencedExecutionCallback callback);
Xusong Wang62a760c2019-10-25 12:07:17 -0700304};