Xusong Wang | 62a760c | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.hardware.neuralnetworks@1.3; |
| 18 | |
| 19 | import @1.0::ErrorStatus; |
Xusong Wang | 62a760c | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 20 | import @1.2::IExecutionCallback; |
| 21 | import @1.2::IPreparedModel; |
Xusong Wang | ebd88ba | 2019-10-28 11:11:19 -0700 | [diff] [blame] | 22 | import @1.2::MeasureTiming; |
| 23 | import @1.2::OutputShape; |
| 24 | import @1.2::Timing; |
Xusong Wang | 931d5a1 | 2019-11-27 12:46:48 -0800 | [diff] [blame] | 25 | import Request; |
Xusong Wang | 62a760c | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * IPreparedModel describes a model that has been prepared for execution and |
| 29 | * is used to launch executions. |
| 30 | */ |
| 31 | interface IPreparedModel extends @1.2::IPreparedModel { |
| 32 | /** |
| 33 | * Launches an asynchronous execution on a prepared model. |
| 34 | * |
| 35 | * The execution is performed asynchronously with respect to the caller. |
Xusong Wang | 931d5a1 | 2019-11-27 12:46:48 -0800 | [diff] [blame] | 36 | * execute_1_3 must verify the inputs to the function are correct, and the usages |
| 37 | * of memory pools allocated by IDevice::allocate are valid. If there is |
Xusong Wang | 62a760c | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 38 | * an error, execute_1_3 must immediately invoke the callback with the |
| 39 | * appropriate ErrorStatus value, then return with the same ErrorStatus. If |
| 40 | * the inputs to the function are valid and there is no error, execute_1_3 must |
| 41 | * launch an asynchronous task to perform the execution in the background, |
| 42 | * and immediately return with ErrorStatus::NONE. If the asynchronous task |
| 43 | * fails to launch, execute_1_3 must immediately invoke the callback with |
| 44 | * ErrorStatus::GENERAL_FAILURE, then return with |
| 45 | * ErrorStatus::GENERAL_FAILURE. |
| 46 | * |
| 47 | * When the asynchronous task has finished its execution, it must |
| 48 | * immediately invoke the callback object provided as an input to the |
| 49 | * execute_1_3 function. This callback must be provided with the ErrorStatus of |
| 50 | * the execution. |
| 51 | * |
| 52 | * If the launch is successful, the caller must not change the content of |
| 53 | * any data object referenced by 'request' (described by the |
| 54 | * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}) until the |
| 55 | * asynchronous task has invoked the callback object. The asynchronous task |
| 56 | * must not change the content of any of the data objects corresponding to |
| 57 | * 'request' inputs. |
| 58 | * |
| 59 | * If the prepared model was prepared from a model wherein all tensor |
| 60 | * operands have fully specified dimensions, and the inputs to the function |
| 61 | * are valid, then: |
| 62 | * - the execution should launch successfully (ErrorStatus::NONE): There |
| 63 | * must be no failure unless the device itself is in a bad state. |
| 64 | * - if at execution time every operation's input operands have legal |
| 65 | * values, the execution should complete successfully (ErrorStatus::NONE): |
| 66 | * There must be no failure unless the device itself is in a bad state. |
| 67 | * |
Xusong Wang | ebd88ba | 2019-10-28 11:11:19 -0700 | [diff] [blame] | 68 | * Any number of calls to the execute* and executeSynchronously* functions, |
| 69 | * in any combination, may be made concurrently, even on the same |
Xusong Wang | 62a760c | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 70 | * IPreparedModel object. |
| 71 | * |
| 72 | * @param request The input and output information on which the prepared |
| 73 | * model is to be executed. |
| 74 | * @param measure Specifies whether or not to measure duration of the execution. |
| 75 | * The duration runs from the time the driver sees the call |
| 76 | * to the execute_1_3 function to the time the driver invokes |
| 77 | * the callback. |
| 78 | * @param callback A callback object used to return the error status of |
| 79 | * the execution. The callback object's notify function must |
| 80 | * be called exactly once, even if the execution was |
| 81 | * unsuccessful. |
| 82 | * @return status Error status of the call, must be: |
| 83 | * - NONE if task is successfully launched |
| 84 | * - DEVICE_UNAVAILABLE if driver is offline or busy |
| 85 | * - GENERAL_FAILURE if there is an unspecified error |
| 86 | * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is |
| 87 | * not large enough to store the resultant values |
| 88 | * - INVALID_ARGUMENT if one of the input arguments is |
| 89 | * invalid |
| 90 | */ |
| 91 | execute_1_3(Request request, MeasureTiming measure, IExecutionCallback callback) |
| 92 | generates (ErrorStatus status); |
Xusong Wang | ebd88ba | 2019-10-28 11:11:19 -0700 | [diff] [blame] | 93 | |
| 94 | /** |
| 95 | * Performs a synchronous execution on a prepared model. |
| 96 | * |
| 97 | * The execution is performed synchronously with respect to the caller. |
| 98 | * executeSynchronously_1_3 must verify the inputs to the function are |
Xusong Wang | 931d5a1 | 2019-11-27 12:46:48 -0800 | [diff] [blame] | 99 | * correct, and the usages of memory pools allocated by IDevice::allocate |
| 100 | * are valid. If there is an error, executeSynchronously_1_3 must immediately |
Xusong Wang | ebd88ba | 2019-10-28 11:11:19 -0700 | [diff] [blame] | 101 | * return with the appropriate ErrorStatus value. If the inputs to the |
| 102 | * function are valid and there is no error, executeSynchronously_1_3 must |
| 103 | * perform the execution, and must not return until the execution is |
| 104 | * complete. |
| 105 | * |
| 106 | * The caller must not change the content of any data object referenced by |
| 107 | * 'request' (described by the {@link @1.0::DataLocation} of a |
| 108 | * {@link @1.0::RequestArgument}) until executeSynchronously_1_3 |
| 109 | * returns. executeSynchronously_1_3 must not change the content of any of the |
| 110 | * data objects corresponding to 'request' inputs. |
| 111 | * |
| 112 | * If the prepared model was prepared from a model wherein all tensor |
| 113 | * operands have fully specified dimensions, and the inputs to the function |
| 114 | * are valid, and at execution time every operation's input operands have |
| 115 | * legal values, then the execution should complete successfully |
| 116 | * (ErrorStatus::NONE): There must be no failure unless the device itself is |
| 117 | * in a bad state. |
| 118 | * |
| 119 | * Any number of calls to the execute* and executeSynchronously* functions, |
| 120 | * in any combination, may be made concurrently, even on the same |
| 121 | * IPreparedModel object. |
| 122 | * |
| 123 | * @param request The input and output information on which the prepared |
| 124 | * model is to be executed. |
| 125 | * @param measure Specifies whether or not to measure duration of the execution. |
| 126 | * The duration runs from the time the driver sees the call |
| 127 | * to the executeSynchronously_1_3 function to the time the driver |
| 128 | * returns from the function. |
| 129 | * @return status Error status of the execution, must be: |
| 130 | * - NONE if execution is performed successfully |
| 131 | * - DEVICE_UNAVAILABLE if driver is offline or busy |
| 132 | * - GENERAL_FAILURE if there is an unspecified error |
| 133 | * - OUTPUT_INSUFFICIENT_SIZE if at least one output |
| 134 | * operand buffer is not large enough to store the |
| 135 | * corresponding output |
| 136 | * - INVALID_ARGUMENT if one of the input arguments is |
| 137 | * invalid |
| 138 | * @return outputShapes A list of shape information of model output operands. |
| 139 | * The index into "outputShapes" corresponds to the index |
| 140 | * of the output operand in the Request outputs vector. |
| 141 | * outputShapes must be empty unless the status is either |
| 142 | * NONE or OUTPUT_INSUFFICIENT_SIZE. |
| 143 | * @return Timing Duration of execution. Unless measure is YES and status is |
| 144 | * NONE, all times must be reported as UINT64_MAX. A driver may |
| 145 | * choose to report any time as UINT64_MAX, indicating that |
| 146 | * measurement is not available. |
| 147 | */ |
| 148 | executeSynchronously_1_3(Request request, MeasureTiming measure) |
| 149 | generates (ErrorStatus status, vec<OutputShape> outputShapes, Timing timing); |
Xusong Wang | 62a760c | 2019-10-25 12:07:17 -0700 | [diff] [blame] | 150 | }; |