1*4d7e907cSAndroid Build Coastguard Worker/* 2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2018 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 @1.0::ErrorStatus; 20*4d7e907cSAndroid Build Coastguard Workerimport @1.0::IPreparedModel; 21*4d7e907cSAndroid Build Coastguard Workerimport @1.0::Request; 22*4d7e907cSAndroid Build Coastguard Workerimport IBurstCallback; 23*4d7e907cSAndroid Build Coastguard Workerimport IBurstContext; 24*4d7e907cSAndroid Build Coastguard Workerimport IExecutionCallback; 25*4d7e907cSAndroid Build Coastguard Worker 26*4d7e907cSAndroid Build Coastguard Worker/** 27*4d7e907cSAndroid Build Coastguard Worker * IPreparedModel describes a model that has been prepared for execution and 28*4d7e907cSAndroid Build Coastguard Worker * is used to launch executions. 29*4d7e907cSAndroid Build Coastguard Worker */ 30*4d7e907cSAndroid Build Coastguard Workerinterface IPreparedModel extends @1.0::IPreparedModel { 31*4d7e907cSAndroid Build Coastguard Worker /** 32*4d7e907cSAndroid Build Coastguard Worker * Launches an asynchronous execution on a prepared model. 33*4d7e907cSAndroid Build Coastguard Worker * 34*4d7e907cSAndroid Build Coastguard Worker * The execution is performed asynchronously with respect to the caller. 35*4d7e907cSAndroid Build Coastguard Worker * execute_1_2 must verify the inputs to the function are correct. If there is 36*4d7e907cSAndroid Build Coastguard Worker * an error, execute_1_2 must immediately invoke the callback with the 37*4d7e907cSAndroid Build Coastguard Worker * appropriate ErrorStatus value, then return with the same ErrorStatus. If 38*4d7e907cSAndroid Build Coastguard Worker * the inputs to the function are valid and there is no error, execute_1_2 must 39*4d7e907cSAndroid Build Coastguard Worker * launch an asynchronous task to perform the execution in the background, 40*4d7e907cSAndroid Build Coastguard Worker * and immediately return with ErrorStatus::NONE. If the asynchronous task 41*4d7e907cSAndroid Build Coastguard Worker * fails to launch, execute_1_2 must immediately invoke the callback with 42*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::GENERAL_FAILURE, then return with 43*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::GENERAL_FAILURE. 44*4d7e907cSAndroid Build Coastguard Worker * 45*4d7e907cSAndroid Build Coastguard Worker * When the asynchronous task has finished its execution, it must 46*4d7e907cSAndroid Build Coastguard Worker * immediately invoke the callback object provided as an input to the 47*4d7e907cSAndroid Build Coastguard Worker * execute_1_2 function. This callback must be provided with the ErrorStatus of 48*4d7e907cSAndroid Build Coastguard Worker * the execution. 49*4d7e907cSAndroid Build Coastguard Worker * 50*4d7e907cSAndroid Build Coastguard Worker * If the launch is successful, the caller must not change the content of 51*4d7e907cSAndroid Build Coastguard Worker * any data object referenced by 'request' (described by the 52*4d7e907cSAndroid Build Coastguard Worker * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}) until the 53*4d7e907cSAndroid Build Coastguard Worker * asynchronous task has invoked the callback object. The asynchronous task 54*4d7e907cSAndroid Build Coastguard Worker * must not change the content of any of the data objects corresponding to 55*4d7e907cSAndroid Build Coastguard Worker * 'request' inputs. 56*4d7e907cSAndroid Build Coastguard Worker * 57*4d7e907cSAndroid Build Coastguard Worker * If the prepared model was prepared from a model wherein all tensor 58*4d7e907cSAndroid Build Coastguard Worker * operands have fully specified dimensions, and the inputs to the function 59*4d7e907cSAndroid Build Coastguard Worker * are valid, then: 60*4d7e907cSAndroid Build Coastguard Worker * - the execution should launch successfully (ErrorStatus::NONE): There 61*4d7e907cSAndroid Build Coastguard Worker * must be no failure unless the device itself is in a bad state. 62*4d7e907cSAndroid Build Coastguard Worker * - if at execution time every operation's input operands have legal 63*4d7e907cSAndroid Build Coastguard Worker * values, the execution should complete successfully (ErrorStatus::NONE): 64*4d7e907cSAndroid Build Coastguard Worker * There must be no failure unless the device itself is in a bad state. 65*4d7e907cSAndroid Build Coastguard Worker * 66*4d7e907cSAndroid Build Coastguard Worker * Any number of calls to the execute, execute_1_2, and executeSynchronously 67*4d7e907cSAndroid Build Coastguard Worker * functions, in any combination, may be made concurrently, even on the same 68*4d7e907cSAndroid Build Coastguard Worker * IPreparedModel object. 69*4d7e907cSAndroid Build Coastguard Worker * 70*4d7e907cSAndroid Build Coastguard Worker * @param request The input and output information on which the prepared 71*4d7e907cSAndroid Build Coastguard Worker * model is to be executed. 72*4d7e907cSAndroid Build Coastguard Worker * @param measure Specifies whether or not to measure duration of the execution. 73*4d7e907cSAndroid Build Coastguard Worker * The duration runs from the time the driver sees the call 74*4d7e907cSAndroid Build Coastguard Worker * to the execute_1_2 function to the time the driver invokes 75*4d7e907cSAndroid Build Coastguard Worker * the callback. 76*4d7e907cSAndroid Build Coastguard Worker * @param callback A callback object used to return the error status of 77*4d7e907cSAndroid Build Coastguard Worker * the execution. The callback object's notify function must 78*4d7e907cSAndroid Build Coastguard Worker * be called exactly once, even if the execution was 79*4d7e907cSAndroid Build Coastguard Worker * unsuccessful. 80*4d7e907cSAndroid Build Coastguard Worker * @return status Error status of the call, must be: 81*4d7e907cSAndroid Build Coastguard Worker * - NONE if task is successfully launched 82*4d7e907cSAndroid Build Coastguard Worker * - DEVICE_UNAVAILABLE if driver is offline or busy 83*4d7e907cSAndroid Build Coastguard Worker * - GENERAL_FAILURE if there is an unspecified error 84*4d7e907cSAndroid Build Coastguard Worker * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is 85*4d7e907cSAndroid Build Coastguard Worker * not large enough to store the resultant values 86*4d7e907cSAndroid Build Coastguard Worker * - INVALID_ARGUMENT if one of the input arguments is 87*4d7e907cSAndroid Build Coastguard Worker * invalid 88*4d7e907cSAndroid Build Coastguard Worker */ 89*4d7e907cSAndroid Build Coastguard Worker execute_1_2(Request request, MeasureTiming measure, IExecutionCallback callback) 90*4d7e907cSAndroid Build Coastguard Worker generates (ErrorStatus status); 91*4d7e907cSAndroid Build Coastguard Worker 92*4d7e907cSAndroid Build Coastguard Worker /** 93*4d7e907cSAndroid Build Coastguard Worker * Performs a synchronous execution on a prepared model. 94*4d7e907cSAndroid Build Coastguard Worker * 95*4d7e907cSAndroid Build Coastguard Worker * The execution is performed synchronously with respect to the caller. 96*4d7e907cSAndroid Build Coastguard Worker * executeSynchronously must verify the inputs to the function are 97*4d7e907cSAndroid Build Coastguard Worker * correct. If there is an error, executeSynchronously must immediately 98*4d7e907cSAndroid Build Coastguard Worker * return with the appropriate ErrorStatus value. If the inputs to the 99*4d7e907cSAndroid Build Coastguard Worker * function are valid and there is no error, executeSynchronously must 100*4d7e907cSAndroid Build Coastguard Worker * perform the execution, and must not return until the execution is 101*4d7e907cSAndroid Build Coastguard Worker * complete. 102*4d7e907cSAndroid Build Coastguard Worker * 103*4d7e907cSAndroid Build Coastguard Worker * The caller must not change the content of any data object referenced by 104*4d7e907cSAndroid Build Coastguard Worker * 'request' (described by the {@link @1.0::DataLocation} of a 105*4d7e907cSAndroid Build Coastguard Worker * {@link @1.0::RequestArgument}) until executeSynchronously 106*4d7e907cSAndroid Build Coastguard Worker * returns. executeSynchronously must not change the content of any of the 107*4d7e907cSAndroid Build Coastguard Worker * data objects corresponding to 'request' inputs. 108*4d7e907cSAndroid Build Coastguard Worker * 109*4d7e907cSAndroid Build Coastguard Worker * If the prepared model was prepared from a model wherein all tensor 110*4d7e907cSAndroid Build Coastguard Worker * operands have fully specified dimensions, and the inputs to the function 111*4d7e907cSAndroid Build Coastguard Worker * are valid, and at execution time every operation's input operands have 112*4d7e907cSAndroid Build Coastguard Worker * legal values, then the execution should complete successfully 113*4d7e907cSAndroid Build Coastguard Worker * (ErrorStatus::NONE): There must be no failure unless the device itself is 114*4d7e907cSAndroid Build Coastguard Worker * in a bad state. 115*4d7e907cSAndroid Build Coastguard Worker * 116*4d7e907cSAndroid Build Coastguard Worker * Any number of calls to the execute, execute_1_2, and executeSynchronously 117*4d7e907cSAndroid Build Coastguard Worker * functions, in any combination, may be made concurrently, even on the same 118*4d7e907cSAndroid Build Coastguard Worker * IPreparedModel object. 119*4d7e907cSAndroid Build Coastguard Worker * 120*4d7e907cSAndroid Build Coastguard Worker * @param request The input and output information on which the prepared 121*4d7e907cSAndroid Build Coastguard Worker * model is to be executed. 122*4d7e907cSAndroid Build Coastguard Worker * @param measure Specifies whether or not to measure duration of the execution. 123*4d7e907cSAndroid Build Coastguard Worker * The duration runs from the time the driver sees the call 124*4d7e907cSAndroid Build Coastguard Worker * to the executeSynchronously function to the time the driver 125*4d7e907cSAndroid Build Coastguard Worker * returns from the function. 126*4d7e907cSAndroid Build Coastguard Worker * @return status Error status of the execution, must be: 127*4d7e907cSAndroid Build Coastguard Worker * - NONE if execution is performed successfully 128*4d7e907cSAndroid Build Coastguard Worker * - DEVICE_UNAVAILABLE if driver is offline or busy 129*4d7e907cSAndroid Build Coastguard Worker * - GENERAL_FAILURE if there is an unspecified error 130*4d7e907cSAndroid Build Coastguard Worker * - OUTPUT_INSUFFICIENT_SIZE if at least one output 131*4d7e907cSAndroid Build Coastguard Worker * operand buffer is not large enough to store the 132*4d7e907cSAndroid Build Coastguard Worker * corresponding output 133*4d7e907cSAndroid Build Coastguard Worker * - INVALID_ARGUMENT if one of the input arguments is 134*4d7e907cSAndroid Build Coastguard Worker * invalid 135*4d7e907cSAndroid Build Coastguard Worker * @return outputShapes A list of shape information of model output operands. 136*4d7e907cSAndroid Build Coastguard Worker * The index into "outputShapes" corresponds to the index 137*4d7e907cSAndroid Build Coastguard Worker * of the output operand in the Request outputs vector. 138*4d7e907cSAndroid Build Coastguard Worker * outputShapes must be empty unless the status is either 139*4d7e907cSAndroid Build Coastguard Worker * NONE or OUTPUT_INSUFFICIENT_SIZE. 140*4d7e907cSAndroid Build Coastguard Worker * @return Timing Duration of execution. Unless measure is YES and status is 141*4d7e907cSAndroid Build Coastguard Worker * NONE, all times must be reported as UINT64_MAX. A driver may 142*4d7e907cSAndroid Build Coastguard Worker * choose to report any time as UINT64_MAX, indicating that 143*4d7e907cSAndroid Build Coastguard Worker * measurement is not available. 144*4d7e907cSAndroid Build Coastguard Worker */ 145*4d7e907cSAndroid Build Coastguard Worker executeSynchronously(Request request, MeasureTiming measure) 146*4d7e907cSAndroid Build Coastguard Worker generates (ErrorStatus status, vec<OutputShape> outputShapes, Timing timing); 147*4d7e907cSAndroid Build Coastguard Worker 148*4d7e907cSAndroid Build Coastguard Worker /** 149*4d7e907cSAndroid Build Coastguard Worker * Configure a Burst object used to execute multiple inferences on a 150*4d7e907cSAndroid Build Coastguard Worker * prepared model in rapid succession. 151*4d7e907cSAndroid Build Coastguard Worker * 152*4d7e907cSAndroid Build Coastguard Worker * If the prepared model was prepared from a model wherein all tensor 153*4d7e907cSAndroid Build Coastguard Worker * operands have fully specified dimensions, and a valid serialized Request 154*4d7e907cSAndroid Build Coastguard Worker * is sent to the Burst for execution, and at execution time every 155*4d7e907cSAndroid Build Coastguard Worker * operation's input operands have legal values, then the execution should 156*4d7e907cSAndroid Build Coastguard Worker * complete successfully (ErrorStatus::NONE): There must be no failure 157*4d7e907cSAndroid Build Coastguard Worker * unless the device itself is in a bad state. 158*4d7e907cSAndroid Build Coastguard Worker * 159*4d7e907cSAndroid Build Coastguard Worker * @param callback A callback object used to retrieve memory resources 160*4d7e907cSAndroid Build Coastguard Worker * corresponding to unique identifiers ("slots"). 161*4d7e907cSAndroid Build Coastguard Worker * @param requestChannel FMQ used by the client to send a serialized Request 162*4d7e907cSAndroid Build Coastguard Worker * to the Burst for execution. The client must not 163*4d7e907cSAndroid Build Coastguard Worker * change the content of any data object referenced by 164*4d7e907cSAndroid Build Coastguard Worker * the Request (described by the 165*4d7e907cSAndroid Build Coastguard Worker * {@link @1.0::DataLocation} of an 166*4d7e907cSAndroid Build Coastguard Worker * {@link OperandInformation}) until a result has been 167*4d7e907cSAndroid Build Coastguard Worker * received from resultChannel. Execution must not 168*4d7e907cSAndroid Build Coastguard Worker * change the content of any of the data objects 169*4d7e907cSAndroid Build Coastguard Worker * corresponding to Request inputs. requestChannel 170*4d7e907cSAndroid Build Coastguard Worker * must not be used to pass a second Request object 171*4d7e907cSAndroid Build Coastguard Worker * until a result has been received from 172*4d7e907cSAndroid Build Coastguard Worker * resultChannel. The client must send the request 173*4d7e907cSAndroid Build Coastguard Worker * messages to the consumer atomically by using 174*4d7e907cSAndroid Build Coastguard Worker * MessageQueue::writeBlocking if the queue is 175*4d7e907cSAndroid Build Coastguard Worker * blocking, or by using MessageQueue::write if the 176*4d7e907cSAndroid Build Coastguard Worker * queue is non-blocking. When the service receives a 177*4d7e907cSAndroid Build Coastguard Worker * packet, it must dequeue the entire packet from the 178*4d7e907cSAndroid Build Coastguard Worker * requestChannel. The client must not send a request 179*4d7e907cSAndroid Build Coastguard Worker * packet that exceeds the length of the FMQ. 180*4d7e907cSAndroid Build Coastguard Worker * @param resultChannel FMQ used by the service to return the results of an 181*4d7e907cSAndroid Build Coastguard Worker * execution to the client: the status of the 182*4d7e907cSAndroid Build Coastguard Worker * execution, OutputShape of all output tensors, and 183*4d7e907cSAndroid Build Coastguard Worker * timing information. resultChannel must be used to 184*4d7e907cSAndroid Build Coastguard Worker * return the results if a Request was sent through the 185*4d7e907cSAndroid Build Coastguard Worker * requestChannel. The service must send the result 186*4d7e907cSAndroid Build Coastguard Worker * messages to the consumer atomically by using 187*4d7e907cSAndroid Build Coastguard Worker * MessageQueue::writeBlocking if the queue is 188*4d7e907cSAndroid Build Coastguard Worker * blocking, or by using MessageQueue::write if the 189*4d7e907cSAndroid Build Coastguard Worker * queue is non-blocking. When the client receives a 190*4d7e907cSAndroid Build Coastguard Worker * packet, it must dequeue the entire packet from the 191*4d7e907cSAndroid Build Coastguard Worker * resultChannel. If the packet's length exceeds the 192*4d7e907cSAndroid Build Coastguard Worker * size of the FMQ, the service must not send this 193*4d7e907cSAndroid Build Coastguard Worker * result packet; instead, the service must send a 194*4d7e907cSAndroid Build Coastguard Worker * packet consisting of the error code 195*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::GENERAL_FAILURE, no information for the 196*4d7e907cSAndroid Build Coastguard Worker * outputShapes, and an indication that timing 197*4d7e907cSAndroid Build Coastguard Worker * information is unavailable. 198*4d7e907cSAndroid Build Coastguard Worker * @return status Error status of configuring the execution burst, must be: 199*4d7e907cSAndroid Build Coastguard Worker * - NONE if the burst is successfully configured 200*4d7e907cSAndroid Build Coastguard Worker * - DEVICE_UNAVAILABLE if driver is offline or busy 201*4d7e907cSAndroid Build Coastguard Worker * - GENERAL_FAILURE if there is an unspecified error 202*4d7e907cSAndroid Build Coastguard Worker * - INVALID_ARGUMENT if one of the input arguments is 203*4d7e907cSAndroid Build Coastguard Worker * invalid 204*4d7e907cSAndroid Build Coastguard Worker * @return context Object containing all resources (such as cached 205*4d7e907cSAndroid Build Coastguard Worker * hidl_memory) related to a Burst if successful, otherwise 206*4d7e907cSAndroid Build Coastguard Worker * nullptr. 207*4d7e907cSAndroid Build Coastguard Worker */ 208*4d7e907cSAndroid Build Coastguard Worker configureExecutionBurst(IBurstCallback callback, 209*4d7e907cSAndroid Build Coastguard Worker fmq_sync<FmqRequestDatum> requestChannel, 210*4d7e907cSAndroid Build Coastguard Worker fmq_sync<FmqResultDatum> resultChannel) 211*4d7e907cSAndroid Build Coastguard Worker generates (ErrorStatus status, IBurstContext context); 212*4d7e907cSAndroid Build Coastguard Worker}; 213