Skip to content

Commit

Permalink
Merge pull request asus4#315 from asus4/v2.13.0
Browse files Browse the repository at this point in the history
Upgrade TensorFlow Lite libraries to v2.13.0
  • Loading branch information
asus4 authored Sep 5, 2023
2 parents 232b16e + 1e92833 commit 2e4f2af
Show file tree
Hide file tree
Showing 27 changed files with 256 additions and 52 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ parameters:
default: "git@github.com:tensorflow/tensorflow.git"
tf-branch:
type: string
default: "v2.12.0"
default: "v2.13.0"

jobs:
build-mac:
macos:
xcode: 12.5.1
xcode: 14.2.0
steps:
- checkout
- run:
Expand Down Expand Up @@ -98,7 +98,7 @@ jobs:
path: Linux.tar
build-ios:
macos:
xcode: 12.5.1
xcode: 14.2.0
steps:
- checkout
- run:
Expand Down Expand Up @@ -130,8 +130,8 @@ jobs:
image: android:202102-01
environment:
ANDROID_SDK_API_LEVEL: 23
ANDROID_NDK_API_LEVEL: 21
ANDROID_BUILD_TOOLS_VERSION: 30.0.3
ANDROID_NDK_API_LEVEL: 26
ANDROID_BUILD_TOOLS_VERSION: 31.0.0
steps:
- checkout
- run:
Expand Down
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
Git LFS file not shown
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
#import <TensorFlowLiteC/common.h>
#import <TensorFlowLiteC/profiler.h>
#import <TensorFlowLiteC/telemetry_setting.h>
#import <TensorFlowLiteC/types.h>
#import <TensorFlowLiteC/xnnpack_delegate.h>
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ typedef enum {
kTfLiteBuiltinAtan2 = 156,
kTfLiteBuiltinUnsortedSegmentMin = 157,
kTfLiteBuiltinSign = 158,
kTfLiteBuiltinBitcast = 159,
kTfLiteBuiltinBitwiseXor = 160,
kTfLiteBuiltinRightShift = 161,
} TfLiteBuiltinOperator;

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ limitations under the License.
#include <stdlib.h>

#include "builtin_ops.h"
#include "types.h"
#include "c_api_types.h" // IWYU pragma: export

// --------------------------------------------------------------------------
Expand Down Expand Up @@ -483,6 +484,13 @@ TFL_CAPI_EXPORT extern TfLiteBuiltinOperator
TfLiteRegistrationExternalGetBuiltInCode(
const TfLiteRegistrationExternal* registration);

/// Return the OP version of the provided external 'registration'. Return -1
/// in case of error, or if the provided address is null.
///
/// \warning This is an experimental API and subject to change.
TFL_CAPI_EXPORT extern int TfLiteRegistrationExternalGetVersion(
const TfLiteRegistrationExternal* registration);

/// Returns the custom name of the provided 'registration'. The returned pointer
/// will be non-null iff the op is a custom op.
///
Expand Down Expand Up @@ -536,6 +544,19 @@ TFL_CAPI_EXPORT extern void TfLiteRegistrationExternalSetInvoke(
TfLiteStatus (*invoke)(TfLiteOpaqueContext* context,
TfLiteOpaqueNode* node));

