Skip to content

Commit

Permalink
Update libraries to v2.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
asus4 committed Nov 25, 2023
1 parent ebd77d9 commit d5c3678
Show file tree
Hide file tree
Showing 17 changed files with 433 additions and 202 deletions.
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,50 @@ typedef enum {
kTfLiteBuiltinBitcast = 159,
kTfLiteBuiltinBitwiseXor = 160,
kTfLiteBuiltinRightShift = 161,
kTfLiteBuiltinStablehloLogistic = 162,
kTfLiteBuiltinStablehloAdd = 163,
kTfLiteBuiltinStablehloDivide = 164,
kTfLiteBuiltinStablehloMultiply = 165,
kTfLiteBuiltinStablehloMaximum = 166,
kTfLiteBuiltinStablehloReshape = 167,
kTfLiteBuiltinStablehloClamp = 168,
kTfLiteBuiltinStablehloConcatenate = 169,
kTfLiteBuiltinStablehloBroadcastInDim = 170,
kTfLiteBuiltinStablehloConvolution = 171,
kTfLiteBuiltinStablehloSlice = 172,
kTfLiteBuiltinStablehloCustomCall = 173,
kTfLiteBuiltinStablehloReduce = 174,
kTfLiteBuiltinStablehloAbs = 175,
kTfLiteBuiltinStablehloAnd = 176,
kTfLiteBuiltinStablehloCosine = 177,
kTfLiteBuiltinStablehloExponential = 178,
kTfLiteBuiltinStablehloFloor = 179,
kTfLiteBuiltinStablehloLog = 180,
kTfLiteBuiltinStablehloMinimum = 181,
kTfLiteBuiltinStablehloNegate = 182,
kTfLiteBuiltinStablehloOr = 183,
kTfLiteBuiltinStablehloPower = 184,
kTfLiteBuiltinStablehloRemainder = 185,
kTfLiteBuiltinStablehloRsqrt = 186,
kTfLiteBuiltinStablehloSelect = 187,
kTfLiteBuiltinStablehloSubtract = 188,
kTfLiteBuiltinStablehloTanh = 189,
kTfLiteBuiltinStablehloScatter = 190,
kTfLiteBuiltinStablehloCompare = 191,
kTfLiteBuiltinStablehloConvert = 192,
kTfLiteBuiltinStablehloDynamicSlice = 193,
kTfLiteBuiltinStablehloDynamicUpdateSlice = 194,
kTfLiteBuiltinStablehloPad = 195,
kTfLiteBuiltinStablehloIota = 196,
kTfLiteBuiltinStablehloDotGeneral = 197,
kTfLiteBuiltinStablehloReduceWindow = 198,
kTfLiteBuiltinStablehloSort = 199,
kTfLiteBuiltinStablehloWhile = 200,
kTfLiteBuiltinStablehloGather = 201,
kTfLiteBuiltinStablehloTranspose = 202,
kTfLiteBuiltinDilate = 203,
kTfLiteBuiltinStablehloRngBitGenerator = 204,
kTfLiteBuiltinReduceWindow = 205,
} TfLiteBuiltinOperator;

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,21 @@ typedef struct TfLiteInterpreter TfLiteInterpreter;
/// data including a dimensionality (or NULL if not currently defined).
typedef struct TfLiteTensor TfLiteTensor;

/// TfLiteSignatureRunner is used to run inference on a signature.
///
/// Note: A signature is used to define a computation in a TF model. A model can
/// have multiple signatures. Each signature contains three components:
/// * Signature Key: A unique string to identify a signature
/// * Inputs: A list of names, each mapped to an input tensor of a signature
/// * Outputs: A list of names, each mapped to an output tensor of a signature
///
/// To learn more about signatures in TFLite, refer to:
/// https://www.tensorflow.org/lite/guide/signatures
///
/// Using the TfLiteSignatureRunner, for a particular signature, you can set its
/// inputs, invoke (i.e. execute) the computation, and retrieve its outputs.
typedef struct TfLiteSignatureRunner TfLiteSignatureRunner;

// --------------------------------------------------------------------------
/// The TensorFlow Lite Runtime version.
///
Expand All @@ -115,6 +130,26 @@ typedef struct TfLiteTensor TfLiteTensor;
/// e.g. "2.12.0" or "2.13.0-rc2".
TFL_CAPI_EXPORT extern const char* TfLiteVersion(void);

