• Stars
    star
    793
  • Rank 57,419 (Top 2 %)
  • Language
    C++
  • Created over 1 year ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MLIR For Beginners tutorial

MLIR For Beginners

This is the code repository for a series of articles on the MLIR framework for building compilers.

Articles

  1. Build System (Getting Started)
  2. Running and Testing a Lowering
  3. Writing Our First Pass
  4. Using Tablegen for Passes
  5. Defining a New Dialect
  6. Using Traits
  7. Folders and Constant Propagation
  8. Verifiers
  9. Canonicalizers and Declarative Rewrite Patterns
  10. Dialect Conversion
  11. Lowering through LLVM
  12. A Global Optimization and Dataflow Analysis

Bazel build

Bazel is one of two supported build systems for this tutorial. The other is CMake. If you're unfamiliar with Bazel, you can read the tutorials at https://bazel.build/start. Familiarity with Bazel is not required to build or test, but it is required to follow the articles in the tutorial series and explained in the first article, Build System (Getting Started). The CMake build is maintained, but was added at article 10 (Dialect Conversion) and will not be explained in the articles.

Prerequisites

Install Bazelisk via instructions at https://github.com/bazelbuild/bazelisk#installation. This should create the bazel command on your system.

You should also have a modern C++ compiler on your system, either gcc or clang, which Bazel will detect.

Build and test

Run

bazel build ...:all
bazel test ...:all

CMake build

CMake is one of two supported build systems for this tutorial. The other is Bazel. If you're unfamiliar with CMake, you can read the tutorials at https://cmake.org/getting-started/. The CMake build is maintained, but was added at article 10 (Dialect Conversion) and will not be explained in the articles.

Prerequisites

Checking out the code

Checkout the tutorial including the LLVM dependency (submodules):

git clone --recurse-submodules https://github.com/j2kun/mlir-tutorial.git
cd mlir-tutorial

Building dependencies

Note: The following steps are suitable for macOs and use ninja as building system, they should not be hard to adapt for your environment.

Build LLVM/MLIR

#!/bin/sh

BUILD_SYSTEM=Ninja
BUILD_TAG=ninja
THIRDPARTY_LLVM_DIR=$PWD/externals/llvm-project
BUILD_DIR=$THIRDPARTY_LLVM_DIR/build
INSTALL_DIR=$THIRDPARTY_LLVM_DIR/install

mkdir -p $BUILD_DIR
mkdir -p $INSTALL_DIR

pushd $BUILD_DIR

cmake ../llvm -G $BUILD_SYSTEM \
      -DCMAKE_CXX_COMPILER="$(xcrun --find clang++)" \
      -DCMAKE_C_COMPILER="$(xcrun --find clang)" \
      -DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
      -DLLVM_LOCAL_RPATH=$INSTALL_DIR/lib \
      -DLLVM_PARALLEL_COMPILE_JOBS=7 \
      -DLLVM_PARALLEL_LINK_JOBS=1 \
      -DLLVM_BUILD_EXAMPLES=OFF \
      -DLLVM_INSTALL_UTILS=ON \
      -DCMAKE_OSX_ARCHITECTURES="$(uname -m)" \
      -DCMAKE_BUILD_TYPE=Release \
      -DLLVM_ENABLE_ASSERTIONS=ON \
      -DLLVM_CCACHE_BUILD=ON \
      -DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
      -DLLVM_ENABLE_PROJECTS='mlir' \
      -DDEFAULT_SYSROOT="$(xcrun --show-sdk-path)" \
      -DCMAKE_OSX_SYSROOT="$(xcrun --show-sdk-path)"

cmake --build . --target check-mlir

popd

Build and test

#!/bin/sh

BUILD_SYSTEM="Ninja"
BUILD_DIR=./build-`echo ${BUILD_SYSTEM}| tr '[:upper:]' '[:lower:]'`

rm -rf $BUILD_DIR
mkdir $BUILD_DIR
pushd $BUILD_DIR

LLVM_BUILD_DIR=externals/llvm-project/build
cmake -G $BUILD_SYSTEM .. \
    -DLLVM_DIR="$LLVM_BUILD_DIR/lib/cmake/llvm" \
    -DMLIR_DIR="$LLVM_BUILD_DIR/lib/cmake/mlir" \
    -DBUILD_DEPS="ON" \
    -DBUILD_SHARED_LIBS="OFF" \
    -DCMAKE_BUILD_TYPE=Debug

popd

cmake --build $BUILD_DIR --target MLIRAffineFullUnrollPasses
cmake --build $BUILD_DIR --target MLIRMulToAddPasses
cmake --build $BUILD_DIR --target MLIRNoisyPasses
cmake --build $BUILD_DIR --target mlir-headers
cmake --build $BUILD_DIR --target mlir-doc
cmake --build $BUILD_DIR --target tutorial-opt
cmake --build $BUILD_DIR --target check-mlir-tutorial

More Repositories

1

svd

