Commit Graph

10042 Commits

Author SHA1 Message Date
Mahesh Ravishankar
fc367dfa67 [mlir] Remove Transforms/SideEffectUtils.h and move the methods into Interface/SideEffectInterfaces.h.
The methods in `SideEffectUtils.h` (and their implementations in
`SideEffectUtils.cpp`) seem to have similar intent to methods already
existing in `SideEffectInterfaces.h`. Move the decleration (and
implementation) from `SideEffectUtils.h` (and `SideEffectUtils.cpp`)
into `SideEffectInterfaces.h` (and `SideEffectInterface.cpp`).

Also drop the `SideEffectInterface::hasNoEffect` method in favor of
`mlir::isMemoryEffectFree` which actually recurses into the operation
instead of just relying on the `hasRecursiveMemoryEffectTrait`
exclusively.

Differential Revision: https://reviews.llvm.org/D137857
2022-11-15 20:07:35 +00:00
Kazu Hirata
eba3fece88 [mlir] Fix warnings
This patch fixes:

  mlir/include/mlir/ExecutionEngine/SparseTensor/Storage.h:955:20:
  error: unused variable 'sz' [-Werror,-Wunused-variable]

  mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp:1460:2:
  error: extra ';' outside of a function is incompatible with C++98
  [-Werror,-Wc++98-compat-extra-semi]
2022-11-15 12:01:00 -08:00
bixia1
13c41757b1 [mlir][sparse] Only insert non-zero values to the result of the concatenate operation.
Modify the integration test to check number_of_entries and use it to limit for
outputing sparse tensor values.

Reviewed By: aartbik, Peiming

Differential Revision: https://reviews.llvm.org/D138046
2022-11-15 11:52:52 -08:00
Peiming Liu
c3821e1684 [mlir][sparse] fix bugs in concatenate rewriter.
Reviewed By: aartbik, bixia

Differential Revision: https://reviews.llvm.org/D138053
2022-11-15 19:49:59 +00:00
Mehdi Amini
9b1bd2357b Apply clang-tidy fixes for modernize-loop-convert in CodegenUtils.cpp (NFC) 2022-11-15 18:14:02 +00:00
Mehdi Amini
fbfca43e6d Apply clang-tidy fixes for llvm-qualified-auto in TileUsingInterface.cpp (NFC) 2022-11-15 18:14:01 +00:00
Mohammed Anany
77533d79f7 [mlir][SCF] Adding custom builder to SCF::WhileOp.
This is a similar builder to the one for SCF::IfOp which allows users to pass region builders to it. Refer to the builders for IfOp.

Reviewed By: tpopp

Differential Revision: https://reviews.llvm.org/D137709
2022-11-15 18:16:49 +01:00
Guray Ozen
beaffb041c [mlir][transform] Decouple GPUDeviceMapping attribute from the GPU transfrom dialect code generator
`DeviceMappingAttrInterface` is implemented as unifiying mechanism for thread mapping. A code generator could use any attribute that implements this interface to lower `scf.foreach_thread` to device specific code. It is allowed to choose its own mapping and interpretation.

Currently, GPU transform dialect supports only `GPUThreadMapping` and `GPUBlockMapping`; however, other mappings should to be supported as well. This change addresses this issue. It decouples gpu transform dialect from the `GPUThreadMapping` and `GPUBlockMapping`. Now, they can work any other mapping.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D138020
2022-11-15 18:16:32 +01:00
River Riddle
1311306410 [mlir][AttrTypeReplacer] Make attribute dictionary replacement optional
This provides an optimization opportunity for clients that don't want/need
to recurse attribute dictionaries.
2022-11-14 18:02:18 -08:00
Jakub Kuderski
c50d0fe570 [mlir][arith][spirv] Clean up arith-to-spirv. NFC.
Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D137978
2022-11-14 20:54:27 -05:00
Jakub Kuderski
64333332db [mlir][arith] Add arith.shrsi support to WIE
This includes LIT tests over the generated ops and runtime tests.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D137965
2022-11-14 20:52:10 -05:00
TatWai Chong
940d3e08cf [mlir][tosa] Create a profile validation pass for TOSA dialect
Add a separate validation pass to check if TOSA operations match with
the specification against given requirement. Perform profile type
checking as the initial feature in the pass.

