Also:
- cleans up some operand names for consistency
- remove the broadcast_dims attribute as it isn't used
- adds an IsNullAttr predicate which is needed to match optional clamp attributes on these kind of ops (needed to simplify some out of tree transforms on the new matmul op)
--
PiperOrigin-RevId: 246370576
Add ConstantOp's Op Definition Spec. Currently we don't use convertFromStorage in the generated patterns and so needed to add a few casts to support patterns restricted to ElementsAttrs and to compensate for old rules where we defined ConstantOp to have a ElementsAttr to simplify writing the pattern.
--
PiperOrigin-RevId: 246361555
This CL builds upon ftynse@'s Linalg dialect conversion (in examples/Linalg/Linalg1) and updates it to support buffers and the fully composed form of view and slice operations.
A new BufferSizeOp is introduced for the purpose of extracting the size information from a buffer.
This will be useful in a followup CL for an end-to-end LLVM execution path where mlir-cpu-runner will allocate a buffer.
--
PiperOrigin-RevId: 246358593
This CL adds a primitive tiling pass for Linalg.
The tiling pass uses the loopToOperandRangesMaps property which should be ideally Tablegen'd and in-class.
The tiling specification uses 0 as a convention to skip loops that should not be tiled.
Tiling proceeds in 3 steps, for each op:
1. Pad tile sizes with 0 to match the number of loops, this simplifies the implementation and avoids affine map manipulations to align dimensions.
2. Create loop ranges that represent the min/max/step by which to iterate. This should be later complemented by a range intersection to avoid the out-of-bounds case.
3. Map the loop ranges to view ranges in order to create subviews on which the op can be called.
Relevant utility and helper functions are added separately that support writing the transformation in a declarative fashion.
Simplifying assumptions are made for now on the views and the ranges that are constructed
in the function and are not passed as function arguments. This restriction will be lifted
in the future.
--
PiperOrigin-RevId: 246124419
Simple mechanism to allow specifying arbitrary function declarations. The modelling will not cover all cases so allow a means for users to declare a method function that they will define in their C++ files. The goal is to allow full C++ flexibility as the goal is to cover cases not modelled.
--
PiperOrigin-RevId: 245889819
This CL implements the previously unsupported parsing for Range, View and Slice operations.
A pass is introduced to lower to the LLVM.
Tests are moved out of C++ land and into mlir/test/Examples.
This allows better fitting within standard developer workflows.
--
PiperOrigin-RevId: 245796600
Enables specifying the documentation for dialect along with defining the ops of the dialect. The doc generator will be expanded in follow up to emit the documentation in the autogenerated files. This is precursor to allowing common base for all ops in a dialect.
All the dialect documentation is super sparse and just added as placeholder.
I was tempted (and started) to move ConstantOp to be generated too, but this will be easier post adding extra_methods, so deferring until then.
--
PiperOrigin-RevId: 245759984
Define a new dialect related to GPU kernels. Currently, it only contains a
single operation for launching a kernel on a three-dimensional grid of thread
blocks, following a model similar to that of CUDA. In particular, the body of
the kernel contains operations executed by each thread and uses region
arguments to accept thread and block identifiers (similar to how the loop body
region accepts the induction value).
--
PiperOrigin-RevId: 245713728
Instead, fold such operations. This way callers don't need to conditionally create cast operations depending on if a value already has the target type.
Also, introduce areCastCompatible to allow cast users to verify that the generated op will be valid before creating the operation.
TESTED with unit tests
--
PiperOrigin-RevId: 245606133
none-type ::= `none`
The `none` type is a unit type, i.e. a type with exactly one possible value, where its value does not have a defined dynamic representation.
--
PiperOrigin-RevId: 245599248
Add a tutorial document explaining how to define a conversion from the Linalg
dialect to the LLVM IR dialect, bypassing the Affine dialect. It defines a
dynamic representation for a range and a view for the sake of type conversion.
Operation conversion becomes straightforward given the dynamic representation.
The code in the tutorial is better structured and better document that what we
currently have in the example, which will be updated separately.
--
PiperOrigin-RevId: 245498394
Since SDBM expressions are a subset of affine expressions, they can be
converted to affine expressions in a straightforward way. The inverse
conversion may fail when the affine expression is not an SDBM. Implement the
inverse convresion assuming affine expressions are simplified and
canonicalizied, detect subtractive and multiplicative forms of the stripe
operation.
--
PiperOrigin-RevId: 245494735
The parser currently expects region arguments to have a fixed, known type when
the %-name of the region argument is parsed. This may not necessarily be the
case, for example, if the region argument types are the same as the operand
types, located at the end of the operation. Furthermore, the parser currently
stores the values for region arguments internally and attaches them to the next
parsed region implicitly. This makes it impossible to attach some of the
arguments to one region and some other arguments to another region if the
regions are not textually interleaved with operation arguments.
Provide `OpAsmParser::parseRegionArgument` that parses an SSA identifier and
delays its type assignment until the region is parsed, similarly to operands.
Update `OpAsmParser::parseRegion` to accept a list of pre-parsed SSA
identifiers and a list of types instead of using SSA identifiers stored in the
parser.
--
PiperOrigin-RevId: 245491133
Striped difference-bound matrix expressions are a subset of affine expressions
supporting low-complexity algorithms that can be useful for loop
transformations. This introduces the basic data data structures for building
such expressions and unique'ing them in a MLIRContext.
--
PiperOrigin-RevId: 245380206
Currently, this is limited to operations that give access to the special registers of
NVIDIA gpus that represent block and thread indices.
--
PiperOrigin-RevId: 245378632
Certain ops can have multiple variadic operands/results, e.g., `tf.DynamicStitch`.
Even if an op has only one variadic operand/result, it is not necessarily the
very last one, e.g., `tf.RaggedGather`. This CL enhances TableGen subsystem to be
able to represent such cases.
In order to deduce the operand/result value range for each variadic operand,
currently we only support variadic operands/results all of the same size.
So two new traits, `SameVariadicOperandSize` and `SameVariadicResultSize` are
introduced.
--
PiperOrigin-RevId: 245310628
A unit attribute is an attribute that represents a value of `unit` type. The
`unit` type allows only one value forming a singleton set. This attribute value
is used to represent attributes that only have meaning from their existence.
One example of such an attribute could be the `swift.self` attribute. This attribute indicates that a function parameter is the self/context
parameter. It could be represented as a boolean attribute(true or false), but a
value of false doesn't really bring any value. The parameter either is the
self/context or it isn't.
```mlir {.mlir}
// A unit attribute defined with the `unit` value specifier.
func @verbose_form(i1 {unitAttr : unit})
// A unit attribute can also be defined without the `unit` value specifier.
func @simple_form(i1 {unitAttr})
```
--
PiperOrigin-RevId: 245254045
Add member functions for Regions to query if another Region is a ancestor. The
implementation is naive and traverses all parent regions performing one-to-one
comparisons. As a side effect, this introduces `getContainingRegion` function
for Operations and Values to return the Region in which they are defined, and
for Regions to return the "parent" region if any.
--
PiperOrigin-RevId: 245057980
Similar to MultiOperandTraitBase, this can simply the implementation of
NResults, AtLeastNResults, and VariadicResults.
--
PiperOrigin-RevId: 245052333
The -all_load flag will apply to all future libraries added on the command line,
while the -force_load flag only applies to the next library. Using the latter
allows to selectively force load the specific libraries we want.
--
PiperOrigin-RevId: 244949770
This CL adds linalg.dot, linalg.matvec and linalg.matmul ops with the proper roundtripping test. These are the first LinalgOp that operate on views and that will lower to library calls.
Linalg ops exhibit some common properties and behavior that are modeled with Traits.
A LinalgOp is defined as a generic Op that operates on input and output views (passed as operands) and has the following properties:
1. a number of input and outputs captured by the `NInputsAndOutputs` trait.
2. a list of ranks for each operand captured by the `ViewRanks` trait.
3. a set of parallel, reduction and windowing loops captured by `NLoopTypes` trait.
These represent are a first set of generic properties that will enable the definition of generic linear algebra operations and the properties necessary for upcoming transformations.
--
PiperOrigin-RevId: 244912754
Extract common code from getAffineSymbolExpr and getAffineConstantExpr into a
utility function safeGetOrCreate, similarly to the existing overloads for sets
and maps. The position in the vector is used as indexing key. NFC.
--
PiperOrigin-RevId: 244820859
LLVM Orc JIT changed the API for DynamicLibrarySearchGenerator::
GetForCurrentProcess to only take one value of the DataLayout that it actually
uses instead of the whole data layout. Update MLIR ExecutionEngine call to
this function accordingly.
--
PiperOrigin-RevId: 244820235
Note that I broke this out as a separate pass because intermediate transformations often produce qcast/dcast ops that are integral to the transformation, and it is typical to want to lower any remaining, unmatched casts at the end of quantization. If this flexibility ends up not being needed, they can be collapsed into the same pass. This is included in the same cpp file because all of the math ops will need to defer to emitting quantize/dequantize logic for cases that they cannot be fully lowered to fixed-point math.
Also, the new convertistof op needs to be evaluated for inclusion in StandardOps.
--
PiperOrigin-RevId: 244768679
During the pattern rewrite, if the function is changed, i.e. ops created,
deleted or swapped, the pattern rewriter needs to re-scan the function entirely
and apply the patterns again, so the patterns whose root ops have been popped
out from the working list nor an immediate users of the changed ops can be
reconsidered.
A command line flag is added to set the max number of iterations rescanning the
function for pattern match. If the rewrite doesn' converge after this number,
this compiling will continue and the result can be sub-optimal.
One unit test is updated because this change fixed the missing optimization opportunities.
--
PiperOrigin-RevId: 244754190
An op can have multiple results. Being explicit that we are binding to the
whole op instead of one of the results. A way to bind to a specific result
is yet to come.
--
PiperOrigin-RevId: 244741137
Both cOp and tAttr were used to perform some native C++ code expression.
Unifying them simplifies the concepts and reduces cognitive burden.
--
PiperOrigin-RevId: 244731946
This allows accessing those bound source ops in result patterns, which can be
useful for invoking native C++ op creation.
We bind the op entirely here because ops can have multiple results. Design a
approach to bind to a specific result is not the concern of this commit.
--
PiperOrigin-RevId: 244724750
The per-layer format is now like:
!quant.uniform<i8<-8:7>:f32, 9.987200e-01:127>
and per-axis is:
!quant.uniform<i8:f32:1, {2.0e+2,0.99872:120}>
I used the following sed script to update the unit tests (invoked with commands like `sed -i -r -f fix_quant.sed $(find . -name '*.mlir')`).
---
# Per-layer
s|\!quant<"uniform\[([iu][0-9]+):([fb]+[0-9]+)\]\{([^\}]+)\}\s*">|!quant.uniform<\1:\2, \3>|g
s|\!quant<"uniform\[([iu][0-9]+)\(([^\)]+)\):([fb]+[0-9]+)\]\{([^\}]+)\}\s*">|!quant.uniform<\1<\2>:\3, \4>|g
# Per-axis
s|\!quant<"uniform\[([iu][0-9]+):([fb]+[0-9]+)(:[0-9]+)?\]\{([^\}]+)\}\s*">|!quant.uniform<\1:\2\3, {\4}>|g
s|\!quant<"uniform\[([iu][0-9]+)\(([^\)]+)\):([fb]+[0-9]+)(:[0-9]+)?\]\{([^\}]+)\}\s*">|!quant.uniform<\1<\2>:\3\4, {\5}>|g
---
I fixed up the one file of error cases manually.
Since this is a one time syntax fix, I am not persisting the script anywhere.
--
PiperOrigin-RevId: 244425331
This CL adds a linalg.slice op with the proper roundtripping test.
A slice op allows taking subviews that may be rank-reducing (if some indexing is of index type) or not (if all indexings are of linalg.range type).
A slice must be constructed directly from a base view (no chains of slices may exist in the IR). Helper functions that fold will be provided for construction if/when necessary.
This also renames base_view to view.
--
PiperOrigin-RevId: 244406827
This CL adds a linalg.view<?x?xf32> type and base_view op with the proper roundtripping test. The parser will be improved in a subsequent CL once portions of the mlir::Parser are exposed.
For now this only supports dynamic views, static views will be introduced at a later time when they are needed.
--
PiperOrigin-RevId: 244374180
This also does the following:
- Removes the poc POT add implementation in favor of a version that does not rescale.
- Adds a handful of FxpMathOps which are needed (these are for comment and we may want to move them to the StandardOps dialect).
- Adds a canonicalizer to the StorageCastOp, which removes some cruft once conversions have been done.
- Adds a couple of predicates to OpBase.
--
PiperOrigin-RevId: 244287706
This CL starts implementing a Linalg dialect with the objective of supporting
optimizing compilation of loops and library calls for a subset of common linear
algebra operations.
This CL starts by simply adding a linalg.range type and an operation with the
proper roundtripping test.
--
PiperOrigin-RevId: 244189468
This CL also moved the UniformSupport.cpp and FakeQuantSupport.cpp into utils because they are not really the core of the IR.
--
PiperOrigin-RevId: 244001666
The description of the backward slice analysis behavior describes what would happen when creating a backward slice from node 9, not 8.
--
PiperOrigin-RevId: 243876599
For ops with the SameValueType trait, we generate a builder without requiring
result type; we get the result type from the operand. However, if the operand
is variadic, we need to index into the first value in the pack.
--
PiperOrigin-RevId: 243866647
other characters within the <>'s now that we can. This will allow quantized
types to use the pretty syntax (among others) after a few changes.
--
PiperOrigin-RevId: 243521268
There are no empty lines in output for three of these directives so removed
them and replaced the remaining one with 'CHECK-NOT:' as otherwise it is
failing with the following error.
error: found 'CHECK-EMPTY' without previous 'CHECK: line
TESTED = n/a
PiperOrigin-RevId: 243288605
Now, op attribute names don't have '.' in their names so the special handling for it
can be removed. Attributes for functions still have dialect prefix with '.' as separator but TableGen does not deal with functions.
TESTED with existing unit tests
--
PiperOrigin-RevId: 243287462
Iterators for a `llvm::DenseMap` can be invalidated when an insertion occurs.
In Pattern's `collectBoundArguments()`, we recursively handle all nested DAG
nodes and grow the the `RecordOperatorMap`, while retaining a reference.
This can cause the reference to be invalid and the program to behave randomly.
Allocate each `Operator` object specifically to solve this issue.
Also, `llvm::DenseMap` is a great way to map pointers to pointers, or map
other small types to each other. This avoids placing the `Operator` object
directly into the map.
--
PiperOrigin-RevId: 243281486
This CL changes various predicates and rewrite rules to use $-placeholders and
`tgfmt` as the driver for substitution. This will make the predicates and rewrite
rules more consistent regarding their arguments and more readable.
--
PiperOrigin-RevId: 243250739
Currently predicates are written with positional placeholders `{N}` and rely on
`formatv` as the engine to do substitution. The problem with this approach is that
the definitions of those positional placeholders are not consistent; they are
entirely up to the defining predicate of question. For example, `{0}` in various
attribute constraints is used to mean the attribute, while it is used to main the
builder for certain attribute transformations. This can become very confusing.
This CL introduces `tgfmt` as a new mechanism to better support for predicate and
rewrite rule specification. Instead of entirely relying on positional placeholders,
`tgfmt` support both positional and special placeholders. The former is used for
DAG operands. The latter, including $_builder, $_op, $_self, are used as special
"hooks" to entities in the context. With this, the predicate and rewrite rules
specification can be more consistent is more readable.
--
PiperOrigin-RevId: 243249671
Recently a default implementation for `match()` was provided (cl/242285885), but the class documentation wasn't updated appropriately.
--
PiperOrigin-RevId: 243128738
This allows client to be able to reuse the same logic to setup a module
for the ExecutionEngine without instanciating one. One use case is running
the optimization pipeline but not JIT-ing.
--
PiperOrigin-RevId: 242614380
When an op in the source pattern specifies more arguments than its definition, we
will have out-of-bound query for op arguments from the definition. That will cause
crashes. This change fixes it.
--
PiperOrigin-RevId: 242548415
TensorContractionBase has become too unwieldy with all the CRTP manipulation once less trivial transformations are implemented.
This CL drops CRTP for inheritance and uses the same name comparison trick to figure out what to cast into.
As a byproduct, all the -inl.h files disappear.
To maintain the separation between directories, a LINALG_STEP variable is introduced
--
PiperOrigin-RevId: 242546977
This adds parsing, printing and some folding/canonicalization.
Also extends rewriting of subi %0, %0 to handle vectors and tensors.
--
PiperOrigin-RevId: 242448164
This dialect does not have a global constructor and has to be registered
manually in `main`. Also fix the way it is exercised in the test.
--
PiperOrigin-RevId: 242434886
For some reason, the OSS build on macOS was not happy with the initialization
syntax and was attempting to call a copy constructor. Hotfix it to use a
different syntax pending further investigation.
--
PiperOrigin-RevId: 242432634
This is only teaching the LLVM converter to propagate the attribute onto
the function type. MLIR will not recognize this arguments, so it would only
be useful when calling for example `printf` with the same arguments across
a module. Since varargs is part of the ABI lowering, this is not NFC.
--
PiperOrigin-RevId: 242382427
making the IR dumps much nicer.
This is part 2/3 of the path to making dialect types more nice. Part 3/3 will
slightly generalize the set of characters allowed in pretty types and make it
more principled.
--
PiperOrigin-RevId: 242249955
restricted grammar. This will make certain common types much easier to read.
This is part tensorflow/mlir#1 of 2, which allows us to accept the new syntax. Part 2 will
change the asmprinter to automatically use it when appropriate, which will
require updating a bunch of tests.
This is motivated by the EuroLLVM tutorial and cleaning up the LLVM dialect aesthetics a bit more.
--
PiperOrigin-RevId: 242234821
Remove undesigned/unimplemented operations: reshape and view.
Add new LangRefDeletions.md file in /experimental to store things removed from public LangRef.md
PiperOrigin-RevId: 242230200
* dyn_cast_or_null
- This will first check if the operation is null before trying to 'dyn_cast':
Value *v = ...;
if (auto forOp = dyn_cast_or_null<AffineForOp>(v->getDefiningOp()))
...
* isa_nonnull
- This will first check if the pointer is null before trying to 'isa':
Value *v = ...;
if (isa_nonnull<AffineForOp>(v->getDefiningOp());
...
--
PiperOrigin-RevId: 242171343
Use MLIR's ExecutionEngine to demonstrate how one can implement a simple
JIT-compiler and executor after fully lowering the Linalg dialect to the LLVM
IR dialect, using the direct conversion (not going through standard
loads/stores).
--
PiperOrigin-RevId: 242127690
The existing implementation of the ExecutionEngine unconditionally runs a list
of "default" MLIR passes on the module upon creation. These passes include,
among others, dialect conversions from affine to standard and from standard to
LLVM IR dialects. In some cases, these conversions might have been performed
before ExecutionEngine is created. More advanced use cases may be performing
additional transformations that the "default" passes will conflict with.
Provide an overload for ExecutionEngine::create that takes a PassManager
configured with the passes to run on the module. If it is not provided, do not
run any passes. The engine will not be created if the input module, after the
pass manager, has any other dialect than the LLVM IR dialect.
--
PiperOrigin-RevId: 242127393
To support automatically constraint composition of ArrayAttr, a new
predicate combiner, Concat, is introduced. It prepends a prefix and
appends a postfix to a child predicate's final predicate string.
--
PiperOrigin-RevId: 242121186
This CL adds declarative tiling support in the linalg dialect by providing:
1. loop tiling on linalg ops by simply calling into mlir::tile
2. view tiling on linalg ops by:
a. computing the subview between for each tile dimension based on the loop tile size and the mapping of loops to operand ranges.
b. declaring that the tiled form of a tensorcontraction is the same tensorcontraction on subviews, which essentially gives us a recursive form.
Point 2.b is potentially subject to change in the future.
--
PiperOrigin-RevId: 242058658
This CL adds the last bit to convert from linalg.LoadOp and linalg.StoreOp to the affine dialect, as well as a unit test to exercise the conversion.
--
PiperOrigin-RevId: 242045826