Commit Graph

8780 Commits

Author SHA1 Message Date
Matthias Springer
16b75cd2bb [mlir][vector] Use DenseI64ArrayAttr for ExtractOp/InsertOp positions
`DenseI64ArrayAttr` provides a better API than `I64ArrayAttr`. E.g., accessors returning `ArrayRef<int64_t>` (instead of `ArrayAttr`) are generated.

Differential Revision: https://reviews.llvm.org/D156684
2023-07-31 15:25:37 +02:00
Matthias Springer
aba0ef7059 [mlir][bufferization] Support casts in EmptyTensorElimination
EmptyTensorElimination is a pre-bufferization transformation that replaces "tensor.empty" ops with "tensor.extract_slice" ops. This revision adds support for cases where the input IR contains "tensor.cast" ops.

Differential Revision: https://reviews.llvm.org/D156167
2023-07-31 15:20:00 +02:00
Matthias Springer
b2826c0209 [mlir][NFC] Move offsets/sizes/strides helper to dialect utils and interface header
* Move `foldDynamicIndexList` to `DialectUtils` and simplify function.
* Move `OpWithOffsetSizesAndStridesConstantArgumentFolder` to `ViewLikeInterface` and add documentation.

Differential Revision: https://reviews.llvm.org/D156581
2023-07-31 14:53:14 +02:00
Alex Zinenko
8e4887a12e [mlir] use a thread-local alternative to llvm::nulls
LLVM is not set up in a thread-safe way, which seems to be leading to
race conditions when sending stuff to llvm::nulls in opt builds. Try a
thread-local alternative.

Reviewed By: pzread

Differential Revision: https://reviews.llvm.org/D156421
2023-07-31 08:21:21 +00:00
Jacques Pienaar
239777c861 [mlir][emitc] Add literal constant.
A literal constant is not emitted as a variable but rather printed inline. The
form used is same as the Attribute emission form.

Differential Revision: https://reviews.llvm.org/D150356
2023-07-29 12:27:23 -07:00
Srishti Srivastava
a9ab845cb1 [MLIR][analysis] Fix error in the sparse backward dataflow analysis
Earlier, in the sparse backward dataflow analysis, data from the results
of an op implementing `RegionBranchOpInterface` was considered to flow
into the operands of every op that did not implement the
`RegionBranchTerminatorOpInterface` but was return-like and present
in a region of the former. It was thus also expected that the number of
results of the former be equal to the number of operands in the latter.

This understanding of dataflow is incorrect and thus this expectation is
also not justified. This commit fixes this incorrect understanding.

This commit ensures that these return-like ops are handled just like the
ops implementing the `RegionBranchTerminatorOpInterface`, which means
that, if this op has a region `A` whose successors are regions `B`, `C`,
and `D`, then data flows from the arguments (successor inputs) of `B`,
`C`, and `D` to the corresponding successor operands of this op.

This fix is also propagated to liveness analysis that earlier relied on
this incorrect implementation of the sparse backward dataflow analysis
framework and corrects some incorrect assumptions made in it.

Also cleaned up some unnecessary comments from the test file.

Issue: https://github.com/llvm/llvm-project/issues/64139.

Signed-off-by: Srishti Srivastava <srishtisrivastava.ai@gmail.com>

Reviewed By: jcai19, matthiaskramm, Mogball

Differential Revision: https://reviews.llvm.org/D156376
2023-07-29 06:31:24 +00:00
Matteo Franciolini
cf0e8dca84 Add support for versioning properties in MLIR bytecode
[mlir] Add support for custom readProperties/writeProperties methods.

Currently, operations that opt-in to adopt properties will see auto-generated readProperties/writeProperties methods to emit and parse bytecode. If a dialects opts in to use `usePropertiesForAttributes`, those definitions will be generated for the current definition of the op without the possibility to handle attribute versioning.

The patch adds the capability for an operation to define its own read/write methods for the encoding of properties so that versioned operations can handle upgrading properties encodings.

