Commit Graph

6112 Commits

Author SHA1 Message Date
Butygin 7d85560583 [mlir] Add populateGpuToLLVMConversionPatterns function
Differential Revision: https://reviews.llvm.org/D107218
2021-08-01 11:51:21 +03:00
Aart Bik 697ea09d47 [mlir][sparse] add sparse tensor type conversion operation
Introduces a conversion from one (sparse) tensor type to another
(sparse) tensor type. See the operation doc for details. Actual
codegen for all cases is still TBD.

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D107205
2021-07-31 12:53:31 -07:00
Uday Bondhugula bf6c46d917 [MLIR] NFC Clean up doc comments on memref replacement utility
NFC. Clean up stale doc comments on memref replacement utility and some
variable renaming in it to avoid confusion.

Differential Revision: https://reviews.llvm.org/D107144
2021-07-31 15:14:52 +05:30
Lei Zhang 233a3a75ac [mlir][spirv] Add support for i8 serialization
Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D107122
2021-07-30 18:06:11 -04:00
Lei Zhang 0065bd2ad5 [mlir][spirv] Fix loading bool with proper storage capabilities
If the source value to load is bool, and we have native storage
capability support for the source bitwidth, we still cannot directly
rewrite uses; we need to perform casting to bool first.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D107119
2021-07-30 18:06:11 -04:00
Lei Zhang 9f5300c8be [mlir][spirv] Fix storing bool with proper storage capabilities
If the source value to store is bool, and we have native storage
capability support for the target bitwidth, we still cannot directly
store; we need to perform casting to match the target memref
element's bitwidth.

Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D107114
2021-07-30 18:06:10 -04:00
Aart Bik 160399c7ce [mlir][sparse] move comments from cpp files into dialect doc
Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D107191
2021-07-30 13:16:50 -07:00
Aart Bik 1d77bb9e1b [mlir][sparse] template the memory resident coordinate scheme storage
Rationale:
External file formats always store the values as doubles, so this was
hard coded in the memory resident COO scheme used to pass data into the
final sparse storage scheme during setup. However, with alternative methods
on the horizon of setting up these temporary COO schemes, it is time to
properly template this data structure.

Reviewed By: gussmith23

Differential Revision: https://reviews.llvm.org/D107001
2021-07-30 11:21:05 -07:00
Nicolas Vasilache 14c1450d5c [mlir][Vector] Add vector to outerproduct lowering for the [reduction, parallel] case.
Differential Revision: https://reviews.llvm.org/D105373
2021-07-30 14:32:57 +00:00
Tung D. Le a2186277be [mlir][affine-loop-fusion] Fix a bug that AffineIfOp prevents fusion of the other loops
The presence of AffineIfOp inside AffineFor prevents fusion of the other loops to happen. For example:

```
  affine.for %i0 = 0 to 10 {
    affine.store %cf7, %a[%i0] : memref<10xf32>
  }
  affine.for %i1 = 0 to 10 {
    %v0 = affine.load %a[%i1] : memref<10xf32>
    affine.store %v0, %b[%i1] : memref<10xf32>
  }
  affine.for %i2 = 0 to 10 {
    affine.if #set(%i2) {
      %v0 = affine.load %b[%i2] : memref<10xf32>
    }
  }
```

The first two loops were not be fused because of `affine.if` inside the last `affine.for`.

The issue seems to come from a conservative constraint that does not allow fusion if there are ops whose number of regions != 0 (affine.if is one of them).

This patch just removes such a constraint when`affine.if` is inside `affine.for`.  The existing `canFuseLoops` method is able to handle `affine.if` correctly.

Reviewed By: bondhugula, vinayaka-polymage

Differential Revision: https://reviews.llvm.org/D105963
2021-07-30 15:22:46 +05:30
Butygin 1e9799e204 [mlir][spirv] Fix crash in convert-gpu-to-spirv pass with memrefs with affine maps
spirv::getElementPtr can return null (for memrefs with affine map) but patterns didn't handle this.

