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