blob: f84bcf4ffc3bfd51bb5600716920ba58e740821d [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;
24import OptionalTimePoint;
Xusong Wang931d5a12019-11-27 12:46:48 -080025import Request;
Michael Butlerc2499ec2019-12-11 18:31:12 -080026import IExecutionCallback;
Miao Wang90cf3dd2019-11-12 14:02:16 -080027import IFencedExecutionCallback;
Xusong Wang62a760c2019-10-25 12:07:17 -070028
29/**
30 * IPreparedModel describes a model that has been prepared for execution and
31 * is used to launch executions.
32 */
33interface IPreparedModel extends @1.2::IPreparedModel {
34 /**
35 * Launches an asynchronous execution on a prepared model.
36 *
37 * The execution is performed asynchronously with respect to the caller.
Xusong Wang931d5a12019-11-27 12:46:48 -080038 * execute_1_3 must verify the inputs to the function are correct, and the usages
39 * of memory pools allocated by IDevice::allocate are valid. If there is
Xusong Wang62a760c2019-10-25 12:07:17 -070040 * an error, execute_1_3 must immediately invoke the callback with the
41 * appropriate ErrorStatus value, then return with the same ErrorStatus. If
42 * the inputs to the function are valid and there is no error, execute_1_3 must
43 * launch an asynchronous task to perform the execution in the background,
44 * and immediately return with ErrorStatus::NONE. If the asynchronous task
45 * fails to launch, execute_1_3 must immediately invoke the callback with
46 * ErrorStatus::GENERAL_FAILURE, then return with
47 * ErrorStatus::GENERAL_FAILURE.
48 *
49 * When the asynchronous task has finished its execution, it must
50 * immediately invoke the callback object provided as an input to the
51 * execute_1_3 function. This callback must be provided with the ErrorStatus of
52 * the execution.
53 *
54 * If the launch is successful, the caller must not change the content of
55 * any data object referenced by 'request' (described by the
56 * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}) until the
57 * asynchronous task has invoked the callback object. The asynchronous task
58 * must not change the content of any of the data objects corresponding to
59 * 'request' inputs.
60 *
61 * If the prepared model was prepared from a model wherein all tensor
62 * operands have fully specified dimensions, and the inputs to the function
63 * are valid, then:
64 * - the execution should launch successfully (ErrorStatus::NONE): There
65 * must be no failure unless the device itself is in a bad state.
66 * - if at execution time every operation's input operands have legal
67 * values, the execution should complete successfully (ErrorStatus::NONE):
68 * There must be no failure unless the device itself is in a bad state.
69 *
Michael Butlerc2499ec2019-12-11 18:31:12 -080070 * execute_1_3 can be called with an optional deadline. If the execution
71 * is not able to completed before the provided deadline, the execution
72 * must be aborted, and either {@link
73 * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
74 * ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
75 * to an abort must be sent the same way as other errors, described above.
76 * If the service reports that it does not support execution deadlines via
77 * IDevice::supportsDeadlines, and execute_1_3 is called with a deadline,
78 * then the argument is invalid, and {@link ErrorStatus::INVALID_ARGUMENT}
79 * must be returned.
80 *
Xusong Wangebd88ba2019-10-28 11:11:19 -070081 * Any number of calls to the execute* and executeSynchronously* functions,
82 * in any combination, may be made concurrently, even on the same
Xusong Wang62a760c2019-10-25 12:07:17 -070083 * IPreparedModel object.
84 *
85 * @param request The input and output information on which the prepared
86 * model is to be executed.
87 * @param measure Specifies whether or not to measure duration of the execution.
88 * The duration runs from the time the driver sees the call
89 * to the execute_1_3 function to the time the driver invokes
90 * the callback.
Michael Butlerc2499ec2019-12-11 18:31:12 -080091 * @param deadline The time by which execution must complete. If the
92 * execution cannot be finished by the deadline, the
93 * execution must be aborted.
Xusong Wang62a760c2019-10-25 12:07:17 -070094 * @param callback A callback object used to return the error status of
Miao Wang90cf3dd2019-11-12 14:02:16 -080095 * the execution, shape information of model output operands, and
96 * duration of execution. The callback object's notify function must
Xusong Wang62a760c2019-10-25 12:07:17 -070097 * be called exactly once, even if the execution was
98 * unsuccessful.
99 * @return status Error status of the call, must be:
100 * - NONE if task is successfully launched
101 * - DEVICE_UNAVAILABLE if driver is offline or busy
102 * - GENERAL_FAILURE if there is an unspecified error
103 * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is
104 * not large enough to store the resultant values
105 * - INVALID_ARGUMENT if one of the input arguments is
106 * invalid
Michael Butlerc2499ec2019-12-11 18:31:12 -0800107 * - MISSED_DEADLINE_* if the deadline for executing a model
108 * cannot be met
109 * - RESOURCE_EXHAUSTED_* if the task was aborted by the
110 * driver
Xusong Wang62a760c2019-10-25 12:07:17 -0700111 */
Michael Butlerc2499ec2019-12-11 18:31:12 -0800112 execute_1_3(Request request, MeasureTiming measure, OptionalTimePoint deadline,
113 IExecutionCallback callback)
Xusong Wang62a760c2019-10-25 12:07:17 -0700114 generates (ErrorStatus status);
Xusong Wangebd88ba2019-10-28 11:11:19 -0700115
116 /**
117 * Performs a synchronous execution on a prepared model.
118 *
119 * The execution is performed synchronously with respect to the caller.
120 * executeSynchronously_1_3 must verify the inputs to the function are
Xusong Wang931d5a12019-11-27 12:46:48 -0800121 * correct, and the usages of memory pools allocated by IDevice::allocate
122 * are valid. If there is an error, executeSynchronously_1_3 must immediately
Xusong Wangebd88ba2019-10-28 11:11:19 -0700123 * return with the appropriate ErrorStatus value. If the inputs to the
124 * function are valid and there is no error, executeSynchronously_1_3 must
125 * perform the execution, and must not return until the execution is
126 * complete.
127 *
128 * The caller must not change the content of any data object referenced by
129 * 'request' (described by the {@link @1.0::DataLocation} of a
130 * {@link @1.0::RequestArgument}) until executeSynchronously_1_3
131 * returns. executeSynchronously_1_3 must not change the content of any of the
132 * data objects corresponding to 'request' inputs.
133 *
134 * If the prepared model was prepared from a model wherein all tensor
135 * operands have fully specified dimensions, and the inputs to the function
136 * are valid, and at execution time every operation's input operands have
137 * legal values, then the execution should complete successfully
138 * (ErrorStatus::NONE): There must be no failure unless the device itself is
139 * in a bad state.
140 *
Michael Butlerc2499ec2019-12-11 18:31:12 -0800141 * executeSynchronously_1_3 can be called with an optional deadline. If the
142 * execution is not able to completed before the provided deadline, the
143 * execution must be aborted, and either {@link
144 * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
145 * ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
146 * to an abort must be sent the same way as other errors, described above.
147 * If the service reports that it does not support execution deadlines via
148 * IDevice::supportsDeadlines, and executeSynchronously_1_3 is called with a
149 * deadline, then the argument is invalid, and
150 * {@link ErrorStatus::INVALID_ARGUMENT} must be returned.
151 *
Xusong Wangebd88ba2019-10-28 11:11:19 -0700152 * Any number of calls to the execute* and executeSynchronously* functions,
153 * in any combination, may be made concurrently, even on the same
154 * IPreparedModel object.
155 *
156 * @param request The input and output information on which the prepared
157 * model is to be executed.
158 * @param measure Specifies whether or not to measure duration of the execution.
159 * The duration runs from the time the driver sees the call
160 * to the executeSynchronously_1_3 function to the time the driver
161 * returns from the function.
Michael Butlerc2499ec2019-12-11 18:31:12 -0800162 * @param deadline The time by which execution must complete. If the
163 * execution cannot be finished by the deadline, the
164 * execution must be aborted.
Xusong Wangebd88ba2019-10-28 11:11:19 -0700165 * @return status Error status of the execution, must be:
166 * - NONE if execution is performed successfully
167 * - DEVICE_UNAVAILABLE if driver is offline or busy
168 * - GENERAL_FAILURE if there is an unspecified error
169 * - OUTPUT_INSUFFICIENT_SIZE if at least one output
170 * operand buffer is not large enough to store the
171 * corresponding output
172 * - INVALID_ARGUMENT if one of the input arguments is
173 * invalid
Michael Butlerc2499ec2019-12-11 18:31:12 -0800174 * - MISSED_DEADLINE_* if the deadline for executing a model
175 * cannot be met
176 * - RESOURCE_EXHAUSTED_* if the task was aborted by the
177 * driver
Xusong Wangebd88ba2019-10-28 11:11:19 -0700178 * @return outputShapes A list of shape information of model output operands.
179 * The index into "outputShapes" corresponds to the index
180 * of the output operand in the Request outputs vector.
181 * outputShapes must be empty unless the status is either
182 * NONE or OUTPUT_INSUFFICIENT_SIZE.
Michael Butlerc2499ec2019-12-11 18:31:12 -0800183 * @return timing Duration of execution. Unless measure is YES and status is
Xusong Wangebd88ba2019-10-28 11:11:19 -0700184 * NONE, all times must be reported as UINT64_MAX. A driver may
185 * choose to report any time as UINT64_MAX, indicating that
186 * measurement is not available.
187 */
Michael Butlerc2499ec2019-12-11 18:31:12 -0800188 executeSynchronously_1_3(Request request, MeasureTiming measure,
189 OptionalTimePoint deadline)
190 generates (ErrorStatus status, vec<OutputShape> outputShapes,
191 Timing timing);
Miao Wang90cf3dd2019-11-12 14:02:16 -0800192
193 /**
194 * Launch a fenced asynchronous execution on a prepared model.
195 *
196 * The execution is performed asynchronously with respect to the caller.
197 * executeFenced must fully validate the request, and only accept one that is
198 * guaranteed to be completed, unless a hardware failure or kernel panic happens on the device.
199 * If there is an error during validation, executeFenced must immediately return with
200 * the corresponding ErrorStatus. If the request is valid and there is no error launching,
201 * executeFenced must dispatch an asynchronous task to perform the execution in the
202 * background, and immediately return with ErrorStatus::NONE, a sync_fence that will be
203 * signaled once the execution is completed, and a callback that can be used by the client
204 * to query the duration and runtime error status. If the task has finished
205 * before the call returns, empty handle may be returned for the sync fence. If the
206 * asynchronous task fails to launch, executeFenced must immediately return with
207 * ErrorStatus::GENERAL_FAILURE, and empty handle for the sync fence and nullptr
208 * for callback. The execution must wait for all the sync fences (if any) in wait_for to be
209 * signaled before starting the actual execution.
210 *
211 * If any of sync fences in wait_for changes to error status after the executeFenced
212 * call succeeds, the driver must immediately set the returned sync fence to error status.
213 *
214 * When the asynchronous task has finished its execution, it must
215 * immediately signal the sync_fence created when dispatching. After
216 * the sync_fence is signaled, the task must not modify the content of
217 * any data object referenced by 'request' (described by the
218 * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}).
219 *
220 * Any number of calls to the executeFenced, execute* and executeSynchronously*
221 * functions, in any combination, may be made concurrently, even on the same
222 * IPreparedModel object.
223 *
224 * @param request The input and output information on which the prepared
225 * model is to be executed.
226 * @param waitFor A vector of sync fence file descriptors.
227 * Execution must not start until all sync fences have been signaled.
228 * @param measure Specifies whether or not to measure duration of the execution.
229 * The duration runs from the time the driver sees the call
230 * to the executeFenced function to the time sync_fence is triggered.
231 * @return status Error status of the call, must be:
232 * - NONE if task is successfully launched
233 * - DEVICE_UNAVAILABLE if driver is offline or busy
234 * - GENERAL_FAILURE if there is an unspecified error
235 * - INVALID_ARGUMENT if one of the input arguments is invalid, including
236 * fences in error states.
237 * @return syncFence The sync fence that will be triggered when the task is completed.
238 * The sync fence will be set to error if a critical error,
239 * e.g. hardware failure or kernel panic, occurs when doing execution.
240 * @return callback The IFencedExecutionCallback can be used to query information like duration
241 * and error status when the execution is completed.
242 */
243 executeFenced(Request request, vec<handle> waitFor, MeasureTiming measure)
244 generates (ErrorStatus status, handle syncFence, IFencedExecutionCallback callback);
Xusong Wang62a760c2019-10-25 12:07:17 -0700245};