Xusong Wang | 1a06e77 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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.2; |
| 18 | |
| 19 | import @1.0::ErrorStatus; |
| 20 | import @1.0::IPreparedModel; |
| 21 | import @1.0::Request; |
Michael Butler | a06e261 | 2019-01-15 10:52:41 -0800 | [diff] [blame] | 22 | import IBurstCallback; |
| 23 | import IBurstContext; |
Xusong Wang | 1a06e77 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 24 | import IExecutionCallback; |
| 25 | |
| 26 | /** |
| 27 | * IPreparedModel describes a model that has been prepared for execution and |
| 28 | * is used to launch executions. |
| 29 | */ |
| 30 | interface IPreparedModel extends @1.0::IPreparedModel { |
| 31 | /** |
| 32 | * Launches an asynchronous execution on a prepared model. |
| 33 | * |
| 34 | * The execution is performed asynchronously with respect to the caller. |
| 35 | * execute_1_2 must verify the inputs to the function are correct. If there is |
| 36 | * an error, execute_1_2 must immediately invoke the callback with the |
| 37 | * appropriate ErrorStatus value, then return with the same ErrorStatus. If |
| 38 | * the inputs to the function are valid and there is no error, execute_1_2 must |
| 39 | * launch an asynchronous task to perform the execution in the background, |
| 40 | * and immediately return with ErrorStatus::NONE. If the asynchronous task |
| 41 | * fails to launch, execute_1_2 must immediately invoke the callback with |
| 42 | * ErrorStatus::GENERAL_FAILURE, then return with |
| 43 | * ErrorStatus::GENERAL_FAILURE. |
| 44 | * |
| 45 | * When the asynchronous task has finished its execution, it must |
| 46 | * immediately invoke the callback object provided as an input to the |
| 47 | * execute_1_2 function. This callback must be provided with the ErrorStatus of |
| 48 | * the execution. |
| 49 | * |
| 50 | * If the prepared model was prepared from a model wherein all |
| 51 | * tensor operands have fully specified dimensions, and the inputs |
| 52 | * to the function are valid, then the execution should launch |
| 53 | * and complete successfully (ErrorStatus::NONE). There must be |
| 54 | * no failure unless the device itself is in a bad state. |
| 55 | * |
David Gross | 4592ed1 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 56 | * Any number of calls to the execute, execute_1_2, and executeSynchronously |
| 57 | * functions, in any combination, may be made concurrently, even on the same |
| 58 | * IPreparedModel object. |
Xusong Wang | 1a06e77 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 59 | * |
| 60 | * @param request The input and output information on which the prepared |
| 61 | * model is to be executed. |
| 62 | * @param callback A callback object used to return the error status of |
| 63 | * the execution. The callback object's notify function must |
| 64 | * be called exactly once, even if the execution was |
| 65 | * unsuccessful. |
| 66 | * @return status Error status of the call, must be: |
| 67 | * - NONE if task is successfully launched |
| 68 | * - DEVICE_UNAVAILABLE if driver is offline or busy |
| 69 | * - GENERAL_FAILURE if there is an unspecified error |
| 70 | * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is |
| 71 | * not large enough to store the resultant values |
| 72 | * - INVALID_ARGUMENT if one of the input arguments is |
| 73 | * invalid |
| 74 | */ |
| 75 | execute_1_2(Request request, IExecutionCallback callback) |
| 76 | generates (ErrorStatus status); |
David Gross | 4592ed1 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 77 | |
| 78 | /** |
| 79 | * Performs a synchronous execution on a prepared model. |
| 80 | * |
| 81 | * The execution is performed synchronously with respect to the caller. |
| 82 | * executeSynchronously must verify the inputs to the function are |
| 83 | * correct. If there is an error, executeSynchronously must immediately |
| 84 | * return with the appropriate ErrorStatus value. If the inputs to the |
| 85 | * function are valid and there is no error, executeSynchronously must |
| 86 | * perform the execution, and must not return until the execution is |
| 87 | * complete. |
| 88 | * |
| 89 | * If the prepared model was prepared from a model wherein all tensor |
| 90 | * operands have fully specified dimensions, and the inputs to the function |
| 91 | * are valid, then the execution should complete successfully |
| 92 | * (ErrorStatus::NONE). There must be no failure unless the device itself is |
| 93 | * in a bad state. |
| 94 | * |
| 95 | * Any number of calls to the execute, execute_1_2, and executeSynchronously |
| 96 | * functions, in any combination, may be made concurrently, even on the same |
| 97 | * IPreparedModel object. |
| 98 | * |
| 99 | * @param request The input and output information on which the prepared |
| 100 | * model is to be executed. |
| 101 | * @return status Error status of the execution, must be: |
| 102 | * - NONE if execution is performed successfully |
| 103 | * - DEVICE_UNAVAILABLE if driver is offline or busy |
| 104 | * - GENERAL_FAILURE if there is an unspecified error |
Michael Butler | a06e261 | 2019-01-15 10:52:41 -0800 | [diff] [blame] | 105 | * - OUTPUT_INSUFFICIENT_SIZE if at least one output |
| 106 | * operand buffer is not large enough to store the |
| 107 | * corresponding output |
David Gross | 4592ed1 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 108 | * - INVALID_ARGUMENT if one of the input arguments is |
| 109 | * invalid |
Michael Butler | a06e261 | 2019-01-15 10:52:41 -0800 | [diff] [blame] | 110 | * @return outputShapes A list of shape information of model output operands. |
| 111 | * The index into "outputShapes" corresponds to the index |
| 112 | * of the output operand in the Request outputs vector. |
| 113 | * outputShapes must be empty unless the status is either |
| 114 | * NONE or OUTPUT_INSUFFICIENT_SIZE. |
David Gross | 4592ed1 | 2018-12-21 11:20:26 -0800 | [diff] [blame] | 115 | */ |
| 116 | executeSynchronously(Request request) |
Michael Butler | a06e261 | 2019-01-15 10:52:41 -0800 | [diff] [blame] | 117 | generates (ErrorStatus status, vec<OutputShape> outputShapes); |
| 118 | |
| 119 | /** |
| 120 | * Configure a Burst object used to execute multiple inferences on a |
| 121 | * prepared model in rapid succession. |
| 122 | * |
| 123 | * @param callback A callback object used to retrieve memory resources |
| 124 | * corresponding to a unique identifiers ("slots"). |
| 125 | * @param requestChannel Used by the client to send a serialized Request to |
| 126 | * the Burst for execution. requestChannel must not be |
| 127 | * used to pass a second Request object until a result |
| 128 | * has been received from resultChannel. |
| 129 | * @param resultChannel Used by the service to return the results of an |
| 130 | * execution to the client: the status of the execution |
| 131 | * and OutputShape of all output tensors. resultChannel |
| 132 | * must be used to return the results if a Request was |
| 133 | * sent through the requestChannel. |
| 134 | * @return status Error status of configuring the execution burst, must be: |
| 135 | * - NONE if the burst is successfully configured |
| 136 | * - DEVICE_UNAVAILABLE if driver is offline or busy |
| 137 | * - GENERAL_FAILURE if there is an unspecified error |
| 138 | * - INVALID_ARGUMENT if one of the input arguments is |
| 139 | * invalid |
| 140 | * @return context Object containing all resources (such as cached |
| 141 | * hidl_memory) related to a Burst if successful, otherwise |
| 142 | * nullptr. |
| 143 | */ |
| 144 | configureExecutionBurst(IBurstCallback callback, |
| 145 | fmq_sync<FmqRequestDatum> requestChannel, |
| 146 | fmq_sync<FmqResultDatum> resultChannel) |
| 147 | generates (ErrorStatus status, IBurstContext context); |
Xusong Wang | 1a06e77 | 2018-10-31 08:43:12 -0700 | [diff] [blame] | 148 | }; |