This guide provides an overview of IREE's project structure and main tools for developers.
IREE‘s compiler components accept programs and code fragments in several formats, including high level TensorFlow Python code, serialized TensorFlow SavedModel programs, and lower level textual MLIR files using combinations of supported dialects like xla_hlo
and IREE’s internal dialects. While input programs are ultimately compiled down to modules suitable for running on some combination of IREE‘s target deployment platforms, IREE’s developer tools can run individual compiler passes, translations, and other transformations step by step.
iree-opt
is a tool for testing IREE‘s compiler passes. It is similar to mlir-opt and runs sets of IREE’s compiler passes on .mlir
input files. See “conversion” in MLIR's Glossary for more information.
Test .mlir
files that are checked in typically include a RUN
block at the top of the file that specifies which passes should be performed and if FileCheck
should be used to test the generated output.
For example, to run some passes on the reshape.mlir test file:
$ bazel run iree/tools:iree-opt -- \ -split-input-file \ -iree-index-computation \ -simplify-spirv-affine-exprs=false \ -convert-iree-to-spirv \ -verify-diagnostics \ $PWD/iree/compiler/Translation/SPIRV/XLAToSPIRV/test/reshape.mlir
Custom passes may also be layered on top of iree-opt
, see iree/samples/custom_modules/dialect for a sample.
iree-translate
converts MLIR input into external formats like IREE modules. It is similar to mlir-translate, see “translation” in MLIR's Glossary for more information.
For example, to translate simple.mlir
to an IREE module:
$ bazel run iree/tools:iree-translate -- \ -iree-mlir-to-vm-bytecode-module \ --iree-hal-target-backends=vmla \ $PWD/iree/tools/test/simple.mlir \ -o /tmp/simple.module
Custom translations may also be layered on top of iree-translate
, see iree/samples/custom_modules/dialect for a sample.
The iree-run-module
program takes an already translated IREE module as input and executes an exported main function using the provided inputs.
This program can be used in sequence with iree-translate
to translate a .mlir
file to an IREE module and then execute it. Here is an example command that executes the simple simple.module
compiled from simple.mlir
above on IREE's VMLA driver:
$ bazel run iree/tools:iree-run-module -- \ --input_file=/tmp/simple.module \ --driver=vmla \ --entry_function=abs \ --inputs="i32=-2"
The iree-check-module
program takes an already translated IREE module as input and executes it as a series of googletest tests. This is the test runner for the IREE check framework.
$ bazel run iree/tools:iree-translate -- \ -iree-mlir-to-vm-bytecode-module \ --iree-hal-target-backends=vmla \ $PWD/iree/test/e2e/xla_ops/abs.mlir \ -o /tmp/abs.module
$ bazel run iree/modules/check:iree-check-module -- \ /tmp/abs.module \ --driver=vmla
The iree-run-mlir
program takes a .mlir
file as input, translates it to an IREE bytecode module, and executes the module.
It is designed for testing and debugging, not production uses, and therefore does some additional work that usually must be explicit, like marking every function as exported by default and running all of them.
For example, to execute the contents of iree/tools/test/simple.mlir:
$ bazel run iree/tools:iree-run-mlir -- \ $PWD/iree/tools/test/simple.mlir \ --input-value="i32=-2" \ --iree-hal-target-backends=vmla
The iree-dump-module
program prints the contents of an IREE module FlatBuffer file.
For example, to inspect the module translated above:
$ bazel run iree/tools:iree-dump-module -- /tmp/simple.module