131 releases (31 stable)

2.0.22 Aug 9, 2024
2.0.21 Jul 3, 2024
2.0.19 Jun 4, 2024
1.0.20-beta Dec 27, 2022
0.1.23 Mar 27, 2022

#27 in Programming languages

Download history 330/week @ 2024-08-11 202/week @ 2024-08-18 164/week @ 2024-08-25 169/week @ 2024-09-01 155/week @ 2024-09-08 165/week @ 2024-09-15 288/week @ 2024-09-22 131/week @ 2024-09-29 143/week @ 2024-10-06 147/week @ 2024-10-13 92/week @ 2024-10-20 84/week @ 2024-10-27 113/week @ 2024-11-03 108/week @ 2024-11-10 79/week @ 2024-11-17 97/week @ 2024-11-24

411 downloads per month
Used in 13 crates (5 directly)

Apache-2.0

635KB
6K SLoC

CUDA 2.5K SLoC // 0.2% comments Rust 2K SLoC // 0.2% comments C 1.5K SLoC // 0.2% comments Typst 34 SLoC

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 for all features listed on its PAPER.

This repository provides a low-level IR language for specifying 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

DISCLAIMER: Windows is currently not supported, please use WSL for now as a workaround.

First install the dependencies:

  • If you want to use the C runtime, install a C-11 compatible compiler like GCC or Clang.
  • If you want to use the CUDA runtime, install CUDA and nvcc (the CUDA compiler).
    • HVM requires CUDA 12.x and currently only works on Nvidia GPUs.

Install HVM2:

cargo 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 by languages aiming to target the HVM. If you're looking to learn more about the core syntax and tech, though, please check the PAPER.

Dependencies

~1–1.4MB
~24K SLoC