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

Commit b345a468 authored by Xusong Wang's avatar Xusong Wang
Browse files

Memory Domain HAL: Define HAL APIs.

- Add and document memory domain HAL APIs.
- Make necessary changes to the existing VTS codes to make them work
  with V1_3::Request.

Bug: 141353602
Bug: 141363565
Test: mma
Test: NNT_static
Test: 1.3 VTS
Change-Id: Ia32555d4fef149fad4a79728981c5d9cca675a1a
Merged-In: Ia32555d4fef149fad4a79728981c5d9cca675a1a
(cherry picked from commit 931d5a18)
parent 7b37dc5d
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -622,10 +622,11 @@ bbeee9604128ede83ee755b67e73b5ad29e6e1dbac9ec41fea6ffe2745b0c50a android.hardwar
27ae3724053940462114228872b3ffaf0b8e6177d5ba97f5a76339d12b8a99dd android.hardware.keymaster@4.1::IKeymasterDevice
adb0efdf1462e9b2e742c0dcadd598666aac551f178be06e755bfcdf5797abd0 android.hardware.keymaster@4.1::IOperation
ac429fca0da4ce91218768ec31b64ded88251f8a26d8c4f27c06abdc5b1926d9 android.hardware.keymaster@4.1::types
9e59fffceed0dd72a9799e04505db5f777bbbea1af0695ba4107ef6d967c6fda android.hardware.neuralnetworks@1.3::IDevice
258825966435b3ed08832055bb736d81516013e405f161d9ccde9a90cfcdde83 android.hardware.neuralnetworks@1.3::IPreparedModel
4b5c8546533db9412fec6d32c0ef42b22e5e68dbf390c775ec3c22bb2d501102 android.hardware.neuralnetworks@1.3::IBuffer
234cc547d63d2f24a447aee0a9a76cab68b31c080adadc5a960598b827a69fa2 android.hardware.neuralnetworks@1.3::IDevice
058b48f0e2e725bb2b3fa2b7917b0f0a696383d03a4c57afe26f0eadb6a7af28 android.hardware.neuralnetworks@1.3::IPreparedModel
94e803236398bed1febb11cc21051bc42ec003700139b099d6c479e02a7ca3c3 android.hardware.neuralnetworks@1.3::IPreparedModelCallback
f3c1e7298da628a755b452cd3325e8d0fe867a2debb873069baab6a27434a72d android.hardware.neuralnetworks@1.3::types
2576ba54711218ce0d7f207baa533fca9af3c630756938ede6e73fe197b7ea38 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
@@ -8,6 +8,7 @@ hidl_interface {
    },
    srcs: [
        "types.hal",
        "IBuffer.hal",
        "IDevice.hal",
        "IPreparedModel.hal",
        "IPreparedModelCallback.hal",
+57 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.0::ErrorStatus;

/**
 * This interface represents a device memory buffer.
 */
interface IBuffer {
    /**
     * Retrieves the content of this buffer to a shared memory region.
     *
     * The IBuffer object must have been initialized before the call to IBuffer::copyTo.
     * For more information on the state of the IBuffer object, refer to IDevice::allocate.
     *
     * @param dst The destination shared memory region.
     * @return status Error status of the call, must be:
     *     - NONE if successful
     *     - DEVICE_UNAVAILABLE if driver is offline or busy
     *     - GENERAL_FAILURE if the IBuffer object is uninitialized, or there is an unspecified
     *       error
     *     - INVALID_ARGUMENT if provided memory is invalid
     */
    copyTo(memory dst) generates (ErrorStatus status);

    /**
     * Sets the content of this buffer from a shared memory region.
     *
     * @param src The source shared memory region.
     * @param dimensions Updated dimensional information. If the dimensions of the IBuffer object
     *     are not fully specified, then the dimensions must be fully specified here. If the
     *     dimensions of the IBuffer object are fully specified, then the dimensions may be empty
     *     here. If dimensions.size() > 0, then all dimensions must be specified here, and any
     *     dimension that was specified in the IBuffer object must have the same value here.
     * @return status Error status of the call, must be:
     *     - NONE if successful
     *     - DEVICE_UNAVAILABLE if driver is offline or busy
     *     - GENERAL_FAILURE if there is an unspecified error
     *     - INVALID_ARGUMENT if provided memory is invalid, or if the dimensions is invalid
     */
    copyFrom(memory src, vec<uint32_t> dimensions) generates (ErrorStatus status);
};
+63 −0
Original line number Diff line number Diff line
@@ -22,6 +22,12 @@ import @1.2::Constant;
import @1.2::DeviceType;
import @1.2::Extension;
import @1.2::IDevice;
import BufferDesc;
import BufferRole;
import Capabilities;
import Model;
import IBuffer;
import IPreparedModel;
import IPreparedModelCallback;

/**
@@ -247,4 +253,61 @@ interface IDevice extends @1.2::IDevice {
                              uint8_t[Constant:BYTE_SIZE_OF_CACHE_TOKEN] token,
                              IPreparedModelCallback callback)
            generates (ErrorStatus status);

    /**
     * Allocates a driver-managed buffer with the properties specified by the buffer descriptor
     * as well as the input and output roles.
     *
     * The allocate function must verify its inputs are correct. If there is an error, or if a
     * certain role or property is not supported by the driver, the allocate
     * function must return with an appropriate ErrorStatus, a nullptr as the IBuffer, and 0 as the
     * buffer token. If the allocation is successful, this method must return with ErrorStatus::NONE
     * and the produced IBuffer with a positive token identifying the allocated buffer. A successful
     * allocation must accommodate all of the specified roles and buffer properties.
     *
     * The buffer is allocated to an uninitialized state. An uninitialized buffer may only be used
     * in ways that are specified by outputRoles. A buffer is initialized after it is used as an
     * output in a successful execution, or after a successful invocation of IBuffer::copyFrom on
     * the buffer. An initialized buffer may be used according to all roles specified in inputRoles
     * and outputRoles. A buffer will return to the uninitialized state if it is used as an output
     * in a failed execution, or after a failed invocation of IBuffer::copyFrom on the buffer.
     *
     * The dimensions of the buffer can be deduced from the buffer descriptor as well as the
     * dimensions of the corresponding model operands of the input and output roles. The dimensions
     * or rank of the buffer may be unknown at this stage. As such, some driver services may only
     * create a placeholder and defer the actual allocation until execution time. Note that the
     * same buffer may be used for different shapes of outputs on different executions. When the
     * buffer is used as an input, the input shape must be the same as the output shape from the
     * last execution using this buffer as an output.
     *
     * The driver must apply proper validatation upon every usage of the buffer, and must fail the
     * execution immediately if the usage is illegal.
     *
     * @param desc A buffer descriptor specifying the properties of the buffer to allocate.
     * @param preparedModels A vector of IPreparedModel objects. Must only contain IPreparedModel
     *     objects from the same IDevice as this method is being invoked on.
     * @param inputRoles A vector of roles with each specifying an input to a prepared model.
     * @param outputRoles A vector of roles with each specifying an output to a prepared model.
     *     Each role specified in inputRoles and outputRoles must be unique. The corresponding
     *     model operands of the roles must have the same OperandType, scale, zero point, and
     *     ExtraParams. The dimensions of the operands and the dimensions specified in the buffer
     *     descriptor must be compatible with each other. Two dimensions are incompatible if there
     *     is at least one axis that is fully specified in both but has different values.
     * @return status Error status of the buffer allocation. Must be:
     *     - NONE if successful
     *     - DEVICE_UNAVAILABLE if driver is offline or busy
     *     - GENERAL_FAILURE if a certain buffer property or a certain role is not supported,
     *       or if there is an unspecified error
     *     - INVALID_ARGUMENT if one of the input arguments is invalid
     * @return buffer The allocated IBuffer object. If the buffer was unable to be allocated
     *     due to an error, nullptr must be returned.
     * @return token A positive token identifying the allocated buffer. The same token will be
     *     provided when referencing the buffer as one of the memory pools in the request of an
     *     execution. The token must not collide with the tokens of other IBuffer objects that are
     *     currently alive in the same driver service. If the buffer was unable to be allocated
     *     due to an error, the token must be 0.
     */
    allocate(BufferDesc desc, vec<IPreparedModel> preparedModels, vec<BufferRole> inputRoles,
             vec<BufferRole> outputRoles)
            generates (ErrorStatus status, IBuffer buffer, int32_t token);
};
+5 −3
Original line number Diff line number Diff line
@@ -17,12 +17,12 @@
package android.hardware.neuralnetworks@1.3;

