or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

api-embedding.mdbuild-system.mdcommand-line-tools.mdcore-compilation.mdfrontend-integration.mdindex.md

index.mddocs/

0

# IREE Base Compiler

1

2

IREE Base Compiler provides Python APIs for compiling Machine Learning models using IREE's MLIR-based end-to-end compiler infrastructure. It enables developers to compile ML models from various frameworks (TensorFlow, PyTorch, ONNX) into IREE's optimized intermediate representation for deployment across diverse hardware targets including CPUs, GPUs, and accelerators.

3

4

## Package Information

5

6

- **Package Name**: iree-base-compiler

7

- **Language**: Python

8

- **Installation**: `pip install iree-base-compiler`

9

- **Repository**: https://github.com/iree-org/iree

10

11

## Core Imports

12

13

```python

14

import iree.compiler

15

```

16

17

High-level compilation tools:

18

19

```python

20

from iree.compiler.tools import compile_str, compile_file, CompilerOptions

21

```

22

23

Low-level embedding API:

24

25

```python

26

from iree.compiler.api import Session, Invocation, Source, Output

27

```

28

29

Build system:

30

31

```python

32

import iree.build

33

```

34

35

## Basic Usage

36

37

```python

38

import iree.compiler.tools

39

40

# Simple MLIR compilation

41

SIMPLE_MUL_ASM = """

42

func.func @simple_mul(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>) -> tensor<4xf32> {

43

%0 = arith.mulf %arg0, %arg1 : tensor<4xf32>

44

return %0 : tensor<4xf32>

45

}

46

"""

47

48

# Compile to FlatBuffer binary for CPU target

49

binary = iree.compiler.tools.compile_str(

50

SIMPLE_MUL_ASM,

51

input_type="auto",

52

target_backends=["llvm-cpu"]

53

)

54

55

# Compile from file with options

56

options = iree.compiler.tools.CompilerOptions(

57

target_backends=["llvm-cpu"],

58

optimize=True,

59

output_file="output.vmfb"

60

)

61

iree.compiler.tools.compile_file("input.mlir", **options.__dict__)

62

```

63

64

## Architecture

65

66

IREE Base Compiler provides multiple API layers for different use cases:

67

68

- **High-level Tools API** (`iree.compiler.tools`): User-friendly compilation functions with simplified options for common workflows

69

- **Low-level Embedding API** (`iree.compiler.api`): Direct access to the C embedding API for advanced control over compilation sessions and invocations

70

- **Build System API** (`iree.build`): Declarative build system for complex compilation workflows with dependencies and actions

71

- **Frontend Integration**: Specialized APIs for TensorFlow and TensorFlow Lite model import

72

- **Command-line Tools**: Console scripts providing command-line access to compilation functionality

73

74

This layered design supports everything from simple model compilation to complex multi-step build pipelines in production ML deployment systems.

75

76

## Capabilities

77

78

### Core Compilation Functions

79

80

High-level compilation functions for compiling MLIR code to IREE VM modules, supporting various input formats and target backends.

81

82

```python { .api }

83

def compile_str(input_str: Union[str, bytes], **kwargs) -> Optional[bytes]: ...

84

def compile_file(input_file: str, **kwargs) -> Optional[bytes]: ...

85

def query_available_targets() -> List[str]: ...

86

```

87

88

[Core Compilation](./core-compilation.md)

89

90

### Compiler API Embedding

91

92

Low-level C API bindings providing direct access to IREE's compiler infrastructure through Session, Invocation, Source, and Output objects.

93

94

```python { .api }

95

class Session: ...

96

class Invocation: ...

97

class Source: ...

98

class Output: ...

99

```

100

101

[API Embedding](./api-embedding.md)

102

103

### Build System

104

105

Declarative build system for managing complex compilation workflows with dependencies, actions, and entrypoints.

106

107

```python { .api }

108

@entrypoint

109

def build_func(): ...

110

111

class CompileSourceAction: ...

112

class CompileStdModuleAction: ...

113

```

114

115

[Build System](./build-system.md)

116

117

### Frontend Integration

118

119

Specialized APIs for importing and compiling models from TensorFlow and TensorFlow Lite frameworks.

120

121

```python { .api }

122

def compile_from_tf_module(tf_module, **kwargs): ...

123

def compile_from_tflite_file(tflite_path, **kwargs): ...

124

```

125

126

[Frontend Integration](./frontend-integration.md)

127

128

### Command-line Tools

129

130

Console scripts providing command-line access to compilation, optimization, and import functionality.

131

132

```python { .api }

133

# Console scripts:

134

# iree-compile, iree-opt, iree-import-onnx, iree-ir-tool, iree-build

135

```

136

137

[Command-line Tools](./command-line-tools.md)