chromium/third_party/tflite/src/tensorflow/lite/nnapi/NeuralNetworksTypes.h

/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.

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.
==============================================================================*/
#ifndef TENSORFLOW_LITE_NNAPI_NEURALNETWORKSTYPES_H_
#define TENSORFLOW_LITE_NNAPI_NEURALNETWORKSTYPES_H_

#include <stdint.h>
#include <stdio.h>

#include <string>

AHardwareBuffer;

// NN api types based on NNAPI header file
// https://developer.android.com/ndk/reference/group/neural-networks

/**
 * Operand types.
 *
 * The type of operands that can be added to a model.
 *
 * Although we define many types, most operators accept just a few
 * types.  Most used are ANEURALNETWORKS_TENSOR_FLOAT32,
 * ANEURALNETWORKS_TENSOR_QUANT8_ASYMM, and ANEURALNETWORKS_INT32.
 */
enum {};

/**
 * Operation types.
 *
 * The type of operations that can be added to a model.
 */
enum {};

/**
 * Fused activation function types.
 *
 */
enum {};

/**
 * Execution preferences.
 */
enum {};

/**
 * Result codes.
 */
// LINT.IfChange
enum {};
// LINT.ThenChange(//tensorflow/lite/delegates/nnapi/nnapi_delegate.cc:NnApiErrorDescription)

/**
 * Implicit padding algorithms.
 */
enum {};

/**
 * Device types.
 *
 * The type of NNAPI device.
 */
enum {};

/**
 * Relative execution priority.
 *
 * Available since API level 30.
 */
enum {};

/**
 * NNAPI feature levels.
 *
 * Each update of the NNAPI specification yields a new NNAPI feature level enum
 * value. NNAPI feature level corrseponds to an NNAPI specification version that
 * a driver and/or the NNAPI runtime can implement.
 */
enum {};

/**
 * ANeuralNetworksMemoryDesc is an opaque type that represents a memory
 * descriptor.
 *
 * A memory descriptor describes the properties of a memory object, and is used
 * by
 * {@link ANeuralNetworksMemory_createFromDesc}.
 *
 * To use:
 *   - Create a new memory descriptor by calling
 *     {@link ANeuralNetworksMemoryDesc_create}.
 *   - Specify all of the intended input and output roles by calling
 *     {@link ANeuralNetworksMemoryDesc_addInputRole} and
 *     {@link ANeuralNetworksMemoryDesc_addOutputRole}.
 *   - Optionally, specify the memory dimensions by calling
 *     {@link ANeuralNetworksMemoryDesc_setDimensions}.
 *   - Complete the memory descriptor with {@link
 * ANeuralNetworksMemoryDesc_finish}.
 *   - Use the memory descriptor as many times as needed with
 *     {@link ANeuralNetworksMemory_createFromDesc}.
 *   - Destroy the memory descriptor with {@link
 * ANeuralNetworksMemoryDesc_free}.
 *
 * A memory descriptor is completed by calling {@link
 * ANeuralNetworksMemoryDesc_finish}. A memory descriptor is destroyed by
 * calling {@link ANeuralNetworksMemoryDesc_free}.
 *
 * A memory descriptor must not be modified once
 * {@link ANeuralNetworksMemoryDesc_finish}
 * has been called on it.
 *
 * It is the application's responsibility to make sure that only
 * one thread modifies a memory descriptor at a given time. It is however
 * safe for more than one thread to use the memory descriptor once
 * {@link ANeuralNetworksMemoryDesc_finish} has returned.
 *
 * It is also the application's responsibility to ensure that there are no other
 * uses of the memory descriptor after calling {@link
 * ANeuralNetworksMemoryDesc_free}. It is however safe to continue using a
 * {@link ANeuralNetworksMemory} object created from the memory descriptor.
 *
 * Available since API level 30.
 */
ANeuralNetworksMemoryDesc;

