Apolynux AIFL: Lockless Flow-Based Inference Architecture
A P4-Inspired Programmable Execution Language and Lockless Flow Bucket Fabric for Independent LLM Pipelines
01 Abstract
Conventional multithreading divides work among threads, and conventional inference servers schedule requests across shared worker queues. Apolynux AIFL (Apolynux Inference Flow Language) proposes a stronger execution model: dividing LLM inference into independently progressing execution flows assigned to independent flow buckets, where threads and heterogeneous hardware serve those flows without global scheduling locks. Drawing architectural inspiration from P4's programmable match-action pipelines and OpenFlow's control/data-plane separation — while adding persistent flow-local state and asynchronous DAG dependency tracking for autoregressive LLMs — AIFL targets maximum resource utilisation on minimal hardware for portable and modular AI.
02 Problem Statement
Network packets are mostly independent units of processing, whereas LLM inference combines parallelisable operations (multi-expert MoE routing, batched prefill) with strict sequential dependencies (autoregressive token decode, persistent KV-cache state). Simply bolting a lockless global queue onto an existing model runner still forces concurrent requests to contend over shared scheduling state. Running capable LLMs on the lowest possible computing resources requires an execution fabric where independent flows progress locally without global coordination.
03 Background & Foundations
P4 (Programming Protocol-Independent Packet Processors) and the Portable Switch Architecture (PSA) established a durable systems precedent: separating a declarative match-action data-plane language from both the control plane and underlying hardware targets. AIFL adapts this control architecture — not to make LLM math resemble packet forwarding, but to make inference execution control behave like a programmable, lockless packet-processing data plane.
04 Existing Architectural Limitations
- Global inference queues and shared ready-lists cause lock and cache-line contention under high concurrency.
- Conflating logical execution domains with OS/SMT threads leads to cache thrashing on memory-bandwidth-bound workloads.
- Tightly coupling request scheduling to model math prevents clean hardware-independent dispatch across CPUs, NPUs, and GPUs.
- Sharing mutable inference state across unrelated workers makes lock-free concurrency fragile and error-prone.
05 Proposed Apolynx Architecture
AIFL restructures the inference runtime around five core constructs (FLOW, BUCKET, TABLE, ACTION, PIPELINE) and five cooperating subsystems: AIFL Compiler, Flow Control Plane, Lockless Flow Data Plane, Parallel Dependency Engine, and Heterogeneous Execution Fabric.
Independent Flow Buckets
Logical execution domains (e.g., 64 power-of-two buckets via hash(flow_id) & (N - 1)) each owning private ready/wait queues, flow-local state, dependency counters, and completion rings.
Flow-Local State vs. Shared Weights
Non-negotiable ownership split: mutable flow state, KV metadata, and dependency counters stay strictly private to the flow, while immutable model weights and versioned policy snapshots are safely shared read-only.
Owner-Computes Lockless Fabric
Only a bucket's owner worker modifies its mutable scheduling state; external producers submit via bounded MPSC ingress rings, while fast paths use SPSC rings.
Asynchronous DAG & 7-Stage Pipeline
Supports INGRESS -> CLASSIFY -> PREPARE -> PREFILL -> DECODE -> POSTPROCESS -> EGRESS plus parallel MoE child-flow fork/join via atomic pending_children counters.
06 Technical Design
Crucially, a flow bucket is NOT synonymous with a CPU thread. AIFL enforces a strict six-level hierarchy: Physical CPU Core -> Optional SMT Logical Processor -> Worker -> Flow Bucket -> Flow -> Operation. Because two SMT siblings share physical execution units and memory bandwidth, SMT is treated as an optional benchmarked configuration rather than assumed to double throughput. For Colibri integration, AIFL sits cleanly between the Apolynux API and a Colibri Adapter — orchestrating flow buckets around existing model execution boundaries before progressively controlling finer-grained operations.
| NPU / P4 Concept | Apolynux AIFL Equivalent | LLM-Specific Extension |
|---|---|---|
| Packet / Header | Inference Operation / Descriptor | Carries model_id, layer_id, tensor shape & precision |
| Flow ID & Metadata | Inference Flow ID & Flow Context | Persistent mutable flow-local state & KV ownership |
| Packet Queue | Independent Flow Bucket | Power-of-two logical domain; owner-computes scheduling |
| Flow Table & Match-Action | Execution Policy Table & Router | Versioned snapshots; selects CPU/NPU/GPU/Prefetch |
| Processing Pipeline | 7-Stage Flow Pipeline + Async DAG | Fork/join parallel MoE children preserving exact math |
| Packet Ordering | Model Dependency Ordering | Atomic dependency counters for autoregressive steps |
07 Execution Workflow
- 1. INGRESS & CLASSIFY: Request enters an MPSC ingress ring, receives a flow_id, and maps deterministically to bucket_id = hash(flow_id) & (bucket_count - 1).
- 2. PREPARE & PREFILL: Bucket owner worker establishes private aifl_flow_t state, binds NUMA/KV affinity, and executes tokenisation and prompt prefill.
- 3. MATCH-ACTION ROUTING: TABLE EXECUTION_ROUTING evaluates operation_type, tensor_size, memory_residency, and hardware availability against immutable policy snapshots.
- 4. PARALLEL DAG FORK/JOIN: For MoE layers, independent child operations (e.g., Expert 17, 27, 42) run concurrently and decrement atomic pending_children until the last child triggers weighted aggregation.
- 5. DECODE, POSTPROCESS & EGRESS: Autoregressive tokens stream out through bounded backpressure queues, releasing private buffers cleanly on completion or cancellation.
08 Algorithms, Interfaces & Specification
/* 1. AIFL 0.1 Five-Construct Declarative Proposal (Not yet a compiled runtime) */
ARCHITECTURE APOLYNX {
MODE LOCKLESS; FLOW_BUCKETS 64;
WORKERS { CPU_PHYSICAL_CORES AUTO; SMT ENABLE; }
MEMORY { LOCAL_RAM ENABLE; HUGE_PAGES ENABLE; MMAP ENABLE; ASYNC_IO ENABLE; }
EXECUTORS { CPU ENABLE; NPU OPTIONAL; GPU OPTIONAL; }
}
BUCKET INFERENCE_BUCKETS {
COUNT 64; DISTRIBUTION HASH(FLOW_ID); QUEUE LOCKLESS;
STATE LOCAL; WORKER AFFINITY CORE_LOCAL; BACKPRESSURE ENABLED;
}
TABLE EXECUTION_ROUTING {
KEY { OPERATION_TYPE; TENSOR_SIZE; MEMORY_RESIDENCY; HARDWARE_AVAILABILITY; }
ACTIONS { EXECUTE_CPU; EXECUTE_NPU; EXECUTE_GPU; PREFETCH; DEFER; }
}
PIPELINE QWEN_INFERENCE {
STAGE INGRESS; STAGE CLASSIFY; STAGE PREPARE; STAGE PREFILL;
STAGE DECODE; STAGE POSTPROCESS; STAGE EGRESS; ON_ERROR RETRY_OR_FAIL;
}
/* 2. Private Flow-Local State & Atomic Parent Continuation (C11) */
typedef struct {
uint64_t flow_id; uint32_t bucket_id; uint32_t model_id;
uint32_t current_stage; uint32_t execution_state;
void *operation_queue; void *dependency_graph;
void *kv_cache_context; void *memory_context;
uint64_t tokens_processed; uint32_t priority;
} aifl_flow_t;
/* Non-blocking child completion triggers parent resume without thread blocking */
if (atomic_fetch_sub_explicit(&parent->pending_children, 1, memory_order_acq_rel) == 1) {
submit_ready_operation(parent);
}
09 Implementation Considerations
- Solve five architectural risks from day one: (1) Flow starvation -> fair priority scheduling; (2) Queue overflow -> bounded queues & backpressure; (3) Flow migration -> safe checkpoint ownership transfer only (never while KV/buffers mutate); (4) Shared-state contention -> owner-computes & immutable snapshots; (5) Dependency deadlocks -> static DAG validation & exactly-once completion.
- Enforce strict resource quotas and tenant isolation: never permit an untrusted flow to allocate unbounded buffers or spawn unlimited child operations.
- Source tree isolation under apolynux/aifl/ (compiler/, control/, dataplane/, runtime/, queues/, memory/, backends/colibri/, benchmarks/).
10 Performance Evaluation Methodology
Recommended First Proof — Experiment A (64 Independent Flow Buckets): benchmark synthetic workloads and identical-prompt Qwen/Colibri inference across six configurations: (A) Conventional shared queue, (B) Lockless global queue, (C) 16 independent buckets, (D) 32 buckets, (E) 64 buckets, and (F) 64 buckets with work stealing. Measure ops/sec, p50/p95/p99 latency, cycles/op, cache misses, context switches, memory bandwidth, and physical-core-only vs. SMT-enabled scaling.
11 Limitations & Scope Boundaries
- Architecture Design stage (AIFL 0.1): conceptual language specification and runtime blueprint, not yet a compiled production toolchain.
- Optimal bucket count (16 vs 32 vs 64) depends on physical host cores, L3 topology, and workload concurrency — must be empirically determined via Experiment A.
- Flow affinity must act as a preference rather than a hard wall so overloaded buckets can shed work safely.
12 Open Research Questions & Challenges
- What exact bucket-to-physical-core ratio minimises L3 cache-line bouncing on commodity 8–32 core CPUs?
- How cleanly can safe checkpoint flow migration rebalance long-context decode flows without stalling KV-cache access?
- At what granularity does decomposing Colibri internals into AIFL child ops outweigh descriptor dispatch overhead?
13 Future Directions
- Phase 1 empirical execution of Experiment A (A–F bucket topology comparison) with Colibri adapter.
- Formal AIFL 0.1 compiler (lexer.c, parser.c, semantic.c, ir.c, codegen.c) targeting CPU, NPU, GPU, and RDMA backends.
- Portable, low-resource Modular Domain Expert AI appliances powered by compiled AIFL execution profiles.
14 Primary Technical References
- P4-16 Language Specification (v1.2.3) — The P4 Language Consortium — Programmable match-action processing, tables, actions, and target independence.
- P4 Portable Switch Architecture (PSA) — p4lang — Programmable processing blocks, metadata ownership, and pipeline architecture.
- Bosshart et al. (P4-14 / ACM SIGCOMM CCR 2014) — P4: Programming Protocol-Independent Packet Processors — Foundational parser and match-action pipeline model.
- Lock-Free Queues, RCU & Work-Stealing Foundations — ISO/IEC 9899 C11 Atomics, Linux RCU, Chase-Lev work-stealing deques, and NUMA-aware task-graph runtimes.
Research Status: Architecture Design • Scientific Integrity Disclosure
This research programme explicitly separates established computer science principles, existing open-source technologies, Apolynux architectural proposals, experimental implementations, and independently validated results. Apolynux does not claim to have invented OpenFlow, lock-free algorithms, RDMA, hugepages, or Mixture-of-Experts. Our research contribution is the proposed integration of these disciplines into a unified programmable inference architecture, evaluated strictly through repeatable empirical measurement.