This is an optional pass that can be enabled via command line. e.g.
$mlir-opt --tosa-validate="profile=bi" for validating against the
base inference profile.

Description:
TOSA defines a variety of operator behavior and requirements in the
specification. It would be helpful to have a separate validation pass
to keep TOSA operation input match with TOSA specification for given
criteria, and also diminish the burden of dialect validation during
compilation.

TOSA supports three profiles of which two are for inference purposes.
The main inference profile supports both integer and floating-point
data types, but the base inference profile only supports integers.
In this initial PR, validate the operations against a given profile
of TOSA, so that validation would fail if a floating point tensor is
present when the base inference profile is selected. Afterward, others
checking will be added to the pass if needed. e.g. control flow
operators and custom operators validation.

The pass is expected to be able to run on any point of TOSA dialect
conversion/transformation pipeline, and not depend on a particular
pass run ahead. So that it is can be used to validate the initial tosa
operations just converted from other dialects, the intermediate form,
or the final tosa operations output.

Change-Id: Ib58349c873c783056e89d2ab3b3312b8d2c61863

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D137279
2022-11-14 17:29:50 -08:00
Aart Bik
910d6270db [mlir][sparse] avoid nop rewriting on runtime lib path in pipeline
Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D137981
2022-11-14 16:38:47 -08:00
Peiming Liu
8ffdcc594e [mlir][sparse] fix memory leak sparse2sparse reshape
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D137994
2022-11-15 00:19:51 +00:00
Stella Stamenova
af5c307945 Revert "[mlir][sparse] Macros to clean up StridedMemRefType in the SparseTensorRuntime" and "[mlir][sparse] move SparseTensorReader functions into the _mlir_ciface_ section"
This reverts commits 6c22dad and 92bc3fb.

These broke the windows mlir buildbot.
2022-11-14 16:18:04 -08:00
wren romano
92bc3fb5b1 [mlir][sparse] move SparseTensorReader functions into the _mlir_ciface_ section
Depends On D137735

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D137737
2022-11-14 13:50:29 -08:00
wren romano
6c22dad9c2 [mlir][sparse] Macros to clean up StridedMemRefType in the SparseTensorRuntime
In particular, this silences warnings from [-Wsign-compare].

Depends On D137681

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D137735
2022-11-14 13:49:38 -08:00
wren romano
c518745bba [mlir][sparse] Making way for SparseTensorRuntime to support non-permutations
Systematically updates the SparseTensorRuntime to properly distinguish tensor-dimensions from storage-levels (and their associated ranks, shapes, sizes, indices, etc).  With a few exceptions which are noted in the code, this ensures the runtime has all the **semantic** changes necessary to support non-permutations.

(Whereas **operationally**, since we're still using `std::vector<uing64_t>` to represent the mappings, there's no way to pass in any interesting non-permutations.  Changing the representation to `std::function` will be done in a separate differential.)

Depends On D137680

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D137681
2022-11-14 13:48:41 -08:00
Jakub Kuderski
afc159bbf1 [mlir][arith][spirv] Handle i1 sign extension in arith-to-spirv
Also fix some surrounding nits.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D137974
2022-11-14 15:07:27 -05:00
Mehdi Amini
beee574000 Apply clang-tidy fixes for readability-identifier-naming in AlgebraicSimplification.cpp (NFC) 2022-11-14 20:04:23 +00:00
Mehdi Amini
3bed21bdd2 Apply clang-tidy fixes for readability-simplify-boolean-expr in GPUDialect.cpp (NFC) 2022-11-14 20:04:16 +00:00
Rob Suderman
0720576141 [mlir][tosa] Remove zero-fill of tosa.concat outputs when lowering to linalg.
Since all output elements are known to be overridden by construction the fill is not required. This change makes the tosa lowering consistent with the MHLO and Torch lowerings of concat which do not do the fill.

