1*4d7e907cSAndroid Build Coastguard Worker/* 2*4d7e907cSAndroid Build Coastguard Worker * Copyright (C) 2019 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.2::IPreparedModel; 20*4d7e907cSAndroid Build Coastguard Workerimport @1.2::MeasureTiming; 21*4d7e907cSAndroid Build Coastguard Workerimport @1.2::OutputShape; 22*4d7e907cSAndroid Build Coastguard Workerimport @1.2::Timing; 23*4d7e907cSAndroid Build Coastguard Workerimport ErrorStatus; 24*4d7e907cSAndroid Build Coastguard Workerimport OptionalTimeoutDuration; 25*4d7e907cSAndroid Build Coastguard Workerimport OptionalTimePoint; 26*4d7e907cSAndroid Build Coastguard Workerimport Request; 27*4d7e907cSAndroid Build Coastguard Workerimport IExecutionCallback; 28*4d7e907cSAndroid Build Coastguard Workerimport IFencedExecutionCallback; 29*4d7e907cSAndroid Build Coastguard Worker 30*4d7e907cSAndroid Build Coastguard Worker/** 31*4d7e907cSAndroid Build Coastguard Worker * IPreparedModel describes a model that has been prepared for execution and 32*4d7e907cSAndroid Build Coastguard Worker * is used to launch executions. 33*4d7e907cSAndroid Build Coastguard Worker */ 34*4d7e907cSAndroid Build Coastguard Workerinterface IPreparedModel extends @1.2::IPreparedModel { 35*4d7e907cSAndroid Build Coastguard Worker /** 36*4d7e907cSAndroid Build Coastguard Worker * Launches an asynchronous execution on a prepared model. 37*4d7e907cSAndroid Build Coastguard Worker * 38*4d7e907cSAndroid Build Coastguard Worker * The execution is performed asynchronously with respect to the caller. 39*4d7e907cSAndroid Build Coastguard Worker * execute_1_3 must verify the inputs to the function are correct, and the usages 40*4d7e907cSAndroid Build Coastguard Worker * of memory pools allocated by IDevice::allocate are valid. If there is 41*4d7e907cSAndroid Build Coastguard Worker * an error, execute_1_3 must immediately invoke the callback with the 42*4d7e907cSAndroid Build Coastguard Worker * appropriate ErrorStatus value, then return with the same ErrorStatus. If 43*4d7e907cSAndroid Build Coastguard Worker * the inputs to the function are valid and there is no error, execute_1_3 must 44*4d7e907cSAndroid Build Coastguard Worker * launch an asynchronous task to perform the execution in the background, 45*4d7e907cSAndroid Build Coastguard Worker * and immediately return with ErrorStatus::NONE. If the asynchronous task 46*4d7e907cSAndroid Build Coastguard Worker * fails to launch, execute_1_3 must immediately invoke the callback with 47*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::GENERAL_FAILURE, then return with 48*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::GENERAL_FAILURE. 49*4d7e907cSAndroid Build Coastguard Worker * 50*4d7e907cSAndroid Build Coastguard Worker * When the asynchronous task has finished its execution, it must 51*4d7e907cSAndroid Build Coastguard Worker * immediately invoke the callback object provided as an input to the 52*4d7e907cSAndroid Build Coastguard Worker * execute_1_3 function. This callback must be provided with the ErrorStatus of 53*4d7e907cSAndroid Build Coastguard Worker * the execution. 54*4d7e907cSAndroid Build Coastguard Worker * 55*4d7e907cSAndroid Build Coastguard Worker * If the launch is successful, the caller must not change the content of 56*4d7e907cSAndroid Build Coastguard Worker * any data object referenced by 'request' (described by the 57*4d7e907cSAndroid Build Coastguard Worker * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}) until the 58*4d7e907cSAndroid Build Coastguard Worker * asynchronous task has invoked the callback object. The asynchronous task 59*4d7e907cSAndroid Build Coastguard Worker * must not change the content of any of the data objects corresponding to 60*4d7e907cSAndroid Build Coastguard Worker * 'request' inputs. 61*4d7e907cSAndroid Build Coastguard Worker * 62*4d7e907cSAndroid Build Coastguard Worker * If the prepared model was prepared from a model wherein all tensor 63*4d7e907cSAndroid Build Coastguard Worker * operands have fully specified dimensions, and the inputs to the function 64*4d7e907cSAndroid Build Coastguard Worker * are valid, then: 65*4d7e907cSAndroid Build Coastguard Worker * - the execution should launch successfully (ErrorStatus::NONE): There 66*4d7e907cSAndroid Build Coastguard Worker * must be no failure unless the device itself is in a bad state. 67*4d7e907cSAndroid Build Coastguard Worker * - if at execution time every operation's input operands have legal 68*4d7e907cSAndroid Build Coastguard Worker * values, the execution should complete successfully (ErrorStatus::NONE): 69*4d7e907cSAndroid Build Coastguard Worker * There must be no failure unless the device itself is in a bad state. 70*4d7e907cSAndroid Build Coastguard Worker * 71*4d7e907cSAndroid Build Coastguard Worker * execute_1_3 can be called with an optional deadline. If the execution 72*4d7e907cSAndroid Build Coastguard Worker * is not able to be completed before the provided deadline, the execution 73*4d7e907cSAndroid Build Coastguard Worker * may be aborted, and either {@link 74*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link 75*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::MISSED_DEADLINE_PERSISTENT} may be returned. The error due 76*4d7e907cSAndroid Build Coastguard Worker * to an abort must be sent the same way as other errors, described above. 77*4d7e907cSAndroid Build Coastguard Worker * The deadline is represented as nanoseconds since the epoch of the steady 78*4d7e907cSAndroid Build Coastguard Worker * clock (as if from std::chrono::steady_clock::time_point), but the service 79*4d7e907cSAndroid Build Coastguard Worker * may convert it to the nanoseconds since boot time (as if from 80*4d7e907cSAndroid Build Coastguard Worker * clock_gettime(CLOCK_BOOTTIME, &ts) or 81*4d7e907cSAndroid Build Coastguard Worker * android::base::boot_clock::time_point) to account for time when the 82*4d7e907cSAndroid Build Coastguard Worker * system is suspended. This conversion can by done by finding the timeout 83*4d7e907cSAndroid Build Coastguard Worker * duration remaining compared to the steady_clock and adding it to the 84*4d7e907cSAndroid Build Coastguard Worker * current boot_clock time. 85*4d7e907cSAndroid Build Coastguard Worker * 86*4d7e907cSAndroid Build Coastguard Worker * Any number of calls to the execute* and executeSynchronously* functions, 87*4d7e907cSAndroid Build Coastguard Worker * in any combination, may be made concurrently, even on the same 88*4d7e907cSAndroid Build Coastguard Worker * IPreparedModel object. 89*4d7e907cSAndroid Build Coastguard Worker * 90*4d7e907cSAndroid Build Coastguard Worker * @param request The input and output information on which the prepared 91*4d7e907cSAndroid Build Coastguard Worker * model is to be executed. 92*4d7e907cSAndroid Build Coastguard Worker * @param measure Specifies whether or not to measure duration of the execution. 93*4d7e907cSAndroid Build Coastguard Worker * The duration runs from the time the driver sees the call 94*4d7e907cSAndroid Build Coastguard Worker * to the execute_1_3 function to the time the driver invokes 95*4d7e907cSAndroid Build Coastguard Worker * the callback. 96*4d7e907cSAndroid Build Coastguard Worker * @param deadline The time by which the execution is expected to complete. 97*4d7e907cSAndroid Build Coastguard Worker * If the execution cannot be completed by the deadline, the 98*4d7e907cSAndroid Build Coastguard Worker * execution may be aborted. 99*4d7e907cSAndroid Build Coastguard Worker * @param loopTimeoutDuration The maximum amount of time that should be spent 100*4d7e907cSAndroid Build Coastguard Worker * executing a {@link OperationType::WHILE} 101*4d7e907cSAndroid Build Coastguard Worker * operation. If a loop condition model does not 102*4d7e907cSAndroid Build Coastguard Worker * output false within this duration, the 103*4d7e907cSAndroid Build Coastguard Worker * execution must be aborted. If no loop timeout 104*4d7e907cSAndroid Build Coastguard Worker * duration is provided, the maximum amount of 105*4d7e907cSAndroid Build Coastguard Worker * time is {@link LoopTimeoutDurationNs::DEFAULT}. 106*4d7e907cSAndroid Build Coastguard Worker * When provided, the duration must not exceed 107*4d7e907cSAndroid Build Coastguard Worker * {@link LoopTimeoutDurationNs::MAXIMUM}. 108*4d7e907cSAndroid Build Coastguard Worker * @param callback A callback object used to return the error status of 109*4d7e907cSAndroid Build Coastguard Worker * the execution, shape information of model output operands, and 110*4d7e907cSAndroid Build Coastguard Worker * duration of execution. The callback object's notify function must 111*4d7e907cSAndroid Build Coastguard Worker * be called exactly once, even if the execution was 112*4d7e907cSAndroid Build Coastguard Worker * unsuccessful. 113*4d7e907cSAndroid Build Coastguard Worker * @return status Error status of the call, must be: 114*4d7e907cSAndroid Build Coastguard Worker * - NONE if task is successfully launched 115*4d7e907cSAndroid Build Coastguard Worker * - DEVICE_UNAVAILABLE if driver is offline or busy 116*4d7e907cSAndroid Build Coastguard Worker * - GENERAL_FAILURE if there is an unspecified error 117*4d7e907cSAndroid Build Coastguard Worker * - OUTPUT_INSUFFICIENT_SIZE if provided output buffer is 118*4d7e907cSAndroid Build Coastguard Worker * not large enough to store the resultant values 119*4d7e907cSAndroid Build Coastguard Worker * - INVALID_ARGUMENT if one of the input arguments is 120*4d7e907cSAndroid Build Coastguard Worker * invalid 121*4d7e907cSAndroid Build Coastguard Worker * - MISSED_DEADLINE_* if the execution is aborted because it 122*4d7e907cSAndroid Build Coastguard Worker * cannot be completed by the deadline 123*4d7e907cSAndroid Build Coastguard Worker * - RESOURCE_EXHAUSTED_* if the task was aborted by the 124*4d7e907cSAndroid Build Coastguard Worker * driver 125*4d7e907cSAndroid Build Coastguard Worker */ 126*4d7e907cSAndroid Build Coastguard Worker execute_1_3(Request request, MeasureTiming measure, OptionalTimePoint deadline, 127*4d7e907cSAndroid Build Coastguard Worker OptionalTimeoutDuration loopTimeoutDuration, IExecutionCallback callback) 128*4d7e907cSAndroid Build Coastguard Worker generates (ErrorStatus status); 129*4d7e907cSAndroid Build Coastguard Worker 130*4d7e907cSAndroid Build Coastguard Worker /** 131*4d7e907cSAndroid Build Coastguard Worker * Performs a synchronous execution on a prepared model. 132*4d7e907cSAndroid Build Coastguard Worker * 133*4d7e907cSAndroid Build Coastguard Worker * The execution is performed synchronously with respect to the caller. 134*4d7e907cSAndroid Build Coastguard Worker * executeSynchronously_1_3 must verify the inputs to the function are 135*4d7e907cSAndroid Build Coastguard Worker * correct, and the usages of memory pools allocated by IDevice::allocate 136*4d7e907cSAndroid Build Coastguard Worker * are valid. If there is an error, executeSynchronously_1_3 must immediately 137*4d7e907cSAndroid Build Coastguard Worker * return with the appropriate ErrorStatus value. If the inputs to the 138*4d7e907cSAndroid Build Coastguard Worker * function are valid and there is no error, executeSynchronously_1_3 must 139*4d7e907cSAndroid Build Coastguard Worker * perform the execution, and must not return until the execution is 140*4d7e907cSAndroid Build Coastguard Worker * complete. 141*4d7e907cSAndroid Build Coastguard Worker * 142*4d7e907cSAndroid Build Coastguard Worker * The caller must not change the content of any data object referenced by 143*4d7e907cSAndroid Build Coastguard Worker * 'request' (described by the {@link @1.0::DataLocation} of a 144*4d7e907cSAndroid Build Coastguard Worker * {@link @1.0::RequestArgument}) until executeSynchronously_1_3 145*4d7e907cSAndroid Build Coastguard Worker * returns. executeSynchronously_1_3 must not change the content of any of the 146*4d7e907cSAndroid Build Coastguard Worker * data objects corresponding to 'request' inputs. 147*4d7e907cSAndroid Build Coastguard Worker * 148*4d7e907cSAndroid Build Coastguard Worker * If the prepared model was prepared from a model wherein all tensor 149*4d7e907cSAndroid Build Coastguard Worker * operands have fully specified dimensions, and the inputs to the function 150*4d7e907cSAndroid Build Coastguard Worker * are valid, and at execution time every operation's input operands have 151*4d7e907cSAndroid Build Coastguard Worker * legal values, then the execution should complete successfully 152*4d7e907cSAndroid Build Coastguard Worker * (ErrorStatus::NONE): There must be no failure unless the device itself is 153*4d7e907cSAndroid Build Coastguard Worker * in a bad state. 154*4d7e907cSAndroid Build Coastguard Worker * 155*4d7e907cSAndroid Build Coastguard Worker * executeSynchronously_1_3 may be called with an optional deadline. If the 156*4d7e907cSAndroid Build Coastguard Worker * execution is not able to be completed before the provided deadline, the 157*4d7e907cSAndroid Build Coastguard Worker * execution may be aborted, and either {@link 158*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link 159*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::MISSED_DEADLINE_PERSISTENT} may be returned. The error due 160*4d7e907cSAndroid Build Coastguard Worker * to an abort must be sent the same way as other errors, described above. 161*4d7e907cSAndroid Build Coastguard Worker * The deadline is represented as nanoseconds since the epoch of the steady 162*4d7e907cSAndroid Build Coastguard Worker * clock (as if from std::chrono::steady_clock::time_point), but the service 163*4d7e907cSAndroid Build Coastguard Worker * may convert it to the nanoseconds since boot time (as if from 164*4d7e907cSAndroid Build Coastguard Worker * clock_gettime(CLOCK_BOOTTIME, &ts) or 165*4d7e907cSAndroid Build Coastguard Worker * android::base::boot_clock::time_point) to account for time when the 166*4d7e907cSAndroid Build Coastguard Worker * system is suspended. This conversion can by done by finding the timeout 167*4d7e907cSAndroid Build Coastguard Worker * duration remaining compared to the steady_clock and adding it to the 168*4d7e907cSAndroid Build Coastguard Worker * current boot_clock time. 169*4d7e907cSAndroid Build Coastguard Worker * 170*4d7e907cSAndroid Build Coastguard Worker * Any number of calls to the execute* and executeSynchronously* functions, 171*4d7e907cSAndroid Build Coastguard Worker * in any combination, may be made concurrently, even on the same 172*4d7e907cSAndroid Build Coastguard Worker * IPreparedModel object. 173*4d7e907cSAndroid Build Coastguard Worker * 174*4d7e907cSAndroid Build Coastguard Worker * @param request The input and output information on which the prepared 175*4d7e907cSAndroid Build Coastguard Worker * model is to be executed. 176*4d7e907cSAndroid Build Coastguard Worker * @param measure Specifies whether or not to measure duration of the execution. 177*4d7e907cSAndroid Build Coastguard Worker * The duration runs from the time the driver sees the call 178*4d7e907cSAndroid Build Coastguard Worker * to the executeSynchronously_1_3 function to the time the driver 179*4d7e907cSAndroid Build Coastguard Worker * returns from the function. 180*4d7e907cSAndroid Build Coastguard Worker * @param deadline The time by which the execution is expected to complete. 181*4d7e907cSAndroid Build Coastguard Worker * If the execution cannot be finished by the deadline, the 182*4d7e907cSAndroid Build Coastguard Worker * execution may be aborted. 183*4d7e907cSAndroid Build Coastguard Worker * @param loopTimeoutDuration The maximum amount of time that should be spent 184*4d7e907cSAndroid Build Coastguard Worker * executing a {@link OperationType::WHILE} 185*4d7e907cSAndroid Build Coastguard Worker * operation. If a loop condition model does not 186*4d7e907cSAndroid Build Coastguard Worker * output false within this duration, the 187*4d7e907cSAndroid Build Coastguard Worker * execution must be aborted. If no loop timeout 188*4d7e907cSAndroid Build Coastguard Worker * duration is provided, the maximum amount of 189*4d7e907cSAndroid Build Coastguard Worker * time is {@link LoopTimeoutDurationNs::DEFAULT}. 190*4d7e907cSAndroid Build Coastguard Worker * When provided, the duration must not exceed 191*4d7e907cSAndroid Build Coastguard Worker * {@link LoopTimeoutDurationNs::MAXIMUM}. 192*4d7e907cSAndroid Build Coastguard Worker * @return status Error status of the execution, must be: 193*4d7e907cSAndroid Build Coastguard Worker * - NONE if execution is performed successfully 194*4d7e907cSAndroid Build Coastguard Worker * - DEVICE_UNAVAILABLE if driver is offline or busy 195*4d7e907cSAndroid Build Coastguard Worker * - GENERAL_FAILURE if there is an unspecified error 196*4d7e907cSAndroid Build Coastguard Worker * - OUTPUT_INSUFFICIENT_SIZE if at least one output 197*4d7e907cSAndroid Build Coastguard Worker * operand buffer is not large enough to store the 198*4d7e907cSAndroid Build Coastguard Worker * corresponding output 199*4d7e907cSAndroid Build Coastguard Worker * - INVALID_ARGUMENT if one of the input arguments is 200*4d7e907cSAndroid Build Coastguard Worker * invalid 201*4d7e907cSAndroid Build Coastguard Worker * - MISSED_DEADLINE_* if the execution is aborted because it 202*4d7e907cSAndroid Build Coastguard Worker * cannot be completed by the deadline 203*4d7e907cSAndroid Build Coastguard Worker * - RESOURCE_EXHAUSTED_* if the task was aborted by the 204*4d7e907cSAndroid Build Coastguard Worker * driver 205*4d7e907cSAndroid Build Coastguard Worker * @return outputShapes A list of shape information of model output operands. 206*4d7e907cSAndroid Build Coastguard Worker * The index into "outputShapes" corresponds to the index 207*4d7e907cSAndroid Build Coastguard Worker * of the output operand in the Request outputs vector. 208*4d7e907cSAndroid Build Coastguard Worker * outputShapes must be empty unless the status is either 209*4d7e907cSAndroid Build Coastguard Worker * NONE or OUTPUT_INSUFFICIENT_SIZE. 210*4d7e907cSAndroid Build Coastguard Worker * @return timing Duration of execution. Unless measure is YES and status is 211*4d7e907cSAndroid Build Coastguard Worker * NONE, all times must be reported as UINT64_MAX. A driver may 212*4d7e907cSAndroid Build Coastguard Worker * choose to report any time as UINT64_MAX, indicating that 213*4d7e907cSAndroid Build Coastguard Worker * measurement is not available. 214*4d7e907cSAndroid Build Coastguard Worker */ 215*4d7e907cSAndroid Build Coastguard Worker executeSynchronously_1_3(Request request, MeasureTiming measure, 216*4d7e907cSAndroid Build Coastguard Worker OptionalTimePoint deadline, 217*4d7e907cSAndroid Build Coastguard Worker OptionalTimeoutDuration loopTimeoutDuration) 218*4d7e907cSAndroid Build Coastguard Worker generates (ErrorStatus status, vec<OutputShape> outputShapes, 219*4d7e907cSAndroid Build Coastguard Worker Timing timing); 220*4d7e907cSAndroid Build Coastguard Worker 221*4d7e907cSAndroid Build Coastguard Worker /** 222*4d7e907cSAndroid Build Coastguard Worker * Launch a fenced asynchronous execution on a prepared model. 223*4d7e907cSAndroid Build Coastguard Worker * 224*4d7e907cSAndroid Build Coastguard Worker * The execution is performed asynchronously with respect to the caller. 225*4d7e907cSAndroid Build Coastguard Worker * executeFenced must verify the inputs to the function are correct, and the usages 226*4d7e907cSAndroid Build Coastguard Worker * of memory pools allocated by IDevice::allocate are valid. If there is an error, 227*4d7e907cSAndroid Build Coastguard Worker * executeFenced must immediately return with the corresponding ErrorStatus, an empty 228*4d7e907cSAndroid Build Coastguard Worker * handle for syncFence, and nullptr for callback. If the inputs to the function 229*4d7e907cSAndroid Build Coastguard Worker * are valid and there is no error, executeFenced must dispatch an asynchronous task 230*4d7e907cSAndroid Build Coastguard Worker * to perform the execution in the background, and immediately return with 231*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::NONE, a sync fence that will be signaled once the execution is completed, 232*4d7e907cSAndroid Build Coastguard Worker * and a callback that can be used by the client to query the duration and runtime error 233*4d7e907cSAndroid Build Coastguard Worker * status. If the task has finished before the call returns, an empty handle may be returned 234*4d7e907cSAndroid Build Coastguard Worker * for syncFence. The execution must wait for all the sync fences (if any) in waitFor 235*4d7e907cSAndroid Build Coastguard Worker * to be signaled before starting the actual execution. 236*4d7e907cSAndroid Build Coastguard Worker * 237*4d7e907cSAndroid Build Coastguard Worker * When the asynchronous task has finished its execution, it must 238*4d7e907cSAndroid Build Coastguard Worker * immediately signal the syncFence returned from the executeFenced call. After 239*4d7e907cSAndroid Build Coastguard Worker * the syncFence is signaled, the task must not modify the content of 240*4d7e907cSAndroid Build Coastguard Worker * any data object referenced by 'request' (described by the 241*4d7e907cSAndroid Build Coastguard Worker * {@link @1.0::DataLocation} of a {@link @1.0::RequestArgument}). 242*4d7e907cSAndroid Build Coastguard Worker * 243*4d7e907cSAndroid Build Coastguard Worker * executeFenced may be called with an optional deadline and an optional duration. 244*4d7e907cSAndroid Build Coastguard Worker * If the execution is not able to be completed before the provided deadline or 245*4d7e907cSAndroid Build Coastguard Worker * within the timeout duration (measured from when all sync fences in waitFor are 246*4d7e907cSAndroid Build Coastguard Worker * signaled), whichever comes earlier, the execution may be aborted, and either 247*4d7e907cSAndroid Build Coastguard Worker * {@link ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link 248*4d7e907cSAndroid Build Coastguard Worker * ErrorStatus::MISSED_DEADLINE_PERSISTENT} may be returned. The error due 249*4d7e907cSAndroid Build Coastguard Worker * to an abort must be sent the same way as other errors, described above. 250*4d7e907cSAndroid Build Coastguard Worker * The deadline is represented as nanoseconds since the epoch of the steady 251*4d7e907cSAndroid Build Coastguard Worker * clock (as if from std::chrono::steady_clock::time_point), but the service 252*4d7e907cSAndroid Build Coastguard Worker * may convert it to the nanoseconds since boot time (as if from 253*4d7e907cSAndroid Build Coastguard Worker * clock_gettime(CLOCK_BOOTTIME, &ts) or 254*4d7e907cSAndroid Build Coastguard Worker * android::base::boot_clock::time_point) to account for time when the 255*4d7e907cSAndroid Build Coastguard Worker * system is suspended. This conversion can by done by finding the timeout 256*4d7e907cSAndroid Build Coastguard Worker * duration remaining compared to the steady_clock and adding it to the 257*4d7e907cSAndroid Build Coastguard Worker * current boot_clock time. 258*4d7e907cSAndroid Build Coastguard Worker * 259*4d7e907cSAndroid Build Coastguard Worker * If any of the sync fences in waitFor changes to error status after the executeFenced 260*4d7e907cSAndroid Build Coastguard Worker * call succeeds, or the execution is aborted because it cannot finish before the deadline 261*4d7e907cSAndroid Build Coastguard Worker * has been reached or the duration has elapsed, the driver must immediately set the returned 262*4d7e907cSAndroid Build Coastguard Worker * syncFence to error status. 263*4d7e907cSAndroid Build Coastguard Worker * 264*4d7e907cSAndroid Build Coastguard Worker * Any number of calls to the executeFenced, execute* and executeSynchronously* 265*4d7e907cSAndroid Build Coastguard Worker * functions, in any combination, may be made concurrently, even on the same 266*4d7e907cSAndroid Build Coastguard Worker * IPreparedModel object. 267*4d7e907cSAndroid Build Coastguard Worker * 268*4d7e907cSAndroid Build Coastguard Worker * @param request The input and output information on which the prepared 269*4d7e907cSAndroid Build Coastguard Worker * model is to be executed. The outputs in the request must have 270*4d7e907cSAndroid Build Coastguard Worker * fully specified dimensions. 271*4d7e907cSAndroid Build Coastguard Worker * @param waitFor A vector of sync fence file descriptors. 272*4d7e907cSAndroid Build Coastguard Worker * Execution must not start until all sync fences have been signaled. 273*4d7e907cSAndroid Build Coastguard Worker * @param measure Specifies whether or not to measure duration of the execution. 274*4d7e907cSAndroid Build Coastguard Worker * @param deadline The time by which the execution is expected to complete. 275*4d7e907cSAndroid Build Coastguard Worker * If the execution cannot be finished by the deadline, the 276*4d7e907cSAndroid Build Coastguard Worker * execution may be aborted. 277*4d7e907cSAndroid Build Coastguard Worker * @param loopTimeoutDuration The maximum amount of time that should be spent 278*4d7e907cSAndroid Build Coastguard Worker * executing a {@link OperationType::WHILE} 279*4d7e907cSAndroid Build Coastguard Worker * operation. If a loop condition model does not 280*4d7e907cSAndroid Build Coastguard Worker * output false within this duration, the 281*4d7e907cSAndroid Build Coastguard Worker * execution must be aborted. If no loop timeout 282*4d7e907cSAndroid Build Coastguard Worker * duration is provided, the maximum amount of 283*4d7e907cSAndroid Build Coastguard Worker * time is {@link LoopTimeoutDurationNs::DEFAULT}. 284*4d7e907cSAndroid Build Coastguard Worker * When provided, the duration must not exceed 285*4d7e907cSAndroid Build Coastguard Worker * {@link LoopTimeoutDurationNs::MAXIMUM}. 286*4d7e907cSAndroid Build Coastguard Worker * @param duration The length of time within which the execution is expected 287*4d7e907cSAndroid Build Coastguard Worker * to complete after all sync fences in waitFor are signaled. 288*4d7e907cSAndroid Build Coastguard Worker * If the execution cannot be finished within the duration, 289*4d7e907cSAndroid Build Coastguard Worker * the execution may be aborted. 290*4d7e907cSAndroid Build Coastguard Worker * @return status Error status of the call, must be: 291*4d7e907cSAndroid Build Coastguard Worker * - NONE if task is successfully launched 292*4d7e907cSAndroid Build Coastguard Worker * - DEVICE_UNAVAILABLE if driver is offline or busy 293*4d7e907cSAndroid Build Coastguard Worker * - GENERAL_FAILURE if there is an unspecified error 294*4d7e907cSAndroid Build Coastguard Worker * - INVALID_ARGUMENT if one of the input arguments is invalid, including 295*4d7e907cSAndroid Build Coastguard Worker * fences in error states. 296*4d7e907cSAndroid Build Coastguard Worker * - MISSED_DEADLINE_* if the execution is aborted because it 297*4d7e907cSAndroid Build Coastguard Worker * cannot be completed by the deadline 298*4d7e907cSAndroid Build Coastguard Worker * - RESOURCE_EXHAUSTED_* if the task was aborted by the 299*4d7e907cSAndroid Build Coastguard Worker * driver 300*4d7e907cSAndroid Build Coastguard Worker * @return syncFence The sync fence that will be signaled when the task is completed. 301*4d7e907cSAndroid Build Coastguard Worker * The sync fence will be set to error if a critical error, 302*4d7e907cSAndroid Build Coastguard Worker * e.g. hardware failure or kernel panic, occurs when doing execution. 303*4d7e907cSAndroid Build Coastguard Worker * @return callback The IFencedExecutionCallback can be used to query information like duration 304*4d7e907cSAndroid Build Coastguard Worker * and error status when the execution is completed. 305*4d7e907cSAndroid Build Coastguard Worker */ 306*4d7e907cSAndroid Build Coastguard Worker executeFenced(Request request, vec<handle> waitFor, MeasureTiming measure, 307*4d7e907cSAndroid Build Coastguard Worker OptionalTimePoint deadline, OptionalTimeoutDuration loopTimeoutDuration, 308*4d7e907cSAndroid Build Coastguard Worker OptionalTimeoutDuration duration) 309*4d7e907cSAndroid Build Coastguard Worker generates (ErrorStatus status, handle syncFence, IFencedExecutionCallback callback); 310*4d7e907cSAndroid Build Coastguard Worker}; 311