Commit Graph

147 Commits

Author SHA1 Message Date
Aart Bik
36fd28752f [mlir][sparse] move emitter ownership into environment
last bits and pieces of the environment refactoring

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D140709
2022-12-27 16:55:07 -08:00
Peiming Liu
781eabeb40 [mlir][sparse] refactoring loop emitter into its own files.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D140701
2022-12-27 19:12:05 +00:00
Peiming Liu
49be68b8aa [mlir][sparse] make loop emitter API more concise.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D140583
2022-12-22 21:17:29 +00:00
Aart Bik
8109d5e911 [mlir][sparse] move loop boundary method to codegenenv
Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D140578
2022-12-22 12:40:45 -08:00
Aart Bik
384049a755 [mlir][sparse] completed codegen environment privatization
All members are now private and access is through delegate
or convenience methods only (except the loop emitter, which
is still under refactoring).

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D140519
2022-12-22 10:34:43 -08:00
Aart Bik
fbe611309e [mlir][sparse] refactored codegen environment into its own file
Also, as a proof of concept, all functionality related to reductions
has been refactored into private fields and a clean public API. As a
result, some dead code was found as well. This approach also simplifies
asserting on a proper environment state for each call.

NOTE: making all other fields private and migrating more methods into
      this new class is still TBD in yes another next revision!

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D140443
2022-12-20 16:58:59 -08:00
Aart Bik
98f93e3b72 [mlir][sparse] factorized merger/emitter/codegen into single environment
This cleans up a lot of parameter passing. It also prepares adding
proper "delegate" functions to the new environment and moving this
out into its own class with a better OO design.

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D140257
2022-12-20 11:34:12 -08:00
Fangrui Song
76b1100372 [mlir] llvm::Optional::value() && => operator*/operator->
std::optional::value() has undesired exception checking semantics and is
unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The
call sites block std::optional migration.
2022-12-17 19:23:50 +00:00
Fangrui Song
cbb0981388 [mlir] llvm::Optional::value => operator*/operator->
std::optional::value() has undesired exception checking semantics and is
unavailable in older Xcode (see _LIBCPP_AVAILABILITY_BAD_OPTIONAL_ACCESS). The
call sites block std::optional migration.
2022-12-17 19:07:38 +00:00
Peiming Liu
faa75f94f1 [mlir][sparse] reject kernels with non-sparsfiable reduction expression.
To address https://github.com/llvm/llvm-project/issues/59394.

Reduction on negation of the output tensor is a non-sparsifiable kernel, it creates cyclic dependency.

This patch reject those cases instead of crashing.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D139659
2022-12-08 23:36:30 +00:00
Kazu Hirata
1a36588ec6 [mlir] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the
compiler would warn if None were deprecated.  The intent is to reduce
the amount of manual work required in migrating from Optional to
std::optional.

This is part of an effort to migrate from llvm::Optional to
std::optional:

https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
2022-12-03 18:50:27 -08:00
Peiming Liu
169f055653 [mlir][sparse] fix compiler warning when using release build.
Differential Revision: https://reviews.llvm.org/D138533
2022-11-23 00:53:50 +00:00
Peiming Liu
27aabca058 [mlir][sparse] make resolve cycle works with affine expressions.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138173
2022-11-23 00:09:33 +00:00
Peiming Liu
e5e4deca5e [mlir][sparse] support affine expression on sparse dimensions (codegen implementation)
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138172
2022-11-23 00:04:55 +00:00
Peiming Liu
372e7939d7 [mlir][sparse] support affine expression on sparse dimensions (analysis implementation)
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138171
2022-11-23 00:02:47 +00:00
Peiming Liu
4fd3a1201e [mlir][sparse] support constant affine expression on dense dimension
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138170
2022-11-22 22:34:42 +00:00
Peiming Liu
fb28733541 [mlir][sparse] support affine expression on dense dimensions (except constant affine)
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138169
2022-11-22 01:31:19 +00:00
Aliia Khasanova
399638f98c Merge kDynamicSize and kDynamicSentinel into one constant.
resolve conflicts