Python code implementing the power method for Singular Value Decomposition
Python
103
star
2

fft

Python code and wav files for the post "The Fast Fourier Transform Algorithm, and Denoising a Sound Clip"
Python
93
star
3

neural-networks

Python code and data sets used in the post on neural networks.
Mathematica
83
star
4

essays

Short essays I've written
75
star
5

simplex-algorithm

Python source code for Linear Programming and the Simplex Algorithm
Python
66
star
6

exp3

Python code for the post "Adversarial Bandits and the Exp3 Algorithm"
Python
49
star
7

finite-fields

Python code and tests for the post 'Programming with Finite Fields'
Python
47
star
8

random-art

Python code for the post "Random (Psychedelic) Art, and a Pinch of Python"
Python
42
star
9

fft-watermark

The code for the post "The Two-Dimensional Fourier Transform and Digital Watermarking"
Python
39
star
10

book-template

A LaTeX template I used for pimbook
TeX
36
star
11

ucb1

The code for the post "Optimism in the Face of Uncertainty: the UCB1 Algorithm"
Python
35
star
12

mwua

Python code implementing the MWUA algorithm and a Linear Program solver
Python
34
star
13

lp-diet

Linear Programming Diet Experiments
Python
32
star
14

zero-knowledge-proofs

Python code for the post Zero Knowledge Proofs โ€” A Primer
Python
31
star
15

imsdb_download_all_scripts

Download all plaintext scripts from imsdb.com
Python
31
star
16

computing-homology

Python code for the post "Computing Homology"
Python
28
star
17

hybrid-images

Python code and images used in the post "Hybrid Images"
Python
25
star
18

eigenfaces

Mathematica notebook and resources for the post "Eigenfaces"
23
star
19

riemann-divisor-sum

Code for the series "Searching for Riemann Hypothesis Counterexamples"
HTML
21
star
20

elliptic-curves-rationals

Code for the post "Elliptic Curves as Python Objects" implementing elliptic curve point addition over rational numbers.
Python
21
star
21

bezier-picasso

Python and Javascript code used in the post "Bezier Curves and Picasso"
JavaScript
20
star
22

art-turing-ellipse

A six-panel artistic rendition of Alan Turing
20
star
23

program-gallery

Program Gallery
Python
18
star
24

restrepo-1957

Rodrigo Restrepo. Tactical Problems Involving Several Actions. Contributions to the Theory of Games, Vol. III. 1957
TeX
18
star
25

chktex-action

A Github action to lint a LaTeX file for style and formatting issues.
Python
17
star
26

elliptic-curves-finite-fields

The combined Python code for the post "Elliptic Curves over Finite Fields"
Python
17
star
27

math-genealogy-scraper

Code for scraping (and a mirror of) the Math Genealogy Database
HTML
17
star
28

load-balancing

A python implementation of a load balancer that uses a 2-universal hash family.
Python
16
star
29

segment

Python code and data for the post "Word Segmentation, or Makingsenseofthis"
Python
15
star
30

elliptic-curve-diffie-hellman

Python code for the post "Elliptic Curve Diffie-Hellman"
Python
15
star
31

earthmover

Implementation of the Earthmover distance metric in python.
Python
14
star
32

new-machine

Scripts for installing utilities and setting preferences on a brand new OS X El Capitan.
Shell
13
star
33

bandits-and-stocks

The python code and data sets for the post "Bandits and Stocks"
Python
11
star
34

seam-carving

Processing and Javascript code for the post "Seam-carving for Content-aware Image Scaling"
Processing
11
star
35

graph-laplacians

Code and data for the post "What's up with Graph Laplacians?"
Python
10
star
36

welch-berlekamp

Python
10
star
37

depth-breadth-first-search

Python code used in the post "Depth- and Breadth-First Search"
Python
10
star
38

math-genealogy-visualizer

A javascript visualization of the math genealogy database
JavaScript
10
star
39

mlir-resources

A list of articles outside of the official MLIR docs that I've found useful for learning MLIR
9
star
40

cave-generation

Mathematica and javascript code used in the post "The Cellular Automaton Method for Procedural Cave Generation"
9
star
41

tex-convert-delimiters

A simple demonstration of how to define a parser that converts latex mathmode delimiters
Python
9
star
42

flask-sockets-example

A simple example app using flask, rethinkdb, and socket.io
Python
8
star
43

dotfiles

vimrc, profile, etc.
Vim Script
8
star
44

elliptic-curve-signature

Python code for the post "Sending and Authenticating Messages with Elliptic Curves"
Python
8
star
45

erdos-renyi

Experiments with Erdos-Renyi random graphs for the post The Erdล‘sโ€“Rรฉnyi Random Graph
Python
8
star
46

boosting

Python code for the post on boosting.
Python
7
star
47

svm-sequential-minimal-optimization

An implementation and blog post about the Sequential Minimal Optimization algorithm for Support Vector Machines
JavaScript
7
star
48

stable-marriages

