Commit Graph

11893 Commits

Author SHA1 Message Date
Matthias Springer c66303c287 [mlir][sparse] Switch to One-Shot Bufferize
This change removes the partial bufferization passes from the sparse compilation pipeline and replaces them with One-Shot Bufferize. One-Shot Analysis (and TensorCopyInsertion) is used to resolve all out-of-place bufferizations, dense and sparse. Dense ops are then bufferized with BufferizableOpInterface. Sparse ops are still bufferized in the Sparsification pass.

Details:
* Dense allocations are automatically deallocated, unless they are yielded from a block. (In that case the alloc would leak.) All test cases are modified accordingly. E.g., some funcs now have an "out" tensor argument that is returned from the function. (That way, the allocation happens at the call site.)
* Sparse allocations are *not* automatically deallocated. They must be "released" manually. (No change, this will be addressed in a future change.)
* Sparse tensor copies are not supported yet. (Future change)
* Sparsification no longer has to consider inplacability. If necessary, allocations and/or copies are inserted during TensorCopyInsertion. All tensors are inplaceable by the time Sparsification is running. Instead of marking a tensor as "not inplaceable", it can be marked as "not writable", which will trigger an allocation and/or copy during TensorCopyInsertion.

Differential Revision: https://reviews.llvm.org/D129356
2022-07-14 09:52:48 +02:00
Kazu Hirata c27d815249 [mlir] Use value instead of getValue (NFC) 2022-07-14 00:19:59 -07:00
Manish Gupta f7d42d5149 [mlir][NVGPU] Verifiers for nvgpu.mma.sync Op
- Adds verification for `nvgpu.mma.sync` op
- Adds tests to `mlir/test/Dialect/NVGPU/invalid.mlir`
- `nvgpu.mma.sync` verifier caught a bug and triggered a failure in m16n8k4_tf32_f32 variant in `mlir/test/Conversion/NVGPUToNVVM/nvgpu-to-nvvm.mlir`
     - The output shape of vector holding thread-level accumulators was inconsistent  and fixed in this change

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D129400
2022-07-13 18:57:07 +00:00
Benoit Jacob 6870a50f43 lowerParallel is also called on unit-size, one-sided reduction dims
See: https://gist.github.com/bjacob/d8be8ec7e70ed0be4b3a5794ced2a7e8

Differential Revision: https://reviews.llvm.org/D129096
2022-07-13 16:21:12 +00:00
Jacques Pienaar 69b6454fff [mlir] Plumb through default attribute populate for extensible dialect. 2022-07-13 09:05:04 -07:00
Nicolas Vasilache cd6e02eebc [mlir][Linalg] Retire TestLinalgCodegenStrategy pass.
This pass tests patterns that are already tested elsewhere by applying them in a semi-targeted
fashion using anchor function and op names.

From now on, targeted tests should use the transform dialect interpreter.

Differential Revision: https://reviews.llvm.org/D129627
2022-07-13 04:20:42 -07:00
Kazu Hirata 491d27013d [mlir] Use has_value instead of hasValue (NFC) 2022-07-13 00:57:02 -07:00
Adrian Kuegel aabfaf901b [mlir] Allow empty lists for DenseArrayAttr.
Differential Revision: https://reviews.llvm.org/D129552
2022-07-13 09:16:09 +02:00
Anlun Xu 033b9f21b0 [mlir][sparse]Replace redundant indices checks in sparse_tensor.conversion
Replace some redundant indices checks with the correct checks

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D129101
2022-07-12 21:04:31 -07:00
Thomas Raoux 5f8cefebd9 [mlir][vector] Fix crash in vector.reduction canonicalization
since vector.reduce support accumulator in all the cases remove the
assert assuming old definition.

Differential Revision: https://reviews.llvm.org/D129602
2022-07-12 23:15:30 +00:00
Thomas Raoux 8fe076ffe0 [mlir][VectorToLLVM] Fix bug in lowering of vector.reduce fmax/fmin
The lowering of fmax/fmin reduce was ignoring the optional accumulator.

