summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/SparseTensor/Utils/Merger.cpp
AgeCommit message (Collapse)Author
2025-07-22[mlir][NFC] update `mlir/Dialect` create APIs (21/n) (#149928)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
2024-05-13[mlir][sparse] recognize ReLu operation during sparsification (#92016)Aart Bik
This is a proof of concept recognition of the most basic forms of ReLu operations, used to show-case sparsification of end-to-end PyTorch models. In the long run, we must avoid lowering such constructs too early (with this need for raising them back). See discussion at https://discourse.llvm.org/t/min-max-abs-relu-recognition-starter-project/78918
2024-05-02[mlir][sparse] make sparse compiler more admissible. (#90927)Peiming Liu
2024-04-01[mlir][sparse] allow YieldOp to yield multiple values. (#87261)Peiming Liu
2024-02-27[mlir][sparse] add merger support on Batch LevelType. (#83186)Peiming Liu
2024-02-15Reapply "[mlir][sparse] remove LevelType enum, construct LevelType from ↵Peiming Liu
LevelFormat and Properties" (#81923) (#81934)
2024-02-15Revert "[mlir][sparse] remove LevelType enum, construct LevelType from ↵Mehdi Amini
LevelF…" (#81923) Reverts llvm/llvm-project#81799 ; this broke the mlir gcc7 bot.
2024-02-15[mlir][sparse] remove LevelType enum, construct LevelType from LevelF… ↵Peiming Liu
(#81799) …ormat and properties instead.
2024-02-08[mlir][sparse] Implement parsing n out of m (#79935)Yinying Li
1. Add parsing methods for block[n, m]. 2. Encode n and m with the newly extended 64-bit LevelType enum. 3. Update 2:4 methods names/comments to n:m.
2023-11-27[mlir][sparse] rename DimLevelType to LevelType (#73561)Aart Bik
The "Dim" prefix is a legacy left-over that no longer makes sense, since we have a very strict "Dimension" vs. "Level" definition for sparse tensor types and their storage.
2023-11-22[mlir][sparse] change dim level type -> level type (#73058)Aart Bik
The "dimension" before "level" does not really make sense Note that renaming the actual type DimLevelType to LevelType is still TBD, since this is an externally visible change (e.g. visible to Python API).
2023-11-16[mlir][sparse] code cleanup (remove dead code related to filter loop). (#72573)Peiming Liu
2023-11-10[mlir][sparse] support sparsifying 2:4 block sparsity (#71749)Peiming Liu
2023-11-07Changed the phrase sparse-compiler to sparsifier in comments (#71578)Tim Harvey
When the Powers That Be decided that the name "sparse compiler" should be changed to "sparsifier", we negected to change some of the comments in the code; this pull request completes the name change.
2023-10-02[mlir][sparse] Fix typos (#67859)Yinying Li
2023-10-02[mlir][sparse] Update Enum name for CompressedWithHigh (#67845)Yinying Li
Change CompressedWithHigh to LooseCompressed.
2023-08-30[mlir][sparse] Pass down constant coefficients of affine index expressions ↵Peiming Liu
to LoopEmitter. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D158914
2023-06-28[mlir][sparse] admit un-sparsifiable operations if all its operands are ↵Peiming Liu
loaded from dense input Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D153998
2023-06-28[mlir][VectorType] Remove `numScalableDims` from the vector typeAndrzej Warzynski
This is a follow-up of https://reviews.llvm.org/D153372 in which `numScalableDims` (single integer) was effectively replaced with `isScalableDim` bitmask. This change is a part of a larger effort to enable scalable vectorisation in Linalg. See this RFC for more context: * https://discourse.llvm.org/t/rfc-scalable-vectorisation-in-linalg/ Differential Revision: https://reviews.llvm.org/D153412
2023-06-15[mlir][sparse] merger extension to support sparsifying arith::CmpI/CmpF ↵Peiming Liu
operation Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D152761
2023-06-14[mlir][sparse] refine single condition set up for semi-ring opsAart Bik
Reviewed By: Peiming, K-Wu Differential Revision: https://reviews.llvm.org/D152874
2023-05-17[mlir][sparse] Renaming the STEA field `dimLevelType` to `lvlTypes`wren romano
This commit is part of the migration of towards the new STEA syntax/design. In particular, this commit includes the following changes: * Renaming compiler-internal functions/methods: * `SparseTensorEncodingAttr::{getDimLevelType => getLvlTypes}` * `Merger::{getDimLevelType => getLvlType}` (for consistency) * `sparse_tensor::{getDimLevelType => buildLevelType}` (to help reduce confusion vs actual getter methods) * Renaming external facets to match: * the STEA parser and printer * the C and Python bindings * PyTACO However, the actual renaming of the `DimLevelType` itself (along with all the "dlt" names) will be handled in a separate commit. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D150330
2023-05-12[mlir] Move casting calls from methods to function callsTres Popp
The MLIR classes Type/Attribute/Operation/Op/Value support cast/dyn_cast/isa/dyn_cast_or_null functionality through llvm's doCast functionality in addition to defining methods with the same name. This change begins the migration of uses of the method to the corresponding function call as has been decided as more consistent. Note that there still exist classes that only define methods directly, such as AffineExpr, and this does not include work currently to support a functional cast/isa call. Caveats include: - This clang-tidy script probably has more problems. - This only touches C++ code, so nothing that is being generated. Context: - https://mlir.llvm.org/deprecation/ at "Use the free function variants for dyn_cast/cast/isa/…" - Original discussion at https://discourse.llvm.org/t/preferred-casting-style-going-forward/68443 Implementation: This first patch was created with the following steps. The intention is to only do automated changes at first, so I waste less time if it's reverted, and so the first mass change is more clear as an example to other teams that will need to follow similar steps. Steps are described per line, as comments are removed by git: 0. Retrieve the change from the following to build clang-tidy with an additional check: https://github.com/llvm/llvm-project/compare/main...tpopp:llvm-project:tidy-cast-check 1. Build clang-tidy 2. Run clang-tidy over your entire codebase while disabling all checks and enabling the one relevant one. Run on all header files also. 3. Delete .inc files that were also modified, so the next build rebuilds them to a pure state. 4. Some changes have been deleted for the following reasons: - Some files had a variable also named cast - Some files had not included a header file that defines the cast functions - Some files are definitions of the classes that have the casting methods, so the code still refers to the method instead of the function without adding a prefix or removing the method declaration at the same time. ``` ninja -C $BUILD_DIR clang-tidy run-clang-tidy -clang-tidy-binary=$BUILD_DIR/bin/clang-tidy -checks='-*,misc-cast-functions'\ -header-filter=mlir/ mlir/* -fix rm -rf $BUILD_DIR/tools/mlir/**/*.inc git restore mlir/lib/IR mlir/lib/Dialect/DLTI/DLTI.cpp\ mlir/lib/Dialect/Complex/IR/ComplexDialect.cpp\ mlir/lib/**/IR/\ mlir/lib/Dialect/SparseTensor/Transforms/SparseVectorization.cpp\ mlir/lib/Dialect/Vector/Transforms/LowerVectorMultiReduction.cpp\ mlir/test/lib/Dialect/Test/TestTypes.cpp\ mlir/test/lib/Dialect/Transform/TestTransformDialectExtension.cpp\ mlir/test/lib/Dialect/Test/TestAttributes.cpp\ mlir/unittests/TableGen/EnumsGenTest.cpp\ mlir/test/python/lib/PythonTestCAPI.cpp\ mlir/include/mlir/IR/ ``` Differential Revision: https://reviews.llvm.org/D150123
2023-04-20[mlir][sparse] support iteration over compressed-hi dimension level in loop ↵Peiming Liu
emitter Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D148668
2023-04-13[mlir][sparse] extend loop emitter to emit slice driven loopsPeiming Liu
Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D142930
2023-04-07[mlir][sparse] Simplifying Merger::expContainsTensorwren romano
`expContainsTensor` used to call `expIsTensor` to short-circuit the recursive calls; however, the very first thing `expContainsTensor` does is to check `expIsTensor`, so the short-circuiting code just causes the function to check that condition redundantly. Depends On D146684 Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D146688
2023-03-29[mlir][sparse] Preliminary code changes for ExprId, LatPointId, LatSetId ↵wren romano
newtypes This commit contains several code changes which are ultimately required for converting the varions `Merger` identifiers from typedefs to newtypes. The actual implementation of the newtypes themselves has been split off into separate commits, in hopes of simplifying the review process. Depends On D146561 Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D146684
2023-03-24[mlir][sparse] moving kInvalidId into "detail" namespacewren romano
In the next few commits I will be converting the various Merger identifier typedefs into newtypes; and once that's done, the `kInvalidId` constant will only be used internally and therefore does not need to be part of the public `mlir::sparse_tensor` namespace. Depends On D146673 Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D146674
2023-03-24[mlir][sparse] Updating TensorExp ctor to catch unknown TensorExp::Kindwren romano
Depends On D146562 Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D146673
2023-03-21[mlir][sparse] fix crash when using pure constant index in indexing mapping ↵Peiming Liu
(fixes #61530) To address https://github.com/llvm/llvm-project/issues/61530 Reviewed By: aartbik, wrengr Differential Revision: https://reviews.llvm.org/D146563
2023-03-21[mlir][sparse] Adding new `Merger::addLat` overloadwren romano
Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D146559
2023-03-20[mlir][sparse] Making `TensorExp::Kind` a nested enum-classwren romano
This improves namespacing, and follows the pattern used for "Kind" enums elsewhere in MLIR. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D146086
2023-03-20[mlir][sparse] extend loop emitter and optimize lattices with the awareness ↵Peiming Liu
of slice based iteration Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D142929
2023-03-20[mlir][sparse] add merger/topo sort support for slice-based affine sparse ↵Peiming Liu
index codegen Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D142928
2023-03-14[mlir][sparse] Cleaning up names in {Merger,LoopEmitter,CodegenEnv}.{h,cpp}wren romano
This change does a bunch of renaming to clear up confusions in these files. In particular, this change: * Renames variables and methods to clarify the "dim"/"lvl" distinction, and changes them to use the `Dimension`/`Level` types as appropriate. * Introduces new typedefs * `ExprId`, `LatPointId`, `LatSetId`: to clarify the interning design of the Merger. * `LoopId`, `LoopOrd`: to clarify the distinction between arbitrary names for loop-variables, vs numeric identifiers based on the actual order of loop generation. * `TensorId` * (Future CLs will change these from typedefs to structs/classes, so that the typechecker can help avoid mixups.) * Updates documentation to match the new terminology * Adds additional assertions * Adds `const` to local variables along the way Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D145756
2023-03-08[mlir][sparse] Factoring out Merger::expIsTensorwren romano
Depends On D145611 Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D145620
2023-03-06[mlir][IR] Clean up mergeBlockBefore and mergeBlocksMatthias Springer
* `RewriterBase::mergeBlocks` is simplified: it is implemented in terms of `mergeBlockBefore`. * The signature of `mergeBlockBefore` is consistent with other API (such as `inlineRegionBefore`): an overload for a `Block::iterator` is added. * Additional safety checks are added to `mergeBlockBefore`: detect cases where the resulting IR could be invalid (no more `dropAllUses`) or partly unreachable (likely a case of incorrect API usage). * Rename `mergeBlockBefore` to `inlineBlockBefore`. Differential Revision: https://reviews.llvm.org/D144969
2023-01-14[mlir] Use std::optional instead of llvm::Optional (NFC)Kazu Hirata
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". 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
2023-01-13[mlir] Add #include <optional> (NFC)Kazu Hirata
This patch adds #include <optional> to those files containing llvm::Optional<...> or Optional<...>. I'll post a separate patch to actually replace llvm::Optional with 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
2023-01-12[mlir] Add operations to BlockAndValueMapping and rename it to IRMappingJeff Niu
The patch adds operations to `BlockAndValueMapping` and renames it to `IRMapping`. When operations are cloned, old operations are mapped to the cloned operations. This allows mapping from an operation to a cloned operation. Example: ``` Operation *opWithRegion = ... Operation *opInsideRegion = &opWithRegion->front().front(); IRMapping map Operation *newOpWithRegion = opWithRegion->clone(map); Operation *newOpInsideRegion = map.lookupOrNull(opInsideRegion); ``` Migration instructions: All includes to `mlir/IR/BlockAndValueMapping.h` should be replaced with `mlir/IR/IRMapping.h`. All uses of `BlockAndValueMapping` need to be renamed to `IRMapping`. Reviewed By: rriddle, mehdi_amini Differential Revision: https://reviews.llvm.org/D139665
2022-12-19[mlir][sparse] minor merger code cleanupAart Bik
Moved larger constructor from header to CPP file. Used toMLIRString() for DimLvlType debug. Minor layout changes. Reviewed By: Peiming Differential Revision: https://reviews.llvm.org/D140342
2022-12-17[mlir] llvm::Optional::value => operator*/operator->Fangrui Song
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-08[mlir][sparse] reject kernels with non-sparsfiable reduction expression.Peiming Liu
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-03[mlir] Use std::nullopt instead of None (NFC)Kazu Hirata
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-11-15[mlir][sparse] cleanup small vector constant hintsAart Bik
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-10-27[mlir][sparse] fix typo "admissable" -> "admissible"Aart Bik
Reviewed By: wrengr, Peiming Differential Revision: https://reviews.llvm.org/D136878
2022-10-18[mlir][sparse] Removing the DimLvlType and DimLevelFormat typeswren romano
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-17[mlir] Simplify DestinationStyleOpInterface.Alexander Belyaev
Differential Revision: https://reviews.llvm.org/D135348
2022-10-06[mlir][sparse] Favors synthetic tensor over other undefined tensorsPeiming Liu
Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D135385
2022-10-06[mlir][sparse] Favors defined dimension when optimize lattice points.Peiming Liu
Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D135337