Commit Graph

887 Commits

Author SHA1 Message Date
Peiming Liu
cf4dd91165 [mlir][sparse] initialize slice-driven loop-related fields in one place (#76099) 2023-12-20 14:20:57 -08:00
Matthias Springer
10056c821a [mlir][SCF] scf.parallel: Make reductions part of the terminator (#75314)
This commit makes reductions part of the terminator. Instead of
`scf.yield`, `scf.reduce` now terminates the body of `scf.parallel` ops.
`scf.reduce` may contain an arbitrary number of reductions, with one
region per reduction.

Example:
```mlir
%init = arith.constant 0.0 : f32
%r:2 = scf.parallel (%iv) = (%lb) to (%ub) step (%step) init (%init, %init)
    -> f32, f32 {
  %elem_to_reduce1 = load %buffer1[%iv] : memref<100xf32>
  %elem_to_reduce2 = load %buffer2[%iv] : memref<100xf32>
  scf.reduce(%elem_to_reduce1, %elem_to_reduce2 : f32, f32) {
    ^bb0(%lhs : f32, %rhs: f32):
      %res = arith.addf %lhs, %rhs : f32
      scf.reduce.return %res : f32
  }, {
    ^bb0(%lhs : f32, %rhs: f32):
      %res = arith.mulf %lhs, %rhs : f32
      scf.reduce.return %res : f32
  }
}
```

`scf.reduce` operations can no longer be interleaved with other ops in
the body of `scf.parallel`. This simplifies the op and makes it possible
to assign the `RecursiveMemoryEffects` trait to `scf.reduce`. (This was
not possible before because the op was not a terminator, causing the op
to be DCE'd.)
2023-12-20 11:06:27 +09:00
Matthias Springer
ea979b24b0 [mlir][SparseTensor][NFC] Remove isNestedIn helper function (#75729)
Use `Region::findAncestorBlockInRegion` instead of a custom IR
traversal.
2023-12-17 13:19:27 +09:00
Peiming Liu
6c06bde7c4 [mlir][sparse] support loop range query using SparseTensorLevel. (#75670) 2023-12-15 16:33:31 -08:00
Peiming Liu
21edad7d07 [mlir][sparse] set up the skeleton for SparseTensorLevel abstraction. (#75645)
Note that at the current moment, the newly-introduced
`SparseTensorLevel` classes are far from complete, we plan to migrate
code generation related to accessing sparse tensor levels to these
classes in the near future to simplify `LoopEmitter`.
2023-12-15 13:34:34 -08:00
Peiming Liu
4a72a4ef12 [NFC][mlir][sparse] remove redundant parameter. (#75551) 2023-12-15 09:29:22 -08:00
Aart Bik
15c06bc4af [mlir][sparse] comment cleanup in iteration graph sorter (#75508) 2023-12-14 10:56:28 -08:00
Aart Bik
e52c941921 [mlir][sparse] minor cleanup of transform/utils (#75396)
Consistent include macro naming
Modified and added comments
2023-12-13 15:18:35 -08:00
Aart Bik
365777ecbe [mlir][sparse] refactor utilities into transform/utils dir (#75250)
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-12-12 15:34:31 -08:00
Aart Bik
047399c213 [mlir][sparse] cleanup of CodegenEnv reduction API (#75243) 2023-12-12 12:44:46 -08:00
Yinying Li
31b72b0742 [mlir][sparse]Make isBlockSparsity more robust (#75113)
1. A single dimension can either be blocked (with floordiv and mod pair)
or non-blocked. Mixing them would be invalid.
2. Block size should be non-zero value.
2023-12-12 13:43:03 -05:00
Aart Bik
d96f46dd20 [mlir][sparse] fix bug in custom reduction scalarization code (#74898)
Bug found with BSR of "spy" SDDMM method
2023-12-11 10:22:17 -08:00
Aart Bik
3d3e46cc4d [mlir][sparse] make test for block sparsity more robust (#74798)
For BSR and convolutions, we encounter

(d0, d1, d2, d3) -> ((d0 + d2) floordiv 2, (d1 + d3) floordiv 2, (d0 +
d2) mod 2, (d1 + d3) mod 2)

which crashed the current test. Note that an actual test and working
code is still to follow (since we need to fix a few other things first)
2023-12-08 11:50:10 -08:00
Peiming Liu
baa192ea65 [mlir][sparse] optimize memory loads to SSA values when generating sp… (#74787)
…arse conv.
2023-12-08 09:22:19 -08:00
Peiming Liu
097d2f1417 [mlir][sparse] optimize memory load to SSA value when generating spar… (#74750)
…se conv kernel.
2023-12-07 12:00:25 -08:00
Matthias Springer
986287e7f3 [mlir][SparseTensor] Fix invalid API usage in patterns (#74690)
Rewrite patterns must return `success` if the IR was modified. This
commit fixes sparse tensor tests such as
`SparseTensor/sparse_fusion.mlir`,
`SparseTensor/CPU/sparse_reduce_custom.mlir`,
`SparseTensor/CPU/sparse_semiring_select.mlir` when running with
`MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS`.
2023-12-07 12:05:20 +09:00
Peiming Liu
78e2b74f96 [mlir][sparse] fix bugs when generate sparse conv_3d kernels. (#74561) 2023-12-06 15:59:10 -08:00
Matthias Springer
861600f175 [mlir][SparseTensor] Fix invalid IR in ForallRewriter pattern (#74547)
The `ForallRewriter` pattern used to generate invalid IR:
```
mlir/test/Dialect/SparseTensor/GPU/gpu_combi.mlir:0:0: error: 'scf.for' op expects region #0 to have 0 or 1 blocks
mlir/test/Dialect/SparseTensor/GPU/gpu_combi.mlir:0:0: note: see current operation:
"scf.for"(%8, %2, %9) ({
^bb0(%arg5: index):
  // ...
  "scf.yield"() : () -> ()
^bb1(%10: index):  // no predecessors
  "scf.yield"() : () -> ()
}) : (index, index, index) -> ()
```

This commit fixes tests such as
`mlir/test/Dialect/SparseTensor/GPU/gpu_combi.mlir` when verifying the
IR after each pattern application (#74270).
2023-12-07 08:47:20 +09:00
Matthias Springer
851f85fffb [mlir][SparseTensor] Fix insertion point in createQuickSort (#74549)
`createQuickSort` used to generate invalid IR:
```
"func.func"() <{function_type = (index, index, memref<?xindex>, memref<?xf32>, memref<?xi32>) -> (), sym_name = "_sparse_qsort_0_1_index_coo_1_f32_i32", sym_visibility = "private"}> ({
^bb0(%arg0: index, %arg1: index, %arg2: memref<?xindex>, %arg3: memref<?xf32>, %arg4: memref<?xi32>):
  %0:2 = "scf.while"(%arg0, %arg1) ({
  ^bb0(%arg5: index, %arg6: index):
    // ...
    "scf.condition"(%3, %arg5, %arg6) : (i1, index, index) -> ()
  }, {
  ^bb0(%arg5: index, %arg6: index):
    // ...
    %7:2 = "scf.if"(%6) ({
      %8 = "arith.cmpi"(%2, %3) <{predicate = 7 : i64}> : (index, index) -> i1
      // ...
      "scf.yield"(%9#0, %9#1) : (index, index) -> ()
      %10 = "arith.constant"() <{value = 0 : index}> : () -> index
    }, {
      "scf.yield"(%arg5, %arg5) : (index, index) -> ()
    }) : (i1) -> (index, index)
    "scf.yield"(%7#0, %7#1) : (index, index) -> ()
  }) : (index, index) -> (index, index)
  "func.return"() : () -> ()
}) : () -> ()
within split at mlir/test/Dialect/SparseTensor/buffer_rewriting.mlir:76 offset :11:1: error: 'scf.yield' op must be the last operation in the parent block
```

This commit fixes tests such as
`mlir/test/Dialect/SparseTensor/buffer_rewriting.mlir` when verifying
the IR after each pattern application (#74270).
2023-12-07 08:47:05 +09:00
Aart Bik
c5a1732cf3 [mlir][sparse] use "current" and "curr" consistently (#74656)
Removes at in favor of curr; also makes method delegates consistent
2023-12-06 14:12:46 -08:00
Aart Bik
98ce2debc6 [mlir][sparse] cleanup ldx/idx/depth/at usage (#74654)
This adds a consistent usage with `at` for everything that refers to the
current loop nesting. This cleans up some redundant legacy code from
when we were still using topSort inside sparsifier code.
2023-12-06 13:23:50 -08:00
Aart Bik
5b0db27ace [mlir][sparse] remove LoopOrd type (#74540)
Rationale:
We no longer deal with topsort during sparsification, so that LoopId ==
LoopOrd for all methods. This first revision removes the types. A follow
up revision will simplify some other remaining constructs that deal with
loop order (e.g. at and ldx).
2023-12-06 09:35:30 -08:00
Aart Bik
067bebb50f [mlir][sparse] minor refactoring of sparsification file (#74403)
Removed obsoleted TODOs and NOTEs, formatting, removed unused parameter
2023-12-05 09:31:17 -08:00
Peiming Liu
8206b75a1e [mlir][sparse] fix crash when generate rotated convolution kernels. (#74146) 2023-12-01 14:13:57 -08:00
Peiming Liu
b6cad75e07 [mlir][sparse] refactoring: using util functions to query the index to load from position array for slice-driven loop. (#73986) 2023-11-30 16:40:11 -08:00
Aart Bik
5b72950394 [mlir][sparse] move all COO related methods into SparseTensorType (#73881)
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-30 09:40:39 -08:00
Aart Bik
98f8b1afb4 [mlir][sparse] remove COO test from trait and encoding (#73733)
This is a minor step towards moving ALL COO related tests into the
SparseTensorType class rather than
having it all over the place (with risk of becoming inconsistent). Next
revision will move ALL COO related methods into this class.
2023-11-28 17:46:02 -08:00
Aart Bik
45288085b5 [mlir][sparse] move toCOOType into SparseTensorType class (#73708)
Migrates dangling convenience method into proper SparseTensorType class.
Also cleans up some details (picking right dim2lvl/lvl2dim). Removes
more dead code.
2023-11-28 16:04:01 -08:00
Peiming Liu
1ece4d3a0d [mlir][sparse] code simplification: always use synthetical tensor for… (#73597)
… loop bound.
2023-11-27 17:41:45 -08:00
Aart Bik
79cb594fdf [mlir][sparse] remove unused COO method (#73595)
step closer towards moving all type related methods into encoding and/or
sparse tensor type class
2023-11-27 17:26:45 -08:00
Peiming Liu
4e2f1521ec [mlir][sparse] code cleanup, remove FIXMEs (#73575) 2023-11-27 14:57:08 -08:00
Aart Bik
1944c4f76b [mlir][sparse] rename DimLevelType to LevelType (#73561)
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-27 14:27:52 -08:00
Aart Bik
1dd387e106 [mlir][sparse] change dim level type -> level type (#73058)
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-22 09:06:22 -08:00
Aart Bik
d213220a9a [mlir][sparse] fixed naming consistency (#73053)
All DLT related methods have DLT at end, removed stale TODO
2023-11-21 16:26:09 -08:00
Aart Bik
d2d29288bd [mlir][sparse] code cleanup (#73047)
removed two unused methods, removed obsoleted FIXME
2023-11-21 14:57:38 -08:00
Peiming Liu
b52eb7c2fe [mlir][sparse] add a csr x bsr matmul test case (#73012) 2023-11-21 09:14:45 -08:00
Peiming Liu
2cc4b3d07c [mlir][sparse] code cleanup using the assumption that dim2lvl maps ar… (#72894)
…e simplified.
2023-11-20 10:25:42 -08:00
Yinying Li
704c224736 [mlir][sparse] Clean up parser (#72571)
Remove unused functions in parser.
2023-11-17 13:38:22 -05:00
Aart Bik
83cf0dc982 [mlir][sparse] implement direct IR alloc/empty/new for non-permutations (#72585)
This change implements the correct *level* sizes set up for the direct
IR codegen fields in the sparse storage scheme. This brings libgen and
codegen together again.

This is step 3 out of 3 to make sparse_tensor.new work for BSR
2023-11-16 17:17:41 -08:00
Yinying Li
c5a67e16b6 [mlir][sparse] Use variable instead of inlining sparse encoding (#72561)
Example:

#CSR = #sparse_tensor.encoding<{
  map = (d0, d1) -> (d0 : dense, d1 : compressed),
}>

// CHECK: #[[$CSR.*]] = #sparse_tensor.encoding<{ map = (d0, d1) -> (d0
: dense, d1 : compressed) }>
// CHECK-LABEL: func private @sparse_csr(
// CHECK-SAME: tensor<?x?xf32, **#[[$CSR]]**>)
func.func private @sparse_csr(tensor<?x?xf32, #CSR>)
2023-11-16 19:30:21 -05:00
Peiming Liu
ccd923e3cb [mlir][sparse] code cleanup (remove dead code related to filter loop). (#72573) 2023-11-16 14:26:09 -08:00
Peiming Liu
ff8815e597 [mlir][sparse] code cleanup (remove topSort in CodegenEnv). (#72550) 2023-11-16 13:21:49 -08:00
Aart Bik
2323f48e0d [mlir][sparse] refactor dim2lvl/lvl2dim lvlsizes setup (#72474)
This change provides access to the individual components of dim sizes
and lvl sizes after each codegenutil call.

This is step 2 out of 3 to make sparse_tensor.new work for BSR
2023-11-15 21:41:43 -08:00
Aart Bik
e8fc282ff2 [mlir][sparse] avoid non-perm on sparse tensor convert for new (#72459)
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-15 20:47:37 -08:00
Peiming Liu
06a65ce500 [mlir][sparse] schedule sparse kernels in a separate pass from sparsification. (#72423) 2023-11-15 12:16:05 -08:00
Tim Harvey
dce7a7cf69 Changed all code and comments that used the phrase "sparse compiler" to instead use "sparsifier" (#71875)
The changes in this p.r. mostly center around the tests that use the
flag sparse_compiler (also: sparse-compiler).
2023-11-15 20:12:35 +00:00
Maksim Levental
e35b606280 [mlir][sparsifier] fix isAdmissibleBSR (#72195)
Fixes https://github.com/llvm/llvm-project/issues/72194.
2023-11-14 16:56:34 -06:00
Aart Bik
5f32bcfbae [mlir][sparse][gpu] re-enable all GPU libgen tests (#72185)
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-14 09:06:15 -08:00
long.chen
1609f1c2a5 [mlir][affine][nfc] cleanup deprecated T.cast style functions (#71269)
detail see the docment: https://mlir.llvm.org/deprecation/

Not all changes are made manually, most of them are made through a clang
tool I wrote https://github.com/lipracer/cpp-refactor.
2023-11-14 13:01:19 +08:00
Peiming Liu
269685545e [mlir][sparse] remove filter-loop based algorithm support to handle a… (#71840)
…ffine subscript expressions.
2023-11-13 11:36:49 -08:00