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

Commit 38dd4789 authored by David Gross's avatar David Gross
Browse files

Add NNAPI specification and infrastructure for FL7.

Adds operations MIRROR_PAD and REVERSE.
Extends RSQRT to support QUANT8_ASYMM and QUANT8_ASYMM_SIGNED.

DOES NOT include tests or CPU reference implementation.

(This is a slightly non-trivial cherry pick that had to be
hand-edited to compensate for the fact that certain nn::Version
changes are absent from the target branch.)

Bug: 202280917

Test: NeuralNetworksTest_static
Test: VtsHalNeuralnetworksTargetTest

Merged-In: I0b2133346b996849faac00c46885e3633c78f024
Change-Id: I0b2133346b996849faac00c46885e3633c78f024
(cherry picked from commit 04ed8595)
parent 2e5a3bac
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -396,7 +396,7 @@
    </hal>
    <hal format="aidl" optional="true">
        <name>android.hardware.neuralnetworks</name>
        <version>1-2</version>
        <version>1-3</version>
        <interface>
            <name>IDevice</name>
            <regex-instance>.*</regex-instance>
+2 −0
Original line number Diff line number Diff line
@@ -138,4 +138,6 @@ enum OperationType {
  RANK = 101,
  BATCH_MATMUL = 102,
  PACK = 103,
  MIRROR_PAD = 104,
  REVERSE = 105,
}
+69 −0
Original line number Diff line number Diff line
@@ -4229,6 +4229,8 @@ enum OperationType {
     * Supported tensor {@link OperandType}:
     * * {@link OperandType::TENSOR_FLOAT16}
     * * {@link OperandType::TENSOR_FLOAT32}
     * * {@link OperandType::TENSOR_QUANT8_ASYMM} (since NNAPI feature level 7)
     * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} (since NNAPI feature level 7)
     *
     * Supported tensor rank: from 1.
     *
@@ -4237,6 +4239,9 @@ enum OperationType {
     *
     * Outputs:
     * * 0: The output tensor of same shape as input0.
     *      For a {@link OperandType::TENSOR_QUANT8_ASYMM} and
     *      {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} tensor,
     *      the scale and zeroPoint can be different from inputs' scale and zeroPoint.
     */
    RSQRT = 83,
    /**
@@ -5214,4 +5219,68 @@ enum OperationType {
     * * 0: The packed tensor.
     */
    PACK = 103,

    /**
     * Pads a tensor with mirrored values.
     *
     * Supported tensor {@link OperandType}:
     * * {@link OperandType::TENSOR_FLOAT16}
     * * {@link OperandType::TENSOR_FLOAT32}
     * * {@link OperandType::TENSOR_QUANT8_ASYMM}
     * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED}
     * * {@link OperandType::TENSOR_INT32}
     *
     * Supported tensor rank: from 1.
     *
     * Inputs:
     * * 0: An n-D tensor, specifying the tensor to be padded.
     * * 1: A 2-D tensor of {@link OperandType::TENSOR_INT32}, the paddings
     *      for each spatial dimension of the input tensor. The shape of the
     *      tensor must be {rank(input0), 2}.
     *      padding[i, 0] specifies the number of elements to be padded in the
     *      front of dimension i.
     *      padding[i, 1] specifies the number of elements to be padded after the
     *      end of dimension i.
     * * 2: An {@link OperandType::INT32} scalar, specifying the mode.
     *      Options are 0:REFLECT and 1:SYMMETRIC.
     *
     * Outputs:
     * * 0: A tensor of the same {@link OperandType} as input0. The
     *      output tensor has the same rank as input0, and each
     *      dimension of the output tensor has the same size as the
     *      corresponding dimension of the input tensor plus the size
     *      of the padding:
     *          output0.dimension[i] =
     *              padding[i, 0] + input0.dimension[i] + padding[i, 1]
     *      For a {@link OperandType::TENSOR_QUANT8_ASYMM} and
     *      {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} tensor,
     *      the scale and zeroPoint must be the same as input0.
     */
    MIRROR_PAD = 104,

    /**
     * Reverses a specified dimension of a tensor.
     *
     * Supported tensor {@link OperandType}:
     * * {@link OperandType::TENSOR_FLOAT16}
     * * {@link OperandType::TENSOR_FLOAT32}
     * * {@link OperandType::TENSOR_QUANT8_ASYMM}
     * * {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED}
     * * {@link OperandType::TENSOR_INT32}
     *
     * Supported tensor rank: up to 8.
     *
     * Inputs:
     * * 0: Input tensor of rank n.
     * * 1: Axis tensor of type {@link OperandType::TENSOR_INT32} and shape [1],
     *      specifying which dimension of the input tensor is to be reversed. The dimension
     *      must be in the range [0, n).
     *
     * Outputs:
     * * 0: The reversed tensor.
     *      For {@link OperandType::TENSOR_QUANT8_ASYMM} and
     *      {@link OperandType::TENSOR_QUANT8_ASYMM_SIGNED} tensors,
     *      the scales and zeroPoint must be the same as input0.
     */
    REVERSE = 105,
}
+1 −1
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ cc_library_static {
        "neuralnetworks_utils_hal_common",
    ],
    shared_libs: [
        "android.hardware.neuralnetworks-V2-ndk",
        "android.hardware.neuralnetworks-V3-ndk",
        "libbinder_ndk",
        "libhidlbase",
        "libnativewindow",
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@
namespace aidl::android::hardware::neuralnetworks::utils {

constexpr auto kDefaultPriority = Priority::MEDIUM;
constexpr auto kVersion = nn::Version::FEATURE_LEVEL_6;
constexpr auto kVersion = nn::Version::FEATURE_LEVEL_7;

template <typename Type>
nn::Result<void> validate(const Type& halObject) {