Differential Revision: https://reviews.llvm.org/D106988
2021-07-30 12:46:13 +03:00
Amy Zhuang a8b7e56f65 [mlir] Set insertion point of vector constant to the top of the vectorized loop body
When we vectorize a scalar constant, the vector constant is inserted before its
first user if the scalar constant is defined outside the loops to be vectorized.
It is possible that the vector constant does not dominate all its users. To fix
the problem, we find the innermost vectorized loop that encloses that first user
and insert the vector constant at the top of the loop body.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D106609
2021-07-29 15:42:23 -07:00
Rob Suderman 2d0ba5e144 [mlir][tosa] Fix tosa.reshape failures due to implicit broadcasting
Make broadcastable needs the output shape to determine whether the operation
includes additional broadcasting. Include some canonicalizations for TOSA
to remove unneeded reshape.

Reviewed By: NatashaKnk

Differential Revision: https://reviews.llvm.org/D106846
2021-07-29 15:21:57 -07:00
Yi Zhang 9a82482313 [mlir][linalg] Fix pad tensor cast folding with changed type
`PadTensorOp` has verification logic to make sure
result dim must be static if all the padding values are static.
Cast folding might add more static information for the src operand
of `PadTensorOp` which might change a valid operation to be invalid.
Change the canonicalizing pattern to fix this.
2021-07-29 17:47:01 -04:00
Lei Zhang 26be7fe27c [mlir] NFC: split MemRef to SPIR-V conversion into their own files
Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D107094
2021-07-29 16:34:10 -04:00
Lei Zhang 995c3984ef [mlir] NFC: split Math to SPIR-V conversion into their own files
Reviewed By: hanchung

Differential Revision: https://reviews.llvm.org/D107093
2021-07-29 16:34:10 -04:00
bakhtiyar 1c144410e7 Refactor AsyncToAsyncRuntime pass to boost understandability.
Depends On D106730

Reviewed By: ezhulenev

Differential Revision: https://reviews.llvm.org/D106731
2021-07-29 12:01:07 -07:00
bakhtiyar 9a5bc83660 Add an escape-hatch for conversion of funcs with blocking awaits to coroutines.
Currently TFRT does not support top-level coroutines, so this functionality will allow to have a single blocking await at the top level until TFRT implements the necessary functionality.

Reviewed By: ezhulenev

Differential Revision: https://reviews.llvm.org/D106730
2021-07-29 08:52:28 -07:00
Tobias Gysi 2a342c7c1e [mlir][linalg] Format bufferization debug print outs (NFC).
Change the formatting of the debug print outs to elide unnecessary information.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D106661
2021-07-29 15:48:58 +00:00
Benjamin Kramer 1c9c2c91d4 [mlir] Remove the default isDynamicallyLegal hook
This is redundant with the callback variant and untested. Also remove
the callback-less methods for adding a dynamically legal op, as they
are no longer useful.

Differential Revision: https://reviews.llvm.org/D106786
2021-07-29 11:00:57 +02:00
Mehdi Amini 0be5d1a96c Implement recursive support into OperationEquivalence::isEquivalentTo()
This allows to use OperationEquivalence to track structural comparison for equality
between two operations.

Differential Revision: https://reviews.llvm.org/D106422
2021-07-29 05:06:37 +00:00
Stella Laurenzo 0cdf491501 Break apart the MLIR ExecutionEngine from core python module.
* For python projects that don't need JIT/ExecutionEngine, cuts the number of files to compile roughly in half (with similar reduction in end binary size).

