summaryrefslogtreecommitdiff
path: root/mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp
AgeCommit message (Collapse)Author
2025-10-06[MLIR][SparseTensor] Loop ordering strategy infrastructure (flag) (#154656)Govind Malasani
As discussed before, this PR adds the basic infrastructure/boiler plate for loop ordering strategies to be implemented. If this looks ok, I wanted to also mention some of the heuristics that I would implement next, if they sound reasonable to you guys: - Parallel first : prioritize parallel loops over reduction loops - Dense outer : prioritize the most dense loops first - Sparse outer : the opposite, potentially useful in some cases? There is another that I am considering, stride/memory aware, which would prioritize loops with better stride patterns (like sequential or linear). Not sure how well this carries over to Sparse Tensor though. Are there any ideas/heuristics that I should definitely try to implement? As we discussed, I will try to incrementally add heuristics. Sorry for the delay on my end, and thank you so much for the feedback! --------- Co-authored-by: Aart Bik <ajcbik@google.com>
2024-12-27[mlir][sparse_tensor] Migrate `SparseIterationToScf.cpp` to dialect ↵Matthias Springer
conversion (#121054) Use the regular dialect conversion driver instead of the 1:N dialect conversion driver. The 1:N dialect conversion driver will be removed soon.
2024-12-20[mlir] Enable decoupling two kinds of greedy behavior. (#104649)Jacques Pienaar
The greedy rewriter is used in many different flows and it has a lot of convenience (work list management, debugging actions, tracing, etc). But it combines two kinds of greedy behavior 1) how ops are matched, 2) folding wherever it can. These are independent forms of greedy and leads to inefficiency. E.g., cases where one need to create different phases in lowering and is required to applying patterns in specific order split across different passes. Using the driver one ends up needlessly retrying folding/having multiple rounds of folding attempts, where one final run would have sufficed. Of course folks can locally avoid this behavior by just building their own, but this is also a common requested feature that folks keep on working around locally in suboptimal ways. For downstream users, there should be no behavioral change. Updating from the deprecated should just be a find and replace (e.g., `find ./ -type f -exec sed -i 's|applyPatternsAndFoldGreedily|applyPatternsGreedily|g' {} \;` variety) as the API arguments hasn't changed between the two.
2024-06-12[mlir][sparse] implement lowering rules for ExtractIterSpaceOp. (#89143)Peiming Liu
**DO NOT MERGE** until https://github.com/llvm/llvm-project/pull/89003
2024-05-28[mlir][sparse] remove sparse encoding propagation pass. (#93593)Peiming Liu
2024-05-13[mlir][sparse] introduce new pass to propagate sparse encodings. (#92052)Peiming Liu
2024-04-11[mlir][sparse] allow for direct-out passing of sparse tensor buffers (#88327)Aart Bik
In order to support various external frameworks (JAX vs PyTorch) we need a bit more flexibility in [dis]assembling external buffers to and from sparse tensors in MLIR land. This PR adds a direct-out option that avoids the rigid pre-allocated for copy-out semantics. Note that over time, we expect the [dis]assemble operations to converge into something that supports all sorts of external frameworks. Until then, this option helps in experimenting with different options.
2024-04-04[mlir][linalg] Fix builder API usage in `RegionBuilderHelper` (#87451)Matthias Springer
Operations must be created with the supplied builder. Otherwise, the dialect conversion / greedy pattern rewrite driver can break. This commit fixes a crash in the dialect conversion: ``` within split at llvm-project/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir:1 offset :8:8: error: failed to legalize operation 'tosa.add' %0 = tosa.add %1, %arg2 : (tensor<10x10xf32>, tensor<*xf32>) -> tensor<*xf32> ^ within split at llvm-project/mlir/test/Conversion/TosaToLinalg/tosa-to-linalg-invalid.mlir:1 offset :8:8: note: see current operation: %9 = "tosa.add"(%8, %arg2) : (tensor<10x10xf32>, tensor<*xf32>) -> tensor<*xf32> mlir-opt: llvm-project/mlir/include/mlir/IR/UseDefLists.h:198: mlir::IRObjectWithUseList<mlir::OpOperand>::~IRObjectWithUseList() [OperandType = mlir::OpOperand]: Assertion `use_empty() && "Cannot destroy a value that still has uses!"' failed. ``` This commit is the proper fix for #87297 (which was reverted).
2024-02-01[mlir][sparse] Support pretty print to debug sparse iteration. (#80207)Peiming Liu
2024-02-01[mlir][sparse] external entry method wrapper for sparse tensors (#80326)Aart Bik
Similar to the emit_c_interface, this pull request adds a pass that converts public entry methods that use sparse tensors as input parameters and/or output return values into wrapper functions that [dis]assemble the individual tensors that constitute the actual storage used externally into MLIR sparse tensors. This pass can be used to prepare the public entry methods of a program that is compiled by the MLIR sparsifier to interface with an external runtime, e.g., when passing sparse tensors as numpy arrays from and to Python. Note that eventual bufferization decisions (e.g. who [de]allocates the underlying memory) should be resolved in agreement with the external runtime (Python, PyTorch, JAX, etc.)
2023-11-14[mlir][sparse][gpu] re-enable all GPU libgen tests (#72185)Aart Bik
Previous change no longer properly used the GPU libgen pass (even though most tests still passed falling back to CPU). This revision puts the proper pass order into place. Also bit of a cleanup of CPU codegen vs. libgen setup.
2023-11-13[mlir][sparse] remove filter-loop based algorithm support to handle a… ↵Peiming Liu
(#71840) …ffine subscript expressions.
2023-11-13[mlir][sparse] unify support of (dis)assemble between direct IR/lib path ↵Aart Bik
(#71880) Note that the (dis)assemble operations still make some simplfying assumptions (e.g. trailing 2-D COO in AoS format) but now at least both the direct IR and support library path behave exactly the same. Generalizing the ops is still TBD.
2023-11-08[mlir][sparse][gpu] cleanup GPUDataTransferStrategy (#71615)Aart Bik
The flag seems to be doing practically the same thing for zero cost and pinned dma. In addition, the register host is not truly the right zero cost mechanism according to Thomas. So we are simplifying the setup for now, until we have a better definition for what to implement and test. https://github.com/llvm/llvm-project/issues/64316
2023-10-30[mlir][sparse] split post-sparsification-rewriting into two passes. (#70727)Peiming Liu
2023-10-27[mlir][sparse] add ReinterpretMapScopeOption for the pass (#70486)Peiming Liu
2023-10-26[mlir][sparse] add boilterplate code for a new reintepret map pass (#70393)Aart Bik
The interesting stuff is of course still coming ;-)
2023-10-12[mlir][sparse] implement sparse_tensor.reorder_coo (#68916)Peiming Liu
As a side effect of the change, it also unifies the convertOp implementation between lib/codegen path.
2023-10-06[mlir][sparse] introduce a pass to stage complex sparse operations in… ↵Peiming Liu
(#68436) …to simple steps
2023-10-03[mlir][sparse] renaming sparse_tensor.sort_coo to sparse_tensor.sort (#68161)Peiming Liu
Rationale: the operation does not always sort COO tensors (also used for sparse_tensor.compress for example).
2023-09-19[mlir][sparse] unifies sparse_tensor.sort_coo/sort into one operation. (#66722)Peiming Liu
The use cases of the two operations are largely overlapped, let's simplify it and only use one of them.
2023-09-13[sparse] allow unpack op to return 0-ranked tensor type. (#66269)Peiming Liu
Many frontends canonicalize scalar into 0-ranked tensor, it change will hopefully make the operation easier to use for those cases.
2023-08-01[mlir][sparse][gpu] introduce flag that controls host to device copy ↵K-Wu
strategies (regular dma default) Differential Revision: https://reviews.llvm.org/D155352
2023-07-18[mlir] NFC: untangle SCF Patterns.h and Transforms.hAlex Zinenko
These two headers both contained a strange mix of definitions related to both patterns and non-pattern transforms. Put patterns and "populate" functions into Patterns.h and standalone transforms into Transforms.h. Depends On: D155223 Reviewed By: nicolasvasilache Differential Revision: https://reviews.llvm.org/D155454
2023-05-15[mlir][sparse][gpu] first implementation of the GPU libgen approachAart Bik
The sparse compiler now has two prototype strategies for GPU acceleration: * CUDA codegen: this converts sparsified code to CUDA threads * CUDA libgen: this converts pre-sparsified code to cuSPARSE library calls This revision introduces the first steps required for the second approach. Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D150170
2023-04-05[mlir][sparse][gpu] a first prototype sparse GPU code generatorAart Bik
This implements a proof-of-concept GPU code generator to the sparse compiler pipeline, currently only capable of generating CUDA threads for outermost parallel loops. The objective, obviously, is to grow this concept to a full blown GPU code generator, capable of the right combinaton of code generation as well as exploiting idiomatic kernels or vector specific libraries (think cuSparse). Reviewed By: ThomasRaoux Differential Revision: https://reviews.llvm.org/D147483
2023-03-27[mlir][sparse] add create-sparse-deallocs options to match the ↵Peiming Liu
create-deallocs in BufferizationOption. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D147010
2023-03-16[mlir][sparse] add new sparisification option for dependent index ↵Peiming Liu
reduction-based codegen Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D142927
2023-01-23[mlir][sparse] clean vectorization bail-out for VL=0Aart Bik
Fixes https://github.com/llvm/llvm-project/issues/59970 Reviewed By: Peiming Differential Revision: https://reviews.llvm.org/D142290
2022-12-22[mlir][sparse] introduce sparse_tensor::StorageSpecifierToLLVM passPeiming Liu
Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D140122
2022-12-08[mlir][sparse] Fix problems in creating complex zero for initialization.bixia1
Reviewed By: aartbik, wrengr Differential Revision: https://reviews.llvm.org/D139591
2022-11-21[mlir][sparse] introduce vectorization pass for sparse loopsAart Bik
This brings back previous SIMD functionality, but in a separate pass. The idea is to improve this new pass incrementally, going beyond for-loops to while-loops for co-iteration as welll (masking), while introducing new abstractions to make the lowering more progressive. The separation of sparsification and vectorization is a very good first step on this journey. Also brings back ArmSVE support Still to be fine-tuned: + use of "index" in SIMD loop (viz. a[i] = i) + check that all ops really have SIMD support + check all forms of reductions + chain reduction SIMD values Reviewed By: dcaballe Differential Revision: https://reviews.llvm.org/D138236
2022-11-17[mlir][sparse] Split SparseTensorRewrite into PreSparsificationRewrite and ↵bixia1
PostSparsificationRewrite. Reviewed By: aartbik, wrengr Differential Revision: https://reviews.llvm.org/D138153
2022-11-15[mlir][sparse] avoid single default parameters in pass constructorsAart Bik
Reviewed By: bixia Differential Revision: https://reviews.llvm.org/D138054
2022-11-14[mlir][sparse] Add rewriting rules for sparse_tensor.sort_coo.bixia1
Refactor the rewriting of sparse_tensor.sort to support the implementation of sparse_tensor.sort_coo. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D137522
2022-11-10[mlir][sparse] Add option enable-buffer-initialization to the ↵bixia1
sparse-tensor-codegen pass. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D137733
2022-11-08[mlir][sparse] Add option enable-buffer-initialization to initialize the ↵bixia1
memory buffers for sparse tensors to support debugging. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D137592
2022-10-19[mlir][sparse] remove vector support in sparsificationPeiming Liu
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-18[mlir][sparse] Add options to sparse-tensor-rewrite to disable rewriting ↵bixia1
rules for operators foreach and convert. This is to help simplify FileCheck tests for sparse-tensor-rewrite. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D136093
2022-10-05[mlir][sparse] move sparse tensor rewriting into its own passAart Bik
Makes individual testing and debugging easier. Reviewed By: bixia Differential Revision: https://reviews.llvm.org/D135319
2022-09-29[mlir][sparse] Move the implementation of sparse_tensor.push_back to the ↵bixia1
buffer rewriter. Reviewed By: aartbik, Peiming Differential Revision: https://reviews.llvm.org/D134777
2022-09-29[mlir][sparse] Add rewrite rule for the sort operator.bixia1
Add sparse-buffer-rewrite pass to rewrite sparse primitives on buffers to MLIR implementation. Add sparse rewrite rule for the sort operator. Add FileCheck test and integration test. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D134627
2022-09-29[mlir][arith] Change dialect name from Arithmetic to ArithJakub Kuderski
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-28[mlir][sparse] add "sort" to the compress op codegenAart Bik
This revision also adds convenience methods to test the dim level type/property (with the codegen being first client) Reviewed By: bixia Differential Revision: https://reviews.llvm.org/D134776
2022-09-16[mlir][sparse] add loop simplification to sparsification passAart Bik
Reviewed By: bixia Differential Revision: https://reviews.llvm.org/D134090
2022-09-09[mlir][sparse] Add new option (enable-runtime-library) to sparse compiler ↵Peiming Liu
pipeline Add new option (enable-runtime-library) to sparse compiler pipeline, it allows us to decide whether we need to rewrite operations (e.g., concatenate, reshape) within sparsification (when using codegen) or convert them after sparsification (when using runtime library). Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D133597
2022-09-08[mlir][sparse] Add codegen for expand op.bixia1
Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D133454
2022-09-07[mlir][sparse] Refactoring: remove dependence on tuple type when lowering ↵Peiming Liu
sparse tensors. Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D133390
2022-09-06[mlir][sparse] Refactoring: renaming StorageNewOp to StorageOpPeiming Liu
To address comment in https://reviews.llvm.org/D133241 Reviewed By: aartbik Differential Revision: https://reviews.llvm.org/D133363
2022-09-06[mlir][sparse] codegen for sparse allocAart Bik
Reviewed By: Peiming Differential Revision: https://reviews.llvm.org/D133241