chromium/third_party/tflite/src/tensorflow/lite/delegates/xnnpack/weight_cache.cc

/* Copyright 2024 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/delegates/xnnpack/weight_cache.h"

#include <fcntl.h>
#include <sys/stat.h>

#if defined(_MSC_VER)
#include <io.h>
#define F_OK
#else
#include <sys/mman.h>
#include <unistd.h>
#endif

#include <algorithm>
#include <cerrno>  // IWYU pragma: keep
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>

#include "xnnpack.h"  // from @XNNPACK
#include "flatbuffers/flatbuffer_builder.h"  // from @flatbuffers
#include "flatbuffers/verifier.h"  // from @flatbuffers
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/delegates/xnnpack/weight_cache_schema_generated.h"
#include "tensorflow/lite/logger.h"
#include "tensorflow/lite/minimal_logging.h"

#define XNNPACK_ABORT_CHECK(TEST, ...)

namespace tflite::xnnpack {

namespace {
constexpr size_t kMinAlignment =;

// Returns the next offset value that is aligned to `alignement`.
size_t Align(size_t offset, const size_t alignment) {}

// Class the provided callback at then end of the scope this was created into.
template <class F>
class ScopeGuard {};

template <class F>
ScopeGuard(F&&) -> ScopeGuard<F>;

// Returns true if the given path exists.
[[nodiscard]]
bool FileExists(const char* path) {}

}  // namespace

void swap(MMapHandle& a, MMapHandle& b) {}

MMapHandle::~MMapHandle() {}

MMapHandle::MMapHandle(MMapHandle&& other) {}

MMapHandle& MMapHandle::operator=(MMapHandle&& other) {}

bool MMapHandle::Map(const char* path) {}

void MMapHandle::UnMap() {}

void swap(WeightCacheBuilder& a, WeightCacheBuilder& b) {}

WeightCacheBuilder::WeightCacheBuilder(WeightCacheBuilder&& other) {}

WeightCacheBuilder& WeightCacheBuilder::operator=(WeightCacheBuilder&& other) {}

WeightCacheBuilder::~WeightCacheBuilder() {}

namespace {

bool WriteData(const int fd, const uint8_t* data, size_t size,
               const char* const file_path, const char* step_description) {}

}  // namespace

bool WeightCacheBuilder::Start(const char* path) {}

void WeightCacheBuilder::Reset() {}

void* WeightCacheBuilder::Reserve(size_t size) {}

BufferLocation WeightCacheBuilder::Append(PackIdentifier pack_id,
                                          const void* data, uint64_t size) {}

bool WeightCacheBuilder::ShouldFinalize() const {}

bool WeightCacheBuilder::Finalize() {}

MMapWeightCacheProvider::MMapWeightCacheProvider(
    MMapWeightCacheProvider&& other) {}

MMapWeightCacheProvider& MMapWeightCacheProvider::operator=(
    MMapWeightCacheProvider&& other) {}

void MMapWeightCacheProvider::SetFilePath(const char* path) {}

bool MMapWeightCacheProvider::LoadOrStartBuild(const char* path) {}

bool MMapWeightCacheProvider::StartBuild(const char* path) {}

bool MMapWeightCacheProvider::Load(const std::string& path) {}

bool MMapWeightCacheProvider::Load() {}

void MMapWeightCacheProvider::MapTensorIdentifiers(
    const TfLiteTensor* tensors, const size_t size,
    const std::unordered_map<size_t, size_t>& tensor_index_to_identifier) {}

size_t MMapWeightCacheProvider::LookUp(
    const xnn_weights_cache_look_up_key* cache_key) {}

void* MMapWeightCacheProvider::ReserveSpace(size_t size) {}

size_t MMapWeightCacheProvider::LookUpOrInsert(
    const xnn_weights_cache_look_up_key* cache_key, void* ptr, size_t size) {}

void* MMapWeightCacheProvider::OffsetToAddr(const size_t offset) {}

void MMapWeightCacheProvider::Release() {}

bool MMapWeightCacheProvider::Finalize() {}

bool MMapWeightCacheProvider::IsFinalized() const {}

size_t MMapWeightCacheProvider::look_up(
    void* context, const xnn_weights_cache_look_up_key* cache_key) {}

void* MMapWeightCacheProvider::reserve_space(void* context, size_t n) {}

size_t MMapWeightCacheProvider::look_up_or_insert(
    void* context, const xnn_weights_cache_look_up_key* cache_key, void* ptr,
    size_t size) {}

bool MMapWeightCacheProvider::is_finalized(void* context) {}

void* MMapWeightCacheProvider::offset_to_addr(void* context, size_t offset) {}

enum xnn_status MMapWeightCacheProvider::delete_cache(void* context) {}

PackIdentifier MMapWeightCacheProvider::BuildPackIdentifier(
    const xnn_weights_cache_look_up_key& key) {}

}  // namespace tflite::xnnpack