Reviewed By: rsuderman

Differential Revision: https://reviews.llvm.org/D137967
2022-11-14 11:39:24 -08:00
Quentin Colombet
d665448a7f [mlir][MemRef] Change the anchor point of a reshapeLikeOp pattern
Essentially, this patches changes the anchor point of the
`extract_strided_metadata(reshapeLikeOp)` pattern from
`extract_strided_metadata` to `reshapeLikeOp`.

In details, this means that instead of replacing:
```
base, offset, sizes, strides =
  extract_strided_metadata(reshapeLikeOp(src))
```
With
```
base, offset = extract_strided_metadata(src)
sizes = <some math>
strides = <some math>
```

We replace only the reshapeLikeOp part and connect it back with a
reinterpret_cast:
```
val = reshapeLikeOp(src)
```
=>
```
base, offset, ... = extract_strided_metadata(src)
sizes = <some math>
strides = <some math>
val = reinterpret_cast base, offset, sizes, strides

Differential Revision: https://reviews.llvm.org/D136386
2022-11-14 18:56:35 +00:00
Quentin Colombet
41783666e4 [mlir][MemRef] Change the anchor point of a subview pattern
Essentially, this patches changes the anchor point of the
`extract_strided_metadata(subview)` pattern from
`extract_strided_metadata` to `subview`.

In details, this means that instead of replacing:
```
base, offset, sizes, strides = extract_strided_metadata(subview(src))
```
With
```
base, ... = extract_strided_metadata(src)
offset = <some math>
sizes = subSizes
strides = <some math>
```

We replace only the subview part and connect it back with a
reinterpret_cast:
```
val = subview(src)
```
=>
```
base, ... = extract_strided_metadata(src)
offset = <some math>
sizes = subSizes
strides = <some math>
val = reinterpret_cast base, offset, sizes, strides
```

Differential Revision: https://reviews.llvm.org/D135839
2022-11-14 18:43:34 +00:00
Quentin Colombet
244af24faf [mlir][MemRef] Simplify extract_strided_metadata(reinterpret_cast)
This patch adds a pattern to simplify
```
base, offset, sizes, strides =
  extract_strided_metadata(
    reinterpret_cast(src, srcOffset, srcSizes, srcStrides))