Differential Revision: https://reviews.llvm.org/D138282
2022-11-21 13:01:26 +00:00
Peiming Liu
d083dc63bb [mlir][sparse] refactoring: move genAffine to loopEmitter
This is the beginning patch of a sequence of dependent patches that in together provide the affine expression on matched indexing mapping for sparse tensors.

This patch itself simply move `genAffine` into loop emitter to be prepared for upcoming patches.

D138169 provides support for affine expression on dense dimensions only (except for constant affine expression)
D138170 provides support for constant affine expressions on dense dimensions
D138171 provides **merger** support for affine expression on sparse dimension (without codegen)
D138172 provides **codegen** support (by generating a "filter" loop) for affine expression on sparse dimensions.
D138173 fixes a crash on resolveCycle when dealing with affine expressions.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138168
2022-11-18 21:39:04 +00:00
Peiming Liu
91e7b9e525 [mlir][sparse] annotate loops that are generated by loop emitter.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D138155
2022-11-17 00:09:33 +00:00
Aart Bik
0e1708ff64 [mlir][sparse] cleanup small vector constant hints
Following advise from

https://llvm.org/docs/ProgrammersManual.html#llvm-adt-smallvector-h

This revision removes the size hints from SmallVector (unless we are
certain of the resulting number of elements). Also, this replaces
SmallVector references with SmallVectorImpl references.

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D138063
2022-11-15 15:09:06 -08:00
Oleg Shyshkov
e6598b053d Revert "Revert "[mlir][linalg] Replace "string" iterator_types attr with enums in LinalgInterface.""
With python code fixed.

This reverts commit 41280908e4.
2022-11-11 10:54:08 +01:00
Oleg Shyshkov
41280908e4 Revert "[mlir][linalg] Replace "string" iterator_types attr with enums in LinalgInterface."
Breaks linalg python tests. Would need to also update python/mlir/dialects/linalg/opdsl.