/**
 * ANeuralNetworksMemory is an opaque type that represents memory.
 *
 * This type is used to represent shared memory, memory mapped files,
 * and similar memories.
 *
 * By using shared memory, a program can efficiently communicate to the
 * runtime and drivers the tensors that define a model. See
 * {@link ANeuralNetworksModel_setOperandValueFromMemory}. An application
 * should typically create one shared memory object that contains every tensor
 * needed to define a model. {@link ANeuralNetworksMemory_createFromFd} can be
 * used to create shared memory from a file handle. {@link
 * ANeuralNetworksMemory_createShared} can be used to directly created shared
 * memory.
 *
 * Memory objects can also be used to specify the input and output arguments of
 * an execution. See {@link ANeuralNetworksExecution_setInputFromMemory}
 * and {@link ANeuralNetworksExecution_setOutputFromMemory}.
 */
ANeuralNetworksMemory;

/**
 * ANeuralNetworksModel is an opaque type that contains a description of the
 * mathematical operations that constitute the model.
 *
 * <p>The model will be built by calling<ul>
 * <li>{@link ANeuralNetworksModel_create},</li>
 * <li>{@link ANeuralNetworksModel_addOperation},</li>
 * <li>{@link ANeuralNetworksModel_addOperand},</li>
 * </ul>
 *
 * A model is completed by calling {@link ANeuralNetworksModel_finish}.
 * A model is destroyed by calling {@link ANeuralNetworksModel_free}.
 *
 * <p>It is the application's responsibility to make sure that only one thread
 * modifies a model at a given time. It is however safe for more than one
 * thread to use the model once {@link ANeuralNetworksModel_finish} has
 * returned.</p>
 *
 * <p>It is also the application's responsibility to ensure that there are no
 * other uses of the model after calling {@link ANeuralNetworksModel_free}. This
 * includes any compilation or execution object created using the model.</p>
 */
ANeuralNetworksModel;

/**
 * ANeuralNetworksCompilation is an opaque type that can be used to compile
 * a machine learning model.
 *
 * <p>To use:<ul>
 *    <li>Create a new compilation instance by calling the
 *        {@link ANeuralNetworksCompilation_create} function.</li>
 *    <li>Perform the compilation with {@link
 * ANeuralNetworksCompilation_start}.</li> <li>Wait for the compilation to
 * complete with {@link ANeuralNetworksCompilation_wait}.</li> <li>Use the
 * compilation as many times as needed with {@link
 * ANeuralNetworksExecution_create}.</li> <li>Destroy the compilation with
 * {@link ANeuralNetworksCompilation_free} once all executions using the
 * compilation have completed.</li></ul></p>
 *
 * <p>A compilation cannot be modified once {@link
 * ANeuralNetworksCompilation_start} has been called on it.</p>
 *
 * <p>It is the application's responsibility to make sure that only one thread
 * modifies a compilation at a given time. It is however safe for more than one
 * thread to use {@link ANeuralNetworksCompilation_wait} at the same time.
 * It is also safe for multiple threads to use a compilation object once
 * {@link ANeuralNetworksCompilation_wait} has completed.</p>
 *
 * <p>It is also the application's responsibility to ensure that there are no
 * other uses of the compilation after calling {@link
 * ANeuralNetworksCompilation_free}. This includes any execution object created
 * using the compilation.</p>
 */
ANeuralNetworksCompilation;

/**
 * ANeuralNetworksExecution is an opaque type that can be used to apply a
 * machine learning model to a set of inputs.
 *
 * <p>To use:<ul>
 *    <li>Create a new execution instance by calling the
 *        {@link ANeuralNetworksExecution_create} function.</li>
 *    <li>Associate data to the model inputs with
 *        {@link ANeuralNetworksExecution_setInput} or
 *        {@link ANeuralNetworksExecution_setInputFromMemory}.</li>
 *    <li>Associate output buffers to the model outputs with
 *        {@link ANeuralNetworksExecution_setOutput} or
 *        {@link ANeuralNetworksExecution_setOutputFromMemory}.</li>
 *    <li>Apply the model with {@link
 * ANeuralNetworksExecution_startCompute}.</li> <li>Wait for the execution to
 * complete with {@link ANeuralNetworksExecution_wait}.</li> <li>Destroy the
 * execution with
 *        {@link ANeuralNetworksExecution_free}.</li></ul></p>
 *
 * <p>An execution cannot be modified once {@link
 * ANeuralNetworksExecution_start} has been called on it.</p>
 *
 * <p>An execution can be applied to a model with
 * {@link ANeuralNetworksExecution_startCompute} only once. Create new
 * executions to do new evaluations of the model.</p>
 *
 * <p>It is the application's responsibility to make sure that only one thread
 * modifies an execution at a given time. It is however safe for more than one
 * thread to use {@link ANeuralNetworksExecution_wait} at the same time.</p>
 *
 * <p>It is also the application's responsibility to ensure that there are no
 * other uses of the request after calling {@link
 * ANeuralNetworksRequest_free}.</p>
 */
