Beaver Project Introduction
Overview of Beaver 🦫
Beaver is an innovative project that blends the power of LLVM/MLIR with the versatility of the Elixir programming language. It leverages the strengths of both ecosystems to provide a flexible, efficient, and modern approach to compiler design and development.
Motivation Behind Beaver
Traditionally, building compilers using MLIR involves working with languages and tools like C/C++, TableGen, CMake, and Python. While these are reliable tools, there's potential in exploring alternative methods. Enter Elixir—a language that naturally fits as an MLIR front end. Elixir provides a strong typing system, pattern matching, and a pipe operator, allowing developers to define MLIR patterns and pipelines in a unified manner. This project facilitates rapid prototyping and exploration of new ideas within the MLIR space, all while maintaining robust functionality.
Beaver's Core Features
Beaver takes advantage of Elixir's composable modularity and meta-programming features, providing a user-friendly interface for MLIR development. It empowers developers to quickly edit, build, test, and debug, all within seconds. Moreover, Beaver aims to compile Elixir to native/wasm/GPU code with the assistance of MLIR, further enhancing its utility. Additionally, the project seeks to resurrect symbolic AI in a hardware-accelerated environment, drawing from Erlang/Elixir's Prolog roots.
Unique Appeal: Why Beaver?
The name "Beaver" is symbolic. Much like beavers boost biodiversity and create habitats for various species, the Beaver project aims to facilitate the development of other compilers and applications. Moreover, in the Elixir community, naming projects after animals (often endangered species) is common, raising awareness about ecological conservation.
Quick Introduction to Key Concepts
-
MLIR for Erlang/Elixir Enthusiasts: Doing for compilers what XML does for data interchange, MLIR allows for the definition of dialects that provide real-world semantics, similar to HTTP standards.
-
Elixir for LLVM/MLIR Enthusiasts: Elixir brings Erlang's fault-tolerance and concurrency capabilities. As a Lisp derivative, it features hygienic macros and dynamic data typing, enabling flexible module systems that adapt easily to runtime needs.
Getting Started and Installation
To begin experimenting with Beaver, one can start with the tutorial "Your first compiler with Beaver!". To install Beaver, add it to the dependencies in your Elixir project:
def deps do
[
{:beaver, "~> 0.3.9"}
]
end
For formatting, add:
import_deps: [:beaver],
Notable Projects Built on Beaver
- Charm: Compiles a subset of Elixir to native targets.
- MLIR Accelerated Nx: Serves as a backend for the Nx project, enhancing its capabilities with MLIR acceleration.
Erlang Apps within Beaver
The Beaver project is structured with a focus on modularity, incorporating multiple Erlang applications under its umbrella:
:beaver
: Combines Elixir and C/C++ for high-level functionalities like IR generation.:kinda
: A hybrid of Elixir and Zig, generates NIFs from MLIR C headers.
Design Principles
Beaver places emphasis on transformation over builder patterns for IR construction, allowing compiler code to mirror generated code more closely. It stresses maintaining a high level of similarity between Beaver's DSL and MLIR's SSA, with tools to convert MLIR text formats into readable Beaver DSL ASTs.
High-Level APIs in Elixir/Erlang Idiomatic Styles
Whenever feasible, C APIs are abstracted into Elixir structures to support common protocols, enabling seamless use of Elixir's rich standard libraries and packages.
Beaver as a Compiler Ecosystem
While not just bindings to LLVM/MLIR or solely a compiler, Beaver aspires to evolve into a sub-ecosystem within the Erlang/Elixir community, much like other large projects such as Phoenix and Nerves.
Development Environment
To set up a development environment for Beaver, one needs to install Elixir, Zig, and LLVM/MLIR. Detailed instructions are provided to assist with setting up these tools efficiently on different operating systems.
Conclusion
The Beaver project represents a fusion of established technologies with emerging platforms, aiming to redefine the potential of compiler design. With its reliance on Elixir and MLIR, it presents a novel approach for developers, encouraging exploration and innovation within the realm of compilation and machine language processing.