Differential Revision: https://reviews.llvm.org/D129597
2022-07-12 22:03:39 +00:00
Jacques Pienaar 0db084d4c7 [mlir] Switch create to use NamedAttrList&&
Avoids needing the two parallel functions as NamedAttrList already takes care
of caching DictionaryAttr and implicitly can convert from either.

Differential Revision: https://reviews.llvm.org/D129527
2022-07-12 13:24:09 -07:00
Krzysztof Drewniak d6ef3d20b4 [mlir] Remove VectorToROCDL
Between issues such as
https://github.com/llvm/llvm-project/issues/56323, the fact that this
lowering (unlike the code in amdgpu-to-rocdl) does not correctly set
up bounds checks (and thus will cause page faults on reads that might
need to be padded instead), and that fixing these problems would,
essentially, involve replicating amdgpu-to-rocdl, remove
--vector-to-rocdl for being broken. In addition, the lowering does not
support many aspects of transfer_{read,write}, like supervectors, and
may not work correctly in their presence.

We (the MLIR-based convolution generator at AMD) do not use this
conversion pass, nor are we aware of any other clients.

Migration strategies:
- Use VectorToLLVM
- If buffer ops are particularly needed in your application, use
amdgpu.raw_buffer_{load,store}

A VectorToAMDGPU pass may be introduced in the future.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D129308
2022-07-12 15:21:22 +00:00
Alex Zinenko a5c802a429 [mlir] fold more eagerly in structured op splitting
Existing implementation of structured op splitting creates several
affine.apply and affine.min operations in its subshape computation.
As these shapes are further used in data slice extraction, this may lead
to slice shapes being dynamic even when the original shapes and the
splitting point are static. This is particularly visible when splitting
is combined with further subsetting transformations such as tiling. Use
composition and folding more aggressively in splitting to avoid this.

In particular, introduce a `createComposedAffineMin` function that the
affine map used in "min" with the maps used by any `affine.apply` that
may be feeding the operands to the "min". This enables production of
more static shapes. Also introduce a `createComposedFoldedAffineApply`
function that combines the existing `createComposedAffineApply` with
in-place folding to propagate constants produced by zero-input affine
maps. Using these when splitting allows the subsequent canonicalizer
pass to recover static shapes for structured ops.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D129379
2022-07-12 15:06:55 +00:00
Thomas Raoux 051b36ba28 [mlir][vector] Add accumulator operand to MultiDimReduce op
This allows vectorizing linalg reductions without changing the operation
order. Therefore this produce a valid vectorization even if operations
are not associative.

Differential Revision: https://reviews.llvm.org/D129535
2022-07-12 14:28:30 +00:00
Alex Zinenko 81b62f7feb [mlir] Handle linalg.index correctly in TilingInterface
The existing implementation of the TilingInterface for Linalg ops was not
modifying the `linalg.index` ops contained within other Linalg ops (they need
to be summed up with the values of respective tile loop induction variables),
which led to the interface-based tiling being incorrect for any Linalg op with
index semantics.

In the process, fix the function performing the index offsetting to use the
pattern rewriter API instead of RAUW as it is being called from patterns and
may mess up the internal state of the rewriter. Also rename the function to
clearly catch all uses.

Depends On D129365

Reviewed By: mravishankar

Differential Revision: https://reviews.llvm.org/D129366
2022-07-12 12:36:33 +00:00
Alex Zinenko e15b855e09 [mlir] Use semantically readable functions for transform op effects
A recent commit introduced helper functions with semantically meaningful names
to populate the lists of memory effects in transform ops, use them whenever
possible.

Depends On D129287

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D129365
2022-07-12 12:36:31 +00:00
Alex Zinenko 3963b4d0dc [mlir] Transform op for multitile size generation
Introduce a structured transform op that emits IR computing the multi-tile
sizes with requested parameters (target size and divisor) for the given
structured op. The sizes may fold to arithmetic constant operations when the
shape is constant. These operations may then be used to call the existing
tiling transformation with a single non-zero dynamic size (i.e. perform
strip-mining) for each of the dimensions separately, thus achieving multi-size
tiling with optional loop interchange. A separate test exercises the entire
script.