ANeuralNetworksExecution;

/**
 * Parameters for ANEURALNETWORKS_TENSOR_QUANT8_SYMM_PER_CHANNEL operand.
 */
ANeuralNetworksSymmPerChannelQuantParams;

/**
 * ANeuralNetworksBurst is an opaque type that can be used to reduce the latency
 * of a rapid sequence of executions. It will likely cause overhead if only used
 * for a single execution.
 *
 * ANeuralNetworksBurst serves as a context object for any number of inferences
 * using {@link ANeuralNetworksExecution} objects. An ANeuralNetworksBurst
 * object and the {@link ANeuralNetworksExecution} objects used with it must all
 * have been created from the same {@link ANeuralNetworksCompilation} object.
 *
 * This object is also used as a hint to drivers, providing insight to the
 * lifetime of a rapid sequence of executions. For example, a driver may choose
 * to increase the clock frequency of its accelerator for the lifetime of a
 * burst object.
 *
 * <p>To use:<ul>
 *    <li>Create a new burst object by calling the
 *        {@link ANeuralNetworksBurst_create} function.</li>
 *    <li>For each execution:</li><ul>
 *        <li>Create {@link ANeuralNetworksExecution} and configure its
 *            properties (see {@link ANeuralNetworksExecution} for
 * details).</li> <li>Apply the model synchronously with
 *            {@link ANeuralNetworksExecution_burstCompute}, reusing the same
 *            {@link ANeuralNetworksBurst} with the new
 *            {@link ANeuralNetworksExecution}.</li>
 *        <li>Use and free the {@link ANeuralNetworksExecution}.</li></ul>
 *    <li>Destroy the burst with
 *        {@link ANeuralNetworksBurst_free}.</li></ul></p>
 *
 * Available since API level 29.
 */
ANeuralNetworksBurst;

/**
 * ANeuralNetworksOperandType describes the type of an operand.
 * This structure is used to describe both scalars and tensors.
 */
ANeuralNetworksOperandType;

/**
 * ANeuralNetworksEvent is an opaque type that represents an event
 * that will be signaled once an execution completes.
 */
ANeuralNetworksEvent;

ANeuralNetworksOperationType;

/**
 * ANeuralNetworksDevice is an opaque type that represents a device.
 *
 * This type is used to query basic properties and supported operations of the
 * corresponding device, and control which device(s) a model is to be run on.
 *
 * Available since API level 29.
 */
ANeuralNetworksDevice;

/**
 * Diagnostic result codes.
 */
ANeuralNetworksDiagnosticResultCode;

/**
 * Diagnostic data class.
 */
ANeuralNetworksDiagnosticDataClass;

/**
 * Diagnostic execution mode.
 */
ANeuralNetworksDiagnosticExecutionMode;

ANeuralNetworksDiagnosticCompilationInfo;
ANeuralNetworksDiagnosticExecutionInfo;
ANeuralNetworksDiagnosticCompilationFinishedCallback;
ANeuralNetworksDiagnosticExecutionFinishedCallback;

// nn api function types

ANeuralNetworksMemory_createFromFd_fn;

ANeuralNetworksMemory_free_fn;

ANeuralNetworksModel_create_fn;

ANeuralNetworksModel_finish_fn;

ANeuralNetworksModel_free_fn;

ANeuralNetworksCompilation_create_fn;

ANeuralNetworksCompilation_free_fn;

ANeuralNetworksCompilation_setPreference_fn;

ANeuralNetworksCompilation_finish_fn;

ANeuralNetworksModel_addOperand_fn;

ANeuralNetworksModel_setOperandValue_fn;

ANeuralNetworksModel_setOperandSymmPerChannelQuantParams_fn;

ANeuralNetworksModel_setOperandValueFromMemory_fn;

