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