In addition to this, the patch adds an example showing versioning on NamedProperties through the dialect version API exposed by the reader.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D155340
2023-07-28 19:44:33 -07:00
Matteo Franciolini
bff6a4292f Expose callbacks for encoding of types/attributes
[mlir] Expose a mechanism to provide a callback for encoding types and attributes in MLIR bytecode.

Two callbacks are exposed, respectively, to the BytecodeWriterConfig and to the ParserConfig. At bytecode parsing/printing, clients have the ability to specify a callback to be used to optionally read/write the encoding. On failure, fallback path will execute the default parsers and printers for the dialect.

Testing shows how to leverage this functionality to support back-deployment and backward-compatibility usecases when roundtripping to bytecode a client dialect with type/attributes dependencies on upstream.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D153383
2023-07-28 16:45:42 -07:00
Mehdi Amini
b86a13211f Revert "Expose callbacks for encoding of types/attributes"
This reverts commit b299ec1666.

The authorship informations were incorrect.
2023-07-28 16:45:42 -07:00
Mehdi Amini
b299ec1666 Expose callbacks for encoding of types/attributes
[mlir] Expose a mechanism to provide a callback for encoding types and attributes in MLIR bytecode.

Two callbacks are exposed, respectively, to the BytecodeWriterConfig and to the ParserConfig. At bytecode parsing/printing, clients have the ability to specify a callback to be used to optionally read/write the encoding. On failure, fallback path will execute the default parsers and printers for the dialect.

Testing shows how to leverage this functionality to support back-deployment and backward-compatibility usecases when roundtripping to bytecode a client dialect with type/attributes dependencies on upstream.

Reviewed By: rriddle

Differential Revision: https://reviews.llvm.org/D153383
2023-07-28 10:44:02 -07:00
Mogball
681d59f9ed [mlir][llvm] Improve error message when translating llvm.call_intrinsic (RELAND)
This is more user-friendly over an opaque crash.

Reland after fixing bad rebase.
2023-07-28 17:03:19 +00:00
Martin Erhart
17aaa651db [mlir][bufferization] Add DeallocOp canonicalizer to remove duplicate values
Duplicate values in the retained list can just be removed, however, for duplicates in the list of memrefs to deallocate, we also need to check the conditions and if thhey don't match, we need to compute the OR in order to not miss a case leading to a memory leak.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D156157
2023-07-28 16:27:32 +00:00
Groverkss
0ff1048409 [mlir][vector] Add transform.apply_patterns.vector.fold_arith_extension
This patch implements a transform op for the FoldArithExtIntoContractionOp
pattern. The pattern folds arith.extf into vector.contract for the
backends with native support for mixed-mode contractions.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D156484
2023-07-28 18:40:31 +05:30
Mehdi Amini
cd029a4f5c Revert "[mlir][llvm] Improve error message when translating llvm.call_intrinsic"
This reverts commit 5a51a44f82.

The build is broken.
2023-07-28 01:07:40 -07:00
Mogball
5a51a44f82 [mlir][llvm] Improve error message when translating llvm.call_intrinsic
This is more user-friendly over an opaque crash.

Reviewed By: lattner

Differential Revision: https://reviews.llvm.org/D156475
2023-07-28 07:17:21 +00:00
River Riddle
cbdf2ef8a4 [mlir-lsp] Guard writing output to JSONTransport with mutex
This allows for users of the lsp transport libraries to process replies
in parallel, without overlapping/clobbering the output.

Differential Revision: https://reviews.llvm.org/D156295
2023-07-27 18:27:55 -07:00
Quinn Dawkins
024ae73fa1 [mlir][Transform] Add transform.any_param type
Introduces a generic parameter type intended for transform dialect use
cases that uses/manipulates the underlying attribute (e.g. op
annotation). Includes a disclaimer that mixing parameter based and
attribute based control is discouraged.

