Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ed8e77bf authored by Michael Butler's avatar Michael Butler Committed by Xusong Wang
Browse files

Add Quality of Service to NNAPI HAL

This CL makes the following changes:
* introduces a new Priority enum
* extends ErrorStatus with new error codes
* adds "supportsDeadline" method to IDevice
* adds priority and deadline arguments to IDevice::prepareModel*
* adds deadline argument to IPreparedModel::execute*
* updates IExecutionCallback with new ErrorStatus
* updates current.txt accordingly

Bug: 136739795
Bug: 142902514
Bug: 145300530
Test: mma
Change-Id: Iaa7877bde1f463635b8bbdb4e8a001d7b79b9c65
Merged-In: Iaa7877bde1f463635b8bbdb4e8a001d7b79b9c65
(cherry picked from commit c2499ecd)
parent f8124a86
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -622,11 +622,12 @@ bbeee9604128ede83ee755b67e73b5ad29e6e1dbac9ec41fea6ffe2745b0c50a android.hardwar
27ae3724053940462114228872b3ffaf0b8e6177d5ba97f5a76339d12b8a99dd android.hardware.keymaster@4.1::IKeymasterDevice
adb0efdf1462e9b2e742c0dcadd598666aac551f178be06e755bfcdf5797abd0 android.hardware.keymaster@4.1::IOperation
ac429fca0da4ce91218768ec31b64ded88251f8a26d8c4f27c06abdc5b1926d9 android.hardware.keymaster@4.1::types
4b5c8546533db9412fec6d32c0ef42b22e5e68dbf390c775ec3c22bb2d501102 android.hardware.neuralnetworks@1.3::IBuffer
5a6b75f13f0e010a4268defa4f627b862ab2899fb04f9d985194a25bd8f9fe0d android.hardware.neuralnetworks@1.3::IDevice
058b48f0e2e725bb2b3fa2b7917b0f0a696383d03a4c57afe26f0eadb6a7af28 android.hardware.neuralnetworks@1.3::IPreparedModel
94e803236398bed1febb11cc21051bc42ec003700139b099d6c479e02a7ca3c3 android.hardware.neuralnetworks@1.3::IPreparedModelCallback
12c51f9d04a52324510419aeee3e37bb3607e6900556cdde79774d80ed989855 android.hardware.neuralnetworks@1.3::types
65c16331e57f6dd68b3971f06f78fe9e3209afb60630c31705aa355f9a52bf0d android.hardware.neuralnetworks@1.3::IBuffer
d1f382d14e1384b907d5bb5780df7f01934650d556fedbed2f15a90773c657d6 android.hardware.neuralnetworks@1.3::IDevice
4167dc3ad35e9cd0d2057d4868c7675ae2c3c9d05bbd614c1f5dccfa5fd68797 android.hardware.neuralnetworks@1.3::IExecutionCallback
7d23020248194abbee8091cc624f39a5a6d7ccba338b172d5d2d3df0cceffbee android.hardware.neuralnetworks@1.3::IPreparedModel
0439a1fbbec7f16e5e4c653d85ac685d51bfafbae15b8f8cca530acdd7d6a8ce android.hardware.neuralnetworks@1.3::IPreparedModelCallback
ee65638f8af3f9f4f222e7208eaa9f1f8e7f8e0a21545846ba67d0e27624efa1 android.hardware.neuralnetworks@1.3::types
3e01d4446cd69fd1c48f8572efd97487bc179564b32bd795800b97bbe10be37b android.hardware.wifi@1.4::IWifi
a64467bae843569f0d465c5be7f0c7a5b987985b55a3ef4794dd5afc68538650 android.hardware.wifi.supplicant@1.3::ISupplicant
44445b8a03d7b9e68b2fbd954672c18a8fce9e32851b0692f4f4ab3407f86ecb android.hardware.wifi.supplicant@1.3::ISupplicantStaIface
+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ hidl_interface {
        "types.hal",
        "IBuffer.hal",
        "IDevice.hal",
        "IExecutionCallback.hal",
        "IPreparedModel.hal",
        "IPreparedModelCallback.hal",
    ],
+1 −1
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package android.hardware.neuralnetworks@1.3;

import @1.0::ErrorStatus;
import ErrorStatus;

