blob: ee36fb4e5174ae85b19c02fdfb6fde8298a04372 [file] [log] [blame]
Lev Proleev5a7b67a2019-08-08 14:08:31 +01001/*
2 * Copyright (C) 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.hardware.neuralnetworks@1.3;
18
19import @1.0::ErrorStatus;
20import @1.1::ExecutionPreference;
21import @1.2::Constant;
22import @1.2::DeviceType;
23import @1.2::Extension;
24import @1.2::IDevice;
25import @1.2::IPreparedModelCallback;
26
27/**
28 * This interface represents a device driver.
29 */
30interface IDevice extends @1.2::IDevice {
31 /**
32 * Gets the capabilities of a driver.
33 *
34 * @return status Error status of the call, must be:
35 * - NONE if successful
36 * - DEVICE_UNAVAILABLE if driver is offline or busy
37 * - GENERAL_FAILURE if there is an unspecified error
38 * @return capabilities Capabilities of the driver.
39 */
40 getCapabilities_1_3() generates (ErrorStatus status, Capabilities capabilities);
41
42 /**
43 * Gets the supported operations in a model.
44 *
45 * getSupportedOperations indicates which operations of a model are fully
46 * supported by the vendor driver. If an operation may not be supported for
47 * any reason, getSupportedOperations must return false for that operation.
48 *
49 * @param model A model whose operations--and their corresponding operands--
50 * are to be verified by the driver.
51 * @return status Error status of the call, must be:
52 * - NONE if successful
53 * - DEVICE_UNAVAILABLE if driver is offline or busy
54 * - GENERAL_FAILURE if there is an unspecified error
55 * - INVALID_ARGUMENT if provided model is invalid
56 * @return supportedOperations A list of supported operations, where true
57 * indicates the operation is supported and false indicates the
58 * operation is not supported. The index of "supported" corresponds with
59 * the index of the operation it is describing.
60 */
61 getSupportedOperations_1_3(Model model)
62 generates (ErrorStatus status, vec<bool> supportedOperations);
63
64 /**
65 * Asynchronously creates a prepared model for execution and optionally
66 * saves it into cache files.
67 *
68 * prepareModel is used to make any necessary transformations to or
69 * alternative representations to a model for execution, possibly including
70 * transformations on the constant data, optimization on the model's graph,
71 * or compilation into the device's native binary format. The model itself
72 * is not changed.
73 *
74 * Optionally, caching information may be provided for the driver to save
75 * the prepared model to cache files for faster model compilation time when
76 * the same model preparation is requested in the future. There are two
77 * types of cache file handles provided to the driver: model cache and data
78 * cache. For more information on the two types of cache handles, refer to
79 * getNumberOfCacheFilesNeeded.
80 *
81 * The file descriptors must be opened with read and write permission. A
82 * file may have any size, and the corresponding file descriptor may have
83 * any offset. The driver must truncate a file to zero size before writing
84 * to that file. The file descriptors may be closed by the client once the
85 * asynchronous preparation has finished. The driver must dup a file
86 * descriptor if it wants to get access to the cache file later.
87 *
88 * The model is prepared asynchronously with respect to the caller. The
89 * prepareModel function must verify the inputs to the preparedModel
90 * function related to preparing the model (as opposed to saving the
91 * prepared model to cache) are correct. If there is an error, prepareModel
92 * must immediately invoke the callback with the appropriate ErrorStatus
93 * value and nullptr for the IPreparedModel, then return with the same
94 * ErrorStatus. If the inputs to the prepareModel function that are related
95 * to preparing the model are valid and there is no error, prepareModel must
96 * launch an asynchronous task to prepare the model in the background, and
97 * immediately return from prepareModel with ErrorStatus::NONE. If the
98 * asynchronous task fails to launch, prepareModel must immediately invoke
99 * the callback with ErrorStatus::GENERAL_FAILURE and nullptr for the
100 * IPreparedModel, then return with ErrorStatus::GENERAL_FAILURE.
101 *
102 * When the asynchronous task has finished preparing the model, it must
103 * immediately invoke the callback function provided as an input to
104 * prepareModel. If the model was prepared successfully, the callback object
105 * must be invoked with an error status of ErrorStatus::NONE and the
106 * produced IPreparedModel object. If an error occurred preparing the model,
107 * the callback object must be invoked with the appropriate ErrorStatus
108 * value and nullptr for the IPreparedModel.
109 *
110 * Optionally, the driver may save the prepared model to cache during the
111 * asynchronous preparation. Any error that occurs when saving to cache must
112 * not affect the status of preparing the model. Even if the input arguments
113 * related to the cache may be invalid, or the driver may fail to save to
114 * cache, the prepareModel function must finish preparing the model. The
115 * driver may choose not to save to cache even if the caching information is
116 * provided and valid.
117 *
118 * The only information that may be unknown to the model at this stage is
119 * the shape of the tensors, which may only be known at execution time. As
120 * such, some driver services may return partially prepared models, where
121 * the prepared model may only be finished when it is paired with a set of
122 * inputs to the model. Note that the same prepared model object may be used
123 * with different shapes of inputs on different (possibly concurrent)
124 * executions.
125 *
126 * Multiple threads may call prepareModel on the same model concurrently.
127 *
128 * @param model The model to be prepared for execution.
129 * @param preference Indicates the intended execution behavior of a prepared
130 * model.
131 * @param modelCache A vector of handles with each entry holding exactly one
132 * cache file descriptor for the security-sensitive cache. The length of
133 * the vector must either be 0 indicating that caching information is
134 * not provided, or match the numModelCache returned from
135 * getNumberOfCacheFilesNeeded. The cache handles will be provided in
136 * the same order when retrieving the preparedModel from cache files
137 * with prepareModelFromCache.
138 * @param dataCache A vector of handles with each entry holding exactly one
139 * cache file descriptor for the constants' cache. The length of the
140 * vector must either be 0 indicating that caching information is not
141 * provided, or match the numDataCache returned from
142 * getNumberOfCacheFilesNeeded. The cache handles will be provided in
143 * the same order when retrieving the preparedModel from cache files
144 * with prepareModelFromCache.
145 * @param token A caching token of length Constant::BYTE_SIZE_OF_CACHE_TOKEN
146 * identifying the prepared model. The same token will be provided when
147 * retrieving the prepared model from the cache files with
148 * prepareModelFromCache. Tokens should be chosen to have a low rate of
149 * collision for a particular application. The driver cannot detect a
150 * collision; a collision will result in a failed execution or in a
151 * successful execution that produces incorrect output values. If both
152 * modelCache and dataCache are empty indicating that caching
153 * information is not provided, this token must be ignored.
154 * @param callback A callback object used to return the error status of
155 * preparing the model for execution and the prepared model if
156 * successful, nullptr otherwise. The callback object's notify function
157 * must be called exactly once, even if the model could not be prepared.
158 * @return status Error status of launching a task which prepares the model
159 * in the background; must be:
160 * - NONE if preparation task is successfully launched
161 * - DEVICE_UNAVAILABLE if driver is offline or busy
162 * - GENERAL_FAILURE if there is an unspecified error
163 * - INVALID_ARGUMENT if one of the input arguments related to preparing
164 * the model is invalid
165 */
166 prepareModel_1_3(Model model, ExecutionPreference preference,
167 vec<handle> modelCache, vec<handle> dataCache,
168 uint8_t[Constant:BYTE_SIZE_OF_CACHE_TOKEN] token,
169 IPreparedModelCallback callback)
170 generates (ErrorStatus status);
171};