import @1.0::ErrorStatus;
import @1.0::Request;
import @1.2::IExecutionCallback;
import @1.2::IPreparedModel;
import @1.2::MeasureTiming;
import @1.2::OutputShape;
import @1.2::Timing;
import Request;

/**
 * IPreparedModel describes a model that has been prepared for execution and
@@ -33,7 +33,8 @@ interface IPreparedModel extends @1.2::IPreparedModel {
     * Launches an asynchronous execution on a prepared model.
     *
     * The execution is performed asynchronously with respect to the caller.
     * execute_1_3 must verify the inputs to the function are correct. If there is
     * execute_1_3 must verify the inputs to the function are correct, and the usages
     * of memory pools allocated by IDevice::allocate are valid. If there is
     * an error, execute_1_3 must immediately invoke the callback with the
     * appropriate ErrorStatus value, then return with the same ErrorStatus. If
     * the inputs to the function are valid and there is no error, execute_1_3 must
@@ -95,7 +96,8 @@ interface IPreparedModel extends @1.2::IPreparedModel {
     *
     * The execution is performed synchronously with respect to the caller.
     * executeSynchronously_1_3 must verify the inputs to the function are
     * correct. If there is an error, executeSynchronously_1_3 must immediately
     * correct, and the usages of memory pools allocated by IDevice::allocate
     * are valid. If there is an error, executeSynchronously_1_3 must immediately
     * return with the appropriate ErrorStatus value. If the inputs to the
     * function are valid and there is no error, executeSynchronously_1_3 must
     * perform the execution, and must not return until the execution is
Loading