Commit Graph

33 Commits

Author SHA1 Message Date
River Riddle b74192b7ae [mlir] Remove support for non-prefixed accessors
This finishes off a year long pursuit to LLVMify the generated
operation accessors, prefixing them with get/set. Support for
any other accessor naming is fully removed after this commit.

https://discourse.llvm.org/t/psa-raw-accessors-are-being-removed/65629

Differential Revision: https://reviews.llvm.org/D136727
2022-12-02 13:32:36 -08:00
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
Matthias Springer 9d51b4e4e7 [mlir][vector] Support vector.extractelement distribution of 1D vectors
Ops such as `%1 = vector.extractelement %0[%pos : index] : vector<96xf32>`.

In case of an extract from a 1D vector, the source vector is distributed. The lane into which the requested position falls, extracts the element and shuffles it to all other lanes.

Differential Revision: https://reviews.llvm.org/D137336
2022-11-10 15:07:56 +01:00
stanley-nod d2061530dc [mlir][vector] Modify constraint and interface for warp reduce on f16 and i8
Quantization method is crucial and ubiqutous in accelerating machine
learning workloads. Most of these methods uses f16 and i8 types.

This patch relaxes the type contraints on warp reduce distribution to
allow these types. Furthermore, this patch also changed the interface
and moved the initial reduction of data to a single thread into the
distributedReductionFn, this gives flexibility for developers to control
how they are obtaining the initial lane value, which might differ based
on the input types. (i.e to shuffle 32-width type, we need to reduce f16
to 2xf16 types rather than a single element).

Reviewed By: ThomasRaoux

Differential Revision: https://reviews.llvm.org/D137691
2022-11-09 11:52:17 -08:00
Thomas Raoux 91f62f0e35 [mlir][vector] Fix distribution of scf.for with value coming from above
When a value used in the forOp is defined outside the region but within
the parent warpOp we need to return and distribute the value to pass it
to new operations created within the loop.
Also simplify the lambda interface.

Differential Revision: https://reviews.llvm.org/D137146
2022-11-02 04:15:18 +00:00
Thomas Raoux 1757164eed [mlir][vector] Add distribution for extract from 0d vector
Differential Revision: https://reviews.llvm.org/D135994
2022-10-14 23:06:42 +00:00
Sanjoy Das 86771d0b65 Introduce a ConditionallySpeculatable op interface
This patch takes the first step towards a more principled modeling of undefined behavior in MLIR as discussed in the following discourse threads:

 1. https://discourse.llvm.org/t/semantics-modeling-undefined-behavior-and-side-effects/4812
 2. https://discourse.llvm.org/t/rfc-mark-tensor-dim-and-memref-dim-as-side-effecting/65729

This patch in particular does the following:

 1. Introduces a ConditionallySpeculatable OpInterface that dynamically determines whether an Operation can be speculated.
 2. Re-defines `NoSideEffect` to allow undefined behavior, making it necessary but not sufficient for speculation.  Also renames it to `NoMemoryEffect`.
 3. Makes LICM respect the above semantics.
 4. Changes all ops tagged with `NoSideEffect` today to additionally implement ConditionallySpeculatable and mark themselves as always speculatable.  This combined trait is named `Pure`.  This makes this change NFC.

For out of tree dialects:

 1. Replace `NoSideEffect` with `Pure` if the operation does not have any memory effects, undefined behavior or infinite loops.
 2. Replace `NoSideEffect` with `NoSideEffect` otherwise.