```

Into
```
base, baseOffset, ... = extract_strided_metadata(src)
offset = srcOffset
sizes = srcSizes
strides = srcStrides
```

Note: Reinterpret_cast with unranked sources are not simplified since
they cannot feed extract_strided_metadata operations.

Differential Revision: https://reviews.llvm.org/D135837
2022-11-14 18:36:31 +00:00
Thomas Raoux
99833cd818 [mlir][linalg] Add reduction tiling using scf.foreachthread
This adds a transformation to tile reduction operations to partial
reduction using scf.foreachthread. This uses
PartialReductionOpInterface to create a merge operation of the partial
tiles.

Differential Revision: https://reviews.llvm.org/D137912
2022-11-14 18:05:40 +00:00
Quentin Colombet
42263fb52d [mlir][MemRef] Make reinterpret_cast(extract_strided_metadata) more robust
Prior to this patch the canonicalization pattern that turns
`reinterpret_cast(extract_strided_metadata)` into cast was only applied
when all the input operands of the `reinterpret_cast` are exactly all the
output results of the `extract_strided_metadata`.

This missed simplification opportunities when the values would have hold
the same constant values, but yet, come from different actual values.

E.g., prior to this patch, a pattern of the form:
```
%base, %offset = extract_strided_metadata %source : memref<i16>
reinterpret_cast %base to offset:[0]
```
Wouldn't have been simplified into a simple cast, because %offset is not
directly the same value object as 0.

This patch teaches this pattern how to check if the constant values
match what the results of the `extract_strided_metadata` operation would
have hold.

Differential Revision: https://reviews.llvm.org/D135736
2022-11-14 18:02:15 +00:00
Nicolas Vasilache
f0a411da77 [mlir][Transform]Significantly cleanup scf.foreach_thread and GPU transform permutation handling
Previously, the need for a dense permutation leaked into the thread_dim_mapping specification.
This revision allows to use a sparse specification of the thread_dim_mapping and the proper completion / sorting is applied automatically.

In the process, the sematics of scf.foreach_thread is tightened to require a matching number of thread dimensions and mappings.
The relevant negative test is added.

Differential Revision: https://reviews.llvm.org/D137906
2022-11-14 09:19:49 -08:00
Lorenzo Chelini
c780184a84 [MLIR][Transform] Expose map layout option in OneShotBufferizeOp
Expose `function-boundary-type-conversion` in `OneShotBufferizeOp`. To
reuse options between passes and transform operations, create a
`BufferizationEnums.td`.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D137833
2022-11-14 18:09:54 +01:00
bixia1
4f729d5a70 [mlir][sparse] Add rewriting rules for sparse_tensor.sort_coo.
Refactor the rewriting of sparse_tensor.sort to support the implementation of
sparse_tensor.sort_coo.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D137522
2022-11-14 08:48:53 -08:00
bixia1
fa46de16db [mlir][sparse][NFC] Add comments to tests that are run for with and without runtime libraries.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D137869
2022-11-14 08:21:33 -08:00
Nicolas Vasilache
6370f75ad7 [mlir][Transform] Add support for dynamically unpacking tile_sizes / num_threads in tile_to_foreach_thread
This commit adds automatic unpacking of Value's of type pdl::OperationType to the underlying single-result OpResult.
This allows mixing single-value, attribute and multi-value pdl::Operation tile sizes and num threads to TileToForeachThreadOp.

Differential Revision: https://reviews.llvm.org/D137896
2022-11-14 04:39:57 -08:00
Johannes Reifferscheid
c9845735a6 Add missing include. 2022-11-14 08:14:47 +01:00
Mehdi Amini
375e5e9542 Apply clang-tidy fixes for llvm-qualified-auto in MLIRContext.cpp (NFC) 2022-11-14 05:16:15 +00:00
Renato Golin
1b99e8ba48 [MLIR] Move JitRunner Options to header, pass to mlirTransformer
This allows the MLIR transformer to see the command line options and
make desicions based on them. No change upstream, but my use-case is to
look at the entry point name and type to make sure I can use them.

Differential Revision: https://reviews.llvm.org/D137861
2022-11-13 18:55:48 +00:00
bzcheeseman
ae461d8b99 [MLIR][Bytecode] Ensure dataIt is aligned coming out of EncodingReader::alignTo.
This addresses the TODO in the code previously and checks that the address of `dataIt` is properly aligned to the requested alignment.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D137855
2022-11-13 09:27:23 -08:00
Mehdi Amini
a4ef4445a0 Apply clang-tidy fixes for readability-container-size-empty in ExecutionEngine.cpp (NFC) 2022-11-12 23:47:38 +00:00
Mehdi Amini
4ecfdf8a73 Apply clang-tidy fixes for readability-identifier-naming in TosaDecomposeConv2D.cpp (NFC) 2022-11-12 23:47:38 +00:00
River Riddle
858a6ec3af [mlir] Add openInputFile overload that accepts the expected alignment
This just forwards to the alignment parameter on `MemoryBuffer::getFileOrSTDIN`.
2022-11-12 15:05:13 -08:00
River Riddle
e50941b8d7 [mlir] Add a new AttrTypeReplacer class to simplify sub element replacements
We currently only have the SubElement interface API for attribute/type
replacement, but this suffers from several issues; namely that it doesn't
allow caching across multiple replacements (very common), and also
creates a somewhat awkward/limited API. The new AttrTypeReplacer class
allows for registering replacements using a much cleaner API, similarly to
the TypeConverter class, removes a lot of manual interaction with the
sub element interfaces, and also better enables large scale replacements.

Differential Revision: https://reviews.llvm.org/D137764
2022-11-12 14:38:45 -08:00
Guray Ozen
d93be483ea [mlir][transform] Make tile_to_foreach_thread_op builder to use ArrayAttr
D137413 clarified `scf_foreach_thread` thread mapping nicely. `tile_to_foreach_thread_op` is one of the op that generates `scf_foreach_thread`, however, its builders are still having integer array.

This is bug fix of potential problem.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D137891
2022-11-12 19:27:25 +01:00
Peiming Liu
725e0849b7 [mlir][sparse] fix incorrect coordinates ordering computed by the foreach operation.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D137877
2022-11-12 04:08:50 +00:00
Mahesh Ravishankar
cb40d5291e [mlir][Linalg] Avoid using tensor.cast by default while folding fill with pad.
This is unnecessary if the generated operation type already matches
the type of the replaced value.  Also use `OpFoldResult` to reduce the
number of cases the casts are needed.

Reviewed By: springerm, hanchung, antiagainst

Differential Revision: https://reviews.llvm.org/D137479
2022-11-11 23:17:07 +00:00
Peiming Liu
5ab1a8aef4 [mlir][sparse] fix crash when calling getTuple on non-sparse tensors.
This enables full sparse convolution codegen in D137298

Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D137853
2022-11-11 21:15:44 +00:00
Jakub Kuderski
7e835ae57c [mlir][arith] Add arith.cmpi support to WIE
This inludes both LIT tests over IR and runtime checks.

Reviewed By: antiagainst

Differential Revision: https://reviews.llvm.org/D137846
2022-11-11 15:14:02 -05:00
Sanjoy Das
ed39825be4 Model UB in integer division operations in the arith dialect
Before this commit `arith.{ceil}div{u|s}i` were marked `Pure` which is
incorrect because these operations invoke UB on certain inputs.

Fixes: https://github.com/llvm/llvm-project/issues/58700

Reviewed By: kuhar

Differential Revision: https://reviews.llvm.org/D137814
2022-11-11 10:42:31 -08:00
bixia1
57416d872a [mlir][sparse] Fix a bug in rewriting dense2dense convert op.
Permutation wasn't handled correctly. Add a test for the rewriting.

Extend an integration test to run with enable_runtime_library=false to
also test the rewriting.

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D137845
2022-11-11 09:11:54 -08:00
Matthias Springer
28b2f79215 [mlir][bufferize][NFC] Consolidate transform header files
Differential Revision: https://reviews.llvm.org/D137830
2022-11-11 14:33:23 +01:00
Guray Ozen
0d845660f4 [mlir] Fix asan errors in gpu transform dialect 2022-11-11 11:57:00 +01:00
Matthias Springer
e62681e70a [mlir][bufferize] Eliminate tensor.empty ops instead of bufferization.alloc_tensor ops
tensor.empty op elimination is an optimization that brings IR in a more bufferization-friendly form. E.g.:

```
%0 = tensor.empty()
%1 = linalg.fill(%cst, %0) {inplace = [true]}
%2 = tensor.insert_slice %1 into %t[10][20][1]
```

Is rewritten to:

```
%0 = tensor.extract_slice %t[10][20][1]
%1 = linalg.fill(%cst, %0) {inplace = [true]}
%2 = tensor.insert_slice %1 into %t[10][20][1]
```

This optimization used to operate on bufferization.alloc_tensor ops. This is not correct because the documentation of bufferization.alloc_tensor says that it always bufferizes to an allocation. Instead, this optimization should operate on tensor.empty ops, which can then be lowered to bufferization.alloc_tensor ops (if they don't get eliminated).

Differential Revision: https://reviews.llvm.org/D137162
2022-11-11 11:39:18 +01:00