#include "tensorflow/lite/core/interpreter_builder.h"
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <map>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "flatbuffers/buffer.h"
#include "flatbuffers/vector.h"
#include "tensorflow/lite/allocation.h"
#include "tensorflow/lite/core/api/error_reporter.h"
#include "tensorflow/lite/core/api/flatbuffer_conversions.h"
#include "tensorflow/lite/core/api/op_resolver.h"
#include "tensorflow/lite/core/c/c_api_types.h"
#include "tensorflow/lite/core/interpreter.h"
#include "tensorflow/lite/core/macros.h"
#include "tensorflow/lite/core/model_builder.h"
#include "tensorflow/lite/core/subgraph.h"
#include "tensorflow/lite/internal/signature_def.h"
#include "tensorflow/lite/interpreter_options.h"
#include "tensorflow/lite/profiling/platform_profiler.h"
#include "tensorflow/lite/profiling/telemetry/c/telemetry_setting.h"
#include "tensorflow/lite/profiling/telemetry/c/telemetry_setting_internal.h"
#include "tensorflow/lite/schema/conversion_metadata_generated.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/schema/schema_utils.h"
#include "tensorflow/lite/shared_library.h"
#include "tensorflow/lite/stderr_reporter.h"
#include "tensorflow/lite/util.h"
#include "tensorflow/lite/version.h"
#if __cplusplus >= 201703L && __STDC_VERSION__ >= 201112L
#if !defined(__ANDROID__) || __ANDROID_API__ >= 28
#if !defined(__APPLE__) && !defined(_WIN32)
#define TFLITE_USE_STD_ALIGNED_ALLOC
#endif
#endif
#endif
#if defined(__ANDROID__)
#define TFLITE_IS_MOBILE_PLATFORM
#endif
#if defined(__APPLE__)
#include "TargetConditionals.h"
#if TARGET_IPHONE_SIMULATOR
#define TFLITE_IS_MOBILE_PLATFORM
#elif TARGET_OS_IPHONE
#define TFLITE_IS_MOBILE_PLATFORM
#endif
#endif
namespace tflite {
namespace {
constexpr char kConversionMetadataKey[] = …;
constexpr char kTelemetryBuilderEventName[] = …;
ErrorReporter* ValidateErrorReporter(ErrorReporter* e) { … }
template <typename T>
TfLiteStatus Copy(const T* data_ptr, TfLiteIntArray** arr) { … }
TfLiteStatus ParseSparseIndexVector(const DimensionMetadata* src,
TfLiteDimensionMetadata* tgt) { … }
std::map<std::string, uint32_t> GetMapFromTensorMap(
const flatbuffers::Vector<flatbuffers::Offset<tflite::TensorMap>>*
tensor_map) { … }
inline bool ShouldCreateLazyDelegateProviders(int num_fp32_tensors) { … }
}
constexpr const char* kEmptyTensorName = …;
TFLITE_ATTRIBUTE_WEAK Interpreter::TfLiteDelegatePtr AcquireFlexDelegate() { … }
InterpreterBuilder::InterpreterBuilder(
const FlatBufferModel& model, const OpResolver& op_resolver,
const InterpreterOptions* options_experimental)
: … { … }
InterpreterBuilder::InterpreterBuilder(
const ::tflite::Model* model, const OpResolver& op_resolver,
ErrorReporter* error_reporter,
const InterpreterOptions* options_experimental,
const Allocation* allocation)
: … { … }
InterpreterBuilder::~InterpreterBuilder() = default;
TfLiteStatus InterpreterBuilder::BuildLocalIndexToRegistrationMapping() { … }
namespace {
template <class T>
std::vector<int> FlatBufferIntArrayToVector(T* flat_array) { … }
class MallocDataAllocator : public BuiltinDataAllocator { … };
}
TfLiteStatus InterpreterBuilder::ParseNodes(
const flatbuffers::Vector<flatbuffers::Offset<Operator>>* operators,
Subgraph* subgraph) { … }
TfLiteStatus InterpreterBuilder::ParseQuantization(
const QuantizationParameters* src_quantization,
TfLiteQuantization* quantization, const std::vector<int>& dims) { … }
TfLiteStatus InterpreterBuilder::ParseSparsity(
const SparsityParameters* src_sparsity, TfLiteSparsity** sparsity_ptr) { … }
TfLiteStatus InterpreterBuilder::ParseSignatureDefs(
const flatbuffers::Vector<flatbuffers::Offset<SignatureDef>>*
signature_def_list,
Interpreter* interpreter) { … }
TfLiteStatus InterpreterBuilder::ParseTensors(
const flatbuffers::Vector<flatbuffers::Offset<Buffer>>* buffers,
const flatbuffers::Vector<flatbuffers::Offset<Tensor>>* tensors,
Subgraph* subgraph, TfLiteTelemetrySubgraphInfo* subgraph_info) { … }
TfLiteStatus InterpreterBuilder::ApplyDelegates(Interpreter* interpreter) { … }
TfLiteStatus InterpreterBuilder::SetNumThreads(int num_threads) { … }
TfLiteStatus InterpreterBuilder::operator()(
std::unique_ptr<Interpreter>* interpreter, int num_threads) { … }
TfLiteStatus InterpreterBuilder::operator()(
std::unique_ptr<Interpreter>* interpreter) { … }
void InterpreterBuilder::AddDelegate(TfLiteDelegate* delegate) { … }
void InterpreterBuilder::AddDelegate(
TfLiteOpaqueDelegateStruct* opaque_delegate) { … }
void InterpreterBuilder::ParseConversionMetadata(
TfLiteTelemetryInterpreterSettings* settings) { … }
}