Differential Revision: https://reviews.llvm.org/D106992
2021-07-28 23:59:32 +00:00
River Riddle f8479d9de5 [mlir] Set the namespace of the BuiltinDialect to 'builtin'
Historically the builtin dialect has had an empty namespace. This has unfortunately created a very awkward situation, where many utilities either have to special case the empty namespace, or just don't work at all right now. This revision adds a namespace to the builtin dialect, and starts to cleanup some of the utilities to no longer handle empty namespaces. For now, the assembly form of builtin operations does not require the `builtin.` prefix. (This should likely be re-evaluated though)

Differential Revision: https://reviews.llvm.org/D105149
2021-07-28 21:00:10 +00:00
bakhtiyar 6ea22d4626 Optionally eliminate blocking runtime.await calls by converting functions to coroutines.
Interop parallelism requires needs awaiting on results. Blocking awaits are bad for performance. TFRT supports lightweight resumption on threads, and coroutines are an abstraction than can be used to lower the kernels onto TFRT threads.

Reviewed By: ezhulenev

Differential Revision: https://reviews.llvm.org/D106508
2021-07-28 12:37:05 -07:00
Mehdi Amini 6cba96332b Add some missing CMake dependencies between MLIR dialects (NFC) 2021-07-28 18:37:05 +00:00
Alex Zinenko 49f745f59c [mlir] run the verifier before translating a module
In translation from MLIR to another IR, run the MLIR verifier on the parsed
module to ensure only valid modules are given to the translation. Previously,
we would send any module that could be parsed to the translation, including
semantically invalid modules, leading to surprising errors or lack thereof down
the pipeline.

Depends On D106937

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D106938
2021-07-28 18:15:58 +02:00
Alex Zinenko c1f719d1a7 [mlir] harden result type verification in llvm.call
The verifier of the llvm.call operation was not checking for mismatches between
the number of operation results and the number of results in the signature of
the callee. Furthermore, it was possible to construct an llvm.call operation
producing an SSA value of !llvm.void type, which should not exist. Add the
verification and treat !llvm.void result type as absence of call results.
Update the GPU conversions to LLVM that were mistakenly assuming that it was
fine for llvm.call to produce values of !llvm.void type and ensure these calls
do not produce results.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D106937
2021-07-28 18:15:56 +02:00
Lei Zhang 23326b9f17 [mlir][spirv] Fix a few issues in ModuleCombiner
- Fixed symbol insertion into `symNameToModuleMap`. Insertion
  needs to happen whether symbols are renamed or not.
- Added check for the VCE triple and avoid dropping it.
- Disabled function deduplication. It requires more careful
  rules. Right now it can remove different functions.
- Added tests for symbol rename listener.
- And some other code/comment cleanups.

Reviewed By: ergawy

Differential Revision: https://reviews.llvm.org/D106886
2021-07-28 10:31:01 -04:00
Tobias Gysi 09635dc7bf [mlir][linalg] Specialize LinalgOp canonicalization patterns (NFC).
Specialize the DeduplicateInputs and RemoveIdentityLinalgOps patterns for GenericOp instead of implementing them for the LinalgOp interface.

This revsion is based on https://reviews.llvm.org/D105622 that moves the logic to erase identity CopyOps in a separate pattern.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D105291
2021-07-28 11:39:34 +00:00
Tobias Gysi ca0d244e99 [mlir][linalg] Introduce a separate EraseIdentityCopyOp Pattern.
Split out an EraseIdentityCopyOp from the existing RemoveIdentityLinalgOps pattern. Introduce an additional check to ensure the pattern checks the permutation maps match. This is a preparation step to specialize RemoveIdentityLinalgOps to GenericOp only.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D105622
2021-07-28 11:18:22 +00:00
Yi Zhang 8ed66cb88b [mlir][memref] Fix collapsed shape ops memref.cast folding with changed type
`memref.collapse_shape` has verification logic to make sure
result dim must be static if all the collapsing src dims are static.
Cast folding might add more static information for the src operand
of `memref.collapse_shape` which might change a valid collapsing
operation to be invalid. Add `CollapseShapeOpMemRefCastFolder` pattern
to fix this.

