tree: 6f9f8c3f3d56484dc4a1f355423f0c7aec5ba48b [path history] [tgz]
  1. __init__.py
  2. CMakeLists.txt
  3. core.py
  4. README.md
  5. setup.py.in
  6. tf.py
  7. tflite.py
  8. tools.py
  9. version.py.in
  10. xla.py
bindings/python/iree/compiler/README.md

IREE Compiler Python Bindings

Core compiler

import iree.compiler

SIMPLE_MUL_ASM = """
func @simple_mul(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>) -> tensor<4xf32>
      attributes { iree.module.export } {
    %0 = "mhlo.multiply"(%arg0, %arg1) {name = "mul.1"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32>
    return %0 : tensor<4xf32>
}
"""

# Also see compile_file()
# There are many keyword options available.
# See iree.compiler.CompilerOptions
binary = iree.compiler.compile_str(SIMPLE_MUL_ASM, target_backends=["vulkan-spirv"])

TensorFlow compiler

import tensorflow as tf
import iree.compiler.tf

class SimpleArithmeticModule(tf.Module):

  @tf.function(input_signature=[
      tf.TensorSpec([4], tf.float32),
      tf.TensorSpec([4], tf.float32)
  ])
  def simple_mul(self, a, b):
    return a * b

# Also see compile_saved_model to directly compile an on-disk saved model.
# There are many keyword options available.
# See: iree.compiler.tf.ImportOptions
binary = iree.compiler.tf.compile_module(
    SimpleArithmeticModule(), target_backends=["vulkan-spirv"])