← index
open source / r&d · 2025 – ongoing · active

Tiny R Labs

Building tiny, zero-dependency, pure-C libraries for resource-constrained environments, embedded systems, and hardware-accelerated machine learning.

CC11EmbeddedSystemsZero-DependencyMachine LearningHardware Acceleration

About

Tiny R Labs is an open-source organization focused on building tiny, zero-dependency, pure-C libraries for resource-constrained environments. Every library is self-contained and designed to work where pulling in a framework isn’t an option — from microcontrollers to hardware-accelerated machine learning on edge devices.

Minimalism isn’t a constraint — it’s a design philosophy.

Design Principles

  • API surface minimalism — Every function, type, and macro is justified by a concrete use case. Features that can live outside the library (built on top of its public API) do.
  • Compile-time configuration — #ifndef guards with sensible defaults let consumers strip features, select allocators, or tune buffer sizes without runtime overhead.
  • Static allocation where possible — Heap-free operation is a first-class goal. Libraries default to fixed-size pools, bump allocators, or stack-local buffers. When dynamic allocation is unavoidable, the allocator is injected via a callback at init time.
  • Error handling patterns — Return codes over errno. Every fallible function returns an enum TINY_<lib>_OK / TINY_<lib>_ERR_* value; output is written through out-parameters. This keeps error paths explicit and usable on bare metal.
  • Hardware-agnostic acceleration — Libraries provide a backend contract for hardware acceleration (e.g., K230 KPU, ARM CMSIS-NN) without tying the core logic to any specific platform.

Build System

Libraries follow a dual-distribution model:

  • Single-header pattern — The default for quick integration. A combined .h (or .h + .c pair) drops into any C11 project with zero setup — inspired by the stb-style, each header documents its preprocessor knobs at the top.
  • Compiled library — Each library provides a hand-written Makefile with all, test, clean, and install targets, outputting static (.a) and shared (.so) builds under build/.
  • Test harness — Every library ships test_<lib>.c compiled by make test using inline assert()-style macros — no external framework. Tests run on host and, where possible, on QEMU for a bare-metal target (e.g., ARM Cortex-M4).

CI (GitHub Actions across GCC and Clang on x86_64 + aarch64) measures coverage with gcov/lcov, targeting >90% line coverage.

Libraries

tinycml

A high-performance machine learning library in pure C11 with zero external dependencies, designed for resource-constrained environments and hardware acceleration. Supports neural networks, preprocessing, model selection, and evaluation — all under 12K LOC.

Key Features

  • Backend Contract for Hardware Acceleration

    • Lifecycle State Machine: INITIALIZED → MODEL_LOADED → READY → RELEASED transitions with explicit error handling
    • Handle-based API: Opaque tinycml_backend_t and tinycml_model_t handles for safe resource management
    • Tensor Descriptor: tinycml_tensor_t with dtype (U8/I8/F32), shape, layout (NCHW/NHWC), and quantization (scale/zero_point)
    • Capability Flags: TINYCML_CAP_DTYPE_*, TINYCML_CAP_LAYOUT_* for backend compatibility checks
    • ABI Hardening: api_version and struct_size fields to prevent runtime mismatches
    • Vendor Config: Opaque backend-specific configuration (e.g., K230 nncase settings)
  • Deterministic Execution

    • No garbage collection, no JIT, no interpreter — direct native machine instructions
    • Monotonic microsecond timestamps for performance measurement
    • Cache-coherent data structures (row-major storage for spatial locality)
  • Mock Backend for Testing

    • Reference implementation (mock_k230.c) for host-based testing
    • Mock Competition Server: Deterministic simulation clock for mission scenarios (takeoff → cruise → landing → QR detection)
    • Orchestrator: Task start/stop, telemetry collection, and result validation
  • Configuration Pipeline

    • YAML → C Header: tools/yaml2c.py converts competition rules to onboard/config/ta_competition_config.h at compile time
    • Commit-Enforced Headers: CI verifies that generated headers match committed versions (diff -q)
  • Platform-Independent Layer

    • aero_types.h: Competition constants, telemetry structures, mission states
    • aero_time.h: Monotonic time for simulation and real hardware
    • aero_protocol.h: Flight/K230/Linux-agnostic communication protocol