Python code for the post "Stable Marriages and Designing Markets"
Python
7
star
49

dissertation

A copy of my PhD dissertation
TeX
6
star
50

top-trading-cycles

Code for the post "Serial Dictatorships and House Allocation"
Python
6
star
51

pmfp-code

Source code for the book Practical Math for Programmers
Python
6
star
52

cryptanalysis-n-grams

Python code and data for the post ["Cryptanalysis with N-Grams"]
Python
6
star
53

guess-the-polynomial

A program that learns your polynomial using just two queries
Python
5
star
54

onecv

Compile many different CVs and resumes from one archival json CV.
Python
5
star
55

complex-numbers

The code respository for the post "Learning to Love Complex Numbers"
Python
5
star
56

rsa

Java code for the post "Encryption & RSA"
Java
5
star
57

cv

My resume/CV, in archival json form and various other formats.
HTML
5
star
58

decision-trees

Python code and data set used in the post "Decision Trees and Political Party Classification"
Python
5
star
59

ellipse

A pure Python library for basic geometry on ellipses
Python
5
star
60

subset-cover

Experiments modeling a subset cover problem
Python
4
star
61

rado.ly

A web tool for quickly building graph counterexamples.
JavaScript
4
star
62

fastlane-codepush

A fastlane action for using codepush
Ruby
4
star
63

my-favorite-math-art

Some of my favorite math art (not made by me)
4
star
64

gadget-decomposition-fhe

Python
4
star
65

johnson-lindenstrauss

The code and data used in the post, "Big Dimensions, and What You Can Do About It"
Mathematica
4
star
66

low-complexity-art

Mathematica notebook for the post "Low-Complexity Art"
4
star
67

fkl-SDM16

Code and experiments for "A confidence-based approach for balancing fairness and accuracy"
Python
4
star
68

negacyclic

Implementations of cyclic and negacyclic polynomial multiplication
Python
4
star
69

p-vs-np-racket

Racket code for the post "P vs. NP (And a Proof Written in Racket)"
Racket
4
star
70

ellipse-approximation

A recreation of the underlying algorithm for github.com/j2kun/art-turing-ellipse in python/numba
Python
4
star
71

j2kun.github.io

A repository for javascript demos used on jeremykun.com
HTML
3
star
72

linear-regression

Python code for the post "Linear Regression"
Python
3
star
73

todo-backlinks

Link from issue 123 to source lines containing `TODO(#123)`
Python
3
star
74

appendonly

A stupid web server that appends to a local file
Python
3
star
75

page-rank

Mathematica notebook for the series on Google's PageRank algorithm
3
star
76

rote

A tiny python library for making human-in-the-loop terminal apps
Python
3
star
77

hunting-serial-killers

Mathematica notebook for the post "Hunting Serial Killers"
3
star
78

fhe-schemes

A tutorial repository for learning implementations of FHE schemes
Python
3
star
79

nvim-config

Neovim config
Lua
3
star
80

jeremykun.com

Source for jeremykun.com
Shell
3
star
81

knn

Python code for the post "K-Nearest-Neighbors and Handwritten Digit Classification"
Python
3
star
82

extension-trigger-gh-workflow

A chrome extension to trigger a GitHub workflow
JavaScript
3
star
83

the-mathematics-of-secret-sharing

The Haskell code for the post "The Mathematics of Secret Sharing"
Haskell
2
star
84

nonnegative-matrix-factorization

Topic modeling using NMF for HN data.
Python
2
star
85

math-intersect-programming

A blog about math, programming, and the interesting ways they intersect
HTML
2
star
86

fhe-packing

Companion repository for an article about FHE packings
Python
2
star
87

art-21-logo

2
star
88

canvas-scripts

Helpful scripts for working with Canvas
Python
2
star
89

binary-search-graphs

Python code for the post "Binary Search on Graphs"
Python
2
star
90

trump-tweets

Trump's tweets and Benford's Law
Python
2
star
91

babel-plugin-react-native-config

A babel plugin for react-native-config to avoid clean/rebuild for javascript config changes
JavaScript
2
star
92

categories-as-types

ML code for the post "Categories as Types"
Standard ML
2
star
93

harmonic-phase-space

An exploration of sums of harmonics with varying phases
JavaScript
2
star
94

machine-learning-pipeline

A tutorial on machine learning pipelines
Python
2
star
95

reality-mining

Python code for parsing the RealityMining dataset in Python using numpy/scipy.
Python
2
star
96

terminal-images

Tinkering with terminal images
Shell
2
star
97

a-taste-of-racket

Racket code for the post "A Taste of Racket, or How I Learned to Love Functional Programming"
Racket
2
star
98

SecretPythonSeminar

Python assignments for my friends who are learning to code.
HTML
2
star
99

j2kun-math3ma

Collaborative math code!
JavaScript
2
star
100

perceptron

Mathematica notebook for the post "The Perceptron, and All the Things it Canโ€™t Perceive"
2
star