/**
 * This interface represents a device memory buffer.
+67 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package android.hardware.neuralnetworks@1.3;

import @1.0::ErrorStatus;
import @1.1::ExecutionPreference;
import @1.2::Constant;
import @1.2::DeviceType;
@@ -25,7 +24,10 @@ import @1.2::IDevice;
import BufferDesc;
import BufferRole;
import Capabilities;
import ErrorStatus;
import Model;
import OptionalTimePoint;
import Priority;
import IBuffer;
import IPreparedModel;
import IPreparedModelCallback;
@@ -45,6 +47,19 @@ interface IDevice extends @1.2::IDevice {
     */
    getCapabilities_1_3() generates (ErrorStatus status, Capabilities capabilities);

    /**
     * Returns whether the device is able to complete or abort a task within a
     * specified duration.
     *
     * @return prepareModelDeadline 'true' if the device supports completing or
     *     aborting model preparation by the deadline when the deadline is supplied,
     *     'false' otherwise.
     * @return executionDeadline 'true' if the device supports completing or
     *     aborting an execution by the deadline when the deadline is supplied,
     *     'false' otherwise.
     */
    supportsDeadlines() generates (bool prepareModelDeadline, bool executionDeadline);

    /**
     * Gets the supported operations in a model.
     *
@@ -118,6 +133,22 @@ interface IDevice extends @1.2::IDevice {
     * the callback object must be invoked with the appropriate ErrorStatus
     * value and nullptr for the IPreparedModel.
     *
     * The model is prepared with a priority. This priority is relative to other
     * prepared models owned by the same client. Higher priority executions may
     * use more compute resources than lower priority executions, and may
     * preempt or starve lower priority executions.
     *
     * prepareModel_1_3 can be called with an optional deadline. If the model
     * is not able to be prepared before the provided deadline, the model
     * preparation must be aborted, and either {@link
     * ErrorStatus::MISSED_DEADLINE_TRANSIENT} or {@link
     * ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The error due
     * to an abort must be sent the same way as other errors, described above.
     * If the service reports that it does not support preparation deadlines via
     * IDevice::supportsDeadlines, and prepareModel_1_3 is called with a
     * deadline, then the argument is invalid, and {@link
     * ErrorStatus::INVALID_ARGUMENT} must be returned.
     *
     * Optionally, the driver may save the prepared model to cache during the
     * asynchronous preparation. Any error that occurs when saving to cache must
     * not affect the status of preparing the model. Even if the input arguments
@@ -139,6 +170,11 @@ interface IDevice extends @1.2::IDevice {
     * @param model The model to be prepared for execution.
     * @param preference Indicates the intended execution behavior of a prepared
     *     model.
     * @param priority The priority of the prepared model relative to other
     *     prepared models owned by the client.
     * @param deadline The time by which the model must be prepared. If the
     *     model cannot be prepared by the deadline, the preparation must be
     *     aborted.
     * @param modelCache A vector of handles with each entry holding exactly one
     *     cache file descriptor for the security-sensitive cache. The length of
     *     the vector must either be 0 indicating that caching information is
@@ -173,8 +209,12 @@ interface IDevice extends @1.2::IDevice {
     *     - GENERAL_FAILURE if there is an unspecified error
     *     - INVALID_ARGUMENT if one of the input arguments related to preparing
     *       the model is invalid
     *     - MISSED_DEADLINE_* if the deadline for preparing a model cannot be
     *       met
     *     - RESOURCE_EXHAUSTED_* if the task was aborted by the driver
     */
    prepareModel_1_3(Model model, ExecutionPreference preference,
                     Priority priority, OptionalTimePoint deadline,
                     vec<handle> modelCache, vec<handle> dataCache,
                     uint8_t[Constant:BYTE_SIZE_OF_CACHE_TOKEN] token,
                     IPreparedModelCallback callback)
