# HVM — Massively Parallel Runtime for Functional Programs > HVM (Higher-order Virtual Machine) is a parallel runtime that executes functional programs across all available CPU and GPU cores automatically, using a novel interaction-net reduction model. ## Install Save in your project root: # HVM — Massively Parallel Runtime for Functional Programs ## Quick Use ```bash # Install via Cargo cargo install hvm # Run a simple program echo ' @main = (* 6 7) ' > hello.hvm hvm run hello.hvm # Or compile to parallel C code hvm compile hello.hvm gcc -O2 -o hello hello.c -lpthread ./hello ``` ## Introduction HVM (Higher-order Virtual Machine) is a runtime and compiler for functional programming that automatically parallelizes programs across CPU cores and GPUs. Built by HigherOrderCO, HVM uses interaction nets — a computation model from the theory of linear logic — that enables safe parallel reduction without locks, mutexes, or manual concurrency annotations. Programs written in the Bend language compile to HVM for execution. ## What HVM Does - Executes functional programs in parallel across all available CPU cores automatically - Compiles programs to C or CUDA code for native and GPU execution - Reduces interaction nets using a lock-free, garbage-collection-free algorithm - Supports higher-order functions, pattern matching, and algebraic data types - Serves as the backend for the Bend programming language ## Architecture Overview HVM is based on interaction combinators, a model of computation where programs are represented as graphs of interacting nodes. Reduction rules are local — each node pair can be reduced independently — which makes the model inherently parallel. The runtime dispatches interaction-net reductions across threads without synchronization. HVM compiles to C with pthreads for CPU parallelism and to CUDA for GPU execution. The absence of a garbage collector is fundamental to the design: interaction nets naturally deallocate memory as nodes are consumed during reduction. ## Self-Hosting & Configuration - Install the HVM binary via Cargo (Rust toolchain required) - Write programs directly in HVM's core syntax or use the Bend language as a frontend - Compile to standalone C executables for deployment without the Rust toolchain - Control thread count with the `-t` flag for CPU execution - Use `hvm compile --cuda` to target GPU execution via CUDA ## Key Features - Automatic parallelism with no manual thread management or async annotations - Lock-free and garbage-collection-free design for predictable performance - Compiles to standalone C or CUDA code for deployment - Optimal beta-reduction via interaction nets based on Lamping's algorithm - Supports the Bend language for a Python-like high-level programming experience ## Comparison with Similar Tools - **GHC (Haskell)** — mature compiler with sophisticated optimizations but limited automatic parallelism; HVM parallelizes by default through its computation model - **Erlang BEAM** — process-level concurrency with message passing; HVM provides instruction-level parallelism without explicit process management - **Futhark** — functional GPU language for array computations; HVM targets general-purpose functional programs, not just numerical workloads - **Chapel** — parallel programming language; HVM achieves parallelism through its computation model rather than language-level parallel constructs ## FAQ **Q: Do I need to write parallel code to get parallelism from HVM?** A: No. HVM automatically parallelizes any functional program. The interaction-net model is inherently parallel without annotations. **Q: What is Bend and how does it relate to HVM?** A: Bend is a high-level programming language with Python-like syntax that compiles to HVM. It is the recommended way to write programs for the HVM runtime. **Q: Does HVM support GPU execution?** A: Yes. HVM can compile programs to CUDA for execution on NVIDIA GPUs. **Q: Is HVM production-ready?** A: HVM is under active development and is suitable for experimentation and research. Production readiness depends on the specific workload. ## Sources - https://github.com/HigherOrderCO/HVM - https://github.com/HigherOrderCO/Bend --- Source: https://tokrepo.com/en/workflows/asset-a1e05da1 Author: AI Open Source