111 releases (11 stable)

new 2.0.0 May 15, 2024
1.0.20-beta Dec 27, 2022
1.0.11 Feb 7, 2024
1.0.10 Oct 16, 2023
0.1.23 Mar 27, 2022

#18 in Programming languages

Download history 6/week @ 2024-01-29 29/week @ 2024-02-05 39/week @ 2024-02-12 151/week @ 2024-02-19 68/week @ 2024-02-26 31/week @ 2024-03-04 95/week @ 2024-03-11 32/week @ 2024-03-18 47/week @ 2024-03-25 94/week @ 2024-04-01 26/week @ 2024-04-08 29/week @ 2024-04-15 33/week @ 2024-04-22 39/week @ 2024-04-29 37/week @ 2024-05-06

144 downloads per month
Used in 10 crates (4 directly)

MIT license

425KB
4.5K SLoC

Rust 1.5K SLoC // 0.2% comments CUDA 1.5K SLoC // 0.3% comments C 1.5K SLoC // 0.2% comments

Higher-order Virtual Machine 2 (HVM2)

Higher-order Virtual Machine 2 (HVM2) is a massively parallel Interaction Combinator evaluator.

By compiling programs from high-level languages (such as Python and Haskell) to HVM, one can run these languages directly on massively parallel hardware, like GPUs, with near-ideal speedup.

HVM2 is the successor to HVM1, a 2022 prototype of this concept. Compared to its predecessor, HVM2 is simpler, faster and, most importantly, more correct. HOC provides long-term support to all features listed on its PAPER.

This repository provides a low-level IR language for specifyig the HVM2 nets, and a compiler from that language to C and CUDA. It is not meant for direct human usage. If you're looking for a high-level language to interface with HVM2, check Bend instead.

Usage

Install HVM2:

cargo +nightly install hvm

There are multiple ways to run an HVM program:

hvm run    <file.hvm> # interpret via Rust
hvm run-c  <file.hvm> # interpret via C
hvm run-cu <file.hvm> # interpret via CUDA
hvm gen-c  <file.hvm> # compile to standalone C
hvm gen-cu <file.hvm> # compile to standalone CUDA

All modes produce the same output. The compiled modes require you to compile the generated file (with gcc file.c -o file, for example), but are faster to run. The CUDA versions have much higher peak performance, but are less stable. As a rule of thumb, gen-c should be used in production.

Language

HVM is a low-level compile target for high-level languages. It provides a raw syntax for wiring interaction nets. For example:

@main = a
  & @sum ~ (28 (0 a))

@sum = (?(((a a) @sum__C0) b) b)

@sum__C0 = ({c a} ({$([*2] $([+1] d)) $([*2] $([+0] b))} f))
  &! @sum ~ (a (b $(:[+] $(e f))))
  &! @sum ~ (c (d e))

The file above implements a recursive sum. If that looks unreadable to you - don't worry, it isn't meant to. Bend is the human-readable language, and should be used both by end users, and languages aiming to target the HVM. If you're are looking to learn more about the core syntax and tech, though, please do check the PAPER.

Dependencies

~1–1.3MB
~21K SLoC