Valen is a high-performance, zero-dependency C++20 inference engine designed to execute compiled deep learning models trained within the NexusDL ecosystem. Valen is engineered with a strict "No-Graph, No-Autograd" execution paradigm, focusing entirely on bare-metal CPU throughput, flat contiguous memory layouts, and low-latency thread-pool data parallelism.
The fundamental tensor layout unit in Valen is the Nexus class. To eliminate the pointer-chasing latency common in traditional frameworks, Valen strips away multi-dimensional heap arrays and forces an all-contiguous data structure.
-
Shape (
std::vector<int>): A vector tracking structural dimensions. The first element represents thebatch_size, and the subsequent elements represent the shape matrix order ($M \times N$ ). -
Data (
std::vector<float>): A single flat 1D heap array storing 32-bit floating-point numbers using Row-Major Memory Alignment.
Nested Matrix POV (User Input): Contiguous Stride POV (Valen Memory):
┌───────────────┐ ┌───────┬───────┬───────┬───────┐
Row 0│ 5.5 2.4 │ │ 5.5 │ 2.4 │ 5.7 │ 2.6 │
Row 1│ 5.7 2.6 │ ───► Flatten ───►└───────┴───────┴───────┴───────┘
└───────────────┘ 0 1 2 3
▲ Row-Major Stride (Index = r * Width + c)
-
load_from_binary: Reads flat binary streams directly into pre-allocated memory allocations from exported model parameter blocks (.bin), matching files to buffers in a single operation. -
load_input: Accepts a nested user-facing multi-dimensional structure (std::vector<std::vector<float>>), infers shape configurations dynamically, purges initialization layout spaces, and packs elements sequentially to prevent memory fragmentation. -
get_index(int row, int col): An inline stride mapping utility function calculating element positions without lookups:
Every computational block in Valen inherits from a pure virtual interface class named BaseForward, enabling runtime polymorphism.
┌─────────────────┐
│ BaseForward │ ◄── Abstract Virtual Interface
└────────┬────────┘
│
┌────────────────┴────────────────┐
▼ ▼
┌─────────────────┐ ┌─────────────────┐
│ Linear : Layer │ │ ReLU : Activn │
└─────────────────┘ └─────────────────┘
The matrix multiplication engine evaluates incoming batch tensor weights through an adaptive execution scheduler gate designed to maximize throughput while minimizing operating system thread scheduling overhead:
-
Low-Throughput Gate (Batch Size
$\le 100$ ): Executes sequentially inside the primary caller thread to prevent thread administration overhead from degrading performance. -
High-Throughput Gate (Batch Size
$> 100$ ): Fragments input batches dynamically by row spans and hands off chunks concurrently to the background execution thread pool.
[ Manifest Directory ]
│
▼
┌──────────────┐ Creates ┌───────────────────────┐
│ CreateModel ├───────────────────► │ Sequential Model │
└──────────────┘ │ │
│ ┌───────────────────┐ │
[ Threadpool ] ────────────────────► │ │ std::vector of │ │
(Passed by Reference) │ │ unique_ptr<Base> │ │
│ └───────────────────┘ │
└───────────────────────┘
-
SequentialClass: Manages an execution timeline stored as a contiguous sequence of smart pointers (std::vector<std::unique_ptr<BaseForward>>). It exposes an internaladd()method for structure building and a publicForwardPass(const Nexus& input)pipeline execution method. -
CreateModelFactory: Encapsulates design patterns to insulate the end user from build steps. Callingcreate_model(dir_path, pool_ref)dynamically parses JSON topology manifests, tracks layer configuration mappings, imports weights, and registers the globalThreadpool.
Valen isolates its execution runtime threads inside a persistent, stateless tracking module to guarantee steady-state execution profiles.
Work Ingestion:
[Compute Kernel Slice] ──► Enqueue ──► [Task Queue] ──► Locked via std::mutex
│
Thread Orchestration: ▼
[Worker 1] ◄── [Worker 2] ◄── [Worker 3] ◄── Woken up via std::condition_variable
│
Thread Barrier Synchronization: ▼
[Caller Pipeline Main Thread] ◄─────── Blocked via C++20 std::latch
-
Persistent Resource Allocation: Worker threads (
std::thread) are spawned exactly once at boot time to match hardware processing limits, eliminating the kernel latency penalties of on-the-fly thread instantiation. -
Passive Waiting States: Workers sit inside an operating-system managed sleep state using a condition variable (
std::condition_variable) when the work loop queue is empty, freeing up CPU cycles for the rest of the engine. -
C++20 Hardware Barriers: Threads communicate state completions back to the caller pipeline main thread via a lightweight native synchronization gate (
std::latch). This completely avoids active memory spin-lock checking loop overhead (std::this_thread::yield()), reducing core processing strain by ~30%.