Depends On D129217

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D129287
2022-07-12 12:36:28 +00:00
Alex Zinenko 4e4a4c0576 [mlir] Allow Tile transform op to take dynamic sizes
Extend the definition of the Tile structured transform op to enable it
accepting handles to operations that produce tile sizes at runtime. This is
useful by itself and prepares for more advanced tiling strategies. Note that
the changes are relevant only to the transform dialect, the tiling
transformation itself already supports dynamic sizes.

Depends On D129216

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D129217
2022-07-12 12:21:54 +00:00
Alex Zinenko 80e17355cd [mlir] assorted fixes in transform dialect documentation
Various typos and formatting fixes that make the generated documentation
hard to follow.
2022-07-12 09:18:51 +00:00
Alex Zinenko 00d1a1a25f [mlir] Add ReplicateOp to the Transform dialect
This handle manipulation operation allows one to define a new handle that is
associated with a the same payload IR operations N times, where N can be driven
by the size of payload IR operation list associated with another handle. This
can be seen as a sort of broadcast that can be used to ensure the lists
associated with two handles have equal numbers of payload IR ops as expected by
many pairwise transform operations.

Introduce an additional "expensive" check that guards against consuming a
handle that is assocaited with the same payload IR operation more than once as
this is likely to lead to double-free or other undesired effects.

Depends On D129110

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D129216
2022-07-12 09:07:59 +00:00
jacquesguan 4d7d5c5f00 [mlir][Math] Support fold SqrtOp with constant dense.
This patch uses constFoldUnaryOpConditional to replace current folder in order to support constant dense.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D129459
2022-07-12 16:46:19 +08:00
Ulrich Weigand 3c4468e67f [mlir] XFAIL IR/elements-attr-interface.mlir on SystemZ
This is still failing as endianness of binary blob external
resources is still not handled correctly.
2022-07-12 09:37:19 +02:00
Ulrich Weigand de9a7260ac Read/write external resource alignment tag in little-endian
https://reviews.llvm.org/D126446 added support for encoding
binary blobs in MLIR assembly.  To enable cross-architecture
compatibility, these need to be encoded in little-endian format.

This patch is a first step in that direction by reading and
writing the alignment tag that those blobs are prefixed by
in little-endian format.  This fixes assertion failures in
several test cases on big-endian platforms.

The actual content of the blob is not yet handled here.

Differential Revision: https://reviews.llvm.org/D129483
2022-07-12 09:36:53 +02:00
Johannes Reifferscheid ad3a078745 Fix linalg.dot over boolean tensors.
dot is currently miscompiled for booleans (uses add instead of or).

Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D129292
2022-07-12 09:08:45 +02:00
River Riddle 7306dc91e0 [mlir] Add support for regex within `expected-*` diagnostics
This can be enabled by using a `-re` suffix when defining the expected line,
e.g. `expected-error-re`. This support is similar to what clang provides in its "expected"
diagnostic framework(e.g. the `-re` is also the same). The regex definitions themselves are
similar to  FileCheck in that regex blocks are specified within `{{` `}}` blocks.

Differential Revision: https://reviews.llvm.org/D129343
2022-07-11 21:01:30 -07:00
Christopher Bate 609c0e1b9b [mlir] Register linalg external TilingInterface models in InitAllDialects
Differential Revision: https://reviews.llvm.org/D129333
2022-07-11 15:54:37 -06:00
Aart Bik faa00c1313 [mlir][sparse] implement sparse2sparse reshaping (expand/collapse)
A previous revision implemented expand/collapse reshaping between
dense and sparse tensors for sparse2dense and dense2sparse since those
could use the "cheap" view reshape on the already materialized
dense tensor (at either the input or output side), and do some
reshuffling from or to sparse. The dense2dense case, as always,
is handled with a "cheap" view change.

This revision implements the sparse2sparse cases. Lacking any "view"
support on sparse tensors this operation necessarily has to perform
data reshuffling on both ends.