This reverts commit b809d73973.
2022-11-09 15:59:54 +01:00
Oleg Shyshkov
b809d73973 [mlir][linalg] Replace "string" iterator_types attr with enums in LinalgInterface.
[RFC: EnumAttr for iterator types in Linalg](https://discourse.llvm.org/t/rfc-enumattr-for-iterator-types-in-linalg/64535)

This affect touches and probably breaks most of the code that creates `linalg.generic`. A fix would be to replace calls to `getParallelIteratorTypeName/getReductionIteratorTypeName` with `mlir::utils::IteratorType::parallel/reduction` and types from `StringRef` to `mlir::utils::IteratorType`.

Due to limitations of tablegen, shared C++ definition of IteratorType enum lives in StructuredOpsUtils.td, but each dialect should have it's own EnumAttr wrapper. To avoid conflict, all enums in a dialect are put into a separate file with a separate tablegen rule.

Test dialect td files are refactored a bit.

Printed format of `linalg.generic` temporarily remains unchanged to avoid breaking code and tests in the same change.

Differential Revision: https://reviews.llvm.org/D137658
2022-11-09 15:47:29 +01:00
Peiming Liu
75ac294b35 [mlir][sparse] support parallel for/reduction in sparsification.
This patch fix the re-revert D135927 (which caused a windows build failure) to re-enable parallel for/reduction. It also fix a warning caused by D137442.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D137565
2022-11-07 18:04:46 +00:00
Stella Stamenova
a2c4ca50ca Revert "[mlir][sparse] support Parallel for/reduction."
This reverts commit 838389780e.

This broke the windows mlir buildbot: https://lab.llvm.org/buildbot/#/builders/13/builds/27934
2022-11-07 08:48:52 -08:00
Adrian Kuegel
abe2738b7b [mlir] Apply two ClangTidy findings.
- argument name 'isLastOutput' in comment does not match parameter name
  'hasOutput'.
- override is redundant since the function is already declared 'final'.
2022-11-07 09:24:32 +01:00
Peiming Liu
838389780e [mlir][sparse] support Parallel for/reduction.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D135927
2022-11-04 22:47:27 +00:00
Aart Bik
5661647e85 [mlir][sparse] build proper insertion chain
The alloc->insert/compress->load chain needs to be
properly represented with an SSA chain now in loops
and if statements to properly reflect the modifying
behavior (runtime support lib is forgiving on breaking
this, but the new codegen is not).

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D136966
2022-10-28 15:58:51 -07:00
Alexander Belyaev
b4db15a949 [mlir] Rename getInputs->getDpsInputs and getOutputs->getDpsInits in DPS interface.
https://discourse.llvm.org/t/rfc-interface-for-destination-style-ops/64056

Differential Revision: https://reviews.llvm.org/D136943
2022-10-28 15:41:12 +02:00
Peiming Liu
32c512e49f [mlir][sparse] code refactoring, move <tid, loop id> -> dim map to Merger.
To address unresolved comments in D136185

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D136780
2022-10-27 21:01:06 +00:00
Peiming Liu
015bc3464d [mlir][sparse] fix crash when sparsifying broadcast operations.
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D136866
2022-10-27 17:43:22 +00:00
Peiming Liu
b0f8057e4c [mlir][sparse] use loop emitter to generate loop in sparsification
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D136185
2022-10-26 00:27:56 +00:00
Peiming Liu
26eb2c6b42 [mlir][sparse] remove vector support in sparsification
Sparse compiler used to generate vectorized code for sparse tensors computation, but it should really be delegated to other vectorization passes for better progressive lowering.

 https://discourse.llvm.org/t/rfc-structured-codegen-beyond-rectangular-arrays/64707

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D136183
2022-10-19 18:11:29 +00:00
wren romano
e0401d2252 [mlir][sparse] Removing the DimLvlType and DimLevelFormat types
This removes another massive source of redundancy, and instead has the Merger.{h,cpp} reuse the SparseTensorEnums library.

Depends On D136005

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D136123
2022-10-18 15:47:40 -07:00
wren romano
0e77b63bc0 [mlir][sparse] Use the runtime DimLevelType instead of a separate tablegen enum
This differential replaces all uses of SparseTensorEncodingAttr::DimLevelType with DimLevelType.  The next differential will break out a separate library for the DimLevelType enum, so that the Dialect code doesn't need to depend on the rest of the runtime

Depends On D135995

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D135996
2022-10-18 13:45:26 -07:00
Alexander Belyaev
a7cccb9cbb [mlir] Simplify DestinationStyleOpInterface.
Differential Revision: https://reviews.llvm.org/D135348
2022-10-17 12:43:41 +02:00
Oleg Shyshkov
c38d9cf20e [mlir] Remove iterator_types() method from LinalgStructuredInterface.
`getIteratorTypesArray` should be used instead. It's a better substitute for all the current usages of the interface.

The current `ArrayAttr iterator_types()` has a few problems:
* It creates an assumption operation has iterators types as an attribute, but it's not always the case. Sometime iterator types can be inferred from other attribute, or they're just static.
* ArrayAttr is an obscure contained and required extracting values in the client code.
* Makes it hard to migrate iterator types from strings to enums ([RFC](https://discourse.llvm.org/t/rfc-enumattr-for-iterator-types-in-linalg/64535/9)).

Concrete ops, like `linalg.generic` will still have iterator types as an attribute if needed.

As a side effect, this change helps a bit with migration to prefixed accessors.

Differential Revision: https://reviews.llvm.org/D135765
2022-10-13 07:52:43 +00:00
Aart Bik
c48e90877f [mlir][sparse] introduce a higher-order tensor mapping
This extension to the sparse tensor type system in MLIR
opens up a whole new set of sparse storage schemes, such as
block sparse storage (e.g. BCSR) and ELL (aka jagged diagonals).

This revision merely introduces the type extension and
initial documentation. The actual interpretation of the type
(reading in tensors, lowering to code, etc.) will follow.

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D135206
2022-10-05 09:40:51 -07:00
Benjamin Kramer
11d75076aa [sparse] Make GenericOpSparsifier not crash on multi-output dense linalg.generic
The actual transformation doesn't support multi-output GenericOps, but
if we encounter one without sparse annotations we can just leave it
alone.

Differential Revision: https://reviews.llvm.org/D135176
2022-10-04 21:48:18 +02:00
Matthias Springer
81ca5aa452 [mlir][tensor][NFC] Rename linalg.init_tensor to tensor.empty
tensor.empty/linalg.init_tensor produces an uninititalized tensor that can be used as a destination operand for destination-style ops (ops that implement `DestinationStyleOpInterface`).

This change makes it possible to implement `TilingInterface` for non-destination-style ops without depending on the Linalg dialect.

RFC: https://discourse.llvm.org/t/rfc-add-tensor-from-shape-operation/65101

Differential Revision: https://reviews.llvm.org/D135129
2022-10-04 17:25:35 +09:00
Jim Kitchen
791935037b [mlir][sparse] Implement sparse_tensor.select
The region within sparse_tensor.select is used as the runtime criteria
for whether to keep the existing value in the sparse tensor.

While the sparse element is provided to the comparison, indices may also
be used to decide on whether to keep the original value. This allows, for
example, to only keep the upper triangle of a matrix.

Reviewed by: aartbik

Differential Revision: https://reviews.llvm.org/D134761
2022-10-03 14:39:26 -05:00
Oleg Shyshkov
c54bc8bd07 [mlir][linalg] Use getIteratorTypeArray instead of raw iterator_type attribute.
Summary:
Also modify helper methods to take StringRefs instread of Attributes. It makes
the code cleaner and will help with future migration from StringRef to
utils::IteratorType ([RFC](https://discourse.llvm.org/t/rfc-enumattr-for-iterator-types-in-linalg/64535)).

Differential Revision: https://reviews.llvm.org/D134888
2022-09-30 16:03:33 +00:00
Oleg Shyshkov
1227b8ab54 [mlir] Rename getTied* methods to getMatching* in LinalgInterface.
Summary:
As mentioned in the comment to https://reviews.llvm.org/D134444, the term `tied`
is a misnomer in this context and `matching` sounds much better.

Differential Revision: https://reviews.llvm.org/D134534
2022-09-30 10:05:45 +00: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
Aart Bik
f231821e6e [mlir][sparse] provide convenience methods for toOrig/toStoredDim
Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D134833
2022-09-28 16:32:03 -07:00
Aart Bik
a3610359b5 [mlir][sparse] change memref argument to proper SSA components
The indices for insert/compress were previously provided as
a memref<?xindex> with proper rank, since that matched the
argument for the runtime support libary better. However, with
proper codegen coming, providing the indices as SSA values
is much cleaner. This also brings the sparse_tensor.insert
closer to unification with tensor.insert, planned in the
longer run.

Reviewed By: Peiming

Differential Revision: https://reviews.llvm.org/D134404
2022-09-27 16:37:37 -07:00
Peiming Liu
b1d1964771 [mlir][sparse] Only try to compute a better iteraton graph when needed
Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D134059
2022-09-16 22:53:32 +00:00
Peiming Liu
55a1d50fb9 [mlir][sparse] Make sparse compiler more admissible.
Previously, the iteration graph is computed without priority. This patch add a heuristic when computing the iteration graph by starting with Reduction iterator when doing topo sort, which makes Reduction iterators (likely) appear as late in the sorted array as possible.

The current sparse compiler also failed to compile the newly added case.

Reviewed By: aartbik

Differential Revision: https://reviews.llvm.org/D133738
2022-09-14 15:59:47 +00:00
Aart Bik
47a715d43e [mlir][sparse] minor merger API simplification
Reviewed By: bixia

Differential Revision: https://reviews.llvm.org/D133821
2022-09-13 18:07:24 -07:00