Differential Revision: https://reviews.llvm.org/D155980
2023-07-27 14:10:29 -04:00
Alex Zinenko
b2b7efb96d [mlir] NFC: rename XDataFlowAnalysis to XForwardDataFlowAnalysis
This makes naming consisnt with XBackwardDataFlowAnalysis.

Reviewed By: Mogball, phisiart

Differential Revision: https://reviews.llvm.org/D155930
2023-07-27 11:11:40 +00:00
Razvan Lupusoru
52a0b6a662 [openacc] Add acc routine support to acc dialect
Adds representation for `acc routine` under new operation named
`acc.routine`. This operation is associated with a function symbol.
It also gets its own compiler generated synthetic symbol name so
that it can be referenced from the associated function. The clauses
associated with the `acc routine` directive are captured in the
`acc.routine` op.

The linking between the `func.func` and its `acc.routine` declaration
is done through the `acc.routine_info` attribute. In practice, a
single `acc routine` is associated with a function. But the spec does
not specifically restrict this - thus the 1:N relationship between
`func.func` and `acc.routine` allowed in the dialect. Additionally, it
makes sense that multiple acc routines could be used for a single
function depending on loop context - to allow flexible parallelization.

Most acc routine clauses are supported including `gang`, `gang(dim:)`,
`vector`, `worker`, `seq`, `nohost`, and `bind`. The only one not
supported is `device_type`. This is because most other clauses also
miss this and the effort to add support for it needs to be coordinated
and consistent.

Reviewed By: clementval, vzakhari

Differential Revision: https://reviews.llvm.org/D156281
2023-07-26 15:06:39 -07:00
Nicolas Vasilache
52556c8e35 [mlir][Linalg] NFC - Retire LinalgToLLVM pass 2023-07-26 20:26:07 +02:00
Mathieu Fehr
6971b83b2f [mlir][irdl] Add Variadicity to IRDL operations
This patch adds optional and variadic operands and results
to IRDL. These are added using the `irdl.variadicity` attribute,
which has to be attached to every `irdl.operands` and `irdl.results`
operations.

For instance:
```mlir
irdl.operands(%0, single %1, optional %2, variadic %3)
```
has 4 operand definitions. The first two are single operands,
the second one is optional, and the last one is variadic.

Note that this patch only adds the variadicities to the definition,
but does not consider them when loading a dialect at runtime. This
will be done in the next patch.

Reviewed By: Mogball, unterumarmung

Differential Revision: https://reviews.llvm.org/D153983
2023-07-26 18:20:48 +01:00
SJW
cdf7ca6db7 [MLIR][ROCDL] Add conversion for gpu.lane_id to ROCDL
Creates rocdl.lane_id op with llvm conversion to:

  __device__ static unsigned int __lane_id() {
      return  __builtin_amdgcn_mbcnt_hi(
                 -1, __builtin_amdgcn_mbcnt_lo(-1, 0));
  }

Reviewed By: krzysz00

Differential Revision: https://reviews.llvm.org/D154666
2023-07-26 15:12:48 +00:00
iambrj
56863adf8e [MLIR][Presburger] Implement findSymbolicIntegerLexMax for IntegerRelation
This patch implements findSymbolicIntegerLexMax for IntegerRelation

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D156023
2023-07-26 19:36:29 +05:30
max
25b8433b75 add set_type to ir.Value
Differential Revision: https://reviews.llvm.org/D156289
2023-07-26 07:28:21 -05:00
Tobias Gysi
0fc8d9e41a [mlir][llvm] Remove the metadata op
This revision removes the metadata op, that to the best of our
knowledge, has no more uses after switching to a purely attribute based
metadata representation:
https://reviews.llvm.org/D155444
https://reviews.llvm.org/D155285
https://reviews.llvm.org/D155159
These changes got unlocked after landing distinct attribute support:
https://reviews.llvm.org/D153360,
which enables modeling distinct metadata using attributes. As a result,
all metadata kinds are now represented using attributes. Previously,
there has been a mix of attribute and op based representations.