Tracker for improving this:
https://github.com/llvm/llvm-project/issues/56477

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D129416
2022-07-11 14:49:06 -07:00
George Petterson 4dc8cf3a86 Fix an issue with grouped conv2d op
Reviewed By: silvas

Differential Revision: https://reviews.llvm.org/D128880
2022-07-11 20:10:58 +00:00
Nirvedh f0cd538985 Revert "Fix an issue with grouped conv2d op"
This reverts commit 45ef20ca71.
2022-07-11 20:03:16 +00:00
George Petterson 45ef20ca71 Fix an issue with grouped conv2d op 2022-07-11 19:59:30 +00:00
Kai Sasaki 7769505ae9 [mlir][complex] Lower complex.log to libm log call
Lower complex.log to corresponding function call with libm.

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D129417
2022-07-11 21:56:00 +02:00
Prabhdeep Singh Soni ac892c70a4 [OMPIRBuilder] Add support for simdlen clause
This patch adds OMPIRBuilder support for the simdlen clause for the
simd directive. It uses the simdlen support in OpenMPIRBuilder when
it is enabled in Clang. Simdlen is lowered by OpenMPIRBuilder by
generating the loop.vectorize.width metadata.

Reviewed By: jdoerfert, Meinersbur

Differential Revision: https://reviews.llvm.org/D129149
2022-07-11 13:29:06 -04:00
jungpark-mlir 6e8e91a7b6 [MLIR][TOSA] Fix converting tosa.clamp and tosa.relu to linalg
Tosa to Linalg conversion crashes when input tensor is a float type other than fp32.
Because tosa.clamp and tosa.reluN have fp32 min/max attribute which is converted as arith.constant with the attribute type.
This commit fixes the crash by correctly setting the float constant type from the input tensor.

Reviewed By: eric-k256

Differential Revision: https://reviews.llvm.org/D128630
2022-07-11 17:18:47 +00:00
Thomas Raoux 0af2680596 [mlir][vector] Add pattern to distribute splat constant
Distribute splat constant out of WarpExecuteOnLane0Op region.

Differential Revision: https://reviews.llvm.org/D129467
2022-07-11 15:50:26 +00:00
Thomas Raoux d7d6443d50 [mlir][vector] Avoid creating duplicate output in warpOp
Prevent creating multiple output for the same Value when distributing
operations out of WarpExecuteOnLane0Op. This avoid creating combinatory
explosion of outputs.

Differential Revision: https://reviews.llvm.org/D129465
2022-07-11 15:37:50 +00:00
Arjun P cdbc5f1e10 [MLIR][Presburger] introduce MPInt to support fast arbitrary precision in Presburger
This uses an int64_t-based fastpath for the common case and falls back to
SlowMPInt to handle the rare cases where larger numbers occur.
It uses `__builtin_*` for performance through the support in LLVM MathExtras.

Using this in the Presburger library results in a minor performance
*improvement* over any commit hash before sequence of patches
starting at d5e31cf38a.

This was previously reverted in 1e10d35ea9 due
to a build failure; relanding now with an attempted fix.

Reviewed By: Groverkss, ftynse

Differential Revision: https://reviews.llvm.org/D128811
2022-07-11 15:46:44 +01:00
Arjun P 1e10d35ea9 Revert "[MLIR][Presburger] introduce MPInt to support fast arbitrary precision in Presburger"
This reverts commit c9035df2fa.
Reverting due to build failure on Windows: https://lab.llvm.org/buildbot/#/builders/172/builds/14767
2022-07-11 14:26:09 +01:00
Arjun P c9035df2fa [MLIR][Presburger] introduce MPInt to support fast arbitrary precision in Presburger
This uses an int64_t-based fastpath for the common case and falls back to
SlowMPInt to handle the rare cases where larger numbers occur.
It uses `__builtin_*` for performance through the support in LLVM MathExtras.

Using this in the Presburger library results in a minor performance
*improvement* over any commit hash before sequence of patches
starting at d5e31cf38a.

Reviewed By: Groverkss, ftynse

