NeuroCache is an adaptive, memory-aware C++ cache library for edge devices with: telemetry/metrics, async prefetching, fixed-memory allocator, and a learned eviction policy abstraction (supports Q-learning and TFLite Micro).
mkdir build && cd build
cmake ..
cmake --build .
./neurocache_demoNotes:
- The FixedAllocator preallocates a pool of entries to avoid dynamic allocation at runtime. Increase the capacity in the
AdaptiveCacheconstructor if you expect more items. - Prefetcher executes loader callbacks in the background; be mindful of stack usage and thread safety in your loader.
- TFLite Micro integration requires you to provide TFLite Micro sources and define
USE_TFLITE_MICROin CMake.
To compile NeuroCache with TFLite Micro enabled, update your CMake configuration and include/link TensorFlow Lite Micro sources.
Clone TensorFlow and include the TFLite Micro subdirectory. For example:
git clone https://github.com/tensorflow/tflite-micro.git external/tflite-microcmake_minimum_required(VERSION 3.10)
project(NeuroCache VERSION 0.5 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
option(USE_TFLITE_MICRO "Enable TensorFlow Lite Micro inference engine" ON)
add_executable(neurocache_demo examples/main.cpp)
target_include_directories(neurocache_demo PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
if(USE_TFLITE_MICRO)
add_definitions(-DUSE_TFLITE_MICRO)
add_subdirectory(external/tflite-micro ${CMAKE_BINARY_DIR}/tflm_build)
target_include_directories(neurocache_demo PUBLIC
external/tflite-micro
external/tflite-micro/tensorflow/lite/micro)
target_link_libraries(neurocache_demo tflite_micro)
endif()
enable_testing()
add_executable(test_basic tests/test_basic.cpp)
target_include_directories(test_basic PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_test(NAME basic_test COMMAND test_basic)Place a lightweight .tflite model file in the project root (e.g., models/cache_policy_model.tflite). This model should output a single float score given input features [age, accessCount, size].
You can include it as binary data in your example:
#include "models/cache_policy_model.tflite.h"
static const unsigned char* modelData = g_cache_policy_model_tflite;
size_t modelSize = g_cache_policy_model_tflite_len;
auto model = std::make_unique<TFLiteMicroModel>(modelData, modelSize);mkdir build && cd build
cmake -DUSE_TFLITE_MICRO=ON ..
cmake --build .
./neurocache_demoThe project now compiles with TensorFlow Lite Micro support enabled. You can switch between Q-learning and TFLite Micro inference by setting or unsetting the USE_TFLITE_MICRO flag in CMake.