Minor changes to `convertReassociationIndicesToExprs` to use `context`
instead of `builder` to avoid extra steps to construct temporary
builders.

Reviewed By: nicolasvasilache, mravishankar

Differential Revision: https://reviews.llvm.org/D106670
2021-07-28 10:19:20 +00:00
Valentin Clement fe7ca1a9fc [mlir][openacc] Initial translation for DataOp to LLVM IR
Add basic translation of acc.data to LLVM IR with runtime calls.

Reviewed By: jdoerfert

Differential Revision: https://reviews.llvm.org/D104301
2021-07-27 22:04:04 -04:00
Fangrui Song f2026f5d6e [mlir] Replace LLVM_ATTRIBUTE_NORETURN with C++11 [[noreturn]]
[[noreturn]] can be used since 2016 when the minimum compiler requirement was bumped to GCC 4.8/MSVC 2015.
2021-07-27 18:57:33 -07:00
River Riddle 6b4ce5fd52 [PDL] Fix the builders for OperationOp and PatternOp 2021-07-27 23:59:14 +00:00
Eugene Zhulenev d94426d22a [mlir] Math: add algebraic simplification patterns to math transforms
Reviewed By: bkramer

Differential Revision: https://reviews.llvm.org/D106822
2021-07-27 09:22:33 -07:00
Stella Laurenzo 310c9496d8 Re-engineer MLIR python build support.
* Implements all of the discussed features:
  - Links against common CAPI libraries that are self contained.
  - Stops using the 'python/' directory at the root for everything, opening the namespace up for multiple projects to embed the MLIR python API.
  - Separates declaration of sources (py and C++) needed to build the extension from building, allowing external projects to build custom assemblies from core parts of the API.
  - Makes the core python API relocatable (i.e. it could be embedded as something like 'npcomp.ir', 'npcomp.dialects', etc). Still a bit more to do to make it truly isolated but the main structural reset is done.
  - When building statically, installed python packages are completely self contained, suitable for direct setup and upload to PyPi, et al.
  - Lets external projects assemble their own CAPI common runtime library that all extensions use. No more possibilities for TypeID issues.
  - Begins modularizing the API so that external projects that just include a piece pay only for what they use.
* I also rolled in a re-organization of the native libraries that matches how I was packaging these out of tree and is a better layering (i.e. all libraries go into a nested _mlir_libs package). There is some further cleanup that I resisted since it would have required source changes that I'd rather do in a followup once everything stabilizes.
* Note that I made a somewhat odd choice in choosing to recompile all extensions for each project they are included into (as opposed to compiling once and just linking). While not leveraged yet, this will let us set definitions controlling the namespacing of the extensions so that they can be made to not conflict across projects (with preprocessor definitions).
* This will be a relatively substantial breaking change for downstreams. I will handle the npcomp migration and will coordinate with the circt folks before landing. We should stage this and make sure it isn't causing problems before landing.
* Fixed a couple of absolute imports that were causing issues.

Differential Revision: https://reviews.llvm.org/D106520
2021-07-27 15:54:58 +00:00
Aart Bik c2415d67a5 [mlir][sparse] fixed bug in verification
The order of testing in two sparse tensor ops was incorrect,
which could cause an invalid cast (crashing the compiler instead
of reporting the error). This revision fixes that bug.

Reviewed By: gussmith23

Differential Revision: https://reviews.llvm.org/D106841
2021-07-27 08:49:21 -07:00
Benjamin Kramer 8c63c24dca [mlir] Fix typo s/applyPermuationMap/applyPermutationMap/ 2021-07-27 12:18:54 +02:00
Jacques Pienaar d425f58939 [mlir] Make ValueShapeRange a new class
Retaining old interface and should be constructable as previous, change would have been NFC except it this doesn't implicitly work with OpAdaptor generated in C++14.

