Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NeuroCache

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).

Build & Run

mkdir build && cd build
cmake ..
cmake --build .
./neurocache_demo

Notes:

  • The FixedAllocator preallocates a pool of entries to avoid dynamic allocation at runtime. Increase the capacity in the AdaptiveCache constructor 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_MICRO in CMake.

To build NeuroCache with TensorFlow Lite Micro support

To compile NeuroCache with TFLite Micro enabled, update your CMake configuration and include/link TensorFlow Lite Micro sources.

Step 1: Fetch TensorFlow Lite Micro

Clone TensorFlow and include the TFLite Micro subdirectory. For example:

git clone https://github.com/tensorflow/tflite-micro.git external/tflite-micro

Step 2: Update CMakeLists.txt

cmake_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)

Step 3: Provide a .tflite model

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);

Step 4: Run demo

mkdir build && cd build
cmake -DUSE_TFLITE_MICRO=ON ..
cmake --build .
./neurocache_demo

The 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.

About

Adaptive Memory-Aware Caching

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages