#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>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include "xnnpack.h"
#include "flatbuffers/flatbuffer_builder.h"
#include "flatbuffers/verifier.h"
#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 = …;
size_t Align(size_t offset, const size_t alignment) { … }
template <class F>
class ScopeGuard { … };
template <class F>
ScopeGuard(F&&) -> ScopeGuard<F>;
[[nodiscard]]
bool FileExists(const char* path) { … }
}
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) { … }
}
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) { … }
}