ANeuralNetworksModel_addOperation_fn;

ANeuralNetworksModel_identifyInputsAndOutputs_fn;

ANeuralNetworksModel_relaxComputationFloat32toFloat16_fn;

ANeuralNetworksExecution_create_fn;

ANeuralNetworksExecution_free_fn;

ANeuralNetworksExecution_setInput_fn;

ANeuralNetworksExecution_setInputFromMemory_fn;

ANeuralNetworksExecution_setOutput_fn;

ANeuralNetworksExecution_setOutputFromMemory_fn;

ANeuralNetworksExecution_startCompute_fn;

ANeuralNetworksEvent_wait_fn;

ANeuralNetworksEvent_free_fn;

ASharedMemory_create_fn;

ANeuralNetworks_getDeviceCount_fn;

ANeuralNetworks_getDevice_fn;

ANeuralNetworksDevice_getName_fn;

ANeuralNetworksDevice_getType_fn;

ANeuralNetworksDevice_getVersion_fn;

ANeuralNetworksDevice_getFeatureLevel_fn;

ANeuralNetworksModel_getSupportedOperationsForDevices_fn;

ANeuralNetworksCompilation_createForDevices_fn;

ANeuralNetworksCompilation_setCaching_fn;

ANeuralNetworksCompilation_setTimeout_fn;

ANeuralNetworksCompilation_setPriority_fn;

ANeuralNetworksExecution_compute_fn;

ANeuralNetworksExecution_setTimeout_fn;

ANeuralNetworksExecution_setLoopTimeout_fn;

ANeuralNetworksExecution_getOutputOperandRank_fn;

ANeuralNetworksExecution_getOutputOperandDimensions_fn;

ANeuralNetworksBurst_create_fn;

ANeuralNetworksBurst_free_fn;

ANeuralNetworksExecution_burstCompute_fn;

ANeuralNetworksMemory_createFromAHardwareBuffer_fn;

ANeuralNetworksExecution_setMeasureTiming_fn;

DurationCode;

ANeuralNetworksExecution_getDuration_fn;

ANeuralNetworksDevice_getExtensionSupport_fn;

ANeuralNetworksModel_getExtensionOperandType_fn;

ANeuralNetworksModel_getExtensionOperationType_fn;

ANeuralNetworksModel_setOperandExtensionData_fn;

ANeuralNetworksMemoryDesc_create_fn;

ANeuralNetworksMemoryDesc_free_fn;

ANeuralNetworksMemoryDesc_addInputRole_fn;

ANeuralNetworksMemoryDesc_addOutputRole_fn;

ANeuralNetworksMemoryDesc_setDimensions_fn;

ANeuralNetworksMemoryDesc_finish_fn;

ANeuralNetworksMemory_createFromDesc_fn;

ANeuralNetworksMemory_copy_fn;

ANeuralNetworksEvent_createFromSyncFenceFd_fn;

ANeuralNetworksEvent_getSyncFenceFd_fn;

ANeuralNetworksExecution_startComputeWithDependencies_fn;

ANeuralNetworksExecution_enableInputAndOutputPadding_fn;

ANeuralNetworksExecution_setReusable_fn;

ANeuralNetworks_getRuntimeFeatureLevel_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_getSessionId_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_getNnApiVersion_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_getModelArchHash_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_getDeviceIds_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_getErrorCode_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_getInputDataClass_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_getOutputDataClass_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_getCompilationTimeNanos_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_isCachingEnabled_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_isControlFlowUsed_fn;

SL_ANeuralNetworksDiagnosticCompilationInfo_areDynamicTensorsUsed_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getSessionId_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getNnApiVersion_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getModelArchHash_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getDeviceIds_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getExecutionMode_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getInputDataClass_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getOutputDataClass_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getErrorCode_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getRuntimeExecutionTimeNanos_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getDriverExecutionTimeNanos_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_getHardwareExecutionTimeNanos_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_isCachingEnabled_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_isControlFlowUsed_fn;

SL_ANeuralNetworksDiagnosticExecutionInfo_areDynamicTensorsUsed_fn;

SL_ANeuralNetworksDiagnostic_registerCallbacks_fn;

#endif  // TENSORFLOW_LITE_NNAPI_NEURALNETWORKSTYPES_H_