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::IDevice; 21*4d7e907cSAndroid Build Coastguard Workerimport @1.0::IPreparedModelCallback; 22*4d7e907cSAndroid Build Coastguard Worker 23*4d7e907cSAndroid Build Coastguard Worker/** 24*4d7e907cSAndroid Build Coastguard Worker * This interface represents a device driver. 25*4d7e907cSAndroid Build Coastguard Worker */ 26*4d7e907cSAndroid Build Coastguard Workerinterface IDevice extends @1.0::IDevice { 27*4d7e907cSAndroid Build Coastguard Worker /** 28*4d7e907cSAndroid Build Coastguard Worker * Gets the capabilities of a driver. 29*4d7e907cSAndroid Build Coastguard Worker * 30*4d7e907cSAndroid Build Coastguard Worker * Note that @1.1::Capabilities provides performance information 31*4d7e907cSAndroid Build Coastguard Worker * on relaxed calculations, whereas @1.0::Capabilities does not. 32*4d7e907cSAndroid Build Coastguard Worker * 33*4d7e907cSAndroid Build Coastguard Worker * @return status Error status of the call, must be: 34*4d7e907cSAndroid Build Coastguard Worker * - NONE if successful 35*4d7e907cSAndroid Build Coastguard Worker * - DEVICE_UNAVAILABLE if driver is offline or busy 36*4d7e907cSAndroid Build Coastguard Worker * - GENERAL_FAILURE if there is an unspecified error 37*4d7e907cSAndroid Build Coastguard Worker * @return capabilities Capabilities of the driver. 38*4d7e907cSAndroid Build Coastguard Worker */ 39*4d7e907cSAndroid Build Coastguard Worker getCapabilities_1_1() generates (ErrorStatus status, Capabilities capabilities); 40*4d7e907cSAndroid Build Coastguard Worker 41*4d7e907cSAndroid Build Coastguard Worker /** 42*4d7e907cSAndroid Build Coastguard Worker * Gets the supported operations in a model. 43*4d7e907cSAndroid Build Coastguard Worker * 44*4d7e907cSAndroid Build Coastguard Worker * getSupportedOperations indicates which operations of a model are fully 45*4d7e907cSAndroid Build Coastguard Worker * supported by the vendor driver. If an operation may not be supported for 46*4d7e907cSAndroid Build Coastguard Worker * any reason, getSupportedOperations must return false for that operation. 47*4d7e907cSAndroid Build Coastguard Worker * 48*4d7e907cSAndroid Build Coastguard Worker * @param model A model whose operations--and their corresponding 49*4d7e907cSAndroid Build Coastguard Worker * operands--are to be verified by the driver. 50*4d7e907cSAndroid Build Coastguard Worker * @return status Error status of the call, must be: 51*4d7e907cSAndroid Build Coastguard Worker * - NONE if successful 52*4d7e907cSAndroid Build Coastguard Worker * - DEVICE_UNAVAILABLE if driver is offline or busy 53*4d7e907cSAndroid Build Coastguard Worker * - GENERAL_FAILURE if there is an unspecified error 54*4d7e907cSAndroid Build Coastguard Worker * - INVALID_ARGUMENT if provided model is invalid 55*4d7e907cSAndroid Build Coastguard Worker * @return supportedOperations A list of supported operations, where true 56*4d7e907cSAndroid Build Coastguard Worker * indicates the operation is supported and 57*4d7e907cSAndroid Build Coastguard Worker * false indicates the operation is not 58*4d7e907cSAndroid Build Coastguard Worker * supported. The index of "supported" 59*4d7e907cSAndroid Build Coastguard Worker * corresponds with the index of the operation 60*4d7e907cSAndroid Build Coastguard Worker * it is describing. 61*4d7e907cSAndroid Build Coastguard Worker */ 62*4d7e907cSAndroid Build Coastguard Worker getSupportedOperations_1_1(Model model) 63*4d7e907cSAndroid Build Coastguard Worker generates (ErrorStatus status, vec<bool> supportedOperations); 64*4d7e907cSAndroid Build Coastguard Worker 65*4d7e907cSAndroid Build Coastguard Worker /** 66*4d7e907cSAndroid Build Coastguard Worker * Creates a prepared model for execution. 67*4d7e907cSAndroid Build Coastguard Worker * 68*4d7e907cSAndroid Build Coastguard Worker * prepareModel is used to make any necessary transformations or alternative 69*4d7e907cSAndroid Build Coastguard Worker * representations to a model for execution, possiblly including 70*4d7e907cSAndroid Build Coastguard Worker * transformations on the constant data, optimization on the model's graph, 71*4d7e907cSAndroid Build Coastguard Worker * or compilation into the device's native binary format. The model itself 72*4d7e907cSAndroid Build Coastguard Worker * is not changed. 73*4d7e907cSAndroid Build Coastguard Worker * 74*4d7e907cSAndroid Build Coastguard Worker * The model is prepared asynchronously with respect to the caller. The 75*4d7e907cSAndroid Build Coastguard Worker * prepareModel function must verify the inputs to the prepareModel function 76*4d7e907cSAndroid Build Coastguard Worker * are correct. If there is an error, prepareModel must immediately invoke 77*4d7e907cSAndroid Build Coastguard Worker * the callback with the appropriate ErrorStatus value and nullptr for the 78*4d7e907cSAndroid Build Coastguard Worker * IPreparedModel, then return with the same ErrorStatus. If the inputs to 79*4d7e907cSAndroid Build Coastguard Worker * the prepareModel function are valid and there is no error, prepareModel 80*4d7e907cSAndroid Build Coastguard Worker * must launch an asynchronous task to prepare the model in the background, 81*4d7e907cSAndroid Build Coastguard Worker * and immediately return from prepareModel with ErrorStatus::NONE. If the 82*4d7e907cSAndroid Build Coastguard Worker * asynchronous task fails to launch, prepareModel must immediately invoke 83*4d7e907cSAndroid Build Coastguard Worker * the callback with ErrorStatus::GENERAL_FAILURE and nullptr for the 84*4d7e907cSAndroid Build Coastguard Worker * IPreparedModel, then return with ErrorStatus::GENERAL_FAILURE. 85*4d7e907cSAndroid Build Coastguard Worker * 86*4d7e907cSAndroid Build Coastguard Worker * When the asynchronous task has finished preparing the model, it must 87*4d7e907cSAndroid Build Coastguard Worker * immediately invoke the callback function provided as an input to 88*4d7e907cSAndroid Build Coastguard Worker * prepareModel. If the model was prepared successfully, the callback object 89*4d7e907cSAndroid Build Coastguard Worker * must be invoked with an error status of ErrorStatus::NONE and the 90*4d7e907cSAndroid Build Coastguard Worker * produced IPreparedModel object. If an error occurred preparing the model, 91*4d7e907cSAndroid Build Coastguard Worker * the callback object must be invoked with the appropriate ErrorStatus 92*4d7e907cSAndroid Build Coastguard Worker * value and nullptr for the IPreparedModel. 93*4d7e907cSAndroid Build Coastguard Worker * 94*4d7e907cSAndroid Build Coastguard Worker * The only information that may be unknown to the model at this stage is 95*4d7e907cSAndroid Build Coastguard Worker * the shape of the tensors, which may only be known at execution time. As 96*4d7e907cSAndroid Build Coastguard Worker * such, some driver services may return partially prepared models, where 97*4d7e907cSAndroid Build Coastguard Worker * the prepared model can only be finished when it is paired with a set of 98*4d7e907cSAndroid Build Coastguard Worker * inputs to the model. Note that the same prepared model object can be 99*4d7e907cSAndroid Build Coastguard Worker * used with different shapes of inputs on different (possibly concurrent) 100*4d7e907cSAndroid Build Coastguard Worker * executions. 101*4d7e907cSAndroid Build Coastguard Worker * 102*4d7e907cSAndroid Build Coastguard Worker * Multiple threads can call prepareModel on the same model concurrently. 103*4d7e907cSAndroid Build Coastguard Worker * 104*4d7e907cSAndroid Build Coastguard Worker * @param model The model to be prepared for execution. 105*4d7e907cSAndroid Build Coastguard Worker * @param preference Indicates the intended execution behavior of a prepared 106*4d7e907cSAndroid Build Coastguard Worker * model. 107*4d7e907cSAndroid Build Coastguard Worker * @param callback A callback object used to return the error status of 108*4d7e907cSAndroid Build Coastguard Worker * preparing the model for execution and the prepared model 109*4d7e907cSAndroid Build Coastguard Worker * if successful, nullptr otherwise. The callback object's 110*4d7e907cSAndroid Build Coastguard Worker * notify function must be called exactly once, even if the 111*4d7e907cSAndroid Build Coastguard Worker * model could not be prepared. 112*4d7e907cSAndroid Build Coastguard Worker * @return status Error status of launching a task which prepares the model 113*4d7e907cSAndroid Build Coastguard Worker * in the background; must be: 114*4d7e907cSAndroid Build Coastguard Worker * - NONE if preparation 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 * - INVALID_ARGUMENT if one of the input arguments is 118*4d7e907cSAndroid Build Coastguard Worker * invalid 119*4d7e907cSAndroid Build Coastguard Worker */ 120*4d7e907cSAndroid Build Coastguard Worker prepareModel_1_1(Model model, ExecutionPreference preference, 121*4d7e907cSAndroid Build Coastguard Worker IPreparedModelCallback callback) 122*4d7e907cSAndroid Build Coastguard Worker generates (ErrorStatus status); 123*4d7e907cSAndroid Build Coastguard Worker}; 124