summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorRewriting.cpp
AgeCommit message (Collapse)Author
2025-07-25[mlir][NFC] update `mlir/Dialect` create APIs (33/n) (#150659)Maksim Levental
See https://github.com/llvm/llvm-project/pull/147168 for more info.
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.
2025-07-07[mlir] Add `isStatic`* size check for `ShapedType`s. NFCI. (#147085)Jakub Kuderski
The motivation is to avoid having to negate `isDynamic*` checks, avoid double negations, and allow for `ShapedType::isStaticDim` to be used in ADT functions without having to wrap it in a lambda performing the negation. Also add the new functions to C and Python bindings.
2025-06-22[mlir] Migrate away from ValueRange(std::nullopt) (NFC) (#145210)Kazu Hirata
ArrayRef has a constructor that accepts std::nullopt. This constructor dates back to the days when we still had llvm::Optional. Since the use of std::nullopt outside the context of std::optional is kind of abuse and not intuitive to new comers, I would like to move away from the constructor and eventually remove it. One of the common uses of std::nullopt is in one of the constructors for ValueRange. This patch takes care of the migration where we need ValueRange() to facilitate perfect forwarding. Note that {} would be ambiguous for perfecting forwarding to work.
2025-05-13[NFC] Use more isa and isa_and_nonnull instead dyn_cast for predicates (#137393)Max Graey
Also fix some typos in comments --------- Co-authored-by: Mehdi Amini <joker.eph@gmail.com>
2024-09-30[mlir][sparse] Replace `getSparseTensorType` with `tryGetSparseTensorType` ↵Longsheng Mou
(#109435) This PR fixes a bug in `SparseTensorDimOpRewriter` when `tensor.dim` has an unranked tensor type. To prevent crashes, we now use `tryGetSparseTensorType` instead of `getSparseTensorType`. Fixes #107807.
2024-08-20[mlir][sparse] support sparsification to coiterate operations. (#102546)Peiming Liu
2024-05-14[mlir][sparse] clone a empty sparse tensor when fuse convert into pro… ↵Peiming Liu
(#92158) …ducer.
2024-05-09[mlir][sparse] Change sparse_tensor.print format (#91528)Yinying Li
1. Remove the trailing comma for the last element of memref and add closing parenthesis. 2. Change integration tests to use the new format.
2024-05-07[mlir][sparse] support 'batch' dimensions in sparse_tensor.print (#91411)Aart Bik
2024-04-30[MLIR] Generalize expand_shape to take shape as explicit input (#90040)Gaurav Shukla
This patch generalizes tensor.expand_shape and memref.expand_shape to consume the output shape as a list of SSA values. This enables us to implement generic reshape operations with dynamic shapes using collapse_shape/expand_shape pairs. The output_shape input to expand_shape follows the static/dynamic representation that's also used in `tensor.extract_slice`. Differential Revision: https://reviews.llvm.org/D140821 --------- Signed-off-by: Gaurav Shukla<gaurav.shukla@amd.com> Signed-off-by: Gaurav Shukla <gaurav.shukla@amd.com> Co-authored-by: Ramiro Leal-Cavazos <ramiroleal050@gmail.com>
2024-04-26[mlir][sparse] fold sparse convert into producer linalg op. (#89999)Peiming Liu
2024-04-24[mlir][sparse] fuse concat and extract_slice op if possible. (#89825)Peiming Liu
2024-04-21Revert "[MLIR] Generalize expand_shape to take shape as explicit input" (#89540)Mehdi Amini
Reverts llvm/llvm-project#69267 this broke some bots.
2024-04-21[MLIR] Generalize expand_shape to take shape as explicit input (#69267)Gaurav Shukla
This patch generalizes tensor.expand_shape and memref.expand_shape to consume the output shape as a list of SSA values. This enables us to implement generic reshape operations with dynamic shapes using collapse_shape/expand_shape pairs. The output_shape input to expand_shape follows the static/dynamic representation that's also used in `tensor.extract_slice`. Differential Revision: https://reviews.llvm.org/D140821 Co-authored-by: Ramiro Leal-Cavazos <ramiroleal050@gmail.com>
2024-04-19Switch member calls to `isa/dyn_cast/cast/...` to free function calls. (#89356)Christian Sigg
This change cleans up call sites. Next step is to mark the member functions deprecated. See https://mlir.llvm.org/deprecation and https://discourse.llvm.org/t/preferred-casting-style-going-forward.
2024-03-29[mlir][sparse] provide an AoS "view" into sparse runtime support lib (#87116)Aart Bik
Note that even though the sparse runtime support lib always uses SoA storage for COO storage (and provides correct codegen by means of views into this storage), in some rare cases we need the true physical SoA storage as a coordinate buffer. This PR provides that functionality by means of a (costly) coordinate buffer call. Since this is currently only used for testing/debugging by means of the sparse_tensor.print method, this solution is acceptable. If we ever want a performing version of this, we should truly support AoS storage of COO in addition to the SoA used right now.
2024-03-12[mlir][sparse] reuse tensor.insert operation to insert elements into … ↵Peiming Liu
(#84987) …a sparse tensor.
2024-03-04[mlir][sparse] support complex type for sparse_tensor.print (#83934)Aart Bik
With an integration test example
2024-03-04[mlir][sparse] support sparsifying batch levels (#83898)Peiming Liu
2024-03-04[mlir][sparse] add dim/lvl information to sparse_tensor.print (#83913)Aart Bik
More information is more testing! Also adjusts already migrated integration tests
2024-02-28[mlir][sparse] infer returned type for sparse_tensor.to_[buffer] ops (#83343)Peiming Liu
The sparse structure buffers might not always be memrefs with rank == 1 with the presence of batch levels.
2024-02-28[mlir][sparse] add a sparse_tensor.print operation (#83321)Aart Bik
This operation is mainly used for testing and debugging purposes but provides a very convenient way to quickly inspect the contents of a sparse tensor (all components over all stored levels). Example: [ [ 1, 0, 2, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 0, 0, 0, 0, 0, 0 ], [ 0, 0, 3, 4, 0, 5, 0, 0 ] when stored sparse as DCSC prints as ---- Sparse Tensor ---- nse = 5 pos[0] : ( 0, 4, ) crd[0] : ( 0, 2, 3, 5, ) pos[1] : ( 0, 1, 3, 4, 5, ) crd[1] : ( 0, 0, 3, 3, 3, ) values : ( 1, 2, 3, 4, 5, ) ----
2024-02-24[mlir] Use `OpBuilder::createBlock` in op builders and patterns (#82770)Matthias Springer
When creating a new block in (conversion) rewrite patterns, `OpBuilder::createBlock` must be used. Otherwise, no `notifyBlockInserted` notification is sent to the listener. Note: The dialect conversion relies on listener notifications to keep track of IR modifications. Creating blocks without the builder API can lead to memory leaks during rollback.
2024-02-20[mlir][sparse] support SoA COO in codegen path. (#82439)Peiming Liu
*NOTE*: the `SoA` property only makes a difference on codegen path, and is ignored in libgen path at the moment (only SoA COO is supported).
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-12Apply clang-tidy fixes for llvm-qualified-auto in SparseTensorRewriting.cpp ↵Mehdi Amini
(NFC)
2024-01-24[mlir][sparse] setup `SparseIterator` to help generating code to traverse a ↵Peiming Liu
sparse tensor level. (#78345)
2024-01-17[mlir][IR] Rename "update root" to "modify op" in rewriter API (#78260)Matthias Springer
This commit renames 4 pattern rewriter API functions: * `updateRootInPlace` -> `modifyOpInPlace` * `startRootUpdate` -> `startOpModification` * `finalizeRootUpdate` -> `finalizeOpModification` * `cancelRootUpdate` -> `cancelOpModification` The term "root" is a misnomer. The root is the op that a rewrite pattern matches against (https://mlir.llvm.org/docs/PatternRewriter/#root-operation-name-optional). A rewriter must be notified of all in-place op modifications, not just in-place modifications of the root (https://mlir.llvm.org/docs/PatternRewriter/#pattern-rewriter). The old function names were confusing and have contributed to various broken rewrite patterns. Note: The new function names use the term "modify" instead of "update" for consistency with the `RewriterBase::Listener` terminology (`notifyOperationModified`).
2024-01-12[mlir][Interfaces] `DestinationStyleOpInterface`: Rename ↵Matthias Springer
`hasTensor/BufferSemantics` (#77574) Rename interface functions as follows: * `hasTensorSemantics` -> `hasPureTensorSemantics` * `hasBufferSemantics` -> `hasPureBufferSemantics` These two functions return "true" if the op has tensor/buffer operands but not buffer/tensor operands. Also drop the "ranked" part from the interface, i.e., do not distinguish between ranked/unranked types. The new function names describe the functions more accurately. They also align their semantics with the notion of "tensor semantics" with the bufferization framework. (An op is supposed to be bufferized if it has tensor operands, and we don't care if it also has memref operands.) This change is in preparation of #75273, which adds `BufferizableOpInterface::hasTensorSemantics`. By renaming the functions in the `DestinationStyleOpInterface`, we can avoid name clashes between the two interfaces.
2023-12-12[mlir][sparse] refactor utilities into transform/utils dir (#75250)Aart Bik
Separates actual transformation files from supporting utility files in the transforms directory. Includes a bazel overlay fix for the build (as well as a bit of cleanup of that file to be less verbose and more flexible).
2023-11-30[mlir][sparse] move all COO related methods into SparseTensorType (#73881)Aart Bik
This centralizes all COO methods, and provides a cleaner API. Note that the "enc" only constructor is a temporary workaround the need for COO methods inside the "enc" only storage specifier.
2023-11-28[mlir][sparse] move toCOOType into SparseTensorType class (#73708)Aart Bik
Migrates dangling convenience method into proper SparseTensorType class. Also cleans up some details (picking right dim2lvl/lvl2dim). Removes more dead code.
2023-11-27[mlir][sparse] code cleanup, remove FIXMEs (#73575)Peiming Liu
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-15[mlir][sparse] avoid non-perm on sparse tensor convert for new (#72459)Aart Bik
This avoids seeing non-perm on the convert from COO to non-COO for higher dimensional new operators (viz. reading in BSR). This is step 1 out of 3 to make sparse_tensor.new work for BSR
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-11-02[mlir][sparse] remove (some) deprecated dim/lvl methods (#71125)Aart Bik
This removes the most obvious ones. The others are still TBD.
2023-11-02[mlir][sparse] support sparse constant to BSR conversion. (#71114)Peiming Liu
support direct convert from a constant tensor defined by SparseArrayElements to BSR
2023-11-02[mlir][sparse] simplify some header code (#70989)Aart Bik
This is a first revision in a small series of changes that removes duplications between direct encoding methods and sparse tensor type wrapper methods (in favor of the latter abstraction, since it provides more safety). The goal is to simply end up with "just" SparseTensorType
2023-11-01[mlir][sparse] Implement rewriters to reinterpret maps on foreach (#70868)Peiming Liu
2023-10-30[mlir][sparse] implements tensor.insert on sparse tensors. (#70737)Peiming Liu
2023-10-30[mlir][sparse] split post-sparsification-rewriting into two passes. (#70727)Peiming Liu
2023-10-27[mlir][sparse] unify sparse_tensor.out rewriting rules (#70518)Peiming Liu
2023-10-24[mlir][sparse] implement sparse_tensor.lvl operation. (#69993)Peiming Liu
2023-10-20[mlir][sparse] support CSR/BSR conversion (#69800)Peiming Liu
2023-10-20[mlir][sparse] implement sparse_tensor.crd_translate operation (#69653)Peiming Liu