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

Commit fdb6b518 authored by Slava Shklyaev's avatar Slava Shklyaev Committed by Android (Google) Code Review
Browse files

Merge "Add NNAPI control flow"

parents ffe909ac a785a3fa
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -651,10 +651,10 @@ ac429fca0da4ce91218768ec31b64ded88251f8a26d8c4f27c06abdc5b1926d9 android.hardwar
df9c79c4fdde2821550c6d5c3d07f5ec0adfb1b702561ce543c906ddef698703 android.hardware.media.c2@1.1::IComponent
a3eddd9bbdc87e8c22764070037dd1154f1cf006e6fba93364c4f85d4c134a19 android.hardware.media.c2@1.1::IComponentStore
4b5c8546533db9412fec6d32c0ef42b22e5e68dbf390c775ec3c22bb2d501102 android.hardware.neuralnetworks@1.3::IBuffer
234cc547d63d2f24a447aee0a9a76cab68b31c080adadc5a960598b827a69fa2 android.hardware.neuralnetworks@1.3::IDevice
5a6b75f13f0e010a4268defa4f627b862ab2899fb04f9d985194a25bd8f9fe0d android.hardware.neuralnetworks@1.3::IDevice
058b48f0e2e725bb2b3fa2b7917b0f0a696383d03a4c57afe26f0eadb6a7af28 android.hardware.neuralnetworks@1.3::IPreparedModel
94e803236398bed1febb11cc21051bc42ec003700139b099d6c479e02a7ca3c3 android.hardware.neuralnetworks@1.3::IPreparedModelCallback
1435cf1724f9f89ff5f97d4aa6fe2a031b0ef43034cb5801b16229dc2ecfea82 android.hardware.neuralnetworks@1.3::types
12c51f9d04a52324510419aeee3e37bb3607e6900556cdde79774d80ed989855 android.hardware.neuralnetworks@1.3::types
3e01d4446cd69fd1c48f8572efd97487bc179564b32bd795800b97bbe10be37b android.hardware.wifi@1.4::IWifi
c67aaf26a7a40d14ea61e70e20afacbd0bb906df1704d585ac8599fbb69dd44b android.hardware.wifi.hostapd@1.2::IHostapd
11f6448d15336361180391c8ebcdfd2d7cf77b3782d577e594d583aadc9c2877 android.hardware.wifi.hostapd@1.2::types
+8 −3
Original line number Diff line number Diff line
@@ -48,9 +48,14 @@ interface IDevice extends @1.2::IDevice {
    /**
     * Gets the supported operations in a model.
     *
     * getSupportedOperations indicates which operations of a model are fully
     * supported by the vendor driver. If an operation may not be supported for
     * any reason, getSupportedOperations must return false for that operation.
     * getSupportedOperations indicates which operations of the top-level
     * subgraph are fully supported by the vendor driver. If an operation may
     * not be supported for any reason, getSupportedOperations must return
     * false for that operation.
     *
     * The {@link OperationType::IF} and {@link OperationType::WHILE}
     * operations may only be fully supported if the vendor driver fully
     * supports all operations in the referenced subgraphs.
     *
     * @param model A model whose operations--and their corresponding operands--
     *     are to be verified by the driver.
+196 −27
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package android.hardware.neuralnetworks@1.3;

import @1.0::DataLocation;
import @1.0::OperandLifeTime;
import @1.0::PerformanceInfo;
import @1.0::RequestArgument;
import @1.2::Model.ExtensionNameAndPrefix;
@@ -42,6 +41,13 @@ enum OperandType : @1.2::OperandType {
     */
    TENSOR_QUANT8_ASYMM_SIGNED = 14,

    /**
     * A reference to a subgraph.
     *
     * Must have the lifetime {@link OperandLifeTime::SUBGRAPH}.
     */
    SUBGRAPH = 15,

    /*
     * DEPRECATED. Since HAL version 1.2, extensions are the preferred
     * alternative to OEM operation and data types.
@@ -70,7 +76,7 @@ enum OperandType : @1.2::OperandType {
enum OperandTypeRange : uint32_t {
    BASE_MIN        = 0,
    FUNDAMENTAL_MIN = 0,
    FUNDAMENTAL_MAX = 14,
    FUNDAMENTAL_MAX = 15,
    OEM_MIN         = 10000,
    OEM_MAX         = 10001,
    BASE_MAX        = 0xFFFF,
@@ -4878,6 +4884,92 @@ enum OperationType : int32_t {
     */
    QUANTIZED_LSTM = 95,

    /**
     * Executes one of the two referenced subgraphs as determined by a boolean
     * value.
     *
     * The inputs and outputs of the two referenced subgraphs must agree with the
     * signature of this operation. That is, if the operation has (3 + n) inputs
     * and m outputs, both subgraphs must have n inputs and m outputs with the same
     * types as the corresponding operation inputs and outputs.
     *
     * Inputs:
     * * 0: A value of type {@link OperandType::TENSOR_BOOL8} and shape [1]
     *      that determines which of the two referenced subgraphs to execute.
     * * 1: A {@link OperandType::SUBGRAPH} reference to the subgraph to be
     *      executed if the condition is true.
     * * 2: A {@link OperandType::SUBGRAPH} reference to the subgraph to be
     *      executed if the condition is false.
     * * 3 ~ (n + 2): Inputs to be passed to the subgraph selected for execution.
     *
     * Outputs:
     * * 0 ~ (m - 1): Outputs produced by the selected subgraph.
     */
    IF = 96,

    /**
     * Executes the body subgraph until the condition subgraph outputs false.
     *
     * The inputs to this operation are the condition subgraph, the body subgraph,
     * and operand values for the first iteration of the loop. The values are
     * implicitly split into three groups of input-output, state-only, and
     * input-only values, as described below.
     *
     * The outputs of this operation are the final values of input-output
     * operands.
     *
     * Both the condition and body subgraph receive (m + k + n) inputs.
     * * The first m (m >= 1) inputs are input-output operands. For the first
     *   iteration, these are initialized from the corresponding inputs of the
     *   WHILE operation. In subsequent iterations, their values come from the
     *   corresponding outputs of the body subgraph produced during the previous
     *   iteration.
     * * The next k (k >= 0) inputs are state-only operands. They are similar to
     *   the input-output operands, except that their values are no longer
     *   available after the loop terminates.
     * * The last n (n >= 0) inputs are input-only operands. Their values come
     *   from the corresponding inputs of the WHILE operation.
     *
     * The body subgraph produces (m + k) outputs.
     * * The first m outputs are input-output operands. They become the outputs
     *   of the WHILE operation when a termination condition is reached.
     * * The last k outputs are state-only operands. Their values are no longer
     *   available after the loop terminates.
     *
     * The numbers m, k, and n are inferred by the driver as follows:
     *     m = (WHILE operation output count)
     *     k = (body subgraph output count) - m
     *     n = (body subgraph input count) - m - k
     *
     * The pseudo-code below illustrates the flow of a WHILE operation with
     * inputs condition, body, initial_input_output, initial_state, input_only
     * (m = 1, k = 1, n = 1):
     *
     *     input_output = initial_input_output
     *     state = initial_state
     *     while condition(input_output, state, input_only):
     *         input_output, state = body(input_output, state, input_only)
     *     return input_output
     *
     * Inputs:
     * * 0: A {@link OperandType::SUBGRAPH} reference to the condition
     *      subgraph. The subgraph must have (m + k + n) inputs with
     *      the same types as the corresponding inputs of the WHILE operation
     *      and exactly one output of {@link OperandType::TENSOR_BOOL8}
     *      and shape [1].
     * * 1: A {@link OperandType::SUBGRAPH} reference to the body subgraph.
     *      The subgraph must have (m + k + n) inputs and (m + k) outputs with
     *      the same types as the corresponding inputs and outputs of the WHILE
     *      operation.
     * * (m inputs): Initial values for input-output operands.
     * * (k inputs): Initial values for state-only operands.
     * * (n inputs): Values for input-only operands.
     *
     * Outputs:
     * * 0 ~ (m - 1): Outputs produced by the loop.
     */
    WHILE = 97,

    /**
     * DEPRECATED. Since NNAPI 1.2, extensions are the preferred alternative to
     * OEM operation and data types.
@@ -4900,13 +4992,12 @@ enum OperationType : int32_t {
enum OperationTypeRange : uint32_t {
    BASE_MIN        = 0,
    FUNDAMENTAL_MIN = 0,
    FUNDAMENTAL_MAX = 95,
    FUNDAMENTAL_MAX = 97,
    OEM_MIN         = 10000,
    OEM_MAX         = 10000,
    BASE_MAX        = 0xFFFF,
};


/**
 * The capabilities of a driver.
 *
@@ -4967,6 +5058,59 @@ struct Operation {
    vec<uint32_t> outputs;
};

/**
 * How an operand is used.
 */
enum OperandLifeTime : int32_t {
    /**
     * The operand is internal to the model. It's created by an operation and
     * consumed by other operations. It must be an output operand of
     * exactly one operation.
     */
    TEMPORARY_VARIABLE,

    /**
     * The operand is an input of a subgraph. It must not be an output
     * operand of any operation.
     *
     * An operand can't be both input and output of a subgraph.
     */
    SUBGRAPH_INPUT,

    /**
     * The operand is an output of a subgraph. It must be an output
     * operand of exactly one operation.
     *
     * An operand can't be both input and output of a subgraph.
     */
    SUBGRAPH_OUTPUT,

    /**
     * The operand is a constant found in Model.operandValues. It must
     * not be an output operand of any operation.
     */
    CONSTANT_COPY,

    /**
     * The operand is a constant that was specified via a Memory
     * object. It must not be an output operand of any operation.
     */
    CONSTANT_REFERENCE,

    /**
     * The operand does not have a value. This is valid only for optional
     * arguments of operations.
     */
    NO_VALUE,

    /**
     * The operand is a reference to a subgraph. It must be an input to one
     * or more {@link OperationType::IF} or {@link OperationType::WHILE}
     * operations.
     */
    SUBGRAPH,
};

/**
 * Describes one operand of the model's graph.
 */
@@ -5003,7 +5147,7 @@ struct Operand {
     *     . The operand has lifetime CONSTANT_COPY or
     *       CONSTANT_REFERENCE.
     *
     *     . The operand has lifetime MODEL_INPUT. Fully
     *     . The operand has lifetime SUBGRAPH_INPUT. Fully
     *       specified dimensions must either be present in the
     *       Operand or they must be provided in the corresponding
     *       RequestArgument.
@@ -5051,8 +5195,8 @@ struct Operand {

    /**
     * Where to find the data for this operand.
     * If the lifetime is TEMPORARY_VARIABLE, MODEL_INPUT, MODEL_OUTPUT, or
     * NO_VALUE:
     * If the lifetime is TEMPORARY_VARIABLE, SUBGRAPH_INPUT, SUBGRAPH_OUTPUT,
     * or NO_VALUE:
     * - All the fields must be 0.
     * If the lifetime is CONSTANT_COPY:
     * - location.poolIndex is 0.
@@ -5062,6 +5206,11 @@ struct Operand {
     * - location.poolIndex is set.
     * - location.offset is the offset in bytes into the specified pool.
     * - location.length is set.
     * If the lifetime is SUBGRAPH:
     * - location.poolIndex is 0.
     * - location.offset is the index of the referenced subgraph in
     *   {@link Model::referenced}.
     * - location.length is 0.
     */
    DataLocation location;

@@ -5100,32 +5249,19 @@ struct Operand {
 */
struct Model {
    /**
     * All operands included in the model.
     * The top-level subgraph.
     */
    vec<Operand> operands;
    Subgraph main;

    /**
     * All operations included in the model.
     * Referenced subgraphs.
     *
     * The operations are sorted into execution order. Every operand
     * with lifetime MODEL_OUTPUT or TEMPORARY_VARIABLE must be
     * written before it is read.
     */
    vec<Operation> operations;

    /**
     * Input indexes of the model. There must be at least one.
     * Each subgraph is referenced by the main subgraph or at least one other
     * referenced subgraph.
     *
     * Each value corresponds to the index of the operand in "operands".
     * There must be no reference cycles.
     */
    vec<uint32_t> inputIndexes;

    /**
     * Output indexes of the model. There must be at least one.
     *
     * Each value corresponds to the index of the operand in "operands".
     */
    vec<uint32_t> outputIndexes;
    vec<Subgraph> referenced;

    /**
     * A byte buffer containing operand data that were copied into the model.
@@ -5177,6 +5313,39 @@ struct Model {
    vec<@1.2::Model.ExtensionNameAndPrefix> extensionNameToPrefix;
};

/**
 * An excerpt of the execution graph.
 */
struct Subgraph {
    /**
     * All operands included in the subgraph.
     */
    vec<Operand> operands;

    /**
     * All operations included in the subgraph.
     *
     * The operations are sorted into execution order. Every operand
     * with lifetime SUBGRAPH_OUTPUT or TEMPORARY_VARIABLE must be
     * written before it is read.
     */
    vec<Operation> operations;

    /**
     * Input indexes of the subgraph. There must be at least one.
     *
     * Each value corresponds to the index of the operand in "operands".
     */
    vec<uint32_t> inputIndexes;

    /**
     * Output indexes of the subgraph. There must be at least one.
     *
     * Each value corresponds to the index of the operand in "operands".
     */
    vec<uint32_t> outputIndexes;
};

/**
 * A buffer descriptor. Describes the properties of a buffer.
 */
+101 −25
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
package android.hardware.neuralnetworks@1.3;

import @1.0::DataLocation;
import @1.0::OperandLifeTime;
import @1.0::PerformanceInfo;
import @1.0::RequestArgument;
import @1.2::Model.ExtensionNameAndPrefix;
@@ -90,7 +89,6 @@ enum OperationTypeRange : uint32_t {
    BASE_MAX        = 0xFFFF,
};


/**
 * The capabilities of a driver.
 *
@@ -151,6 +149,59 @@ struct Operation {
    vec<uint32_t> outputs;
};

/**
 * How an operand is used.
 */
enum OperandLifeTime : int32_t {
    /**
     * The operand is internal to the model. It's created by an operation and
     * consumed by other operations. It must be an output operand of
     * exactly one operation.
     */
    TEMPORARY_VARIABLE,

    /**
     * The operand is an input of a subgraph. It must not be an output
     * operand of any operation.
     *
     * An operand can't be both input and output of a subgraph.
     */
    SUBGRAPH_INPUT,

    /**
     * The operand is an output of a subgraph. It must be an output
     * operand of exactly one operation.
     *
     * An operand can't be both input and output of a subgraph.
     */
    SUBGRAPH_OUTPUT,

    /**
     * The operand is a constant found in Model.operandValues. It must
     * not be an output operand of any operation.
     */
    CONSTANT_COPY,

    /**
     * The operand is a constant that was specified via a Memory
     * object. It must not be an output operand of any operation.
     */
    CONSTANT_REFERENCE,

    /**
     * The operand does not have a value. This is valid only for optional
     * arguments of operations.
     */
    NO_VALUE,

    /**
     * The operand is a reference to a subgraph. It must be an input to one
     * or more {@link OperationType::IF} or {@link OperationType::WHILE}
     * operations.
     */
    SUBGRAPH,
};

/**
 * Describes one operand of the model's graph.
 */
@@ -187,7 +238,7 @@ struct Operand {
     *     . The operand has lifetime CONSTANT_COPY or
     *       CONSTANT_REFERENCE.
     *
     *     . The operand has lifetime MODEL_INPUT. Fully
     *     . The operand has lifetime SUBGRAPH_INPUT. Fully
     *       specified dimensions must either be present in the
     *       Operand or they must be provided in the corresponding
     *       RequestArgument.
@@ -235,8 +286,8 @@ struct Operand {

    /**
     * Where to find the data for this operand.
     * If the lifetime is TEMPORARY_VARIABLE, MODEL_INPUT, MODEL_OUTPUT, or
     * NO_VALUE:
     * If the lifetime is TEMPORARY_VARIABLE, SUBGRAPH_INPUT, SUBGRAPH_OUTPUT,
     * or NO_VALUE:
     * - All the fields must be 0.
     * If the lifetime is CONSTANT_COPY:
     * - location.poolIndex is 0.
@@ -246,6 +297,11 @@ struct Operand {
     * - location.poolIndex is set.
     * - location.offset is the offset in bytes into the specified pool.
     * - location.length is set.
     * If the lifetime is SUBGRAPH:
     * - location.poolIndex is 0.
     * - location.offset is the index of the referenced subgraph in
     *   {@link Model::referenced}.
     * - location.length is 0.
     */
    DataLocation location;

@@ -284,32 +340,19 @@ struct Operand {
 */
struct Model {
    /**
     * All operands included in the model.
     * The top-level subgraph.
     */
    vec<Operand> operands;
    Subgraph main;

    /**
     * All operations included in the model.
     * Referenced subgraphs.
     *
     * The operations are sorted into execution order. Every operand
     * with lifetime MODEL_OUTPUT or TEMPORARY_VARIABLE must be
     * written before it is read.
     */
    vec<Operation> operations;

    /**
     * Input indexes of the model. There must be at least one.
     * Each subgraph is referenced by the main subgraph or at least one other
     * referenced subgraph.
     *
     * Each value corresponds to the index of the operand in "operands".
     * There must be no reference cycles.
     */
    vec<uint32_t> inputIndexes;

    /**
     * Output indexes of the model. There must be at least one.
     *
     * Each value corresponds to the index of the operand in "operands".
     */
    vec<uint32_t> outputIndexes;
    vec<Subgraph> referenced;

    /**
     * A byte buffer containing operand data that were copied into the model.
@@ -361,6 +404,39 @@ struct Model {
    vec<@1.2::Model.ExtensionNameAndPrefix> extensionNameToPrefix;
};

/**
 * An excerpt of the execution graph.
 */
struct Subgraph {
    /**
     * All operands included in the subgraph.
     */
    vec<Operand> operands;

    /**
     * All operations included in the subgraph.
     *
     * The operations are sorted into execution order. Every operand
     * with lifetime SUBGRAPH_OUTPUT or TEMPORARY_VARIABLE must be
     * written before it is read.
     */
    vec<Operation> operations;

    /**
     * Input indexes of the subgraph. There must be at least one.
     *
     * Each value corresponds to the index of the operand in "operands".
     */
    vec<uint32_t> inputIndexes;

    /**
     * Output indexes of the subgraph. There must be at least one.
     *
     * Each value corresponds to the index of the operand in "operands".
     */
    vec<uint32_t> outputIndexes;
};

/**
 * A buffer descriptor. Describes the properties of a buffer.
 */
+1 −1
Original line number Diff line number Diff line
@@ -308,7 +308,7 @@ class CompilationCachingTestBase : public testing::Test {
                model,
                [&fullySupportsModel, &model](ErrorStatus status, const hidl_vec<bool>& supported) {
                    ASSERT_EQ(ErrorStatus::NONE, status);
                    ASSERT_EQ(supported.size(), model.operations.size());
                    ASSERT_EQ(supported.size(), model.main.operations.size());
                    fullySupportsModel = std::all_of(supported.begin(), supported.end(),
                                                     [](bool valid) { return valid; });
                });
Loading