Scott Todd | b2e34de | 2019-10-25 15:20:45 -0700 | [diff] [blame^] | 1 | # Getting Started |
| 2 | |
| 3 | This document provides an overview of the systems in IREE, including entry |
| 4 | points to get started exploring IREE's capabilities. |
| 5 | |
| 6 | For information on how to set up a development environment, see |
| 7 | [Getting Started on Windows](getting_started_on_windows.md) and |
| 8 | [Getting Started on Linux](getting_started_on_linux.md). |
| 9 | |
| 10 | ## Code Layout |
| 11 | |
| 12 | [base/](../iree/base/) |
| 13 | |
| 14 | * Common types and utilities used throughout IREE |
| 15 | |
| 16 | [compiler/](../iree/compiler/) |
| 17 | |
| 18 | * IREE's MLIR dialect, LLVM compiler passes, IREE module translation, etc. |
| 19 | |
| 20 | [hal/](../iree/hal/) |
| 21 | |
| 22 | * **H**ardware **A**bstraction **L**ayer for IREE's runtime, containing |
| 23 | implementations for different hardware and software backends |
| 24 | |
| 25 | [rt/](../iree/rt/) |
| 26 | |
| 27 | * **R**un**t**ime API for interfacing with IREE |
| 28 | |
| 29 | [schemas/](../iree/schemas/) |
| 30 | |
| 31 | * Shared data storage format definitions, primarily using |
| 32 | [FlatBuffers](https://google.github.io/flatbuffers/) |
| 33 | |
| 34 | [tools/](../iree/tools/) |
| 35 | |
| 36 | * Assorted tools used to optimize, translate, and evaluate IREE, including |
| 37 | IREE's debugger |
| 38 | |
| 39 | [vm/](../iree/vm/) |
| 40 | |
| 41 | * Bytecode **V**irtual **M**achine used to work with IREE modules and provide |
| 42 | an interface for hosting applications to invoke IREE functions |
| 43 | |
| 44 | ## Working with IREE's Components |
| 45 | |
| 46 | IREE ingests MLIR in a high-level dialect like |
| 47 | [XLA/HLO](https://github.com/tensorflow/tensorflow/tree/master/tensorflow/compiler/mlir/xla), |
| 48 | after which it can perform its own compiler passes to eventually translate the |
| 49 | IR into an 'IREE module', which can be executed via IREE's runtime. IREE |
| 50 | contains programs for running each step in that pipeline under various |
| 51 | configurations (e.g. for tests, with a debugger attached, etc.). |
| 52 | |
| 53 | ### iree-opt |
| 54 | |
| 55 | The `iree-opt` program invokes |
| 56 | [MlirOptMain](https://github.com/tensorflow/mlir/blob/master/lib/Support/MlirOptMain.cpp) |
| 57 | to run some set of IREE's optimization passes on a provided .mlir input file. |
| 58 | Test .mlir files that are checked in typically include a `RUN` block at the top |
| 59 | of the file that specifies which passes should be performed and if `FileCheck` |
| 60 | should be used to test the generated output. |
| 61 | |
| 62 | For example, to run some passes on the |
| 63 | [reshape.mlir](../iree/compiler/Translation/SPIRV/test/reshape.mlir) test file |
| 64 | with Bazel on Linux, use this command: |
| 65 | |
| 66 | ```shell |
| 67 | $ bazel run //iree/tools:iree-opt -- \ |
| 68 | -split-input-file \ |
| 69 | -convert-iree-to-spirv \ |
| 70 | -simplify-spirv-affine-exprs=false \ |
| 71 | -verify-diagnostics \ |
| 72 | $PWD/iree/compiler/Translation/SPIRV/test/reshape.mlir |
| 73 | ``` |
| 74 | |
| 75 | ### iree-translate |
| 76 | |
| 77 | The `iree-translate` program invokes |
| 78 | [mlir-translate](https://github.com/tensorflow/mlir/blob/master/tools/mlir-translate/mlir-translate.cpp) |
| 79 | to translate from a .mlir input file into an IREE module. |
| 80 | |
| 81 | For example, to translate `simple_compute_test.mlir` to an IREE module with |
| 82 | Bazel on Linux, use this command: |
| 83 | |
| 84 | ```shell |
| 85 | $ bazel run //iree/tools:iree-translate -- \ |
| 86 | -mlir-to-iree-module \ |
| 87 | $PWD/iree/samples/hal/simple_compute_test.mlir \ |
| 88 | -o /tmp/module.fb |
| 89 | ``` |
| 90 | |
| 91 | ### run_module |
| 92 | |
| 93 | The `run_module` program takes an already translated IREE module as input and |
| 94 | executes an exported main function using the provided inputs. |
| 95 | |
| 96 | This program can be used in sequence with `iree-translate` to translate a .mlir |
| 97 | file to an IREE module and then execute it. Here is an example command that runs |
| 98 | the `simple_mul` function in `simple_compute_test.mlir`. |
| 99 | |
| 100 | ```shell |
| 101 | $ bazel build -c opt //iree/tools:iree-translate //iree/tools:run_module |
| 102 | $ ./bazel-bin/iree/tools/run_module \ |
| 103 | --main_module=/tmp/module.fb \ |
| 104 | --main_function=simple_mul \ |
| 105 | --input_values="4xf32=1 2 3 4 |
| 106 | 4xf32=5 6 7 8" |
| 107 | ``` |
| 108 | |
| 109 | ### iree-run-mlir |
| 110 | |
| 111 | The `iree-run-mlir` program takes a .mlir file as input, translates it to an |
| 112 | IREE bytecode module, and executes the module. |
| 113 | |
| 114 | For example, to execute the contents of a test .mlir file, use this command: |
| 115 | |
| 116 | ```shell |
| 117 | $ bazel run //iree/tools:iree-run-mlir -- $PWD/test/e2e/scalars.mlir |
| 118 | ``` |