Developer overviewlink
This guide provides an overview of IREE's project structure and main tools for developers.
Project code layoutlink
- /compiler/:
MLIR dialects, LLVM compiler passes, module translation code, etc.
- bindings/: Python and other language bindings
- /runtime/:
Standalone runtime code including the VM and HAL drivers
- bindings/: Python and other language bindings
- /integrations/: Integrations between IREE and other frameworks, such as TensorFlow
- /tests/: Tests for full compiler->runtime workflows
- /tools/:
Developer tools (
iree-compile,iree-run-module, etc.) - /samples/: Also see the separate https://github.com/iree-org/iree-samples repository
IREE compiler code layoutlink
- API/: Public C API
- Codegen/: Code generation for compute kernels
- Dialect/:
MLIR dialects (
Flow,HAL,Stream,VM, etc.) - InputConversion/: Conversions from input dialects and preprocessing
IREE runtime code layoutlink
- base/: Common types and utilities used throughout the runtime
- hal/: Hardware Abstraction Layer for IREE's runtime, with implementations for hardware and software backends
- schemas/: Data storage format definitions, primarily using FlatBuffers
- task/: System for running tasks across multiple CPU threads
- tooling/: Utilities for tests and developer tools, not suitable for use as-is in downstream applications
- vm/: Bytecode Virtual Machine used to work with IREE modules and invoke IREE functions
Developer toolslink
IREE's core compiler accepts programs in supported input MLIR dialects (e.g.
stablehlo, tosa, linalg). Import tools and APIs may be used to convert
from framework-specific formats like TensorFlow
SavedModel to MLIR modules.
While 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-optlink
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. Transformations performed by iree-opt can range from
individual passes performing isolated manipulations to broad pipelines that
encompass a sequence of steps.
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.
Here's an example of a small compiler pass running on a test file:
$ ../iree-build/tools/iree-opt \
--split-input-file \
--mlir-print-ir-before-all \
--iree-util-drop-compiler-hints \
$PWD/compiler/src/iree/compiler/Dialect/Util/Transforms/test/drop_compiler_hints.mlir
For a more complex example, here's how to run IREE's complete transformation pipeline targeting the VMVX backend on the fullyconnected.mlir model file:
$ ../iree-build/tools/iree-opt \
--iree-transformation-pipeline \
--iree-hal-target-backends=vmvx \
$PWD/tests/e2e/stablehlo_models/fullyconnected.mlir
iree-compilelink
iree-compile is IREE's main compiler driver for generating binaries from
supported input MLIR assembly.
For example, to translate simple.mlir to an IREE module:
$ ../iree-build/tools/iree-compile \
--iree-hal-target-backends=vmvx \
$PWD/samples/models/simple_abs.mlir \
-o /tmp/simple_abs_vmvx.vmfb
iree-run-modulelink
The iree-run-module program takes an already translated IREE module as input
and executes an exported function using the provided inputs.
This program can be used in sequence with iree-compile to translate a
.mlir file to an IREE module and then execute it. Here is an example command
that executes the simple simple_abs_vmvx.vmfb compiled from simple_abs.mlir
above on IREE's local-task CPU device:
$ ../iree-build/tools/iree-run-module \
--module=/tmp/simple_abs_vmvx.vmfb \
--device=local-task \
--function=abs \
--input=f32=-2
Input scalars are passed as value and input buffers are passed as
[shape]xtype=[value].
- Input buffers may also be read from raw binary files or Numpy npy files.
| MLIR type | Description | Input example |
|---|---|---|
i32 |
Scalar | --input=1234 |
tensor<i32> |
0-D tensor | --input=i32=1234 |
tensor<1xi32> |
1-D tensor (shape [1]) | --input=1xi32=1234 |
tensor<2xi32> |
1-D tensor (shape [2]) | --input="2xi32=12 34" |
tensor<2x3xi32> |
2-D tensor (shape [2, 3]) | --input="2x3xi32=[1 2 3][4 5 6]" |
Other usage examples
See these test files for advanced usage examples:
Source file: tools/test/iree-run-module.mlir
| tools/test/iree-run-module.mlir | |
|---|---|
1 2 3 4 5 6 7 8 9 10 | |
Source file: tools/test/iree-run-module-inputs.mlir
| tools/test/iree-run-module-inputs.mlir | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
Source file: tools/test/iree-run-module-outputs.mlir
| tools/test/iree-run-module-outputs.mlir | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
Source file: tools/test/iree-run-module-expected.mlir
| tools/test/iree-run-module-expected.mlir | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | |
iree-check-modulelink
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.
$ ../iree-build/tools/iree-compile \
--iree-input-type=stablehlo \
--iree-hal-target-backends=vmvx \
$PWD/tests/e2e/stablehlo_ops/abs.mlir \
-o /tmp/abs.vmfb
$ ../iree-build/tools/iree-check-module \
--device=local-task \
--module=/tmp/abs.vmfb
iree-run-mlirlink
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 samples/models/simple_abs.mlir:
# iree-run-mlir <compiler flags> [input.mlir] <runtime flags>
$ ../iree-build/tools/iree-run-mlir \
--iree-hal-target-backends=vmvx \
$PWD/samples/models/simple_abs.mlir \
--input=f32=-2
iree-dump-modulelink
The iree-dump-module program prints the contents of an IREE module FlatBuffer
file.
For example, to inspect the module translated above:
../iree-build/tools/iree-dump-module /tmp/simple_abs_vmvx.vmfb
Useful generic flagslink
Read inputs from a filelink
All the IREE tools support reading input values from a file. This is quite
useful for debugging. Use --help for each tool to see what the flag to set.
The inputs are expected to be newline-separated. Each input should be either a
scalar or a buffer. Scalars should be in the format type=value and buffers
should be in the format [shape]xtype=[value]. For example:
1x5xf32=1,-2,-3,4,-5
1x5x3x1xf32=15,14,13,12,11,10,9,8,7,6,5,4,3,2,1
--iree-flow-trace-dispatch-tensorslink
This flag will enable tracing inputs and outputs for each dispatch function. It is easier to narrow down test cases, since IREE breaks a ML workload into multiple dispatch function. When the flag is on, IREE will insert trace points before and after each dispatch function. The first trace op is for inputs, and the second trace op is for outputs. There will be two events for one dispatch function.