1*4d7e907cSAndroid Build Coastguard Worker/* 2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2017 The Android Open Source Project 3*4d7e907cSAndroid Build Coastguard Worker * 4*4d7e907cSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*4d7e907cSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*4d7e907cSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*4d7e907cSAndroid Build Coastguard Worker * 8*4d7e907cSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*4d7e907cSAndroid Build Coastguard Worker * 10*4d7e907cSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*4d7e907cSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*4d7e907cSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*4d7e907cSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*4d7e907cSAndroid Build Coastguard Worker * limitations under the License. 15*4d7e907cSAndroid Build Coastguard Worker */ 16*4d7e907cSAndroid Build Coastguard Worker 17*4d7e907cSAndroid Build Coastguard Workerpackage [email protected]; 18*4d7e907cSAndroid Build Coastguard Worker 19*4d7e907cSAndroid Build Coastguard Workerimport IExecutionCallback; 20*4d7e907cSAndroid Build Coastguard Worker 21*4d7e907cSAndroid Build Coastguard Worker/** 22*4d7e907cSAndroid Build Coastguard Worker * IPreparedModel describes a model that has been prepared for execution and 23*4d7e907cSAndroid Build Coastguard Worker * is used to launch executions. 24*4d7e907cSAndroid Build Coastguard Worker */ 25*4d7e907cSAndroid Build Coastguard Workerinterface IPreparedModel { 26*4d7e907cSAndroid Build Coastguard Worker /** 27*4d7e907cSAndroid Build Coastguard Worker * Launches an asynchronous execution on a prepared model. 28*4d7e907cSAndroid Build Coastguard Worker * 29*4d7e907cSAndroid Build Coastguard Worker * The execution is performed asynchronously with respect to the caller. 30*4d7e907cSAndroid Build Coastguard Worker * execute must verify the inputs to the function are correct. If there is 31*4d7e907cSAndroid Build Coastguard Worker * an error, execute must immediately invoke the callback with the 32*4d7e907cSAndroid Build Coastguard Worker * appropriate ErrorStatus value, then return with the same ErrorStatus. If 33*4d7e907cSAndroid Build Coastguard Worker * the inputs to the function are valid and there is no error, execute must 34*4d7e907cSAndroid Build Coastguard Worker * launch an asynchronous task to perform the execution in the background, 35*4d7e907cSAndroid Build Coastguard Worker * and immediately return with ErrorStatus::NONE. If the asynchronous task 36*4d7e907cSAndroid Build Coastguard Worker * fails to launch, execute must immediately invoke the callback with 37*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::GENERAL_FAILURE, then return with 38*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::GENERAL_FAILURE. 39*4d7e907cSAndroid Build Coastguard Worker * 40*4d7e907cSAndroid Build Coastguard Worker * When the asynchronous task has finished its execution, it must 41*4d7e907cSAndroid Build Coastguard Worker * immediately invoke the callback object provided as an input to the 42*4d7e907cSAndroid Build Coastguard Worker * execute function. This callback must be provided with the ErrorStatus of 43*4d7e907cSAndroid Build Coastguard Worker * the execution. 44*4d7e907cSAndroid Build Coastguard Worker * 45*4d7e907cSAndroid Build Coastguard Worker * If the launch is successful, the caller must not change the content of 46*4d7e907cSAndroid Build Coastguard Worker * any data object referenced by 'request' (described by the 47*4d7e907cSAndroid Build Coastguard Worker * {@link DataLocation} of a {@link RequestArgument}) until the 48*4d7e907cSAndroid Build Coastguard Worker * asynchronous task has invoked the callback object. The asynchronous task 49*4d7e907cSAndroid Build Coastguard Worker * must not change the content of any of the data objects corresponding to 50*4d7e907cSAndroid Build Coastguard Worker * 'request' inputs. 51*4d7e907cSAndroid Build Coastguard Worker * 52*4d7e907cSAndroid Build Coastguard Worker * If the prepared model was prepared from a model wherein all tensor 53*4d7e907cSAndroid Build Coastguard Worker * operands have fully specified dimensions, and the inputs to the function 54*4d7e907cSAndroid Build Coastguard Worker * are valid, then: 55*4d7e907cSAndroid Build Coastguard Worker * - the execution should launch successfully (ErrorStatus::NONE): There 56*4d7e907cSAndroid Build Coastguard Worker * must be no failure unless the device itself is in a bad state. 57*4d7e907cSAndroid Build Coastguard Worker * - if at execution time every operation's input operands have legal 58*4d7e907cSAndroid Build Coastguard Worker * values, the execution should complete successfully (ErrorStatus::NONE): 59*4d7e907cSAndroid Build Coastguard Worker * There must be no failure unless the device itself is in a bad state. 60*4d7e907cSAndroid Build Coastguard Worker * 61*4d7e907cSAndroid Build Coastguard Worker * Multiple threads can call the execute function on the same IPreparedModel 62*4d7e907cSAndroid Build Coastguard Worker * object concurrently with different requests. 63*4d7e907cSAndroid Build Coastguard Worker * 64*4d7e907cSAndroid Build Coastguard Worker * @param request The input and output information on which the prepared 65*4d7e907cSAndroid Build Coastguard Worker * model is to be executed. 66*4d7e907cSAndroid Build Coastguard Worker * @param callback A callback object used to return the error status of 67*4d7e907cSAndroid Build Coastguard Worker * the execution. The callback object's notify function must 68*4d7e907cSAndroid Build Coastguard Worker * be called exactly once, even if the execution was 69*4d7e907cSAndroid Build Coastguard Worker * unsuccessful. 70*4d7e907cSAndroid Build Coastguard Worker * @return status Error status of the call, must be: 71*4d7e907cSAndroid Build Coastguard Worker * - NONE if task is successfully launched 72*4d7e907cSAndroid Build Coastguard Worker * - DEVICE_UNAVAILABLE if driver is offline or busy 73*4d7e907cSAndroid Build Coastguard Worker * - GENERAL_FAILURE if there is an unspecified error 74*4d7e907cSAndroid Build Coastguard Worker * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is 75*4d7e907cSAndroid Build Coastguard Worker * not large enough to store the resultant values 76*4d7e907cSAndroid Build Coastguard Worker * - INVALID_ARGUMENT if one of the input arguments is 77*4d7e907cSAndroid Build Coastguard Worker * invalid 78*4d7e907cSAndroid Build Coastguard Worker */ 79*4d7e907cSAndroid Build Coastguard Worker execute(Request request, IExecutionCallback callback) 80*4d7e907cSAndroid Build Coastguard Worker generates (ErrorStatus status); 81*4d7e907cSAndroid Build Coastguard Worker}; 82