MLIR
I am not an expert!
Today
Gap leading to domain specific IRs elsewhere
LLVM IR
Machine IR
Asm
Swift
Java & JVM Languages
Java BC
SIL IR
Swift AST
Rust
MIR IR
Rust AST
Julia
Julia IR
Julia AST
XLA HLO
TF Graph
TensorFlow Ecosystem
Clang AST
C, C++, ObjC, CUDA, OpenCL, ...
CIL IR
The TensorFlow compiler ecosystem
Many “Graph” IRs, each with challenges:
TensorFlow Graph
LLVM IR
XLA HLO
TPU IR
TensorFlow Lite
Several others
Tensor RT
nGraph
NNAPI
Many others
Core ML
Grappler
Domain Specific IRs
Great!
Not great!
What is MLIR?
What is MLIR?
Extensible Operations Allow Multi-Level IR
TensorFlow
XLA HLO
LLVM IR
Also: TF-Lite, Core ML, other frontends, etc ...
%x = "tf.Conv2d"(%input, %filter)
{strides: [1,1,2,1], padding: "SAME", dilations: [2,1,1,1]}
: (tensor<*xf32>, tensor<*xf32>) -> tensor<*xf32>
%m = “xla.AllToAll"(%z)� {split_dimension: 1, concat_dimension: 0, split_count: 2}� : (memref<300x200x32xf32>) -> memref<600x100x32xf32>
%f = llvm.add %a, %b
: !llvm.float
Don’t we end up with the JSON of compiler IRs????
Lowering
MLIR “Dialects”: Families of defined operations
Example Dialects:
Dialects can define:
Operation can define:
MLIR Type System - some examples
Scalars:
Vectors:
Tensors, including dynamic shape and rank:
Others: functions, memory buffers, quantized integers, other TensorFlow stuff, ...
Extensible!!
Applications
TensorFlow Lite Converter
TF
Graph
translate
legalize
optimize
translate
TFlite flatbuffer
tf.*
tfl.*
tfl.*
One of the focusses: Usability
Old “TOCO” User Experience
F0122 11:20:14.691357 27738 import_tensorflow.cc:2549] Check failed: status.ok() Unexpected value for attribute 'data_format'. Expected 'NHWC'
*** Check failure stack trace: ***
@ 0x5557b0ac3e78 base_logging::LogMessage::SendToLog()
@ 0x5557b0ac46c2 base_logging::LogMessage::Flush()
@ 0x5557b0ac6665 base_logging::LogMessageFatal::~LogMessageFatal()
@ 0x5557af51e22b toco::ImportTensorFlowGraphDef()
@ 0x5557af51f60c toco::ImportTensorFlowGraphDef()
(...)
@ 0x5557af4ac679 main
@ 0x7f7fa2057bbd __libc_start_main
@ 0x5557af4ac369 _start
*** SIGABRT received by PID 27738 (TID 27738) from PID 27738; ***
F0122 11:20:14.691357 27738 import_tensorflow.cc:2549] Check failed: status.ok() Unexpected value for attribute 'data_format'. Expected 'NHWC'
E0122 11:20:14.881460 27738 process_state.cc:689] RAW: Raising signal 6 with default behavior
Aborted
Improved User Experience
node “MobilenetV1/MobilenetV1/Conv2d_0/Conv2D” defined
at 'convolution2d'(tensorflow/contrib/layers/python/layers/layers.py:1156):
conv_dims=2)
at 'func_with_args'(tensorflow/contrib/framework/python/ops/arg_scope.py:182):
return func(*args, **current_args)
at 'mobilenet_base'(tensorflow_models/slim/nets/mobilenet/mobilenet.py:278):
net = opdef.op(net, **params)
...
at 'network_fn'(resnet/nets_factory.py:93):
return func(images, num_classes, is_training=is_training, **kwargs)
at 'build_model'(resnet/train_experiment.py:165):
inputs, depth_multiplier=FLAGS.depth_multiplier)
...
error: 'tf.Conv2D' op requires data_format attribute to be either 'NHWC' or 'NCHW'
This output is also evolving (caret pointing to error ala clang)
For the Web?
Some facts from MLIR investigations
MLIR dialect on the web