# MLIR

Multi-Level IR Compiler Framework

# 'ml_program' Dialect

The MLProgram dialect contains structural operations and types for defining a compiled Machine-Learning program, as created from common ML frameworks, such as TensorFlow, PyTorch, JAX, etc. It does not itself define computation ops common to such frameworks but establishes a common programming model for establishing modules, functions, globals and memory model components appropriate for such an abstract level of detail.

This dialect is under active development, and while stability is an eventual goal, it is not guaranteed at this juncture. Given the early state, it is recommended to inquire further prior to using this dialect.

## Operation definition ¶

### ml_program.func (::mlir::ml_program::FuncOp) ¶

Function containing a single SSACFG region

This simple function container represents callables in an ML program where the body is an SSACFG region. It must be terminated by a return op which yields values with the same arity and types as the FunctionType results of the containing func.

This op is a Symbol but does not introduce a new SymbolTable. As such, it cannot represent nested symbols.

Example:

ml_program.func private @some_extern(i32) -> i32
ml_program.func @compute(%arg0 : i32) -> i32 {
ml_program.return %arg0 : i32
}


Traits: IsolatedFromAbove

Interfaces: CallableOpInterface, FunctionOpInterface, RegionKindInterface, Symbol

#### Attributes: ¶

AttributeMLIR TypeDescription
sym_name::mlir::StringAttrstring attribute
function_type::mlir::TypeAttrtype attribute of function type
sym_visibility::mlir::StringAttrstring attribute

### ml_program.global_load_const (::mlir::ml_program::GlobalLoadConstOp) ¶

Direct load a constant value from a global

Syntax:

operation ::= ml_program.global_load_const $global attr-dict : type($result)


Loads a constant (immutable) value from a global directly by symbol.

This op is only legal for globals that are not mutable and exists because such a load can be considered to have no side effects.

Example:

%0 = ml_program.global_load_const @foobar : tensor<?xi32>


Interfaces: NoSideEffect (MemoryEffectOpInterface), SymbolUserOpInterface

Effects: MemoryEffects::Effect{}

#### Attributes: ¶

AttributeMLIR TypeDescription
global::mlir::FlatSymbolRefAttrflat symbol reference attribute

#### Results: ¶

ResultDescription
resultany type

### ml_program.global (::mlir::ml_program::GlobalOp) ¶

Module level declaration of a global variable

Syntax:

operation ::= ml_program.global custom<SymbolVisibility>($sym_visibility) (mutable$is_mutable^)?
$sym_name  custom<TypedInitialValue>($type, $value) attr-dict  Declares a named global variable (or constant). A global contains a value of a specified type which can be accessed at runtime via appropriate load/store operations. It can be mutable or constant, optionally taking an initial value or declared as extern (in which case, the initial value is found in external storage by symbol name). Generally, the type of the global and the type of the initial value will be the same. However, for type hierarchies which can have a more generalized bounding type that can be assigned from a narrow type, this is allowed (but not verified). Examples: // Constant global. ml_program.global @foobar(dense<4> : tensor<4xi32>) : tensor<?xi32> // Constant with external linkage. ml_program.global mutable @foobar(#ml_program.extern<tensor<4xi32>>) : tensor<?xi32> // Mutable global with an undefined initial value. ml_program.global mutable @foobar : tensor<?xi32>  Interfaces: Symbol #### Attributes: ¶ AttributeMLIR TypeDescription sym_name::mlir::StringAttrstring attribute type::mlir::TypeAttrany type attribute is_mutable::mlir::UnitAttrunit attribute value::mlir::Attributeany attribute sym_visibility::mlir::StringAttrstring attribute ### ml_program.output (::mlir::ml_program::OutputOp) ¶ Outputs values from a subgraph function Syntax: operation ::= ml_program.output attr-dict ($operands^ : type($operands))?  The output operation terminates a subgraph by yielding values to the caller. The operation takes variable number of operands and produces no results. The operand number and types must match the signature of the function that contains the operation. Traits: HasParent, ReturnLike, Terminator Interfaces: NoSideEffect (MemoryEffectOpInterface) Effects: MemoryEffects::Effect{} #### Operands: ¶ OperandDescription operandsany type ### ml_program.return (::mlir::ml_program::ReturnOp) ¶ Returns values from a func function Syntax: operation ::= ml_program.return attr-dict ($operands^ : type(\$operands))?


The return operation terminates a func function by yielding values to the caller. The operation takes variable number of operands and produces no results. The operand number and types must match the signature of the function that contains the operation.

Traits: HasParent, ReturnLike, Terminator

Interfaces: NoSideEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

#### Operands: ¶

OperandDescription
operandsany type

### ml_program.subgraph (::mlir::ml_program::SubgraphOp) ¶

An function containing a single Graph region

This simple function container represents callables in an ML program where the body is a Graph region containing a single block. It must be terminated by an output op which yields values with the same arity and types as the FunctionType results of the containing subgraph.

This op is a Symbol but does not introduce a new SymbolTable. As such, it cannot represented nested symbols.

Example:

ml_program.subgraph private @some_extern(i32) -> i32
ml_program.subgraph @compute(%arg0 : i32) -> i32 {
ml_program.output %arg0 : i32
}


Traits: HasOnlyGraphRegion, IsolatedFromAbove, SingleBlock

Interfaces: CallableOpInterface, FunctionOpInterface, RegionKindInterface, Symbol

#### Attributes: ¶

AttributeMLIR TypeDescription
sym_name::mlir::StringAttrstring attribute
function_type::mlir::TypeAttrtype attribute of function type
sym_visibility::mlir::StringAttrstring attribute