Having attribute only metadata makes it possible to update the metadata
in-parallel, while updating the global metadata operation has been
a sequential process. The LLVM Dialect inliner already benefits from
this change and now creates new alias scopes and domains during
inlining rather than dropping the no alias information:
https://reviews.llvm.org/D155712

Reviewed By: Dinistro

Differential Revision: https://reviews.llvm.org/D156217
2023-07-26 11:42:52 +00:00
Nicolas Vasilache
44e6318cea [mlir][transforms] Revamp the implementation of mapping loops to GPUs
This revision significantly simplifies the specification and implementation of mapping loops to GPU ids.

Each type of mapping (block, warpgroup, warp, thread) now comes with 2 mapping modes:
  1. a 3-D "grid-like" mode, subject to alignment considerations on threadIdx.x, on which predication
     may occur on a per-dimension 3-D sub-rectangle basis.
  2. a n-D linearized mode, on which predication may only occur on a linear basis.

In the process, better size and alignment requirement inference are introduced along with improved runtime verification messages.

The `warp_dims` attribute was deemed confusing and is removed from the transform in favor of better size inference.

Differential Revision: https://reviews.llvm.org/D155941
2023-07-26 00:09:08 +02:00
Fangrui Song
1b162fabe8 [Support] Change SetVector's default template parameter to SmallVector<*, 0>
Similar to D156016 for MapVector.

This brings back commit fae7b98c22 with a
fix to llvm/unittests/Support/ThreadPool.cpp's `_WIN32` code path.
2023-07-25 13:13:35 -07:00
Quinn Dawkins
ff8775f3ff [mlir][GPU] Add op for unrolling contractions to a native size
Adds `apply_patterns.gpu.unroll_vectors_subgroup_mma` which allows
specifying a native MMA shape of `m`, `n`, and `k` to unroll to,
greedily unrolling the inner most dimension of contractions and other
vector operations based on expected usage.

Differential Revision: https://reviews.llvm.org/D156079
2023-07-25 13:11:32 -04:00
Simon Pilgrim
3d83912c0c Revert rGfae7b98c221b5b28797f7b56b656b6b819d99f27 "[Support] Change SetVector's default template parameter to SmallVector<*, 0>"
This is failing on Windows MSVC builds:
llvm\unittests\Support\ThreadPool.cpp(380): error C2440: 'return': cannot convert from 'Vector' to 'std::vector<llvm::BitVector,std::allocator<llvm::BitVector>>'
        with
        [
            Vector=llvm::SmallVector<llvm::BitVector,0>
        ]
2023-07-25 10:22:08 +01:00
Cullen Rhodes
ca9a3354d0 [mlir][ArmSME] Add tile load op and extend tile store tile size support
This extends the existing 'arm_sme.tile_store' op to support all tile
sizes and adds a new op 'arm_sme.tile_load', as well as lowerings from
vector -> custom ops and custom ops -> intrinsics. Currently there's no
lowering for i128.

Depends on D154867

Reviewed By: awarzynski, dcaballe

Differential Revision: https://reviews.llvm.org/D155306
2023-07-25 08:28:36 +00:00
Fangrui Song
fae7b98c22 [Support] Change SetVector's default template parameter to SmallVector<*, 0>
Similar to D156016 for MapVector.
2023-07-25 00:39:17 -07:00
Fangrui Song
480d7a3aff [mlir-tblgen] Fix IWYU
Right now std::vector is instantiated with an incomplete element type,
which is ok but best to avoid.
2023-07-24 21:50:29 -07:00
Mehdi Amini
9ea6b30ac2 Update ODS variadic segments "magic" attributes to use native Properties
The operand_segment_sizes and result_segment_sizes Attributes are now inlined
in the operation as native propertie. We continue to support building an
Attribute on the fly for `getAttr("operand_segment_sizes")` and setting the
property from an attribute with `setAttr("operand_segment_sizes", attr)`.

A new bytecode version is introduced to support backward compatibility and
backdeployments.

