chromium/third_party/tflite/src/tensorflow/lite/core/tools/verifier.cc

/* 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.
==============================================================================*/

#include "tensorflow/lite/core/tools/verifier.h"

#include <algorithm>
#include <climits>
#include <complex>
#include <cstdint>
#include <cstring>

#include "absl/container/flat_hash_set.h"
#include "absl/types/optional.h"
#include "flatbuffers/string.h"  // from @flatbuffers
#include "tensorflow/compiler/mlir/lite/schema/schema_utils.h"
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/core/api/error_reporter.h"
#include "tensorflow/lite/core/api/op_resolver.h"
#include "tensorflow/lite/core/tools/verifier_internal.h"
#include "tensorflow/lite/schema/schema_generated.h"
#include "tensorflow/lite/util.h"
#include "tensorflow/lite/version.h"

namespace tflite {
namespace {

const char* NameOrEmptyString(const flatbuffers::String* str) {}

bool IsNullOrEmptyString(const flatbuffers::String* str) {}

void ReportError(ErrorReporter* error_reporter, const char* format, ...) {}

// Returns the int32_t value pointed by ptr.
const uint32_t GetIntPtr(const char* ptr) {}

const uint32_t kMaxNumString =;

// Verifies string tensor has legit buffer contents that follow the schema
// defined in lite/string_util.h
bool VerifyStringTensorBuffer(const Tensor& tensor, const Buffer& buffer,
                              ErrorReporter* error_reporter) {}

bool CheckArraySegments(const DimensionMetadata* dim_metadata) {}

int GetSizeOfSegments(const DimensionMetadata* dim_metadata) {}

int GetValueOfSegmentsAt(const DimensionMetadata* dim_metadata, const int i) {}

bool CheckArrayIndices(const DimensionMetadata* dim_metadata) {}

int GetSizeOfIndices(const DimensionMetadata* dim_metadata) {}

int GetValueOfIndicesAt(const DimensionMetadata* dim_metadata, const int i) {}

// The sparsity parameter defines a tree structure to map each non-zero element
// stored in the flattened buffer back to its index in the conceptual dense
// tensor.
// Traverse the tree level by level, count total number of elements, and
// validate the sparsity parameters along the way.
absl::optional<uint64_t> VerifyAndCountElements(
    const SparsityParameters& sparsity, const std::vector<int>& dim_sizes) {}

absl::optional<uint64_t> VerifyAndCountSparseElements(const Tensor& tensor) {}

// Verifies numeric tensor has legit buffer.
bool VerifyNumericTensorBuffer(const Tensor& tensor, const Buffer& buffer,
                               ErrorReporter* error_reporter) {}

Offset;
Vector;

bool VerifyOperators(const Vector<Offset<Operator>>& operators,
                     ErrorReporter* error_reporter) {}

bool IsConstantTensor(const Tensor& tensor, const Model& model) {}

// Performs basic consistency checks on a sub-graph.
bool VerifySubGraphConsistency(const Model& model, const SubGraph& subgraph,
                               ErrorReporter* error_reporter) {}

bool VerifySubGraphs(const Model& model, ErrorReporter* error_reporter) {}

// Verifies tensors have valid properties and legit buffer if set.
bool VerifyTensors(const Model& model, ErrorReporter* error_reporter) {}

bool VerifyOps(const Model& model, const OpResolver& resolver,
               ErrorReporter* error_reporter) {}

bool VerifyModel(const Model* model, ErrorReporter* error_reporter) {}

}  // namespace

bool Verify(const void* buf, size_t len, ErrorReporter* error_reporter) {}

// Deprecated: see comments in header.
bool Verify(const void* buf, size_t len, const OpResolver& resolver,
            ErrorReporter* error_reporter) {}

}  // namespace tflite