┌──────────────────────────────────────────────────────────────────────────────┐
│ Docudactyl HPC Engine │
│ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ Chapel Orchestrator (N locales) │ │
│ │ │ │
│ │ DocudactylHPC.chpl ──── main entry point, forall loop │ │
│ │ ├── Config.chpl ───── runtime config (--manifestPath, etc.) │ │
│ │ ├── ManifestLoader ── load 170M paths (plain or NDJSON) │ │
│ │ ├── NdjsonManifest ── enriched manifests (size/mtime/kind) │ │
│ │ ├── ContentType ───── detect format from extension │ │
│ │ ├── FaultHandler ──── retry loop, abort detection, timing │ │
│ │ ├── ProgressReporter background status on locale 0 │ │
│ │ ├── ShardedOutput ─── output/shard-{localeId}/ │ │
│ │ ├── ResultAggregator per-locale → global stats (.scm + .json) │ │
│ │ └── Checkpoint ────── resume after node failure │ │
│ │ │ │
│ │ forall idx in dynamic(docEntries.domain, chunkSize) { │ │
│ │ handle = ddac_init() │ │
│ │ ddac_set_ml_handle(handle, mlHandle) // attach ML engine │ │
│ │ ddac_set_gpu_ocr_handle(handle, gpuOcr) // attach GPU OCR │ │
│ │ conduit = ddac_conduit_process(path) // validate + SHA-256 │ │
│ │ result = safeParse(handle, path, out, fmt) // parse + stages │ │
│ │ accumulate(result) │ │
│ │ } │ │
│ └────────────────────────────┬───────────────────────────────────────────┘ │
│ │ C FFI (by value, flat struct) │
│ ┌────────────────────────────▼───────────────────────────────────────────┐ │
│ │ Zig FFI Dispatcher (zero overhead) │ │
│ │ ffi/zig/src/docudactyl_ffi.zig │ │
│ │ │ │
│ │ ddac_parse() ─── detect format ─── dispatch to C library: │ │
│ │ ├── .pdf ──────→ Poppler (poppler-glib) │ │
│ │ ├── .jpg/.png ─→ GPU OCR → Tesseract (fallback) │ │
│ │ ├── .mp3/.wav ─→ FFmpeg (libavformat) │ │
│ │ ├── .mp4/.mkv ─→ FFmpeg (libavformat + libavcodec) │ │
│ │ ├── .epub ─────→ libxml2 │ │
│ │ └── .shp/.tif ─→ GDAL │ │
│ │ │ │
│ │ Processing Stages (stages.zig + capnp.zig → .stages.capnp) │ │
│ │ ├── Phase 1: PREMIS, exact dedup, OCR confidence │ │
│ │ ├── Phase 2: language, readability, keywords, citations │ │
│ │ ├── Phase 3: Merkle proof (streaming, O(log n) memory) │ │
│ │ ├── Phase 4: TOC extract (PDF), subtitle extract (AV) │ │
│ │ ├── Phase 5: perceptual hash, near dedup, multi-lang OCR │ │
│ │ ├── Phase 6: coordinate normalize (geospatial) │ │
│ │ └── Phase 7: ML stages → ONNX Runtime (NER/Whisper/Layout/etc.) │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌───────────── Subsystem Modules (Zig, all dlopen, zero link deps) ──────┐ │
│ │ │ │
│ │ conduit.zig ───── magic-byte detection + file validation + SHA-256 │ │
│ │ gpu_ocr.zig ───── PaddleOCR GPU → Tesseract CUDA → CPU fallback │ │
│ │ ml_inference.zig ONNX Runtime (TensorRT > CUDA > OpenVINO > CPU) │ │
│ │ hw_crypto.zig ─── SHA-NI/AVX2/ARM-SHA2 detection + multi-buffer │ │
│ │ cache.zig ──────── LMDB L1 per-locale (zero-copy mmap, ACID) │ │
│ │ dragonfly.zig ─── Dragonfly L2 cross-locale (RESP2, 25x Redis) │ │
│ │ prefetch.zig ──── io_uring async I/O + posix_fadvise fallback │ │
│ │ capnp.zig ──────── Cap'n Proto single-segment message builder │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ Idris2 ABI Proofs (compile-time) │ │
│ │ src/abi/{Types,Layout,Foreign}.idr │ │
│ │ │ │
│ │ ContentKind ─── 7 variants, injective, decidably equal │ │
│ │ ParseStatus ─── 7 variants, retryable predicate │ │
│ │ ParseResult ─── 952-byte struct, LP64 layout proof │ │
│ │ OcrResult ───── 48-byte struct proof │ │
│ │ ConduitResult ─ 88-byte struct proof │ │
│ │ OcrStatus ───── gpu fallback predicate │ │
│ │ GpuBackend ──── 3 variants with conversions │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
│ │
│ ┌──────────────────────────────┐ ┌──────────────────────────────────────┐ │
│ │ OCaml (offline, not HPC) │ │ Ada TUI (standalone) │ │
│ │ docudactyl-scm │ │ docudactyl-tui │ │
│ │ JSON/text → S-expressions │ │ Terminal document inspector │ │
│ └──────────────────────────────┘ └──────────────────────────────────────┘ │
│ │
│ ┌────────────────────────────────────────────────────────────────────────┐ │
│ │ Julia (legacy — replaced by Chapel HPC pipeline) │ │
│ │ src/julia/ — extraction, analysis, parallel, CLI │ │
│ └────────────────────────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────────────────────┘
Data Flow (hot path):
manifest ──→ Chapel ──→ Conduit ──→ L1 Cache ──→ L2 Dragonfly ──→ Parse
(170M paths) (distribute) (validate) (LMDB hit?) (SHA-256 hit?) (Zig FFI)
│ │
└── skip invalid ──→ recordFailure() │
▼
output/shard-N/*.{scm,json,csv} ◄──── C parsers
output/shard-N/*.stages.capnp ◄──── stage results
output/run-report.scm
Cache Architecture:
┌─────────────────────┐ ┌──────────────────────────┐
│ L1: LMDB per-locale │ │ L2: Dragonfly (shared) │
│ Zero-copy mmap │ │ RESP2 protocol │
│ Key: path+mtime+sz │────→│ Key: SHA-256 hex │
│ 10GB / locale │ │ Cross-locale dedup │
└─────────────────────┘ └──────────────────────────┘
▲ ▲
│ Conduit pre-computes │ Conduit SHA-256 feeds
│ file_size (no stat) │ L2 lookup on cold runs
└────────────────────────────┘
Offline:
output/*.json ──→ OCaml docudactyl-scm ──→ *.scm (S-expressions)
docudactyl_ffi.zig (root — C-ABI exports, format dispatch)
├── stages.zig (20 processing stages + Cap'n Proto output)
├── capnp.zig (Cap'n Proto single-segment message builder)
├── cache.zig (LMDB L1 cache — zero-copy mmap)
├── dragonfly.zig (Dragonfly L2 cache — RESP2 protocol)
├── prefetch.zig (io_uring I/O prefetcher + fadvise fallback)
├── conduit.zig (magic-byte detection + SHA-256 pre-compute)
├── gpu_ocr.zig (batched GPU OCR — PaddleOCR/Tesseract CUDA)
├── hw_crypto.zig (SHA-NI/AVX2 detection + multi-buffer hash)
└── ml_inference.zig (ONNX Runtime — 5 ML stages via dlopen)