Skip to content

Commit d374a78

Browse files
[mlir][sparse] Treat high and 2OutOf4 as level formats (#67203)
In the new syntax, we will parse **loose_compressed** as **CompressedWithHigh** and **block2_4** as **TwoOutOfFour** level format. Currently, we support unique and order as level properties.
1 parent 10edd5d commit d374a78

File tree

6 files changed

+11
-19
lines changed

6 files changed

+11
-19
lines changed

mlir/include/mlir/Dialect/SparseTensor/IR/Enums.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ enum class LevelFormat : uint8_t {
203203
enum class LevelNondefaultProperty : uint8_t {
204204
Nonunique = 1, // 0b00000_01
205205
Nonordered = 2, // 0b00000_10
206-
High = 32, // 0b01000_00
207-
Block2_4 = 64 // 0b10000_00
208206
};
209207

210208
/// Returns string representation of the given dimension level type.

mlir/lib/Dialect/SparseTensor/IR/Detail/LvlTypeParser.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,11 @@ FailureOr<uint8_t> LvlTypeParser::parseLvlType(AsmParser &parser) const {
6464
if (base.compare("dense") == 0) {
6565
properties |= static_cast<uint8_t>(LevelFormat::Dense);
6666
} else if (base.compare("compressed") == 0) {
67-
// TODO: Remove this condition once dimLvlType enum is refactored. Current
68-
// enum treats High and TwoOutOfFour as formats instead of properties.
69-
if (!(properties & static_cast<uint8_t>(LevelNondefaultProperty::High) ||
70-
properties &
71-
static_cast<uint8_t>(LevelNondefaultProperty::Block2_4))) {
72-
properties |= static_cast<uint8_t>(LevelFormat::Compressed);
73-
}
67+
properties |= static_cast<uint8_t>(LevelFormat::Compressed);
68+
} else if (base.compare("block2_4") == 0) {
69+
properties |= static_cast<uint8_t>(LevelFormat::TwoOutOfFour);
70+
} else if (base.compare("loose_compressed") == 0) {
71+
properties |= static_cast<uint8_t>(LevelFormat::CompressedWithHi);
7472
} else if (base.compare("singleton") == 0) {
7573
properties |= static_cast<uint8_t>(LevelFormat::Singleton);
7674
} else {
@@ -93,10 +91,6 @@ ParseResult LvlTypeParser::parseProperty(AsmParser &parser,
9391
*properties |= static_cast<uint8_t>(LevelNondefaultProperty::Nonunique);
9492
} else if (strVal.compare("nonordered") == 0) {
9593
*properties |= static_cast<uint8_t>(LevelNondefaultProperty::Nonordered);
96-
} else if (strVal.compare("high") == 0) {
97-
*properties |= static_cast<uint8_t>(LevelNondefaultProperty::High);
98-
} else if (strVal.compare("block2_4") == 0) {
99-
*properties |= static_cast<uint8_t>(LevelNondefaultProperty::Block2_4);
10094
} else {
10195
parser.emitError(loc, "unknown level property: ") << strVal;
10296
return failure();

mlir/test/Dialect/SparseTensor/roundtrip_encoding.mlir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func.func private @sparse_coo(tensor<?x?xf32, #COO>)
6565
// -----
6666

6767
#BCOO = #sparse_tensor.encoding<{
68-
map = (d0, d1, d2) -> (d0 : dense, d1 : compressed(nonunique, high), d2 : singleton)
68+
map = (d0, d1, d2) -> (d0 : dense, d1 : loose_compressed(nonunique), d2 : singleton)
6969
}>
7070

7171
// CHECK-LABEL: func private @sparse_bcoo(
@@ -148,7 +148,7 @@ func.func private @sparse_slice(tensor<?x?xf64, #CSR_SLICE>)
148148
// below) to encode a 2D matrix, but it would require dim2lvl mapping which is not ready yet.
149149
// So we take the simple path for now.
150150
#NV_24= #sparse_tensor.encoding<{
151-
map = (d0, d1) -> (d0 : dense, d1 : compressed(block2_4))
151+
map = (d0, d1) -> (d0 : dense, d1 : block2_4)
152152
}>
153153

154154
// CHECK-LABEL: func private @sparse_2_out_of_4(
@@ -199,7 +199,7 @@ func.func private @BCSR_explicit(%arg0: tensor<?x?xf64, #BCSR_explicit>) {
199199
map = ( i, j ) ->
200200
( i : dense,
201201
j floordiv 4 : dense,
202-
j mod 4 : compressed(block2_4)
202+
j mod 4 : block2_4
203203
)
204204
}>
205205

mlir/test/Dialect/SparseTensor/sparse_2d.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,7 @@ func.func @cmp_ss_ss(%arga: tensor<32x16xf32, #Tss>, %argb: tensor<32x16xf32, #T
10501050
}
10511051

10521052
#BatchedVector = #sparse_tensor.encoding<{
1053-
map = (d0, d1) -> (d0 : dense, d1 : compressed(high))
1053+
map = (d0, d1) -> (d0 : dense, d1 : loose_compressed)
10541054
}>
10551055
// CHECK-LABEL: func.func @sub_ss_batched(
10561056
// CHECK-SAME: %[[VAL_0:.*]]: tensor<2x3xf64, #{{.*}}>>,

mlir/test/Dialect/SparseTensor/sparse_foreach.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func.func @foreach_print_slice(%A: tensor<4x4xf64, #CSR_SLICE>) {
141141
}
142142

143143
#BCOO = #sparse_tensor.encoding<{
144-
map = (d0, d1, d2) -> (d0 : dense, d1 : compressed(nonunique, high), d2 : singleton)
144+
map = (d0, d1, d2) -> (d0 : dense, d1 : loose_compressed(nonunique), d2 : singleton)
145145
}>
146146

147147
// CHECK-LABEL: func.func @foreach_bcoo(

mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_pack.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
}>
4444

4545
#BCOO = #sparse_tensor.encoding<{
46-
map = (d0, d1, d2) -> (d0 : dense, d1 : compressed(nonunique, high), d2 : singleton)
46+
map = (d0, d1, d2) -> (d0 : dense, d1 : loose_compressed(nonunique), d2 : singleton)
4747
}>
4848

4949
module {

0 commit comments

Comments
 (0)