@@ -220,6 +260,22 @@ interface IDevice extends @1.2::IDevice {
     * the model, the callback object must be invoked with the appropriate
     * ErrorStatus value and nullptr for the IPreparedModel.
     *
     * The model is prepared with a priority. This priority is relative to other
     * prepared models owned by the same client. Higher priority executions may
     * use more compute resources than lower priority executions, and may
     * preempt or starve lower priority executions.
     *
     * prepareModelFromCache_1_3 can be called with an optional deadline. If the
     * model is not able to prepared before the provided deadline, the model
     * preparation must be aborted, and either {@link
     * ErrorStatus::MISSED_DEADLINE_TRANSIENT}
     * or {@link ErrorStatus::MISSED_DEADLINE_PERSISTENT} must be returned. The
     * error due to an abort must be sent the same way as other errors,
     * described above. If the service reports that it does not support
     * preparation deadlines via IDevice::supportsDeadlines, and
     * prepareModelFromCache_1_3 is called with a deadline, then the argument is
     * invalid, and {@link ErrorStatus::INVALID_ARGUMENT} must be returned.
     *
     * The only information that may be unknown to the model at this stage is
     * the shape of the tensors, which may only be known at execution time. As
     * such, some driver services may return partially prepared models, where
@@ -228,6 +284,11 @@ interface IDevice extends @1.2::IDevice {
     * used with different shapes of inputs on different (possibly concurrent)
     * executions.
     *
     * @param priority The priority of the prepared model relative to other
     *     prepared models owned by the client.
     * @param deadline The time by which the model must be prepared. If the
     *     model cannot be prepared by the deadline, the preparation must be
     *     aborted.
     * @param modelCache A vector of handles with each entry holding exactly one
     *     cache file descriptor for the security-sensitive cache. The length of
     *     the vector must match the numModelCache returned from getNumberOfCacheFilesNeeded.
@@ -253,8 +314,12 @@ interface IDevice extends @1.2::IDevice {
     *     - GENERAL_FAILURE if caching is not supported or if there is an
     *       unspecified error
     *     - INVALID_ARGUMENT if one of the input arguments is invalid
     *     - MISSED_DEADLINE_* if the deadline for preparing a model cannot be
     *       met
     *     - RESOURCE_EXHAUSTED_* if the task was aborted by the driver
     */
    prepareModelFromCache_1_3(vec<handle> modelCache, vec<handle> dataCache,
    prepareModelFromCache_1_3(Priority priority, OptionalTimePoint deadline,
                              vec<handle> modelCache, vec<handle> dataCache,
                              uint8_t[Constant:BYTE_SIZE_OF_CACHE_TOKEN] token,
                              IPreparedModelCallback callback)
            generates (ErrorStatus status);
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.hardware.neuralnetworks@1.3;

import @1.2::IExecutionCallback;
import @1.2::OutputShape;
import @1.2::Timing;

/**
 * IExecutionCallback must be used to return the error status result from an
 * execution asynchronously launched from IPreparedModel::execute*.
 */
interface IExecutionCallback extends @1.2::IExecutionCallback {

    /**
     * There are three notify methods declared for the IExecutionCallback
     * interface: notify_1_3, notify_1_2, and notify. One of the three notify
     * methods must be invoked immediately after the asynchronous task has
     * finished performing the execution. One of the notify methods must be
     * provided with the ErrorStatus from the execution. If the asynchronous
     * task is not launched, one of the notify methods must be invoked with the
     * appropriate error.
     *
     * @param status Error status returned from launching the asynchronous task
     *               (if the launch fails) or from the asynchronous task itself
     *               (if the launch succeeds). Must be:
     *               - NONE if the asynchronous execution was successful
     *               - DEVICE_UNAVAILABLE if driver is offline or busy
     *               - GENERAL_FAILURE if the asynchronous task resulted in an
     *                 unspecified error
     *               - OUTPUT_INSUFFICIENT_SIZE if at least one output
     *                 operand buffer is not large enough to store the
     *                 corresponding output
     *               - INVALID_ARGUMENT if one of the input arguments to
     *                 prepareModel is invalid
     *               - MISSED_DEADLINE_* if the deadline could not be met
     *               - RESOURCE_EXHAUSTED_* if the task was aborted by the driver
     * @param outputShapes A list of shape information of model output operands.
     *                     The index into "outputShapes" corresponds with to index
     *                     of the output operand in the Request outputs vector.
     *                     outputShapes must be empty unless the status is either
     *                     NONE or OUTPUT_INSUFFICIENT_SIZE.
     * @param timing Duration of execution. Unless MeasureTiming::YES was passed when
     *               launching the execution and status is NONE, all times must
     *               be reported as UINT64_MAX. A driver may choose to report
     *               any time as UINT64_MAX, indicating that particular measurement is
     *               not available.
     */
  oneway notify_1_3(ErrorStatus status, vec<OutputShape> outputShapes, Timing timing);
};
Loading