Differential Revision: https://reviews.llvm.org/D106772
2021-07-26 17:08:32 -07:00
Tres Popp 539437e288 [mlir] split type conversion to two lines for GCC's sake 2021-07-26 14:15:47 +02:00
Vladislav Vinogradov eb6c63cb0b [mlir] Fix RankedTensorType::walkImmediateSubElements method
Add 'enconding' attribute visitor.
Without it ASM printer doesn't use attribute aliases for 'enconding'.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D105554
2021-07-26 11:49:25 +03:00
Marcel Koester 0425332015 [mlir] Added new RegionBranchTerminatorOpInterface and adapted uses of hasTrait<ReturnLike>.
This CL adds a new RegionBranchTerminatorOpInterface to query information about operands that can be
passed to successor regions. Similar to the BranchOpInterface, it allows to freely define the
involved operands. However, in contrast to the BranchOpInterface, it expects an additional region
number to distinguish between various use cases which might require different operands passed to
different regions.

Moreover, we added new utility functions (namely getMutableRegionBranchSuccessorOperands and
getRegionBranchSuccessorOperands) to query (mutable) operand ranges for operations equiped with the
ReturnLike trait and/or implementing the newly added interface.  This simplifies reasoning about
terminators in the scope of the nested regions.

We also adjusted the SCF.ConditionOp to benefit from the newly added capabilities.

Differential Revision: https://reviews.llvm.org/D105018
2021-07-26 06:39:31 +02:00
Eugene Zhulenev de7a4e53a2 [mlir] Async: lower SCF operations into CFG inside coroutines
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D106747
2021-07-24 14:36:26 -07:00
Butygin b7a4649899 [mlir] ConversionTarget legality callbacks refactoring
* Get rid of Optional<std::function> as std::function already have a null state
* Add private setLegalityCallback function to set legality callback for unknown ops
* Get rid of unknownOpsDynamicallyLegal flag, use unknownLegalityFn state insted. This causes behavior change when user first calls markUnknownOpDynamicallyLegal with callback and then without but I am not sure is the original behavior was really a 'feature', or just oversignt in the original implementation.

Differential Revision: https://reviews.llvm.org/D105496
2021-07-24 14:59:36 +03:00
Rahul Joshi 17de7ed556 [MLIR][NFC] Minor cleanup in liveness.
- Rename isLastUse to isDeadAfter to reflect what the function does.
- Avoid a second walk over all operations in BlockInfoBuilder constructor.
- use std::move() to save the new in set.

Differential Revision: https://reviews.llvm.org/D106702
2021-07-23 13:30:02 -07:00
Yi Zhang deebf18512 [mlir][linalg] Add pooling_nchw_max, conv_2d_nchw as yaml ops.
- Add pooling_nchw_max.
- Move conv_2d_nchw to yaml ops and add strides and dilation attributes.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D106658
2021-07-23 17:37:15 +00:00
thomasraoux 73a9d6d0e2 [mlir][linalg] Fix bug in contraction op vectorization with output perm
When the output indexing map has a permutation we need to consider in
the contraction vector type.

Differential Revision: https://reviews.llvm.org/D106469
2021-07-23 08:39:43 -07:00
Adrian Kuegel fb978f092c [mlir][Complex]: Add lowerings for AddOp and SubOp from Complex dialect to
Standard.

Differential Revision: https://reviews.llvm.org/D106429
2021-07-23 12:43:45 +02:00
Eugene Zhulenev 6c1f655818 [mlir] Async: special handling for parallel loops with zero iterations
Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D106590
2021-07-23 01:22:59 -07:00
Nicolas Vasilache 06d2fb55ca [mlir][Linalg] Fix a missing copy when source of insert_slice is not inplace.
When the source tensor of a tensor.insert_slice is not equivalent to an inplace buffer an extra copy is necessary. This revision adds the missing copy.

Reviewed By: gysit

Differential Revision: https://reviews.llvm.org/D106587
2021-07-23 07:41:45 +00:00