Differential Revision: https://reviews.llvm.org/D128811
2022-07-11 11:41:29 +01:00
Jacques Pienaar 136d746ec7 [mlir] Flip accessors to prefixed form (NFC)
Another mechanical sweep to keep diff small for flip to _Prefixed.
2022-07-10 21:19:11 -07:00
jacquesguan ad4b7fb3ce [mlir][Math] Support fold Log2Op with constant dense.
This patch is similar to D129108, it adds a conditional unary constant folder which allow to exit when the constants not meet the fold condition. And use it for Log2Op to make it able to fold the constant dense.

Differential Revision: https://reviews.llvm.org/D129251
2022-07-11 10:34:28 +08:00
Stella Laurenzo 2aa6d56dce Restore Python install behavior from before D128230.
In D128230, we accidentally moved the install for Python sources outside of the loop, having one install() per group of files. While it would be nice if we could do this, it means that we flatten the relative directory tree and every source ends up in the root. The right way to do this is to use FILE_SETS, which preserve the relative directory tree, but they are not available until CMake 3.23.

Differential Revision: https://reviews.llvm.org/D129434
2022-07-09 19:22:51 -07:00
Thomas Raoux 0660f3c5a0 [mlir][vector] Relax reduction distribution pattern
Support distributing reductions with vector size multiple of the warp
size.

Differential Revision: https://reviews.llvm.org/D129387
2022-07-09 18:36:39 +00:00
Matthias Springer fc9b37dd53 [mlir][bufferization] Do not canonicalize to_tensor(to_memref(x))
This is a partial revert of D128615.

to_memref(to_tensor(x)) always be folded to x. But to_tensor(to_memref(x)) cannot be folded in the general case because writes to the intermediary memref may go unnoticed.

Differential Revision: https://reviews.llvm.org/D129354
2022-07-09 09:16:52 +02:00
River Riddle 9bbc0d4eb1 [mlir:LSP] Drop potentialy annoying completion commit characters
These can result in accidentally accepting a completion when it isn't intended.
2022-07-08 17:56:48 -07:00
River Riddle 34b3f0665c [mlir:LSP] Add code completions for builtin signed/unsigned integers 2022-07-08 17:55:30 -07:00
River Riddle fe4f512be7 [mlir:LSP] Add support for code completing attributes and types
This required changing a bit of how attributes/types are parsed. A new
`KeywordSwitch` class was added to AsmParser that provides a StringSwitch
like API for parsing keywords with a set of potential matches. It intends to
both provide a cleaner API, and enable injection for code completion. This
required changing the API of `generated(Attr|Type)Parser` to handle the
parsing of the keyword, instead of having the user do it. Most upstream
dialects use the autogenerated handling and didn't require a direct update.

Differential Revision: https://reviews.llvm.org/D129267
2022-07-08 16:24:55 -07:00
River Riddle 2e41ea3247 [mlir:LSP] Add support for keyword code completions
This commit adds code completion results to the MLIR LSP when
parsing keywords. Keyword support is currently limited to the
case where the expected keyword is provided, but a followup will
work on expanding the set of keyword cases we handle (e.g. to
allow capturing attribute/type mnemonics).

Differential Revision: https://reviews.llvm.org/D129184
2022-07-08 16:24:55 -07:00
Jacques Pienaar 82140ad728 [mlir] Add method to populate default attributes
Previously default attributes were only usable by way of the ODS generated
accessors, but this was undesirable as
1. The ODS getters could construct Attribute each get request;
2. For non-C++ uses this would require either duplicating some of tee default
   attribute generating or generating additional bindings to generate methods;
3. Accessing op.getAttr("foo") and op.getFoo() would return different results;
Generate method to populate default attributes that can be used to address
these.

This merely adds this facility but does not employ by default on any path.

Differential Revision: https://reviews.llvm.org/D128962
2022-07-08 11:31:13 -07:00
Ryan Thomas Lynch (@emosy) f192392299 [vscode-mlir] add tablegen <> bracket colorization
Add support for colorizing angle brackets "<>" in TableGen files.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D128229
2022-07-08 10:58:38 -07:00