Michael Butler | 376ec0c | 2017-07-27 18:28:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | |
Michael Butler | 376ec0c | 2017-07-27 18:28:20 -0700 | [diff] [blame] | 17 | package android.hardware.neuralnetworks@1.0; |
| 18 | |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 19 | import IExecutionCallback; |
Michael Butler | 0e2ac1b | 2017-09-01 10:59:38 -0700 | [diff] [blame] | 20 | |
Michael Butler | c782110 | 2017-09-11 16:03:36 -0700 | [diff] [blame] | 21 | /** |
| 22 | * IPreparedModel describes a model that has been prepared for execution and |
| 23 | * is used to launch executions. |
| 24 | */ |
Michael Butler | 376ec0c | 2017-07-27 18:28:20 -0700 | [diff] [blame] | 25 | interface IPreparedModel { |
Michael Butler | c782110 | 2017-09-11 16:03:36 -0700 | [diff] [blame] | 26 | /** |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 27 | * Launches an asynchronous execution on a prepared model. |
Michael Butler | c782110 | 2017-09-11 16:03:36 -0700 | [diff] [blame] | 28 | * |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 29 | * The execution is performed asynchronously with respect to the caller. |
| 30 | * execute must verify the inputs to the function are correct. If there is |
| 31 | * an error, execute must immediately invoke the callback with the |
| 32 | * appropriate ErrorStatus value, then return with the same ErrorStatus. If |
| 33 | * the inputs to the function are valid and there is no error, execute must |
| 34 | * launch an asynchronous task to perform the execution in the background, |
| 35 | * and immediately return with ErrorStatus::NONE. If the asynchronous task |
| 36 | * fails to launch, execute must immediately invoke the callback with |
| 37 | * ErrorStatus::GENERAL_FAILURE, then return with |
| 38 | * ErrorStatus::GENERAL_FAILURE. |
Michael Butler | c782110 | 2017-09-11 16:03:36 -0700 | [diff] [blame] | 39 | * |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 40 | * When the asynchronous task has finished its execution, it must |
| 41 | * immediately invoke the callback object provided as an input to the |
| 42 | * execute function. This callback must be provided with the ErrorStatus of |
| 43 | * the execution. |
| 44 | * |
David Gross | f406bf9 | 2019-06-20 13:30:54 -0700 | [diff] [blame] | 45 | * If the launch is successful, the caller must not change the content of |
| 46 | * any data object referenced by 'request' (described by the |
| 47 | * {@link DataLocation} of a {@link RequestArgument}) until the |
| 48 | * asynchronous task has invoked the callback object. The asynchronous task |
| 49 | * must not change the content of any of the data objects corresponding to |
| 50 | * 'request' inputs. |
| 51 | * |
David Gross | 48544cc | 2019-09-09 14:32:09 -0700 | [diff] [blame] | 52 | * If the prepared model was prepared from a model wherein all tensor |
| 53 | * operands have fully specified dimensions, and the inputs to the function |
| 54 | * are valid, then: |
| 55 | * - the execution should launch successfully (ErrorStatus::NONE): There |
| 56 | * must be no failure unless the device itself is in a bad state. |
| 57 | * - if at execution time every operation's input operands have legal |
| 58 | * values, the execution should complete successfully (ErrorStatus::NONE): |
| 59 | * There must be no failure unless the device itself is in a bad state. |
David Gross | 2a970cb | 2018-06-06 19:57:27 -0700 | [diff] [blame] | 60 | * |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 61 | * Multiple threads can call the execute function on the same IPreparedModel |
| 62 | * object concurrently with different requests. |
Michael Butler | c782110 | 2017-09-11 16:03:36 -0700 | [diff] [blame] | 63 | * |
| 64 | * @param request The input and output information on which the prepared |
| 65 | * model is to be executed. |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 66 | * @param callback A callback object used to return the error status of |
| 67 | * the execution. The callback object's notify function must |
| 68 | * be called exactly once, even if the execution was |
| 69 | * unsuccessful. |
Michael Butler | 926df1e | 2017-09-19 16:26:47 -0700 | [diff] [blame] | 70 | * @return status Error status of the call, must be: |
| 71 | * - NONE if task is successfully launched |
| 72 | * - DEVICE_UNAVAILABLE if driver is offline or busy |
| 73 | * - GENERAL_FAILURE if there is an unspecified error |
| 74 | * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is |
| 75 | * not large enough to store the resultant values |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 76 | * - INVALID_ARGUMENT if one of the input arguments is |
Michael Butler | 926df1e | 2017-09-19 16:26:47 -0700 | [diff] [blame] | 77 | * invalid |
Michael Butler | c782110 | 2017-09-11 16:03:36 -0700 | [diff] [blame] | 78 | */ |
Michael Butler | cf22a57 | 2017-09-22 13:26:12 -0700 | [diff] [blame] | 79 | execute(Request request, IExecutionCallback callback) |
| 80 | generates (ErrorStatus status); |
Michael Butler | 376ec0c | 2017-07-27 18:28:20 -0700 | [diff] [blame] | 81 | }; |