Differential Revision: https://reviews.llvm.org/D155919
2023-07-24 18:16:58 -07:00
Nicolas Vasilache
90ecfa2a40 [mlir][linalg] NFC - Move some utils in preparation for revamping mapping of scf.forall 2023-07-25 01:19:57 +02:00
Ivan Butygin
8568921d43 [mlir][spirv] Convert ub.poison to spirv.undef
SPIR-V doesn't have poison, but poison can be converted to undef.

Differential Revision: https://reviews.llvm.org/D156163
2023-07-25 00:23:09 +02:00
Mehdi Amini
a7cd64c9f1 Revert "Update ODS variadic segments "magic" attributes to use native Properties"
This reverts commit 20b93abca6.

One python test is broken, WIP.
2023-07-24 12:27:42 -07:00
Mehdi Amini
20b93abca6 Update ODS variadic segments "magic" attributes to use native Properties
The operand_segment_sizes and result_segment_sizes Attributes are now inlined
in the operation as native propertie. We continue to support building an
Attribute on the fly for `getAttr("operand_segment_sizes")` and setting the
property from an attribute with `setAttr("operand_segment_sizes", attr)`.

A new bytecode version is introduced to support backward compatibility and
backdeployments.

Differential Revision: https://reviews.llvm.org/D155919
2023-07-24 11:37:57 -07:00
Mehdi Amini
5e8a1164f2 Revert "[mlir][gpu] Fallback to JIT compilation" "[mlir][gpu] Increase default SM version from 35 to 50" and "[mlir][gpu] Improving Cubin Serialization with ptxas Compiler"
This reverts commit 2e0e00ed84
and reverts commit a6eb40692c
and reverts commit 585cbe3f63.

15 tests are broken on the mlir-nvidia buildbot:

'cuModuleLoadData(&module, data)' failed with 'CUDA_ERROR_INVALID_SOURCE'
'cuModuleGetFunction(&function, module, name)' failed with 'CUDA_ERROR_INVALID_HANDLE'
'cuLaunchKernel(function, gridX, gridY, gridZ, blockX, blockY, blockZ, smem, stream, params, extra)' failed with 'CUDA_ERROR_INVALID_HANDLE'
'cuModuleUnload(module)' failed with 'CUDA_ERROR_INVALID_HANDLE'
2023-07-24 10:23:15 -07:00
Ivan Butygin
0f446adf67 [mlir] Convert ub.poison to llvm.poison
Differential Revision: https://reviews.llvm.org/D155945
2023-07-24 18:40:12 +02:00
Lorenzo Chelini
0736200de4 [MLIR][Linalg] Move AggregatedOpInterface in linalg namespace (NFC)
For now, the interface is specific to linalg only.

Reviewed By: qcolombet

Differential Revision: https://reviews.llvm.org/D156091
2023-07-24 16:22:39 +02:00
Quinn Dawkins
80aed2ea45 [mlir][Transform] Allow printing inside matchers
Enables printf style debugging of matchers through `transform.print`
within the body of a matcher.

Differential Revision: https://reviews.llvm.org/D156078
2023-07-24 10:00:23 -04:00
Guray Ozen
585cbe3f63 [mlir][gpu] Improving Cubin Serialization with ptxas Compiler
This work improves how we compile the generated PTX code using the `ptxas` compiler. Currently, we rely on the driver's jit API to compile the PTX code. However, this approach has some limitations. It doesn't always produce the same binary output as the ptxas compiler, leading to potential inconsistencies in the generated Cubin files.

This work introduces a significant improvement by directly utilizing the ptxas compiler for PTX compilation. By doing so, we can achieve more consistent and reliable results in generating cubin files. Key Benefits:
- Using the Ptxas compiler directly ensures that the cubin files generated during the build process remain consistent with CUDA compilation using `nvcc` or `clang`.
- Another advantage of this work is that it allows developers to experiment with different ptxas compilers without the need to change the compiler. Performance among ptxas compiler versions are vary, therefore, one can easily try different ptxas compilers.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D155563
2023-07-24 12:29:53 +02:00
Daniil Dudkin
8be07adfb4 [mlir][LLVM] Introduce reduction intrinsics for minimum/maximum
This patch adds supports for the reduction intrinsic
for floating point minimum and maximum that have
been added to LLVM by https://reviews.llvm.org/D152370.

