blob: bce6ee227a08ec728453528fee98ccb9aa81f810 [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;
Xusong Wang62a760c2019-10-25 12:07:17 -070027
28/**
29 * IPreparedModel describes a model that has been prepared for execution and
30 * is used to launch executions.
31 */
32interface IPreparedModel extends @1.2::IPreparedModel {
33 /**
34 * Launches an asynchronous execution on a prepared model.
35 *
36 * The execution is performed asynchronously with respect to the caller.
Xusong Wang931d5a12019-11-27 12:46:48 -080037 * execute_1_3 must verify the inputs to the function are correct, and the usages
38 * of memory pools allocated by IDevice::allocate are valid. If there is
Xusong Wang62a760c2019-10-25 12:07:17 -070039 * an error, execute_1_3 must immediately invoke the callback with the
40 * appropriate ErrorStatus value, then return with the same ErrorStatus. If
41 * the inputs to the function are valid and there is no error, execute_1_3 must
42 * launch an asynchronous task to perform the execution in the background,
43 * and immediately return with ErrorStatus::NONE. If the asynchronous task
44 * fails to launch, execute_1_3 must immediately invoke the callback with
45 * ErrorStatus::GENERAL_FAILURE, then return with
46 * ErrorStatus::GENERAL_FAILURE.
47 *
48 * When the asynchronous task has finished its execution, it must
49 * immediately invoke the callback object provided as an input to the
50 * execute_1_3 function. This callback must be provided with the ErrorStatus of
51 * the execution.
52 *
53 * If the launch is successful, the caller must not change the content of
54 * any data object referenced by 'request' (described by the
55 * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}) until the
56 * asynchronous task has invoked the callback object. The asynchronous task
57 * must not change the content of any of the data objects corresponding to
58 * 'request' inputs.
59 *
60 * If the prepared model was prepared from a model wherein all tensor
61 * operands have fully specified dimensions, and the inputs to the function
62 * are valid, then:
63 * - the execution should launch successfully (ErrorStatus::NONE): There
64 * must be no failure unless the device itself is in a bad state.
65 * - if at execution time every operation's input operands have legal
66 * values, the execution should complete successfully (ErrorStatus::NONE):
67 * There must be no failure unless the device itself is in a bad state.
68 *
Michael Butlerc2499ec2019-12-11 18:31:12 -080069 * execute_1_3 can be called with an optional deadline. If the execution
70 * is not able to completed before the provided deadline, the execution
71 * must be aborted, and either {@link
72 * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
73 * ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
74 * to an abort must be sent the same way as other errors, described above.
75 * If the service reports that it does not support execution deadlines via
76 * IDevice::supportsDeadlines, and execute_1_3 is called with a deadline,
77 * then the argument is invalid, and {@link ErrorStatus::INVALID_ARGUMENT}
78 * must be returned.
79 *
Xusong Wangebd88ba2019-10-28 11:11:19 -070080 * Any number of calls to the execute* and executeSynchronously* functions,
81 * in any combination, may be made concurrently, even on the same
Xusong Wang62a760c2019-10-25 12:07:17 -070082 * IPreparedModel object.
83 *
84 * @param request The input and output information on which the prepared
85 * model is to be executed.
86 * @param measure Specifies whether or not to measure duration of the execution.
87 * The duration runs from the time the driver sees the call
88 * to the execute_1_3 function to the time the driver invokes
89 * the callback.
Michael Butlerc2499ec2019-12-11 18:31:12 -080090 * @param deadline The time by which execution must complete. If the
91 * execution cannot be finished by the deadline, the
92 * execution must be aborted.
Xusong Wang62a760c2019-10-25 12:07:17 -070093 * @param callback A callback object used to return the error status of
94 * the execution. The callback object's notify function must
95 * be called exactly once, even if the execution was
96 * unsuccessful.
97 * @return status Error status of the call, must be:
98 * - NONE if task is successfully launched
99 * - DEVICE_UNAVAILABLE if driver is offline or busy
100 * - GENERAL_FAILURE if there is an unspecified error
101 * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is
102 * not large enough to store the resultant values
103 * - INVALID_ARGUMENT if one of the input arguments is
104 * invalid
Michael Butlerc2499ec2019-12-11 18:31:12 -0800105 * - MISSED_DEADLINE_* if the deadline for executing a model
106 * cannot be met
107 * - RESOURCE_EXHAUSTED_* if the task was aborted by the
108 * driver
Xusong Wang62a760c2019-10-25 12:07:17 -0700109 */
Michael Butlerc2499ec2019-12-11 18:31:12 -0800110 execute_1_3(Request request, MeasureTiming measure, OptionalTimePoint deadline,
111 IExecutionCallback callback)
Xusong Wang62a760c2019-10-25 12:07:17 -0700112 generates (ErrorStatus status);
Xusong Wangebd88ba2019-10-28 11:11:19 -0700113
114 /**
115 * Performs a synchronous execution on a prepared model.
116 *
117 * The execution is performed synchronously with respect to the caller.
118 * executeSynchronously_1_3 must verify the inputs to the function are
Xusong Wang931d5a12019-11-27 12:46:48 -0800119 * correct, and the usages of memory pools allocated by IDevice::allocate
120 * are valid. If there is an error, executeSynchronously_1_3 must immediately
Xusong Wangebd88ba2019-10-28 11:11:19 -0700121 * return with the appropriate ErrorStatus value. If the inputs to the
122 * function are valid and there is no error, executeSynchronously_1_3 must
123 * perform the execution, and must not return until the execution is
124 * complete.
125 *
126 * The caller must not change the content of any data object referenced by
127 * 'request' (described by the {@link @1.0::DataLocation} of a
128 * {@link @1.0::RequestArgument}) until executeSynchronously_1_3
129 * returns. executeSynchronously_1_3 must not change the content of any of the
130 * data objects corresponding to 'request' inputs.
131 *
132 * If the prepared model was prepared from a model wherein all tensor
133 * operands have fully specified dimensions, and the inputs to the function
134 * are valid, and at execution time every operation's input operands have
135 * legal values, then the execution should complete successfully
136 * (ErrorStatus::NONE): There must be no failure unless the device itself is
137 * in a bad state.
138 *
Michael Butlerc2499ec2019-12-11 18:31:12 -0800139 * executeSynchronously_1_3 can be called with an optional deadline. If the
140 * execution is not able to completed before the provided deadline, the
141 * execution must be aborted, and either {@link
142 * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
143 * ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
144 * to an abort must be sent the same way as other errors, described above.
145 * If the service reports that it does not support execution deadlines via
146 * IDevice::supportsDeadlines, and executeSynchronously_1_3 is called with a
147 * deadline, then the argument is invalid, and
148 * {@link ErrorStatus::INVALID_ARGUMENT} must be returned.
149 *
Xusong Wangebd88ba2019-10-28 11:11:19 -0700150 * Any number of calls to the execute* and executeSynchronously* functions,
151 * in any combination, may be made concurrently, even on the same
152 * IPreparedModel object.
153 *
154 * @param request The input and output information on which the prepared
155 * model is to be executed.
156 * @param measure Specifies whether or not to measure duration of the execution.
157 * The duration runs from the time the driver sees the call
158 * to the executeSynchronously_1_3 function to the time the driver
159 * returns from the function.
Michael Butlerc2499ec2019-12-11 18:31:12 -0800160 * @param deadline The time by which execution must complete. If the
161 * execution cannot be finished by the deadline, the
162 * execution must be aborted.
Xusong Wangebd88ba2019-10-28 11:11:19 -0700163 * @return status Error status of the execution, must be:
164 * - NONE if execution is performed successfully
165 * - DEVICE_UNAVAILABLE if driver is offline or busy
166 * - GENERAL_FAILURE if there is an unspecified error
167 * - OUTPUT_INSUFFICIENT_SIZE if at least one output
168 * operand buffer is not large enough to store the
169 * corresponding output
170 * - INVALID_ARGUMENT if one of the input arguments is
171 * invalid
Michael Butlerc2499ec2019-12-11 18:31:12 -0800172 * - MISSED_DEADLINE_* if the deadline for executing a model
173 * cannot be met
174 * - RESOURCE_EXHAUSTED_* if the task was aborted by the
175 * driver
Xusong Wangebd88ba2019-10-28 11:11:19 -0700176 * @return outputShapes A list of shape information of model output operands.
177 * The index into "outputShapes" corresponds to the index
178 * of the output operand in the Request outputs vector.
179 * outputShapes must be empty unless the status is either
180 * NONE or OUTPUT_INSUFFICIENT_SIZE.
Michael Butlerc2499ec2019-12-11 18:31:12 -0800181 * @return timing Duration of execution. Unless measure is YES and status is
Xusong Wangebd88ba2019-10-28 11:11:19 -0700182 * NONE, all times must be reported as UINT64_MAX. A driver may
183 * choose to report any time as UINT64_MAX, indicating that
184 * measurement is not available.
185 */
Michael Butlerc2499ec2019-12-11 18:31:12 -0800186 executeSynchronously_1_3(Request request, MeasureTiming measure,
187 OptionalTimePoint deadline)
188 generates (ErrorStatus status, vec<OutputShape> outputShapes,
189 Timing timing);
Xusong Wang62a760c2019-10-25 12:07:17 -0700190};