/// Sets the async kernel accessor callback for the registration.
///
/// The callback is called to retrieve the async kernel if the delegate supports
/// it. If the delegate does not support async execution, either this function
/// should not be called, or `async_kernel` needs to be nullptr.
/// `node` is the delegate TfLiteNode created by `ModifyGraphWithDelegate`.
/// Please refer `async_kernel` of `TfLiteRegistration` for the detail.
/// \warning This is an experimental API and subject to change.
TFL_CAPI_EXPORT extern void TfLiteRegistrationExternalSetAsyncKernel(
TfLiteRegistrationExternal* registration,
TfLiteAsyncKernel* (*async_kernel)(TfLiteOpaqueContext* context,
TfLiteOpaqueNode* node));

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

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ TFL_CAPI_EXPORT extern TfLiteStatus TfLiteInterpreterResetVariableTensors(
/// practice is making the provided `TfLiteRegistration` instance static.
///
/// Code that uses this function should NOT call
/// `TfLiteInterpreterOptionsSetOpResolver` on the same options object.
/// `TfLiteInterpreterOptionsSetOpResolver` (or related functions) on the same
/// options object.
///
/// WARNING: This is an experimental API and subject to change.
TFL_CAPI_EXPORT void TfLiteInterpreterOptionsAddBuiltinOp(
Expand All @@ -86,14 +87,41 @@ TFL_CAPI_EXPORT void TfLiteInterpreterOptionsAddBuiltinOp(
/// as the lifetime of the `TfLiteInterpreterOptions`.
///
/// Code that uses this function should NOT call
/// `TfLiteInterpreterOptionsSetOpResolver` on the same options object.
/// `TfLiteInterpreterOptionsSetOpResolver` (or related functions) on the same
/// options object.
///
/// WARNING: This is an experimental API and subject to change.
TFL_CAPI_EXPORT void TfLiteInterpreterOptionsAddCustomOp(
TfLiteInterpreterOptions* options, const char* name,
const TfLiteRegistration* registration, int32_t min_version,
int32_t max_version);

/// Registers callbacks for resolving builtin or custom operators.
///
/// The `TfLiteInterpreterOptionsSetOpResolverExternal` function provides an
/// alternative method for registering builtin ops and/or custom ops, by
/// providing operator resolver callbacks. Unlike using
/// `TfLiteInterpreterOptionsAddBuiltinOp` and/or
/// `TfLiteInterpreterOptionsAddAddCustomOp`, these let you register all the
/// operators in a single call.
///
/// Code that uses this function should NOT call
/// `TfLiteInterpreterOptionsAddBuiltin` or
/// `TfLiteInterpreterOptionsAddCustomOp` on the same options object.
///
/// If `op_resolver_user_data` is non-null, its lifetime must be at least as
/// long as the lifetime of the `TfLiteInterpreterOptions`.
///
/// WARNING: This is an experimental API and subject to change.
void TfLiteInterpreterOptionsSetOpResolverExternal(
TfLiteInterpreterOptions* options,
const TfLiteRegistrationExternal* (*find_builtin_op)(void* user_data,
int op, int version),
const TfLiteRegistrationExternal* (*find_custom_op)(void* user_data,
const char* custom_op,
int version),
void* op_resolver_user_data);

/// Registers callbacks for resolving builtin or custom operators.
///
/// The `TfLiteInterpreterOptionsSetOpResolver` function provides an alternative
Expand All @@ -110,6 +138,8 @@ TFL_CAPI_EXPORT void TfLiteInterpreterOptionsAddCustomOp(
/// long as the lifetime of the `TfLiteInterpreterOptions`.
///
/// WARNING: This is an experimental API and subject to change.
///
/// DEPRECATED: use TfLiteInterpreterOptionsSetOpResolverExternal instead.
void TfLiteInterpreterOptionsSetOpResolver(
TfLiteInterpreterOptions* options,
const TfLiteRegistration* (*find_builtin_op)(void* user_data,
Expand All @@ -121,7 +151,22 @@ void TfLiteInterpreterOptionsSetOpResolver(
void* op_resolver_user_data);

/// \private
/// `TfLiteRegistration_V1` version of TfLiteInterpreterOptionsSetOpResolver.
/// Backward-compat version of TfLiteInterpreterOptionsSetOpResolver.
///
/// WARNING: This function is deprecated / not an official part of the API, is
/// only for binary backwards compatibility, and should not be called.
void TfLiteInterpreterOptionsSetOpResolverV2(
TfLiteInterpreterOptions* options,
const TfLiteRegistration_V2* (*find_builtin_op_v2)(void* user_data,
TfLiteBuiltinOperator op,
int version),
const TfLiteRegistration_V2* (*find_custom_op_v2)(void* user_data,
const char* op,
int version),
void* op_resolver_user_data);

/// \private
/// Backward-compat version of TfLiteInterpreterOptionsSetOpResolver.
///
/// WARNING: This function is deprecated / not an official part of the API, is
/// only for binary backwards compatibility, and should not be called.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ limitations under the License.
/// "third_party/tensorflow/lite/c/c_api_types.h".
/// Only the TensorFlow Lite implementation itself should include this
/// file directly.
// IWYU pragma: private, include "third_party/tensorflow/lite/c/c_api_types.h"

#ifndef TENSORFLOW_LITE_CORE_C_C_API_TYPES_H_
#define TENSORFLOW_LITE_CORE_C_C_API_TYPES_H_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ limitations under the License.
/// "third_party/tensorflow/lite/c/common.h".
/// Only the TensorFlow Lite implementation itself should include this
/// file directly.
// IWYU pragma: private, include "third_party/tensorflow/lite/c/common.h"

#ifndef TENSORFLOW_LITE_CORE_C_COMMON_H_
#define TENSORFLOW_LITE_CORE_C_COMMON_H_
Expand Down Expand Up @@ -157,6 +158,10 @@ int TfLiteFloatArrayGetSizeInBytes(int size);
// This returns a pointer, that you must free using TfLiteFloatArrayFree().
TfLiteFloatArray* TfLiteFloatArrayCreate(int size);

// Create a copy of an array passed as `src`.
// You are expected to free memory with TfLiteFloatArrayFree.
TfLiteFloatArray* TfLiteFloatArrayCopy(const TfLiteFloatArray* src);

// Free memory of array `a`.
void TfLiteFloatArrayFree(TfLiteFloatArray* a);
#endif // TF_LITE_STATIC_MEMORY
Expand Down Expand Up @@ -959,12 +964,53 @@ typedef struct TfLiteRegistration {
// ops. We keep it inside of `TfLiteRegistration` and use it to route
// callbacks properly.
TfLiteRegistrationExternal* registration_external;

// Retrieves asynchronous kernel.
//
// If the `async_kernel` field is nullptr, it means the operation described by
// this TfLiteRegistration object does not support asynchronous execution.
// Otherwise, the function that the field points to should only be called for
// delegate kernel nodes, i.e. `node` should be a delegate kernel node created
// by applying a delegate.
// If the function returns nullptr, that means that the underlying delegate
// does not support asynchronous execution for this `node`.
struct TfLiteAsyncKernel* (*async_kernel)(TfLiteContext* context,
TfLiteNode* node);
} TfLiteRegistration;

/// \private
// Old version of `TfLiteRegistration` to maintain binary backward
// compatibility.
// The legacy registration type must be a POD struct type whose field types must
// be a prefix of the field types in TfLiteRegistration, and offset of the first
// field in TfLiteRegistration that is not present in the legacy registration
// type must be greater than or equal to the size of the legacy registration
// type.
// WARNING: This structure is deprecated / not an official part of the
// API. It should be only used for binary backward compatibility.
typedef struct TfLiteRegistration_V2 {
void* (*init)(TfLiteContext* context, const char* buffer, size_t length);
void (*free)(TfLiteContext* context, void* buffer);
TfLiteStatus (*prepare)(TfLiteContext* context, TfLiteNode* node);
TfLiteStatus (*invoke)(TfLiteContext* context, TfLiteNode* node);
const char* (*profiling_string)(const TfLiteContext* context,
const TfLiteNode* node);
int32_t builtin_code;
const char* custom_name;
int version;
TfLiteRegistrationExternal* registration_external;
} TfLiteRegistration_V2;

/// \private
// Old version of `TfLiteRegistration` to maintain binary backward
// compatibility.
// WARNING: This structure is deprecated / not an official part of the API.
// It should be only used for binary backward compatibility.
// The legacy registration type must be a POD struct type whose field types must
// be a prefix of the field types in TfLiteRegistration, and offset of the first
// field in TfLiteRegistration that is not present in the legacy registration
// type must be greater than or equal to the size of the legacy registration
// type.
// WARNING: This structure is deprecated / not an official part of the
// API. It should be only used for binary backward compatibility.
typedef struct TfLiteRegistration_V1 {
void* (*init)(TfLiteContext* context, const char* buffer, size_t length);
void (*free)(TfLiteContext* context, void* buffer);
Expand Down Expand Up @@ -1148,6 +1194,9 @@ void TfLiteOpaqueDelegateDelete(TfLiteOpaqueDelegate* delegate);
// - Or in case of any other error.
// - The 'delegate' has been constructed via a 'TfLiteOpaqueDelegateBuilder',
// but the 'data' field of the 'TfLiteOpaqueDelegateBuilder' is null.
//
// The data_ field of 'delegate' will be returned if the
// 'opaque_delegate_builder' field is null.
void* TfLiteOpaqueDelegateGetData(const TfLiteOpaqueDelegate* delegate);

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,12 @@ const TfLiteTelemetrySubgraphInfo*
TfLiteTelemetryInterpreterSettingsGetSubgraphInfo(
const TfLiteTelemetryInterpreterSettings* settings);

size_t TfLiteTelemetrySubgraphInfoGetNumOpTypes(
TfLiteTelemetrySubgraphInfo* subgraph_info);

const int32_t* TfLiteTelemetrySubgraphInfoGetOpTypes(
TfLiteTelemetrySubgraphInfo* subgraph_info);

size_t TfLiteTelemetrySubgraphInfoGetNumQuantizations(
TfLiteTelemetrySubgraphInfo* subgraph_info);

const TfLiteQuantization* TfLiteTelemetrySubgraphInfoGetQuantizations(
TfLiteTelemetrySubgraphInfo* subgraph_info);

size_t TfLiteTelemetrySubgraphInfoGetNumCustomOpNames(
TfLiteTelemetrySubgraphInfo* subgraph_info);

const char** TfLiteTelemetrySubgraphInfoGetCustomOpNames(
TfLiteTelemetrySubgraphInfo* subgraph_info);

// Telemetry information for GPU delegate.
typedef struct TfLiteTelemetryGpuDelegateSettings
TfLiteTelemetryGpuDelegateSettings;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright 2022 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_CORE_ASYNC_C_TYPES_H_
#define TENSORFLOW_LITE_CORE_ASYNC_C_TYPES_H_

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/// Opaque type for TfLiteAsyncKernel.
typedef struct TfLiteAsyncKernel TfLiteAsyncKernel;

/// Opaque type for TfLiteExecutionTask.
///
/// See tensorflow/lite/core/async/c/task.h
/// NOTE: TfLiteExecutionTask is NOT thread-safe.
typedef struct TfLiteExecutionTask TfLiteExecutionTask;

/// Enum tag for specifying whether a tensor is the input or output to the
/// model.
typedef enum TfLiteIoType {
kTfLiteIoTypeUnknown = 0,
kTfLiteIoTypeInput = 1,
kTfLiteIoTypeOutput = 2,
} TfLiteIoType;

#ifdef __cplusplus
} // extern "C"
#endif // __cplusplus

#endif // TENSORFLOW_LITE_CORE_ASYNC_C_TYPES_H_
Loading

0 comments on commit 2e4f2af

Please sign in to comment.