The next steps in this process are (I'm proposing to do these in upcoming patches):

 1. Update operations like `tensor.dim`, `memref.dim`, `scf.for`, `affine.for` to implement a correct hook for `ConditionallySpeculatable`.  I'm also happy to update ops in other dialects if the respective dialect owners would like to and can give me some pointers.
 2. Update other passes that speculate operations to consult `ConditionallySpeculatable` in addition to `NoMemoryEffect`.  I could not find any other than LICM on a quick skim, but I could have missed some.
 3. Add some documentation / FAQs detailing the differences between side effects, undefined behavior, speculatabilty.

Reviewed By: rriddle, mehdi_amini

Differential Revision: https://reviews.llvm.org/D135505
2022-10-12 10:56:12 -07:00
Jakub Kuderski abc362a107 [mlir][arith] Change dialect name from Arithmetic to Arith
Suggested by @lattner in https://discourse.llvm.org/t/rfc-define-precise-arith-semantics/65507/22.

Tested with:
`ninja check-mlir check-mlir-integration check-mlir-mlir-spirv-cpu-runner check-mlir-mlir-vulkan-runner check-mlir-examples`

and `bazel build --config=generic_clang @llvm-project//mlir:all`.

Reviewed By: lattner, Mogball, rriddle, jpienaar, mehdi_amini

Differential Revision: https://reviews.llvm.org/D134762
2022-09-29 11:23:28 -04:00
Thomas Raoux 4abb9e5d20 [mlir][vector] Clean up and generalize lowering of warp_execute to scf
Simplify the lowering of warp_execute_on_lane0 of scf.if by making the
logic more generic. Also remove the assumption that the most inner
dimension is the dimension distributed.

Differential Revision: https://reviews.llvm.org/D133826
2022-09-14 17:36:16 +00:00
Nicolas Vasilache 845dc178c0 [mlir][Vector] Support broadcast vector type in distribution of vector.warp_execute_on_lane_0.
This revision significantly improves and tests the broadcast behavior of vector.warp_execute_on_lane_0.

Previously, the implementation of the broadcast behavior of vector.warp_execute_on_lane_0
assumed that the broadcasted value was always of scalar type.

This is not necessarily the case.

Differential Revision: https://reviews.llvm.org/D133767
2022-09-13 08:18:47 -07:00
Nicolas Vasilache 20df17fd2d [mlir][vector] Extend WarpExecutionOnLane0 pattern support to allow deduplicating identical yield values.
Differential Revision: https://reviews.llvm.org/D133573
2022-09-09 06:53:36 -07:00
Nicolas Vasilache 27cc31b64c [mlir][vector] NFC - Clean up vector patterns and propagate benefit through populate functions
Differential Revision: https://reviews.llvm.org/D133559
2022-09-09 02:45:22 -07:00
Thomas Raoux 06413618ea [mlir][vector] Don't duplicate transfer_read during vector distribution
Only apply the pattern if the transfer_read can be distributed for all
its uses.

Differential Revision: https://reviews.llvm.org/D133538
2022-09-09 06:35:40 +00:00
Mehdi Amini 61f06774ff Apply clang-tidy fixes for performance-unnecessary-value-param in VectorDistribute.cpp (NFC) 2022-09-08 00:05:22 +00:00
Nicolas Vasilache fa8a10a1fd [mlir][Vector] Refactor vector distribution and fix an issue related to non-homogenous transfer indices.
Running: `mlir-opt -test-vector-warp-distribute=rewrite-warp-ops-to-scf-if -canonicalize -verify-each=0`.

Prior to this revision, IR resembling the following would be produced:
```
  %4 = "vector.load"(%3, %arg0) : (memref<1x32xf32, 3>, index) -> vector<1x1xf32>
```
This fails verification since it needs 2 indices to load but only 1 is provided.

Differential Revision: https://reviews.llvm.org/D133106
2022-09-02 02:18:26 -07:00
Thomas Raoux f48ce52c4c [mlir][vector] Pattern to clean up vector.extract during distribution
This prevents blocking propagation when converting between scalar and
vector<1>

Differential Revision: https://reviews.llvm.org/D129782
2022-07-14 17:07:32 +00:00
Thomas Raoux ffa7384f10 [mlir][vector] Support distribution of vector.reduce with accumulator
Right now the pattern was ignoring the optional accumulator.

Differential Revision: https://reviews.llvm.org/D129719
2022-07-14 14:28:38 +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
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
Nicolas Vasilache 6a57d8fba5 [mlir][vector] Untangle TransferWriteDistribution and avoid crashing in the 0-D case.
This revision avoids a crash in the 0-D case of distributing vector.transfer ops out of
vector.warp_execute_on_lane_0.
Due to the code complexity and lack of documentation, it took untangling the implementation
before realizing that the simple fix was to fail in the 0-D case.
The rewrite is still very useful to understand this code better.

Differential Revision: https://reviews.llvm.org/D128793
2022-07-01 00:15:34 -07:00
Mehdi Amini 08d651d7ba Apply clang-tidy fixes for performance-unnecessary-value-param in VectorDistribute.cpp (NFC) 2022-06-28 19:52:46 +00:00
Thomas Raoux d343cdd509 [mlir][vector] Fix bug when swapping scf.for and vector warp op
When creating a scf.for without argument a scf.yield is automatically
created. Make sure we don't create a second one.

Differential Revision: https://reviews.llvm.org/D128405
2022-06-24 19:13:02 +00:00
Thomas Raoux 7eba5cdf9c [mlir][vector] Relax transfer_write vector distribution pattern
Small change to relax the pattern to support any vector containing a
single element.

Differential Revision: https://reviews.llvm.org/D128545
2022-06-24 19:03:14 +00:00
Nicolas Vasilache f6c79c6ae4 [mlir][Vector]Fix bug where vector::WarpExecuteOnLane0Op are created with 2 blocks in the region
Differential Revision: https://reviews.llvm.org/D128534
2022-06-24 07:33:58 -07:00
Alex Zinenko 8b68da2c7d [mlir] move SCF headers to SCF/{IR,Transforms} respectively
This aligns the SCF dialect file layout with the majority of the dialects.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D128049
2022-06-20 10:18:01 +02:00
Thomas Raoux 6834803c3d [mlir][vector] NFC remove dependency of VectorTransform to GPU dialect
Make the reduction distribution pattern more generic and remove layering
problem. The new pattern to distribute reduction is now independent of
GPU and takes a lamdba to decide how the distributed reduction should be
generated.

Differential Revision: https://reviews.llvm.org/D127867
2022-06-15 16:08:29 +00:00
Thomas Raoux 087aba4f0f [mlir][vector] Add pattern to distribute vector reduction to GPU shuffles
Add a pattern to do ad hoc lowering of vector.reduction to a sequence of
warp shuffles. This allow distributing reduction on a warp for GPU targets.
Also add an execution test for warp reduction.

co-authored with @springerm

Differential Revision: https://reviews.llvm.org/D127176
2022-06-14 05:49:16 +00:00
Thomas Raoux 76cf33dab2 [mlir][vector] Add patterns to ppropagate vector distribution
Add patterns to propagate vector distribution and remove dead
arguments. This handles propagation for several vector operations.

recommit after minor bug fix.

Differential Revision: https://reviews.llvm.org/D127167
2022-06-14 05:26:10 +00:00
Thomas Raoux 2d32dac8bb Revert "[mlir][vector] Add patterns to ppropagate vector distribution"
This reverts commit 1c84800c42.

This was causing asan crash.
2022-06-13 17:55:31 +00:00
Thomas Raoux 1c84800c42 [mlir][vector] Add patterns to ppropagate vector distribution
Add patterns to propagate vector distribution and remove dead
arguments. This handles propagation for several vector operations.

Differential Revision: https://reviews.llvm.org/D127167
2022-06-13 16:38:50 +00:00
Thomas Raoux ed0288f7c4 [mlir][vector] Add patterns for vector distribution
Add pattern to hoist scalar code outside of warp distribute region as
those cannot be distributed and we would want to execute them on all
the lanes.
Add patterns to distribute transfer_write ops. Those operations can be
distributed in different ways and it is control by user.

Differential Revision: https://reviews.llvm.org/D127152
2022-06-10 17:46:51 +00:00
Thomas Raoux d02f10d96d [mlir][vector] Add lowering pattern for vector.warp_execute_on_lane_0 op
Add lowering of the vector.warp_execute_on_lane_0 into scf.if plus memory
transfer for the operands and yield values.

This also add an integration test running on GPU warp. The same tests can be
later re-used with different comment lines to tests distribution
transformations.

This is mostly from @springerm contribution.

Differential Revision: https://reviews.llvm.org/D125430
2022-05-12 13:27:43 +00:00