Slide 1

Slide 1 text

The MLIR Framework A Brief Introduction to Deep Learning Compilers Dafna Mordechai 2021

Slide 2

Slide 2 text

Hello! @Dafna_Mordechai ● Dafna Mordechai, BSc. in Computer Science, The Hebrew University of Jerusalem (2008) ● Senior RT Embedded Software Engineer ● LOVE technology, and LOVE sharing it with others

Slide 3

Slide 3 text

AGENDA The LLVM Compiler Deep Learning MLIR

Slide 4

Slide 4 text

The LLVM Compiler

Slide 5

Slide 5 text

Compiler(Source Code) --> Machine Code C/C++ Fortran Rust Swift Go X86 ARM RISC-V AVR PowerPC ● ● ● ● ● ● ● ● ● ● Translations + Transformations [semantic preserving] Compiler == ( )

Slide 6

Slide 6 text

C/C++ Fortran Rust Swift Go X86 ARM RISC-V AVR PowerPC LLVM - Low Level Virtual Machine

Slide 7

Slide 7 text

C/C++ Fortran Rust Swift Go X86 ARM RISC-V AVR PowerPC ● ● ● ● ● ● ● ● ● ● Hardware agnostic operations Language agnostic operations

Slide 8

Slide 8 text

C/C++ Fortran Rust Swift Go X86 ARM RISC-V AVR PowerPC Front-End Clang / Flang / Gollvm / rustc / … Back-End LLVM - An Open Source Modular Compiler Hardware agnostic operations Language agnostic operations Examples: • Machine instruction selection • Register allocation • Scheduling Examples: • Lexical analysis • Syntax analysis • Semantic analysis

Slide 9

Slide 9 text

C/C++ Fortran Rust Swift Go X86 ARM RISC-V AVR PowerPC Front-End Back-End LLVM - An Open Source Modular Compiler Hardware agnostic operations Language agnostic operations ?

Slide 10

Slide 10 text

C/C++ Fortran Rust Swift Go X86 ARM RISC-V AVR PowerPC LLVM-IR - Standardized Intermediate Representation Hardware agnostic operations Language agnostic operations Middle-End LLVM-IR Standardized IR Front-End High Level Language to LLVM-IR Back-End LLVM-IR to Machine Code

Slide 11

Slide 11 text

➔ Three-address code ➔ Typed ➔ Static single assignment (SSA) form LLVM-IR - Standardized Intermediate Representation

Slide 12

Slide 12 text

C/C++ Fortran Rust Swift Go X86 ARM RISC-V AVR PowerPC Back-End LLVM - Three-Stage Compiler Hardware agnostic operations Language agnostic operations Front-End Middle-End LLVM Optimizer Examples: • Constant folding • Loop-invariant code motion • Dead code elimination

Slide 13

Slide 13 text

LLVM - Low Level Virtual Machine Three-Stage Compiler ➢ Frontend ➢ Middle-end ➢ Backend ‐ Modularity ‐ Reusability ‐ Standardization of the IR ‐ Open-source ‐ Shared debug tools

Slide 14

Slide 14 text

Deep Learning and MLIR

Slide 15

Slide 15 text

Image by Gordon Johnson from Pixabay Deep Learning - A World of Dataflow Graphs ➔ Training ➔ Inference Time Series Data Numerical Data Categorical Data Images Categorical Data Categorical Data Text

Slide 16

Slide 16 text

Example: GANILLA Image source: GANILLA’s paper: arXiv:2002.05638v2

Slide 17

Slide 17 text

Inference edge-devices Deep Learning - Multiple Frameworks and Multiple Devices CPU GPU TPU ?

Slide 18

Slide 18 text

Example: GANILLA GANILLA’s generator architecture (Image source: GANILLA’s paper: arXiv:2002.05638v2) Code written by Lior Dagan Leib, Liron Soffer and Dafna Mordechai.

Slide 19

Slide 19 text

A Huge Amount of Data but Just A Few Lines of Code... Code written by Lior Dagan Leib, Liron Soffer and Dafna Mordechai.

Slide 20

Slide 20 text

Inference edge-devices Deep Learning - Multiple Frameworks and Multiple Devices CPU GPU TPU Image by Gordon Johnson from Pixabay ? ➔ Operations definition and type handling ➔ Graph optimization ➔ Handling Memory related operation ➔ Handling model / data parallelism ➔ Code-Generation for multiple devices

Slide 21

Slide 21 text

MLIR is a compiler intermediate representation that allows lowering dataflow graphs to target-specific machine code of high-performance data-parallel systems. MLIR: Multi Level Intermediate Representation

Slide 22

Slide 22 text

PyTorch TensorFlow Mxnet Onnx Caffe … CPU GPU TPU Inference edge-devices MLIR - Multi Level Intermediate Representation Middle-End LLVM-IR MLIR LLVM - Instruction Based IR MLIR - Operation Based IR

Slide 23

Slide 23 text

MLIR

Slide 24

Slide 24 text

MLIR: Multi Level Intermediate Representation MLIR’s key concepts are operation, which gathers into Dialects. Compiler passes are used to transform operations, lowering one dialect to another.

Slide 25

Slide 25 text

MLIR Operations An Operation represents a concept. A high-level concept like: function definitions, function calls, buffer allocations, view or slices of buffers, process creation, etc. A low-level concept like: target-independent arithmetic, target-specific instructions, configuration registers, logic gates, etc. Operation semantics can be described abstractly using Traits and Interfaces.

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

MLIR Dialects ➔ Dialects are the mechanism for extending the MLIR ecosystem. ➔ Dialects can define new operations, attributes, and types. ➔ In MLIR, dialects are interleaved. At any given time, the IR can be comprised of multiple dialects. ➔ Dialects don’t necessarily define hierarchies, but rather represent different abstraction levels.

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

Examples: Affine dialect - provides a powerful abstraction for affine operations and analyses. Standard dialect - a collection of operations such as: compare, casts, select, branch, conditional branch, return, assert, Atomic-RMW, fma, div, neg, or, and, etc. math dialect – sin, cos, exp, tanh, atan, pow, log, sqrt, rsqrt, etc. GPU dialect - middle-level abstractions for launching GPU kernels following a programming model that resembles CUDA or OpenCL. Vector dialect – operations such as load, store, shuffle, gather, transpose, reduction, etc. LLVM dialect - maps LLVM IR into MLIR by defining the corresponding operations and types.

Slide 30

Slide 30 text

MLIR - Different Types of Transformation Middle-End LLVM-IR MLIR Importing Exporting Converting Translation Vs. Conversion

Slide 31

Slide 31 text

Dialect Conversion ➔ MLIR support Partial Lowering (Also called Progressive Lowering) ➔ An operation of one dialect can be converted to another operation, or a group of operations, from the same dialect or other dialects. ➔ MLIR supports a pattern matching mechanism

Slide 32

Slide 32 text

Partial Lowering / Progressive Lowering

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

MLIR: Multi Level Intermediate Representation Multi-Stage Compiler ➢ Import to MLIR ➢ Dialect conversion ➢ Export from MLIR ‐ Extendable operation-based IR - Designed for partial lowering ‐ Open source ‐ Part of the LLVM project, and can be easily lowered to LLVM-IR.

Slide 35

Slide 35 text

Thank You! https://www.linkedin.com/in/dafna-mordechai @Dafna_Mordechai