Related to: #63969

Reviewed By: dcaballe

Differential Revision: https://reviews.llvm.org/D155869
2023-07-22 16:25:32 +03:00
Fabian Mora
4538347fb2 [mlir][rocdl] Change the translation of GridDim*Op to __ockl_get_num_groups
Currently, `ROCDL::GridDim*Op` is being translated to `__ockl_get_global_size`, however
to match the meaning of `gpu.grid_dim` it should instead be translated to
`__ockl_get_num_groups`. This change would also make it agree with the meaning
of `gridDimx.*` in HIP, see:
https://github.com/ROCm-Developer-Tools/hipamd/blob/develop/include/hip/amd_detail/amd_hip_runtime.h#L257

Difference between the functions:
```
__ockl_get_global_size =  blockDim * numBlocks
__ockl_get_num_groups = numBlocks
```

Reviewed By: krzysz00

Differential Revision: https://reviews.llvm.org/D156009
2023-07-22 11:33:11 +00:00
Matthias Springer
0318123f67 [mlir][Transforms] GreedyPatternRewriteDriver: Fix changed parameter
`changed` was not updated correctly when it was already set to "true" before calling `applyPatternsAndFoldGreedily`.

Differential Revision: https://reviews.llvm.org/D155934
2023-07-22 08:31:24 +02:00
Matthias Springer
c2d5d348a8 [mlir][transform] Add transform.apply_dce op
Add a transform that eliminates dead operations. This is useful after certain transforms (such as fusion) that create/clone new IR but leave the original IR in place.

Differential Revision: https://reviews.llvm.org/D155954
2023-07-22 08:25:02 +02:00
TatWai Chong
a5f0b237be [mlir][tosa][fix] Add proper type checking trait for tosa mul
when operating integer type tensors, tosa elementwise multiplication
requires the element type of result to be a 32-bit integer rather
than the same type as inputs.

Change-Id: Ifd3d7ebd879be5c6b2c8e23aa6d7ef41f39c6d41

Reviewed By: mgehre-amd

Differential Revision: https://reviews.llvm.org/D154988
2023-07-21 23:29:05 +00:00
Jakub Kuderski
eaa4bc6557 [mlir][arith] Add canon pattern for chained arith.muli
@benvanik reported this as missing.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D155907
2023-07-21 18:20:31 -04:00
Rafael Ubal Tena
b2d76a063d TOSA-to-Linalg lowering for element-wise ops
- Wrote complete documentation for the `Broadcastable` op trait. This is mostly meant as a thorough description of its previous behavior, with the exception of minor feature updates.

- Restricted legality criteria for a `Broadcastable` op in order to simplify current and future lowering passes and increase efficiency of code generated by those passes. New restriction are: 1) A dynamic dimension in an inferred result is not compatible with a static dimension in the actual result. 2) Broadcast semantics are restricted to input operands and not supported between inferred and actual result shapes.

- Implemented TOSA-to-Linalg lowering support for unary, binary, tertiary element-wise ops. This support is complete for all legal cases described in the `Broadcastable` trait documentation.

- Added unit tests for `tosa.abs`, `tosa.add`, and `tosa.select` as examples of unary, binary, and tertiary ops.

Reviewed By: eric-k256

Differential Revision: https://reviews.llvm.org/D153291
2023-07-21 22:08:33 +00:00
Jacques Pienaar
863e8123df [mlir] Move attr -> properties to not require Operation
This allows for converting before/without an Operation is created.

Differential Revision: https://reviews.llvm.org/D155996
2023-07-21 14:54:43 -07:00