// --------------------------------------------------------------------------
/// The TensorFlow Lite Extension APIs version.
///
/// Returns a pointer to a statically allocated string that is the version
/// number of the TF Lite Extension APIs supported by the (potentially
/// dynamically loaded) TF Lite Runtime library. The TF Lite "Extension APIs"
/// are the APIs for extending TF Lite with custom ops and delegates.
/// More specifically, this version number covers the (non-experimental)
/// functionality documented in the following header files:
///
/// * lite/c/c_api_opaque.h
/// * lite/c/common.h
/// * lite/c/builtin_op_data.h
/// * lite/builtin_ops.h
///
/// This version number uses semantic versioning, and the return value should
/// be in semver 2 format <http://semver.org>, starting with MAJOR.MINOR.PATCH,
/// e.g. "2.14.0" or "2.15.0-rc2".
TFL_CAPI_EXPORT extern const char* TfLiteExtensionApisVersion(void);

/// The supported TensorFlow Lite model file Schema version.
///
/// Returns the (major) version number of the Schema used for model
Expand Down Expand Up @@ -414,6 +449,137 @@ TfLiteTensor* TfLiteInterpreterGetTensor(const TfLiteInterpreter* interpreter,
TFL_CAPI_EXPORT extern TfLiteStatus TfLiteInterpreterCancel(
const TfLiteInterpreter* interpreter);

/// --------------------------------------------------------------------------
/// SignatureRunner APIs
///
/// You can run inference by either:
///
/// (i) (recommended) using the Interpreter to initialize SignatureRunner(s) and
/// then only using SignatureRunner APIs.
///
/// (ii) only using Interpreter APIs.
///
/// NOTE:
/// * Only use one of the above options to run inference, i.e. avoid mixing both
/// SignatureRunner APIs and Interpreter APIs to run inference as they share
/// the same underlying data (e.g. updating an input tensor “A” retrieved
/// using the Interpreter APIs will update the state of the input tensor “B”
/// retrieved using SignatureRunner APIs, if they point to the same underlying
/// tensor in the model; as it is not possible for a user to debug this by
/// analyzing the code, it can lead to undesirable behavior).
/// * The TfLiteSignatureRunner type is conditionally thread-safe, provided that
/// no two threads attempt to simultaneously access two TfLiteSignatureRunner
/// instances that point to the same underlying signature, or access a
/// TfLiteSignatureRunner and its underlying TfLiteInterpreter, unless all
/// such simultaneous accesses are reads (rather than writes).
/// * The lifetime of a TfLiteSignatureRunner object ends when
/// TfLiteSignatureRunnerDelete() is called on it (or when the lifetime of the
/// underlying TfLiteInterpreter ends -- but you should call
/// TfLiteSignatureRunnerDelete() before that happens in order to avoid
/// resource leaks).
/// * You can only apply delegates to the interpreter (via
/// TfLiteInterpreterOptions) and not to a signature.

/// Returns the number of signatures defined in the model.
TFL_CAPI_EXPORT extern int32_t TfLiteInterpreterGetSignatureCount(
const TfLiteInterpreter* interpreter);

/// Returns the key of the Nth signature in the model, where N is specified as
/// `signature_index`.
///
/// NOTE: The lifetime of the returned key is the same as (and depends on) the
/// lifetime of `interpreter`.
TFL_CAPI_EXPORT extern const char* TfLiteInterpreterGetSignatureKey(
const TfLiteInterpreter* interpreter, int32_t signature_index);

/// Returns a new signature runner using the provided interpreter and signature
/// key, or nullptr on failure.
///
/// NOTE: `signature_key` is a null-terminated C string that must match the
/// key of a signature in the interpreter's model.
///
/// NOTE: The returned signature runner should be destroyed, by calling
/// TfLiteSignatureRunnerDelete(), before the interpreter is destroyed.
TFL_CAPI_EXPORT extern TfLiteSignatureRunner*
TfLiteInterpreterGetSignatureRunner(const TfLiteInterpreter* interpreter,
const char* signature_key);

/// Returns the number of inputs associated with a signature.
TFL_CAPI_EXPORT extern size_t TfLiteSignatureRunnerGetInputCount(
const TfLiteSignatureRunner* signature_runner);

/// Returns the (null-terminated) name of the Nth input in a signature, where N
/// is specified as `input_index`.
///
/// NOTE: The lifetime of the returned name is the same as (and depends on) the
/// lifetime of `signature_runner`.
TFL_CAPI_EXPORT extern const char* TfLiteSignatureRunnerGetInputName(
const TfLiteSignatureRunner* signature_runner, int32_t input_index);

/// Resizes the input tensor identified as `input_name` to be the dimensions
/// specified by `input_dims` and `input_dims_size`. Only unknown dimensions can
/// be resized with this function. Unknown dimensions are indicated as `-1` in
/// the `dims_signature` attribute of a TfLiteTensor.
///
/// Returns status of failure or success. Note that this doesn't actually resize
/// any existing buffers. A call to TfLiteSignatureRunnerAllocateTensors() is
/// required to change the tensor input buffer.
///
/// NOTE: This function is similar to TfLiteInterpreterResizeInputTensorStrict()
/// and not TfLiteInterpreterResizeInputTensor().
///
/// NOTE: `input_name` must match the name of an input in the signature.
///
/// NOTE: This function makes a copy of the input dimensions, so the caller can
/// safely deallocate `input_dims` immediately after this function returns.
TFL_CAPI_EXPORT extern TfLiteStatus TfLiteSignatureRunnerResizeInputTensor(
TfLiteSignatureRunner* signature_runner, const char* input_name,
const int* input_dims, int32_t input_dims_size);

/// Updates allocations for tensors associated with a signature and resizes
/// dependent tensors using the specified input tensor dimensionality.
/// This is a relatively expensive operation and hence should only be called
/// after initializing the signature runner object and/or resizing any inputs.
TFL_CAPI_EXPORT extern TfLiteStatus TfLiteSignatureRunnerAllocateTensors(
TfLiteSignatureRunner* signature_runner);

/// Returns the input tensor identified by `input_name` in the given signature.
/// Returns nullptr if the given name is not valid.
///
/// NOTE: The lifetime of the returned tensor is the same as (and depends on)
/// the lifetime of `signature_runner`.
TFL_CAPI_EXPORT extern TfLiteTensor* TfLiteSignatureRunnerGetInputTensor(
TfLiteSignatureRunner* signature_runner, const char* input_name);

/// Runs inference on a given signature.
///
/// Before calling this function, the caller should first invoke
/// TfLiteSignatureRunnerAllocateTensors() and should also set the values for
/// the input tensors. After successfully calling this function, the values for
/// the output tensors will be set.
TFL_CAPI_EXPORT extern TfLiteStatus TfLiteSignatureRunnerInvoke(
TfLiteSignatureRunner* signature_runner);

/// Returns the number of output tensors associated with the signature.
TFL_CAPI_EXPORT extern size_t TfLiteSignatureRunnerGetOutputCount(
const TfLiteSignatureRunner* signature_runner);

/// Returns the (null-terminated) name of the Nth output in a signature, where
/// N is specified as `output_index`.
///
/// NOTE: The lifetime of the returned name is the same as (and depends on) the
/// lifetime of `signature_runner`.
TFL_CAPI_EXPORT extern const char* TfLiteSignatureRunnerGetOutputName(
const TfLiteSignatureRunner* signature_runner, int32_t output_index);

/// Returns the output tensor identified by `output_name` in the given
/// signature. Returns nullptr if the given name is not valid.
///
/// NOTE: The lifetime of the returned tensor is the same as (and depends on)
/// the lifetime of `signature_runner`.
TFL_CAPI_EXPORT extern const TfLiteTensor* TfLiteSignatureRunnerGetOutputTensor(
const TfLiteSignatureRunner* signature_runner, const char* output_name);

// --------------------------------------------------------------------------
// TfLiteTensor wraps data associated with a graph tensor.
//
Expand Down Expand Up @@ -466,6 +632,10 @@ TFL_CAPI_EXPORT extern TfLiteStatus TfLiteTensorCopyToBuffer(
const TfLiteTensor* output_tensor, void* output_data,
size_t output_data_size);

/// Destroys the signature runner.
TFL_CAPI_EXPORT extern void TfLiteSignatureRunnerDelete(
TfLiteSignatureRunner* signature_runner);

// NOLINTEND(modernize-redundant-void-arg)

/** @} */
Expand Down
Loading

0 comments on commit d5c3678

Please sign in to comment.