Skip to content

Commit 2696855

Browse files
authored
[mlir][sparse] remove filter-loop based algorithm support to handle a… (#71840)
…ffine subscript expressions.
1 parent 41021e8 commit 2696855

17 files changed

+36
-217
lines changed

mlir/include/mlir/Dialect/SparseTensor/Pipelines/Passes.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ struct SparseCompilerOptions
5353
"any-storage-any-loop",
5454
"Enable sparse parallelization for any storage and loop."))};
5555

56-
PassOptions::Option<bool> enableIndexReduction{
57-
*this, "enable-index-reduction",
58-
desc("Enable dependent index reduction based algorithm to handle "
59-
"non-trivial index expressions on sparse inputs (experimental "
60-
"features)"),
61-
init(false)};
62-
6356
PassOptions::Option<bool> enableRuntimeLibrary{
6457
*this, "enable-runtime-library",
6558
desc("Enable runtime library for manipulating sparse tensors"),
@@ -151,8 +144,8 @@ struct SparseCompilerOptions
151144

152145
/// Projects out the options for `createSparsificationPass`.
153146
SparsificationOptions sparsificationOptions() const {
154-
return SparsificationOptions(parallelization, enableIndexReduction,
155-
enableGPULibgen, enableRuntimeLibrary);
147+
return SparsificationOptions(parallelization, enableGPULibgen,
148+
enableRuntimeLibrary);
156149
}
157150

158151
/// Projects out the options for `createConvertVectorToLLVMPass`.

mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,14 @@ std::unique_ptr<Pass> createPreSparsificationRewritePass();
7474

7575
/// Options for the Sparsification pass.
7676
struct SparsificationOptions {
77-
SparsificationOptions(SparseParallelizationStrategy p, bool idxReduc,
78-
bool gpuLibgen, bool enableRT)
79-
: parallelizationStrategy(p), enableIndexReduction(idxReduc),
80-
enableGPULibgen(gpuLibgen), enableRuntimeLibrary(enableRT) {}
77+
SparsificationOptions(SparseParallelizationStrategy p, bool gpuLibgen,
78+
bool enableRT)
79+
: parallelizationStrategy(p), enableGPULibgen(gpuLibgen),
80+
enableRuntimeLibrary(enableRT) {}
8181
SparsificationOptions()
8282
: SparsificationOptions(SparseParallelizationStrategy::kNone, false,
83-
false, true) {}
83+
true) {}
8484
SparseParallelizationStrategy parallelizationStrategy;
85-
bool enableIndexReduction;
8685
bool enableGPULibgen;
8786
bool enableRuntimeLibrary;
8887
};

mlir/include/mlir/Dialect/SparseTensor/Transforms/Passes.td

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ def SparsificationPass : Pass<"sparsification", "ModuleOp"> {
114114
];
115115
// TODO(57514): These enum options are duplicated in Passes.h.
116116
let options = [
117-
Option<"enableIndexReduction", "enable-index-reduction", "bool",
118-
"false",
119-
"Enable dependent index reduction based algorithm to handle non-trivial index expressions on sparse inputs (experimental features)">,
120117
Option<"parallelization", "parallelization-strategy", "mlir::SparseParallelizationStrategy",
121118
"mlir::SparseParallelizationStrategy::kNone",
122119
"Set the parallelization strategy", [{llvm::cl::values(

mlir/lib/Dialect/SparseTensor/Transforms/SparseTensorPasses.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,15 @@ struct SparsificationPass
8282
SparsificationPass(const SparsificationPass &pass) = default;
8383
SparsificationPass(const SparsificationOptions &options) {
8484
parallelization = options.parallelizationStrategy;
85-
enableIndexReduction = options.enableIndexReduction;
8685
enableGPULibgen = options.enableGPULibgen;
8786
enableRuntimeLibrary = options.enableRuntimeLibrary;
8887
}
8988

9089
void runOnOperation() override {
9190
auto *ctx = &getContext();
9291
// Translate strategy flags to strategy options.
93-
SparsificationOptions options(parallelization, enableIndexReduction,
94-
enableGPULibgen, enableRuntimeLibrary);
92+
SparsificationOptions options(parallelization, enableGPULibgen,
93+
enableRuntimeLibrary);
9594
// Apply GPU libgen (if requested), sparsification, and cleanup rewriting.
9695
RewritePatternSet patterns(ctx);
9796
if (enableGPULibgen)

mlir/lib/Dialect/SparseTensor/Transforms/Sparsification.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,16 @@ static bool findDepIdxSet(Merger &merger, TensorId tensor, Level lvl,
323323
return true;
324324
}
325325
case AffineExprKind::Constant:
326-
// TODO: Support Constant AffineExp for slice-based codegen
327326
case AffineExprKind::Mul: {
328327
// TODO: Support index expression like `2 * d0`, we now only support more
329328
// complicated cases like `2 * d0 + d1`.
330329
if (!isSubExp)
331330
return false;
331+
332+
// TODO: Support Constant AffineExp for slice-based codegen
333+
if (a.isa<AffineConstantExpr>())
334+
llvm_unreachable("Not yet implemented");
335+
332336
auto binOp = a.cast<AffineBinaryOpExpr>();
333337
auto lhs = binOp.getLHS(), rhs = binOp.getRHS();
334338
if (rhs.isa<AffineConstantExpr>())
@@ -1953,7 +1957,7 @@ struct GenericOpSparsifier : public OpRewritePattern<linalg::GenericOp> {
19531957
const unsigned numFilterLoops = getNumNonTrivialIdxExpOnSparseLvls(op);
19541958
// TODO: we should probably always use slice-based codegen whenever
19551959
// possible, we can even intermix slice-based and filter-loop based codegen.
1956-
bool idxReducBased = options.enableIndexReduction && numFilterLoops != 0;
1960+
bool idxReducBased = numFilterLoops != 0;
19571961
// If we have indexing map like (d0) -> (0, d0), there might be more
19581962
// levels then loops because of the constant index, that means we can not
19591963
// use numLoops as the upper bound for ranks of all tensors.

0 commit comments

Comments
 (0)