CINXE.COM
'ml_program' Dialect - MLIR
<!doctype html><html lang=en-us><head><meta charset=utf-8><meta http-equiv=x-ua-compatible content="IE=edge"><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no"><title>'ml_program' Dialect - MLIR</title><meta name=description content="Multi-Level IR Compiler Framework"><meta name=generator content="Hugo 0.119.0"><link href=https://mlir.llvm.org/index.xml rel=alternate type=application/rss+xml><link rel=canonical href=https://mlir.llvm.org/docs/Dialects/MLProgramOps/><link rel=stylesheet href=https://mlir.llvm.org/css/theme.css><script src=https://use.fontawesome.com/releases/v5.0.6/js/all.js></script> <link rel=stylesheet href=https://mlir.llvm.org/css/chroma.min.css><script src=https://cdn.jsdelivr.net/npm/jquery@3.3.1/dist/jquery.min.js></script> <script src=https://cdn.jsdelivr.net/npm/jquery.easing@1.4.1/jquery.easing.min.js></script> <script src=https://mlir.llvm.org/js/bundle.js></script> <script type=text/javascript src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script> <script type=text/x-mathjax-config> MathJax.Hub.Config({ tex2jax: { inlineMath: [['$', '$'] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ] } }); </script><link rel=apple-touch-icon sizes=180x180 href="/apple-touch-icon.png?v=1"><link rel=icon type=image/png sizes=32x32 href="/favicon-32x32.png?v=1"><link rel=icon type=image/png sizes=16x16 href="/favicon-16x16.png?v=1"><link rel=manifest href="/site.webmanifest?v=1"><link rel=mask-icon href="/safari-pinned-tab.svg?v=1" color=#3775e0><link rel="shortcut icon" href="/favicon.ico?v=1"><meta name=msapplication-TileColor content="#2d89ef"><meta name=theme-color content="#ffffff"><link rel=icon href=/favicon.svg type=image/svg+xml sizes=any><style>:root{}</style></head><body><div class=container><header><h1><div><img src=https://mlir.llvm.org//mlir-logo.png width=40px align=absmiddle> MLIR</div></h1><p class=description>Multi-Level IR Compiler Framework</p></header><div class=global-menu><nav><ul><li class=parent><a href>Community<i class="fas fa-angle-right"></i></a><ul class=sub-menu><li class=child><a href=https://llvm.discourse.group/c/mlir/31>Forums</a></li><li class=child><a href=https://discord.gg/xS7Z362>Chat</a></li></ul></li><li><a href=/getting_started/Debugging/>Debugging Tips</a></li><li><a href=/getting_started/Faq/>FAQ</a></li><li class=parent><a href=https://github.com/llvm/llvm-project/tree/main/mlir>Source<i class="fas fa-angle-right"></i></a><ul class=sub-menu><li class=child><a href=/doxygen/>Doxygen</a></li><li class=child><a href=https://github.com/llvm/llvm-project/tree/main/mlir>GitHub</a></li></ul></li><li><a href="https://bugs.llvm.org/buglist.cgi?bug_status=__open__&list_id=177877&order=changeddate%20DESC%2Cpriority%2Cbug_severity&product=MLIR&query_format=specific">Bugs</a></li><li><a href=https://github.com/llvm/mlir-www/tree/main/website/static/LogoAssets>Logo Assets</a></li><li><a href=https://www.youtube.com/MLIRCompiler>Youtube Channel</a></li></ul></nav></div><div class=content-container><main><h1>'ml_program' Dialect</h1><p>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.</p><p>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.</p><p><nav id=TableOfContents><ul><li><a href=#operations>Operations</a><ul><li><a href=#ml_programfunc-ml_programfuncop><code>ml_program.func</code> (ml_program::FuncOp)</a></li><li><a href=#ml_programglobal-ml_programglobalop><code>ml_program.global</code> (ml_program::GlobalOp)</a></li><li><a href=#ml_programglobal_load-ml_programgloballoadop><code>ml_program.global_load</code> (ml_program::GlobalLoadOp)</a></li><li><a href=#ml_programglobal_load_const-ml_programgloballoadconstop><code>ml_program.global_load_const</code> (ml_program::GlobalLoadConstOp)</a></li><li><a href=#ml_programglobal_load_graph-ml_programgloballoadgraphop><code>ml_program.global_load_graph</code> (ml_program::GlobalLoadGraphOp)</a></li><li><a href=#ml_programglobal_store-ml_programglobalstoreop><code>ml_program.global_store</code> (ml_program::GlobalStoreOp)</a></li><li><a href=#ml_programglobal_store_graph-ml_programglobalstoregraphop><code>ml_program.global_store_graph</code> (ml_program::GlobalStoreGraphOp)</a></li><li><a href=#ml_programoutput-ml_programoutputop><code>ml_program.output</code> (ml_program::OutputOp)</a></li><li><a href=#ml_programreturn-ml_programreturnop><code>ml_program.return</code> (ml_program::ReturnOp)</a></li><li><a href=#ml_programsubgraph-ml_programsubgraphop><code>ml_program.subgraph</code> (ml_program::SubgraphOp)</a></li><li><a href=#ml_programtoken-ml_programtokenop><code>ml_program.token</code> (ml_program::TokenOp)</a></li></ul></li><li><a href=#attributes-8>Attributes</a><ul><li><a href=#externattr>ExternAttr</a></li></ul></li><li><a href=#types>Types</a><ul><li><a href=#tokentype>TokenType</a></li></ul></li></ul></nav><h2 id=operations>Operations <a class=headline-hash href=#operations>¶</a></h2><p><a href=https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Dialect/MLProgram/IR/MLProgramOps.td>source</a></p><h3 id=ml_programfunc-ml_programfuncop><code>ml_program.func</code> (ml_program::FuncOp) <a class=headline-hash href=#ml_programfunc-ml_programfuncop>¶</a></h3><p><em>Function containing a single <code>SSACFG</code> region</em></p><p>This simple function container represents callables in an ML program where the body is an <code>SSACFG</code> region. It must be terminated by a <code>return</code> op which yields values with the same arity and types as the <code>FunctionType</code> results of the containing <code>func</code>.</p><p>This op is a <code>Symbol</code> but does not introduce a new <code>SymbolTable</code>. As such, it cannot represent nested symbols.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl>ml_program<span class=p>.</span><span class=kt>func</span> private <span class=nf>@some_extern</span><span class=p>(</span><span class=k>i32</span><span class=p>)</span> <span class=p>-></span> <span class=k>i32</span> </span></span><span class=line><span class=cl>ml_program<span class=p>.</span><span class=kt>func</span> <span class=nf>@compute</span><span class=p>(</span><span class=nv>%arg0</span> <span class=p>:</span> <span class=k>i32</span><span class=p>)</span> <span class=p>-></span> <span class=k>i32</span> <span class=p>{</span> </span></span><span class=line><span class=cl> ml_program<span class=p>.</span><span class=kt>return</span> <span class=nv>%arg0</span> <span class=p>:</span> <span class=k>i32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>Traits: <code>IsolatedFromAbove</code></p><p>Interfaces: <code>CallableOpInterface</code>, <code>FunctionOpInterface</code>, <code>RegionKindInterface</code>, <code>Symbol</code></p><h4 id=attributes>Attributes: <a class=headline-hash href=#attributes>¶</a></h4><table><tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr><tr><td><code>sym_name</code></td><td>::mlir::StringAttr</td><td>string attribute</td></tr><tr><td><code>function_type</code></td><td>::mlir::TypeAttr</td><td>type attribute of function type</td></tr><tr><td><code>arg_attrs</code></td><td>::mlir::ArrayAttr</td><td>Array of dictionary attributes</td></tr><tr><td><code>res_attrs</code></td><td>::mlir::ArrayAttr</td><td>Array of dictionary attributes</td></tr><tr><td><code>sym_visibility</code></td><td>::mlir::StringAttr</td><td>string attribute</td></tr></table><h3 id=ml_programglobal-ml_programglobalop><code>ml_program.global</code> (ml_program::GlobalOp) <a class=headline-hash href=#ml_programglobal-ml_programglobalop>¶</a></h3><p><em>Module level declaration of a global variable</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `ml_program.global` custom<SymbolVisibility>($sym_visibility) (`mutable` $is_mutable^)? $sym_name `` custom<TypedInitialValue>($type, $value) attr-dict </code></pre><p>Declares a named global variable (or constant).</p><p>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).</p><p>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).</p><p>Examples:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=c>// Constant global. </span></span></span><span class=line><span class=cl><span class=c></span>ml_program<span class=p>.</span>global <span class=nf>@foobar</span><span class=p>(</span>dense<span class=p><</span><span class=m>4</span><span class=p>></span> <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>4x</span><span class=k>i32</span><span class=p>>)</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>?x</span><span class=k>i32</span><span class=p>></span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl><span class=c>// Constant with external linkage. </span></span></span><span class=line><span class=cl><span class=c></span>ml_program<span class=p>.</span>global mutable <span class=nf>@foobar</span><span class=p>(</span><span class=nv>#ml_program.extern</span><span class=p><</span><span class=kt>tensor</span><span class=p><</span><span class=m>4x</span><span class=k>i32</span><span class=p>>>)</span> </span></span><span class=line><span class=cl> <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>?x</span><span class=k>i32</span><span class=p>></span> </span></span><span class=line><span class=cl> </span></span><span class=line><span class=cl><span class=c>// Mutable global with an undefined initial value. </span></span></span><span class=line><span class=cl><span class=c></span>ml_program<span class=p>.</span>global mutable <span class=nf>@foobar</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>?x</span><span class=k>i32</span><span class=p>></span> </span></span></code></pre></div><p>Interfaces: <code>Symbol</code></p><h4 id=attributes-1>Attributes: <a class=headline-hash href=#attributes-1>¶</a></h4><table><tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr><tr><td><code>sym_name</code></td><td>::mlir::StringAttr</td><td>string attribute</td></tr><tr><td><code>type</code></td><td>::mlir::TypeAttr</td><td>any type attribute</td></tr><tr><td><code>is_mutable</code></td><td>::mlir::UnitAttr</td><td>unit attribute</td></tr><tr><td><code>value</code></td><td>::mlir::Attribute</td><td>any attribute</td></tr><tr><td><code>sym_visibility</code></td><td>::mlir::StringAttr</td><td>string attribute</td></tr></table><h3 id=ml_programglobal_load-ml_programgloballoadop><code>ml_program.global_load</code> (ml_program::GlobalLoadOp) <a class=headline-hash href=#ml_programglobal_load-ml_programgloballoadop>¶</a></h3><p><em>Direct load of a mutable value from a global</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `ml_program.global_load` $global `:` type($result) attr-dict </code></pre><p>Performs a non-atomic, non-volatile, non-synchronized load from a global that may be mutable.</p><p>It is fully expected that these constraints are not suitable for all situations, and alternative ops should be defined and used for more advanced cases.</p><p>This op is side effecting and may not be valid to use in graph regions without additional consideration to evaluation order constraints. See <code>global_load_graph</code> for op which allows for explicit ordering constraints.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%0</span> <span class=p>=</span> ml_program<span class=p>.</span>global_load <span class=nf>@foobar</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>?x</span><span class=k>i32</span><span class=p>></span> </span></span></code></pre></div><p>Interfaces: <code>OpAsmOpInterface</code>, <code>SymbolUserOpInterface</code></p><h4 id=attributes-2>Attributes: <a class=headline-hash href=#attributes-2>¶</a></h4><table><tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr><tr><td><code>global</code></td><td>::mlir::SymbolRefAttr</td><td>symbol reference attribute</td></tr></table><h4 id=results>Results: <a class=headline-hash href=#results>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>result</code></td><td>any type</td></tr></tbody></table><h3 id=ml_programglobal_load_const-ml_programgloballoadconstop><code>ml_program.global_load_const</code> (ml_program::GlobalLoadConstOp) <a class=headline-hash href=#ml_programglobal_load_const-ml_programgloballoadconstop>¶</a></h3><p><em>Direct load a constant value from a global</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `ml_program.global_load_const` $global `:` type($result) attr-dict </code></pre><p>Loads a constant (immutable) value from a global directly by symbol.</p><p>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.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%0</span> <span class=p>=</span> ml_program<span class=p>.</span>global_load_const <span class=nf>@foobar</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>?x</span><span class=k>i32</span><span class=p>></span> </span></span></code></pre></div><p>Traits: <code>AlwaysSpeculatableImplTrait</code></p><p>Interfaces: <code>ConditionallySpeculatable</code>, <code>NoMemoryEffect (MemoryEffectOpInterface)</code>, <code>OpAsmOpInterface</code>, <code>SymbolUserOpInterface</code></p><p>Effects: <code>MemoryEffects::Effect{}</code></p><h4 id=attributes-3>Attributes: <a class=headline-hash href=#attributes-3>¶</a></h4><table><tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr><tr><td><code>global</code></td><td>::mlir::SymbolRefAttr</td><td>symbol reference attribute</td></tr></table><h4 id=results-1>Results: <a class=headline-hash href=#results-1>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>result</code></td><td>any type</td></tr></tbody></table><h3 id=ml_programglobal_load_graph-ml_programgloballoadgraphop><code>ml_program.global_load_graph</code> (ml_program::GlobalLoadGraphOp) <a class=headline-hash href=#ml_programglobal_load_graph-ml_programgloballoadgraphop>¶</a></h3><p><em>Direct load of a mutable value from a global in Graph region</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `ml_program.global_load_graph` $global `` custom<TokenOrdering>($consumeTokens, type($produceToken)) `:` type($result) attr-dict </code></pre><p>Performs a non-atomic, non-volatile, non-synchronized load from a global that may be mutable.</p><p>It is fully expected that these constraints are not suitable for all situations, and alternative ops should be defined and used for more advanced cases.</p><p>This op is side effecting and may not be valid to use in graph regions without additional consideration to evaluation order constraints.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%0</span><span class=p>,</span> <span class=nv>%cstr</span> <span class=p>=</span> ml_program<span class=p>.</span>global_load_graph <span class=nf>@foobar</span> </span></span><span class=line><span class=cl> ordering <span class=p>(</span><span class=nv>%token</span> <span class=p>-></span> <span class=p>!</span>ml_program<span class=p>.</span>token<span class=p>)</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>?x</span><span class=k>i32</span><span class=p>></span> </span></span></code></pre></div><p>Interfaces: <code>SymbolUserOpInterface</code></p><h4 id=attributes-4>Attributes: <a class=headline-hash href=#attributes-4>¶</a></h4><table><tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr><tr><td><code>global</code></td><td>::mlir::SymbolRefAttr</td><td>symbol reference attribute</td></tr></table><h4 id=operands>Operands: <a class=headline-hash href=#operands>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>consumeTokens</code></td><td>variadic of Token for establishing execution ordering in a graph</td></tr></tbody></table><h4 id=results-2>Results: <a class=headline-hash href=#results-2>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>result</code></td><td>any type</td></tr><tr><td style=text-align:center><code>produceToken</code></td><td>Token for establishing execution ordering in a graph</td></tr></tbody></table><h3 id=ml_programglobal_store-ml_programglobalstoreop><code>ml_program.global_store</code> (ml_program::GlobalStoreOp) <a class=headline-hash href=#ml_programglobal_store-ml_programglobalstoreop>¶</a></h3><p><em>Direct store of a value into a mutable global</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `ml_program.global_store` $global `=` $value `:` type($value) attr-dict </code></pre><p>Performs a non-atomic, non-volatile, non-synchronized store to a mutable global.</p><p>It is fully expected that these constraints are not suitable for all situations, and alternative ops should be defined and used for more advanced cases.</p><p>This op is side effecting and may not be valid to use in graph regions without additional consideration to evaluation order constraints. See <code>global_store_graph</code> for op which allows for explicit ordering constraints.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl>ml_program<span class=p>.</span>global_store <span class=nf>@foobar</span> <span class=p>=</span> <span class=nv>%0</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>?x</span><span class=k>i32</span><span class=p>></span> </span></span></code></pre></div><p>Interfaces: <code>SymbolUserOpInterface</code></p><h4 id=attributes-5>Attributes: <a class=headline-hash href=#attributes-5>¶</a></h4><table><tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr><tr><td><code>global</code></td><td>::mlir::SymbolRefAttr</td><td>symbol reference attribute</td></tr></table><h4 id=operands-1>Operands: <a class=headline-hash href=#operands-1>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>value</code></td><td>any type</td></tr></tbody></table><h3 id=ml_programglobal_store_graph-ml_programglobalstoregraphop><code>ml_program.global_store_graph</code> (ml_program::GlobalStoreGraphOp) <a class=headline-hash href=#ml_programglobal_store_graph-ml_programglobalstoregraphop>¶</a></h3><p><em>Direct store of a value into a mutable global</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `ml_program.global_store_graph` $global `=` $value `` custom<TokenOrdering>($consumeTokens, type($produceToken)) `:` type($value) attr-dict </code></pre><p>Performs a non-atomic, non-volatile, non-synchronized store to a mutable global.</p><p>It is fully expected that these constraints are not suitable for all situations, and alternative ops should be defined and used for more advanced cases.</p><p>This op is side effecting and may not be valid to use in graph regions without additional consideration to evaluation order constraints.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl><span class=nv>%token</span> <span class=p>=</span> ml_program<span class=p>.</span>global_store <span class=nf>@foobar</span> <span class=p>=</span> <span class=nv>%0</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>?x</span><span class=k>i32</span><span class=p>></span> </span></span><span class=line><span class=cl> ordering <span class=p>(</span><span class=nv>%in_token</span> <span class=p>-></span> <span class=p>!</span>ml_program<span class=p>.</span>token<span class=p>)</span> <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>?x</span><span class=k>i32</span><span class=p>></span> </span></span></code></pre></div><p>Interfaces: <code>SymbolUserOpInterface</code></p><h4 id=attributes-6>Attributes: <a class=headline-hash href=#attributes-6>¶</a></h4><table><tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr><tr><td><code>global</code></td><td>::mlir::SymbolRefAttr</td><td>symbol reference attribute</td></tr></table><h4 id=operands-2>Operands: <a class=headline-hash href=#operands-2>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>value</code></td><td>any type</td></tr><tr><td style=text-align:center><code>consumeTokens</code></td><td>variadic of Token for establishing execution ordering in a graph</td></tr></tbody></table><h4 id=results-3>Results: <a class=headline-hash href=#results-3>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>produceToken</code></td><td>Token for establishing execution ordering in a graph</td></tr></tbody></table><h3 id=ml_programoutput-ml_programoutputop><code>ml_program.output</code> (ml_program::OutputOp) <a class=headline-hash href=#ml_programoutput-ml_programoutputop>¶</a></h3><p><em>Outputs values from a subgraph function</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `ml_program.output` attr-dict ($operands^ `:` type($operands))? </code></pre><p>The <code>output</code> 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.</p><p>Traits: <code>AlwaysSpeculatableImplTrait</code>, <code>HasParent<SubgraphOp></code>, <code>ReturnLike</code>, <code>Terminator</code></p><p>Interfaces: <code>ConditionallySpeculatable</code>, <code>NoMemoryEffect (MemoryEffectOpInterface)</code>, <code>RegionBranchTerminatorOpInterface</code></p><p>Effects: <code>MemoryEffects::Effect{}</code></p><h4 id=operands-3>Operands: <a class=headline-hash href=#operands-3>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>operands</code></td><td>variadic of any type</td></tr></tbody></table><h3 id=ml_programreturn-ml_programreturnop><code>ml_program.return</code> (ml_program::ReturnOp) <a class=headline-hash href=#ml_programreturn-ml_programreturnop>¶</a></h3><p><em>Returns values from a <code>func</code> function</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `ml_program.return` attr-dict ($operands^ `:` type($operands))? </code></pre><p>The <code>return</code> operation terminates a <code>func</code> 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.</p><p>Traits: <code>AlwaysSpeculatableImplTrait</code>, <code>HasParent<FuncOp></code>, <code>ReturnLike</code>, <code>Terminator</code></p><p>Interfaces: <code>ConditionallySpeculatable</code>, <code>NoMemoryEffect (MemoryEffectOpInterface)</code>, <code>RegionBranchTerminatorOpInterface</code></p><p>Effects: <code>MemoryEffects::Effect{}</code></p><h4 id=operands-4>Operands: <a class=headline-hash href=#operands-4>¶</a></h4><table><thead><tr><th style=text-align:center>Operand</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>operands</code></td><td>variadic of any type</td></tr></tbody></table><h3 id=ml_programsubgraph-ml_programsubgraphop><code>ml_program.subgraph</code> (ml_program::SubgraphOp) <a class=headline-hash href=#ml_programsubgraph-ml_programsubgraphop>¶</a></h3><p><em>An function containing a single <code>Graph</code> region</em></p><p>This simple function container represents callables in an ML program where the body is a <code>Graph</code> region containing a single block. It must be terminated by an <code>output</code> op which yields values with the same arity and types as the <code>FunctionType</code> results of the containing <code>subgraph</code>.</p><p>This op is a <code>Symbol</code> but does not introduce a new <code>SymbolTable</code>. As such, it cannot represented nested symbols.</p><p>Example:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl>ml_program<span class=p>.</span>subgraph private <span class=nf>@some_extern</span><span class=p>(</span><span class=k>i32</span><span class=p>)</span> <span class=p>-></span> <span class=k>i32</span> </span></span><span class=line><span class=cl>ml_program<span class=p>.</span>subgraph <span class=nf>@compute</span><span class=p>(</span><span class=nv>%arg0</span> <span class=p>:</span> <span class=k>i32</span><span class=p>)</span> <span class=p>-></span> <span class=k>i32</span> <span class=p>{</span> </span></span><span class=line><span class=cl> ml_program<span class=p>.</span>output <span class=nv>%arg0</span> <span class=p>:</span> <span class=k>i32</span> </span></span><span class=line><span class=cl><span class=p>}</span> </span></span></code></pre></div><p>Traits: <code>HasOnlyGraphRegion</code>, <code>IsolatedFromAbove</code>, <code>SingleBlock</code></p><p>Interfaces: <code>CallableOpInterface</code>, <code>FunctionOpInterface</code>, <code>RegionKindInterface</code>, <code>Symbol</code></p><h4 id=attributes-7>Attributes: <a class=headline-hash href=#attributes-7>¶</a></h4><table><tr><th>Attribute</th><th>MLIR Type</th><th>Description</th></tr><tr><td><code>sym_name</code></td><td>::mlir::StringAttr</td><td>string attribute</td></tr><tr><td><code>function_type</code></td><td>::mlir::TypeAttr</td><td>type attribute of function type</td></tr><tr><td><code>arg_attrs</code></td><td>::mlir::ArrayAttr</td><td>Array of dictionary attributes</td></tr><tr><td><code>res_attrs</code></td><td>::mlir::ArrayAttr</td><td>Array of dictionary attributes</td></tr><tr><td><code>sym_visibility</code></td><td>::mlir::StringAttr</td><td>string attribute</td></tr></table><h3 id=ml_programtoken-ml_programtokenop><code>ml_program.token</code> (ml_program::TokenOp) <a class=headline-hash href=#ml_programtoken-ml_programtokenop>¶</a></h3><p><em>Produces a new token value</em></p><p>Syntax:</p><pre tabindex=0><code>operation ::= `ml_program.token` attr-dict </code></pre><p>Token values are used to chain side effecting ops in a graph so as to establish an execution order. This op produces a token.</p><p>Traits: <code>AlwaysSpeculatableImplTrait</code></p><p>Interfaces: <code>ConditionallySpeculatable</code>, <code>NoMemoryEffect (MemoryEffectOpInterface)</code></p><p>Effects: <code>MemoryEffects::Effect{}</code></p><h4 id=results-4>Results: <a class=headline-hash href=#results-4>¶</a></h4><table><thead><tr><th style=text-align:center>Result</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center><code>token</code></td><td>Token for establishing execution ordering in a graph</td></tr></tbody></table><h2 id=attributes-8>Attributes <a class=headline-hash href=#attributes-8>¶</a></h2><h3 id=externattr>ExternAttr <a class=headline-hash href=#externattr>¶</a></h3><p>Value used for a global signalling external resolution</p><p>Syntax:</p><pre tabindex=0><code>#ml_program.extern< ::mlir::Type # type > </code></pre><p>When used as the value for a GlobalOp, this indicates that the actual value should be resolved externally in an implementation defined manner. The <code>sym_name</code> of the global is the key for locating the value.</p><p>Examples:</p><div class=highlight><pre tabindex=0 class=chroma><code class=language-mlir data-lang=mlir><span class=line><span class=cl>extern <span class=p>:</span> <span class=kt>tensor</span><span class=p><</span><span class=m>4x</span><span class=k>i32</span><span class=p>></span> </span></span></code></pre></div><h4 id=parameters>Parameters: <a class=headline-hash href=#parameters>¶</a></h4><table><thead><tr><th style=text-align:center>Parameter</th><th style=text-align:center>C++ type</th><th>Description</th></tr></thead><tbody><tr><td style=text-align:center>type</td><td style=text-align:center><code>::mlir::Type</code></td><td></td></tr></tbody></table><h2 id=types>Types <a class=headline-hash href=#types>¶</a></h2><h3 id=tokentype>TokenType <a class=headline-hash href=#tokentype>¶</a></h3><p>Token for establishing execution ordering in a graph</p><p>Syntax: <code>!ml_program.token</code></p><div class=edit-meta><br></div><nav class=pagination><a class="nav nav-prev" href=https://mlir.llvm.org/docs/Dialects/Mesh/ title="'mesh' Dialect"><i class="fas fa-arrow-left" aria-hidden=true></i> Prev - 'mesh' Dialect</a> <a class="nav nav-next" href=https://mlir.llvm.org/docs/Dialects/MPI/ title="'mpi' Dialect">Next - 'mpi' Dialect <i class="fas fa-arrow-right" aria-hidden=true></i></a></nav><footer><p class=powered>Powered by <a href=https://gohugo.io>Hugo</a>. Theme by <a href=https://themes.gohugo.io/hugo-theme-techdoc/>TechDoc</a>. Designed by <a href=https://github.com/thingsym/hugo-theme-techdoc>Thingsym</a>.</p></footer></main><div class=sidebar><nav class=slide-menu><ul><li><a href=https://mlir.llvm.org/>Home</a></li><li><a href=https://mlir.llvm.org/users/>Users of MLIR</a></li><li><a href=https://mlir.llvm.org/pubs/>MLIR Related Publications</a></li><li><a href=https://mlir.llvm.org/talks/>Talks</a></li><li><a href=https://mlir.llvm.org/deprecation/>Deprecations & Current Refactoring</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/getting_started/>Getting Started<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/getting_started/ReportingIssues/>Reporting Issues</a></li><li><a href=https://mlir.llvm.org/getting_started/Debugging/>Debugging Tips</a></li><li><a href=https://mlir.llvm.org/getting_started/Faq/>FAQ</a></li><li><a href=https://mlir.llvm.org/getting_started/Contributing/>How to Contribute</a></li><li><a href=https://mlir.llvm.org/getting_started/DeveloperGuide/>Developer Guide</a></li><li><a href=https://mlir.llvm.org/getting_started/openprojects/>Open Projects</a></li><li><a href=https://mlir.llvm.org/getting_started/Glossary/>Glossary</a></li><li><a href=https://mlir.llvm.org/getting_started/TestingGuide/>Testing Guide</a></li></ul></li><li class="parent has-sub-menu"><a href=https://mlir.llvm.org/docs/>Code Documentation<span class="mark opened">-</span></a><ul class=sub-menu><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Bindings/>Bindings<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Bindings/Python/>MLIR Python Bindings</a></li></ul></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Tools/>Tools<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Tools/MLIRLSP/>MLIR : Language Server Protocol</a></li><li><a href=https://mlir.llvm.org/docs/Tools/mlir-reduce/>MLIR Reduce</a></li><li><a href=https://mlir.llvm.org/docs/Tools/mlir-rewrite/>mlir-rewrite</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/QuantPasses/></a></li><li><a href=https://mlir.llvm.org/docs/ActionTracing/>Action: Tracing and Debugging MLIR-based Compilers</a></li><li><a href=https://mlir.llvm.org/docs/BufferDeallocationInternals/>Buffer Deallocation - Internals</a></li><li><a href=https://mlir.llvm.org/docs/Bufferization/>Bufferization</a></li><li><a href=https://mlir.llvm.org/docs/DataLayout/>Data Layout Modeling</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/DefiningDialects/>Defining Dialects<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/DefiningDialects/Constraints/>Constraints</a></li><li><a href=https://mlir.llvm.org/docs/DefiningDialects/AttributesAndTypes/>Defining Dialect Attributes and Types</a></li><li><a href=https://mlir.llvm.org/docs/DefiningDialects/Operations/>Operation Definition Specification (ODS)</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/Diagnostics/>Diagnostic Infrastructure</a></li><li><a href=https://mlir.llvm.org/docs/DialectConversion/>Dialect Conversion</a></li><li class="parent has-sub-menu"><a href=https://mlir.llvm.org/docs/Dialects/>Dialects<span class="mark opened">-</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Dialects/DLTITransformOps/></a></li><li><a href=https://mlir.llvm.org/docs/Dialects/OpenACCDialect/>'acc' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Affine/>'affine' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/AMDGPU/>'amdgpu' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/AMX/>'amx' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ArithOps/>'arith' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ArmNeon/>'arm_neon' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ArmSVE/>'arm_sve' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ArmSME/>'ArmSME' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/AsyncDialect/>'async' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/BufferizationOps/>'bufferization' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ControlFlowDialect/>'cf' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ComplexOps/>'complex' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/DLTIDialect/>'dlti' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/EmitC/>'emitc' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Func/>'func' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/GPU/>'gpu' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/IndexOps/>'index' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/IRDL/>'irdl' Dialect</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Dialects/Linalg/>'linalg' Dialect<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Dialects/Linalg/OpDSL/>Linalg OpDSL</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/Dialects/LLVM/>'llvm' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/MathOps/>'math' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/MemRef/>'memref' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Mesh/>'mesh' Dialect</a></li><li class=active><a href=https://mlir.llvm.org/docs/Dialects/MLProgramOps/>'ml_program' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/MPI/>'mpi' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/NVGPU/>'nvgpu' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/NVVMDialect/>'nvvm' Dialect</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Dialects/OpenMPDialect/>'omp' Dialect<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Dialects/OpenMPDialect/ODS/>ODS Documentation</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/Dialects/PDLInterpOps/>'pdl_interp' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/PDLOps/>'pdl' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/PolynomialDialect/>'polynomial' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/PtrOps/>'ptr' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/QuantDialect/>'quant' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ROCDLDialect/>'rocdl' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/SCFDialect/>'scf' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/ShapeDialect/>'shape' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/SparseTensorOps/>'sparse_tensor' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/TensorOps/>'tensor' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/UBOps/>'ub' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/VCIXDialect/>'vcix' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Vector/>'vector' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/X86Vector/>'x86vector' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/XeGPU/>'xegpu' Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Builtin/>Builtin Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/MatchOpInterfaces/>OpInterface definitions</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/SPIR-V/>SPIR-V Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/TOSA/>Tensor Operator Set Architecture (TOSA) Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Dialects/Transform/>Transform Dialect</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/Interfaces/>Interfaces</a></li><li><a href=https://mlir.llvm.org/docs/TargetLLVMIR/>LLVM IR Target</a></li><li><a href=https://mlir.llvm.org/docs/BytecodeFormat/>MLIR Bytecode Format</a></li><li><a href=https://mlir.llvm.org/docs/CAPI/>MLIR C API</a></li><li><a href=https://mlir.llvm.org/docs/LangRef/>MLIR Language Reference</a></li><li><a href=https://mlir.llvm.org/docs/ReleaseNotes/>MLIR Release Notes</a></li><li><a href=https://mlir.llvm.org/docs/Canonicalization/>Operation Canonicalization</a></li><li><a href=https://mlir.llvm.org/docs/OwnershipBasedBufferDeallocation/>Ownership-based Buffer Deallocation</a></li><li><a href=https://mlir.llvm.org/docs/PassManagement/>Pass Infrastructure</a></li><li><a href=https://mlir.llvm.org/docs/Passes/>Passes</a></li><li><a href=https://mlir.llvm.org/docs/PatternRewriter/>Pattern Rewriting : Generic DAG-to-DAG Rewriting</a></li><li><a href=https://mlir.llvm.org/docs/PDLL/>PDLL - PDL Language</a></li><li><a href=https://mlir.llvm.org/docs/Quantization/>Quantization</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Rationale/>Rationale<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Rationale/RationaleGenericDAGRewriter/>Generic DAG Rewriter Infrastructure Rationale</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/RationaleLinalgDialect/>Linalg Dialect Rationale: The Case For Compiler-Friendly Custom Operations</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/Rationale/>MLIR Rationale</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/MLIRForGraphAlgorithms/>MLIR: Incremental Application to Graph Algorithms in ML Frameworks</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/RationaleSimplifiedPolyhedralForm/>MLIR: The case for a simplified polyhedral form</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/SideEffectsAndSpeculation/>Side Effects & Speculation</a></li><li><a href=https://mlir.llvm.org/docs/Rationale/UsageOfConst/>Usage of 'const' in MLIR, for core IR types</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/ShapeInference/>Shape Inference</a></li><li><a href=https://mlir.llvm.org/docs/SPIRVToLLVMDialectConversion/>SPIR-V Dialect to LLVM Dialect conversion manual</a></li><li><a href=https://mlir.llvm.org/docs/SymbolsAndSymbolTables/>Symbols and Symbol Tables</a></li><li><a href=https://mlir.llvm.org/docs/DeclarativeRewrites/>Table-driven Declarative Rewrite Rule (DRR)</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Traits/>Traits<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Traits/Broadcastable/>The `Broadcastable` Trait</a></li></ul></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Tutorials/>Tutorials<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Tutorials/CreatingADialect/>Creating a Dialect</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/QuickstartRewrites/>Quickstart tutorial to adding MLIR graph rewrite</a></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Tutorials/Toy/>Toy Tutorial<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-1/>Chapter 1: Toy Language and AST</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-2/>Chapter 2: Emitting Basic MLIR</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-3/>Chapter 3: High-level Language-Specific Analysis and Transformation</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-4/>Chapter 4: Enabling Generic Transformation with Interfaces</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-5/>Chapter 5: Partial Lowering to Lower-Level Dialects for Optimization</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-6/>Chapter 6: Lowering to LLVM and CodeGeneration</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/Toy/Ch-7/>Chapter 7: Adding a Composite Type to Toy</a></li></ul></li><li class=has-sub-menu><a href=https://mlir.llvm.org/docs/Tutorials/transform/>Transform Dialect Tutorial<span class="mark closed">+</span></a><ul class=sub-menu><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/Ch0/>Chapter 0: A Primer on “Structured” Linalg Operations</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/Ch1/>Chapter 1: Combining Existing Transformations</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/Ch2/>Chapter 2: Adding a Simple New Transformation Operation</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/Ch3/>Chapter 3: More than Simple Transform Operations</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/Ch4/>Chapter 4: Matching Payload with Transform Operations</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/transform/ChH/>Chapter H: Reproducing Halide Schedule</a></li></ul></li><li><a href=https://mlir.llvm.org/docs/Tutorials/UnderstandingTheIRStructure/>Understanding the IR Structure</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/MlirOpt/>Using `mlir-opt`</a></li><li><a href=https://mlir.llvm.org/docs/Tutorials/DataFlowAnalysis/>Writing DataFlow Analyses in MLIR</a></li></ul></li></ul></li></ul></nav><div class=sidebar-footer></div></div></div><a href=# id=backtothetop-fixed class=backtothetop data-backtothetop-duration=600 data-backtothetop-easing=easeOutQuart data-backtothetop-fixed-fadein=1000 data-backtothetop-fixed-fadeout=1000 data-backtothetop-fixed-bottom=10 data-backtothetop-fixed-right=20><span class="fa-layers fa-fw"><i class="fas fa-circle"></i> <i class="fas fa-arrow-circle-up"></i></span></a></div></body></html>