GithubHelp home page GithubHelp logo

khatharsis42 / hvm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from higherorderco/hvm

0.0 0.0 0.0 2.45 MB

A massively parallel, optimal functional runtime in Rust

Home Page: https://higherorderco.com

License: Apache License 2.0

C 32.87% Rust 28.78% Cuda 38.02% Typst 0.32%

hvm's Introduction

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. The environment variable HVM_NUM_THREADS sets the number of threads use when using run-c

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.

hvm's People

Contributors

victortaelin avatar enricozb avatar kings177 avatar edusporto avatar tjjfvi avatar developedby avatar eduhenke avatar felipegalind0 avatar sukrucildirr avatar khatharsis42 avatar renxida avatar schrodingerzhu avatar reinaldorauch avatar eltociear avatar ethe avatar szabgab avatar alpinevm avatar brurucy avatar miolini avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.