Supported Algorithms

| Category | Algorithms | |----------|------------| | Supervised Learning | Linear Regression, Logistic Regression, k-Nearest Neighbors, Naive Bayes, Decision Tree, Random Forest, Support Vector Machine (linear/RBF), Softmax Regression, Ridge Regression, Lasso Regression, Neural Network (feedforward, backpropagation) | | Unsupervised Learning | k-Means Clustering, DBSCAN, Principal Component Analysis | | Feature Engineering | SelectKBest, VarianceThreshold, StandardScaler, MinMaxScaler, OneHotEncoder, PolynomialFeatures | | Model Selection | Cross-Validation (K-fold, stratified), GridSearchCV, Pipeline | | Evaluation Metrics | MSE, RMSE, MAE, R² (regression); Accuracy, Precision, Recall, F1, Confusion Matrix (classification); Inertia, Silhouette (clustering) |

Memory Management

Two modes selectable via TINY_CML_ALLOC at compile time:

  • Static Allocation: Fixed pool with bump allocator, zero malloc/free, ideal for microcontrollers
  • Dynamic Allocation: Lightweight arena over the heap (configurable max tensor dimension: TINY_CML_MAX_DIMS, default 4)

Code Size Breakdown (x86_64 GCC -Os)

| Component | LOC | |-----------|----| | Tensor ops | 3.8K | | Activations | 1.2K | | Layers | 2.4K | | Loss functions | 600 | | Training loop | 1.8K | | Preprocessing | 800 | | Utilities | 1.4K | | Backend Contract | 1.2K | | Mock Backend | 800 |

Integration with Tiny-Aero

Tiny-Aero (TEKNOFEST 2026 Savaşan İHA) uses tinycml as its machine learning backend for real-time aerial target detection, temporal tracking, lock verification, and QR-based Kamikaze missions. Key integration points:

  • Backend Contract: Tiny-Aero implements the tinycml_backend.h contract with a mock backend for host testing and a future K230 KPU backend for real hardware
  • Mock Competition Server: Simulates mission scenarios with a deterministic clock for testing
  • Configuration Pipeline: YAML competition rules are converted to C headers at compile time
  • Lifecycle Management: Explicit state transitions (INITIALIZED → MODEL_LOADED → READY → RELEASED) ensure safe resource handling

View tinycml on GitHub → View Tiny-Aero on GitHub →

More coming

The lab is actively expanding. Planned libraries:

  • tinyvec — Vector and embedding ops for small-scale similarity search. Target: <3K LOC, cosine/Euclidean distance, LSH, flat index for <10K vectors.
  • tinyparse — Minimal CSV/JSON parser for embedded ingestion. Target: <2K LOC, single-pass tokeniser, no dynamic allocation.
  • tinycrypto — Bare-minimum cryptographic primitives (SHA-256, HMAC, base64, constant-time compare). Target: <4K LOC, no libcrypto, AES as compile-time backend.
  • tinysched — Cooperative round-robin scheduler for embedded systems without an RTOS. Target: <1K LOC, setjmp/longjmp context-switch.
  • tinybuf — Ring buffers, FIFOs, and pooled allocators (no malloc) with SPSC lock-free annotations. Target: <2K LOC.

Each follows the same design principles, build conventions, and test harness as tinycml. Releases are SemVer with a single-header archive per tag.

Philosophy

  • Zero dependencies — No stdlib beyond what C11 guarantees. No libm, no pthreads unless explicitly opted in.
  • Testable — Every library ships with a test suite that runs without a framework.
  • Auditable — Small codebase, clear ownership, no magic numbers.
  • Portable — Standard C11, no platform-specific assumptions.
  • Hardware-accelerated — Backend contracts enable acceleration without tying the core logic to specific hardware.