blob: a1814b5156081b76db696310da8ae575f72c92ab [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 Butler9b9a8042020-02-13 16:37:22 -080073 * may be aborted, and either {@link
Michael Butlerc2499ec2019-12-11 18:31:12 -080074 * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
Michael Butler9b9a8042020-02-13 16:37:22 -080075 * ErrorStatus::MISSED_DEADLINE_PERSISTENT} may be returned. The error due
Michael Butlerc2499ec2019-12-11 18:31:12 -080076 * to an abort must be sent the same way as other errors, described above.
Michael Butlerc2499ec2019-12-11 18:31:12 -080077 *
Xusong Wangebd88ba2019-10-28 11:11:19 -070078 * Any number of calls to the execute* and executeSynchronously* functions,
79 * in any combination, may be made concurrently, even on the same
Xusong Wang62a760c2019-10-25 12:07:17 -070080 * IPreparedModel object.
81 *
82 * @param request The input and output information on which the prepared
83 * model is to be executed.
84 * @param measure Specifies whether or not to measure duration of the execution.
85 * The duration runs from the time the driver sees the call
86 * to the execute_1_3 function to the time the driver invokes
87 * the callback.
Michael Butler9b9a8042020-02-13 16:37:22 -080088 * @param deadline The time by which the execution is expected to complete.
89 * If the execution cannot be completed by the deadline, the
90 * execution may be aborted.
Slava Shklyaevf034bf92020-02-11 14:27:02 +000091 * @param loopTimeoutDuration The maximum amount of time that should be spent
92 * executing a {@link OperationType::WHILE}
93 * operation. If a loop condition model does not
94 * output false within this duration, the
95 * execution must be aborted. If the model
96 * contains a {@link OperationType::WHILE}
97 * operation and no loop timeout duration is
98 * provided, the maximum amount of time is {@link
99 * LoopTimeoutDurationNs::DEFAULT}. When
100 * provided, the duration must not exceed {@link
101 * LoopTimeoutDurationNs::MAXIMUM}.
Xusong Wang62a760c2019-10-25 12:07:17 -0700102 * @param callback A callback object used to return the error status of
Miao Wang90cf3dd2019-11-12 14:02:16 -0800103 * the execution, shape information of model output operands, and
104 * duration of execution. The callback object's notify function must
Xusong Wang62a760c2019-10-25 12:07:17 -0700105 * be called exactly once, even if the execution was
106 * unsuccessful.
107 * @return status Error status of the call, must be:
108 * - NONE if task is successfully launched
109 * - DEVICE_UNAVAILABLE if driver is offline or busy
110 * - GENERAL_FAILURE if there is an unspecified error
111 * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is
112 * not large enough to store the resultant values
113 * - INVALID_ARGUMENT if one of the input arguments is
114 * invalid
Michael Butler9b9a8042020-02-13 16:37:22 -0800115 * - MISSED_DEADLINE_* if the execution is aborted because it
116 * cannot be completed by the deadline
Michael Butlerc2499ec2019-12-11 18:31:12 -0800117 * - RESOURCE_EXHAUSTED_* if the task was aborted by the
118 * driver
Xusong Wang62a760c2019-10-25 12:07:17 -0700119 */
Michael Butlerc2499ec2019-12-11 18:31:12 -0800120 execute_1_3(Request request, MeasureTiming measure, OptionalTimePoint deadline,
Slava Shklyaevf034bf92020-02-11 14:27:02 +0000121 OptionalTimeoutDuration loopTimeoutDuration, IExecutionCallback callback)
Xusong Wang62a760c2019-10-25 12:07:17 -0700122 generates (ErrorStatus status);
Xusong Wangebd88ba2019-10-28 11:11:19 -0700123
124 /**
125 * Performs a synchronous execution on a prepared model.
126 *
127 * The execution is performed synchronously with respect to the caller.
128 * executeSynchronously_1_3 must verify the inputs to the function are
Xusong Wang931d5a12019-11-27 12:46:48 -0800129 * correct, and the usages of memory pools allocated by IDevice::allocate
130 * are valid. If there is an error, executeSynchronously_1_3 must immediately
Xusong Wangebd88ba2019-10-28 11:11:19 -0700131 * return with the appropriate ErrorStatus value. If the inputs to the
132 * function are valid and there is no error, executeSynchronously_1_3 must
133 * perform the execution, and must not return until the execution is
134 * complete.
135 *
136 * The caller must not change the content of any data object referenced by
137 * 'request' (described by the {@link @1.0::DataLocation} of a
138 * {@link @1.0::RequestArgument}) until executeSynchronously_1_3
139 * returns. executeSynchronously_1_3 must not change the content of any of the
140 * data objects corresponding to 'request' inputs.
141 *
142 * If the prepared model was prepared from a model wherein all tensor
143 * operands have fully specified dimensions, and the inputs to the function
144 * are valid, and at execution time every operation's input operands have
145 * legal values, then the execution should complete successfully
146 * (ErrorStatus::NONE): There must be no failure unless the device itself is
147 * in a bad state.
148 *
Michael Butler9b9a8042020-02-13 16:37:22 -0800149 * executeSynchronously_1_3 may be called with an optional deadline. If the
Miao Wang3fd70b02020-01-21 13:15:09 -0800150 * execution is not able to be completed before the provided deadline, the
Michael Butler9b9a8042020-02-13 16:37:22 -0800151 * execution may be aborted, and either {@link
Michael Butlerc2499ec2019-12-11 18:31:12 -0800152 * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
Michael Butler9b9a8042020-02-13 16:37:22 -0800153 * ErrorStatus::MISSED_DEADLINE_PERSISTENT} may be returned. The error due
Michael Butlerc2499ec2019-12-11 18:31:12 -0800154 * to an abort must be sent the same way as other errors, described above.
Michael Butlerc2499ec2019-12-11 18:31:12 -0800155 *
Xusong Wangebd88ba2019-10-28 11:11:19 -0700156 * Any number of calls to the execute* and executeSynchronously* functions,
157 * in any combination, may be made concurrently, even on the same
158 * IPreparedModel object.
159 *
160 * @param request The input and output information on which the prepared
161 * model is to be executed.
162 * @param measure Specifies whether or not to measure duration of the execution.
163 * The duration runs from the time the driver sees the call
164 * to the executeSynchronously_1_3 function to the time the driver
165 * returns from the function.
Michael Butler9b9a8042020-02-13 16:37:22 -0800166 * @param deadline The time by which the execution is expected to complete.
167 * If the execution cannot be finished by the deadline, the
168 * execution may be aborted.
Slava Shklyaevf034bf92020-02-11 14:27:02 +0000169 * @param loopTimeoutDuration The maximum amount of time that should be spent
170 * executing a {@link OperationType::WHILE}
171 * operation. If a loop condition model does not
172 * output false within this duration, the
173 * execution must be aborted. If the model
174 * contains a {@link OperationType::WHILE}
175 * operation and no loop timeout duration is
176 * provided, the maximum amount of time is {@link
177 * LoopTimeoutDurationNs::DEFAULT}. When
178 * provided, the duration must not exceed {@link
179 * LoopTimeoutDurationNs::MAXIMUM}.
Xusong Wangebd88ba2019-10-28 11:11:19 -0700180 * @return status Error status of the execution, must be:
181 * - NONE if execution is performed successfully
182 * - DEVICE_UNAVAILABLE if driver is offline or busy
183 * - GENERAL_FAILURE if there is an unspecified error
184 * - OUTPUT_INSUFFICIENT_SIZE if at least one output
185 * operand buffer is not large enough to store the
186 * corresponding output
187 * - INVALID_ARGUMENT if one of the input arguments is
188 * invalid
Michael Butler9b9a8042020-02-13 16:37:22 -0800189 * - MISSED_DEADLINE_* if the execution is aborted because it
190 * cannot be completed by the deadline
Michael Butlerc2499ec2019-12-11 18:31:12 -0800191 * - RESOURCE_EXHAUSTED_* if the task was aborted by the
192 * driver
Xusong Wangebd88ba2019-10-28 11:11:19 -0700193 * @return outputShapes A list of shape information of model output operands.
194 * The index into "outputShapes" corresponds to the index
195 * of the output operand in the Request outputs vector.
196 * outputShapes must be empty unless the status is either
197 * NONE or OUTPUT_INSUFFICIENT_SIZE.
Michael Butlerc2499ec2019-12-11 18:31:12 -0800198 * @return timing Duration of execution. Unless measure is YES and status is
Xusong Wangebd88ba2019-10-28 11:11:19 -0700199 * NONE, all times must be reported as UINT64_MAX. A driver may
200 * choose to report any time as UINT64_MAX, indicating that
201 * measurement is not available.
202 */
Michael Butlerc2499ec2019-12-11 18:31:12 -0800203 executeSynchronously_1_3(Request request, MeasureTiming measure,
Slava Shklyaevf034bf92020-02-11 14:27:02 +0000204 OptionalTimePoint deadline,
205 OptionalTimeoutDuration loopTimeoutDuration)
Michael Butlerc2499ec2019-12-11 18:31:12 -0800206 generates (ErrorStatus status, vec<OutputShape> outputShapes,
207 Timing timing);
Miao Wang90cf3dd2019-11-12 14:02:16 -0800208
209 /**
210 * Launch a fenced asynchronous execution on a prepared model.
211 *
212 * The execution is performed asynchronously with respect to the caller.
Miao Wang3fd70b02020-01-21 13:15:09 -0800213 * executeFenced must verify the inputs to the function are correct, and the usages
214 * of memory pools allocated by IDevice::allocate are valid. If there is an error,
215 * executeFenced must immediately return with the corresponding ErrorStatus, an empty
216 * handle for syncFence, and nullptr for callback. If the inputs to the function
217 * are valid and there is no error, executeFenced must dispatch an asynchronous task
218 * to perform the execution in the background, and immediately return with
219 * ErrorStatus::NONE, a sync fence that will be signaled once the execution is completed,
220 * and a callback that can be used by the client to query the duration and runtime error
221 * status. If the task has finished before the call returns, an empty handle may be returned
222 * for syncFence. The execution must wait for all the sync fences (if any) in waitFor
223 * to be signaled before starting the actual execution.
Miao Wang90cf3dd2019-11-12 14:02:16 -0800224 *
225 * When the asynchronous task has finished its execution, it must
Miao Wang3fd70b02020-01-21 13:15:09 -0800226 * immediately signal the syncFence returned from the executeFenced call. After
227 * the syncFence is signaled, the task must not modify the content of
Miao Wang90cf3dd2019-11-12 14:02:16 -0800228 * any data object referenced by 'request' (described by the
229 * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}).
230 *
Michael Butler9b9a8042020-02-13 16:37:22 -0800231 * executeFenced may be called with an optional deadline and an optional duration.
Miao Wang3fd70b02020-01-21 13:15:09 -0800232 * If the execution is not able to be completed before the provided deadline or
233 * within the timeout duration (measured from when all sync fences in waitFor are
Michael Butler9b9a8042020-02-13 16:37:22 -0800234 * signaled), whichever comes earlier, the execution may be aborted, and either
Miao Wang3fd70b02020-01-21 13:15:09 -0800235 * {@link ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
Michael Butler9b9a8042020-02-13 16:37:22 -0800236 * ErrorStatus::MISSED_DEADLINE_PERSISTENT} may be returned. The error due
Miao Wang3fd70b02020-01-21 13:15:09 -0800237 * to an abort must be sent the same way as other errors, described above.
Miao Wang3fd70b02020-01-21 13:15:09 -0800238 *
239 * If any of the sync fences in waitFor changes to error status after the executeFenced
240 * call succeeds, or the execution is aborted because it cannot finish before the deadline
241 * has been reached or the duration has elapsed, the driver must immediately set the returned
242 * syncFence to error status.
243 *
Miao Wang90cf3dd2019-11-12 14:02:16 -0800244 * Any number of calls to the executeFenced, execute* and executeSynchronously*
245 * functions, in any combination, may be made concurrently, even on the same
246 * IPreparedModel object.
247 *
248 * @param request The input and output information on which the prepared
Miao Wang3fd70b02020-01-21 13:15:09 -0800249 * model is to be executed. The outputs in the request must have
250 * fully specified dimensions.
Miao Wang90cf3dd2019-11-12 14:02:16 -0800251 * @param waitFor A vector of sync fence file descriptors.
252 * Execution must not start until all sync fences have been signaled.
253 * @param measure Specifies whether or not to measure duration of the execution.
Michael Butler9b9a8042020-02-13 16:37:22 -0800254 * @param deadline The time by which the execution is expected to complete.
255 * If the execution cannot be finished by the deadline, the
256 * execution may be aborted.
Slava Shklyaevf034bf92020-02-11 14:27:02 +0000257 * @param loopTimeoutDuration The maximum amount of time that should be spent
258 * executing a {@link OperationType::WHILE}
259 * operation. If a loop condition model does not
260 * output false within this duration, the
261 * execution must be aborted. If the model
262 * contains a {@link OperationType::WHILE}
263 * operation and no loop timeout duration is
264 * provided, the maximum amount of time is {@link
265 * LoopTimeoutDurationNs::DEFAULT}. When
266 * provided, the duration must not exceed {@link
267 * LoopTimeoutDurationNs::MAXIMUM}.
Michael Butler9b9a8042020-02-13 16:37:22 -0800268 * @param duration The length of time within which the execution is expected
269 * to complete after all sync fences in waitFor are signaled.
270 * If the execution cannot be finished within the duration,
271 * the execution may be aborted.
Miao Wang90cf3dd2019-11-12 14:02:16 -0800272 * @return status Error status of the call, must be:
273 * - NONE if task is successfully launched
274 * - DEVICE_UNAVAILABLE if driver is offline or busy
275 * - GENERAL_FAILURE if there is an unspecified error
276 * - INVALID_ARGUMENT if one of the input arguments is invalid, including
277 * fences in error states.
Michael Butler9b9a8042020-02-13 16:37:22 -0800278 * - MISSED_DEADLINE_* if the execution is aborted because it
279 * cannot be completed by the deadline
Miao Wang3fd70b02020-01-21 13:15:09 -0800280 * - RESOURCE_EXHAUSTED_* if the task was aborted by the
281 * driver
282 * @return syncFence The sync fence that will be signaled when the task is completed.
Miao Wang90cf3dd2019-11-12 14:02:16 -0800283 * The sync fence will be set to error if a critical error,
284 * e.g. hardware failure or kernel panic, occurs when doing execution.
285 * @return callback The IFencedExecutionCallback can be used to query information like duration
286 * and error status when the execution is completed.
287 */
Miao Wang3fd70b02020-01-21 13:15:09 -0800288 executeFenced(Request request, vec<handle> waitFor, MeasureTiming measure,
Slava Shklyaevf034bf92020-02-11 14:27:02 +0000289 OptionalTimePoint deadline, OptionalTimeoutDuration loopTimeoutDuration,
290 OptionalTimeoutDuration duration)
Miao Wang90cf3dd2019-11-12 14:02:16 -0800291 generates (ErrorStatus status, handle syncFence, IFencedExecutionCallback callback);
Xusong Wang62a760c2019-10-25 12:07:17 -0700292};