Skip to content

Commit fd2f19e

Browse files
address comments
1 parent 4ba9d91 commit fd2f19e

File tree

12 files changed

+65
-64
lines changed

12 files changed

+65
-64
lines changed

mlir/include/mlir-c/Dialect/SparseTensor.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(SparseTensor, sparse_tensor);
2626
/// If updating, keep them in sync and update the static_assert in the impl
2727
/// file.
2828
enum MlirSparseTensorLevelType {
29-
MLIR_SPARSE_TENSOR_LEVEL_DENSE = 65536, // 0x00_00_0001_0000
30-
MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED = 131072, // 0x00_00_0002_0000
31-
MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU = 131073, // 0x00_00_0002_0001
32-
MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NO = 131074, // 0x00_00_0002_0002
33-
MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU_NO = 131075, // 0x00_00_0002_0003
34-
MLIR_SPARSE_TENSOR_LEVEL_SINGLETON = 262144, // 0x00_00_0004_0000
35-
MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU = 262145, // 0x00_00_0004_0001
36-
MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NO = 262146, // 0x00_00_0004_0002
37-
MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU_NO = 262147, // 0x00_00_0004_0003
38-
MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED = 524288, // 0x00_00_0008_0000
39-
MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU = 524289, // 0x00_00_0008_0001
40-
MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NO = 524290, // 0x00_00_0008_0002
41-
MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU_NO = 524291, // 0x00_00_0008_0003
42-
MLIR_SPARSE_TENSOR_LEVEL_N_OUT_OF_M = 1048576, // 0x00_00_0010_0000
29+
MLIR_SPARSE_TENSOR_LEVEL_DENSE = 0x000000010000,
30+
MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED = 0x000000020000,
31+
MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU = 0x000000020001,
32+
MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NO = 0x000000020002,
33+
MLIR_SPARSE_TENSOR_LEVEL_COMPRESSED_NU_NO = 0x000000020003,
34+
MLIR_SPARSE_TENSOR_LEVEL_SINGLETON = 0x000000040000,
35+
MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU = 0x000000040001,
36+
MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NO = 0x000000040002,
37+
MLIR_SPARSE_TENSOR_LEVEL_SINGLETON_NU_NO = 0x000000040003,
38+
MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED = 0x000000080000,
39+
MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU = 0x000000080001,
40+
MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NO = 0x000000080002,
41+
MLIR_SPARSE_TENSOR_LEVEL_LOOSE_COMPRESSED_NU_NO = 0x000000080003,
42+
MLIR_SPARSE_TENSOR_LEVEL_N_OUT_OF_M = 0x000000100000,
4343
};
4444

4545
//===----------------------------------------------------------------------===//

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

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -172,36 +172,36 @@ enum class Action : uint32_t {
172172
/// | 8-bit n | 8-bit m | 16-bit LevelFormat | 16-bit LevelProperty |
173173
///
174174
enum class LevelType : uint64_t {
175-
Undef = 0, // 0x00_00_0000_0000
176-
Dense = 65536, // 0x00_00_0001_0000
177-
Compressed = 131072, // 0x00_00_0002_0000
178-
CompressedNu = 131073, // 0x00_00_0002_0001
179-
CompressedNo = 131074, // 0x00_00_0002_0002
180-
CompressedNuNo = 131075, // 0x00_00_0002_0003
181-
Singleton = 262144, // 0x00_00_0004_0000
182-
SingletonNu = 262145, // 0x00_00_0004_0001
183-
SingletonNo = 262146, // 0x00_00_0004_0002
184-
SingletonNuNo = 262147, // 0x00_00_0004_0003
185-
LooseCompressed = 524288, // 0x00_00_0008_0000
186-
LooseCompressedNu = 524289, // 0x00_00_0008_0001
187-
LooseCompressedNo = 524290, // 0x00_00_0008_0002
188-
LooseCompressedNuNo = 524291, // 0x00_00_0008_0003
189-
NOutOfM = 1048576, // 0x00_00_0010_0000
175+
Undef = 0x000000000000,
176+
Dense = 0x000000010000,
177+
Compressed = 0x000000020000,
178+
CompressedNu = 0x000000020001,
179+
CompressedNo = 0x000000020002,
180+
CompressedNuNo = 0x000000020003,
181+
Singleton = 0x000000040000,
182+
SingletonNu = 0x000000040001,
183+
SingletonNo = 0x000000040002,
184+
SingletonNuNo = 0x000000040003,
185+
LooseCompressed = 0x000000080000,
186+
LooseCompressedNu = 0x000000080001,
187+
LooseCompressedNo = 0x000000080002,
188+
LooseCompressedNuNo = 0x000000080003,
189+
NOutOfM = 0x000000100000,
190190
};
191191

192192
/// This enum defines all supported storage format without the level properties.
193193
enum class LevelFormat : uint64_t {
194-
Dense = 65536, // 0x0001_0000
195-
Compressed = 131072, // 0x0002_0000
196-
Singleton = 262144, // 0x0004_0000
197-
LooseCompressed = 524288, // 0x0008_0000
198-
NOutOfM = 1048576, // 0x0010_0000
194+
Dense = 0x00010000,
195+
Compressed = 0x00020000,
196+
Singleton = 0x00040000,
197+
LooseCompressed = 0x00080000,
198+
NOutOfM = 0x00100000,
199199
};
200200

201201
/// This enum defines all the nondefault properties for storage formats.
202202
enum class LevelPropertyNondefault : uint64_t {
203-
Nonunique = 1, // 0x0001
204-
Nonordered = 2, // 0x0002
203+
Nonunique = 0x0001,
204+
Nonordered = 0x0002,
205205
};
206206

207207
/// Get N of NOutOfM level type.
@@ -265,7 +265,7 @@ constexpr const char *toMLIRString(LevelType lt) {
265265
return "loose_compressed(nonunique, nonordered)";
266266
default:
267267
if (isNOutOfMLT(lt)) {
268-
return "block";
268+
return "structured";
269269
}
270270
}
271271
return "";

mlir/include/mlir/Dialect/SparseTensor/IR/SparseTensorAttrDefs.td

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ def SparseTensorEncodingAttr : SparseTensor_Attr<"SparseTensorEncoding",
145145
- **compressed** : only nonzeros along this level are stored
146146
- **loose_compressed** : as compressed, but allows for free space between regions
147147
- **singleton** : a variant of the compressed format, where coordinates have no siblings
148-
- **block[n, m]** : the compression uses a n:m encoding per 1xm block
148+
- **structured[n, m]** : the compression uses a n:m encoding
149+
(viz. n out of m consecutive elements are nonzero)
149150

150151
For a compressed level, each position interval is represented in a compact
151152
way with a lowerbound `pos(i)` and an upperbound `pos(i+1) - 1`, which implies

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ FailureOr<uint64_t> LvlTypeParser::parseLvlType(AsmParser &parser) const {
3535
ERROR_IF(failed(parser.parseOptionalKeyword(&base)),
3636
"expected valid level format (e.g. dense, compressed or singleton)")
3737
uint64_t properties = 0;
38-
SmallVector<unsigned> blockSizes;
38+
SmallVector<unsigned> structure;
3939

40-
if (base.compare("block") == 0) {
40+
if (base.compare("structured") == 0) {
4141
ParseResult res = parser.parseCommaSeparatedList(
4242
mlir::OpAsmParser::Delimiter::OptionalSquare,
43-
[&]() -> ParseResult { return parseBlockSizes(parser, &blockSizes); },
43+
[&]() -> ParseResult { return parseStructure(parser, &structure); },
4444
" in block n out of m");
4545
FAILURE_IF_FAILED(res)
4646
}
@@ -56,13 +56,13 @@ FailureOr<uint64_t> LvlTypeParser::parseLvlType(AsmParser &parser) const {
5656
properties |= static_cast<uint64_t>(LevelFormat::Dense);
5757
} else if (base.compare("compressed") == 0) {
5858
properties |= static_cast<uint64_t>(LevelFormat::Compressed);
59-
} else if (base.compare("block") == 0) {
60-
if (blockSizes.size() != 2) {
61-
parser.emitError(loc, "expected exactly 2 block sizes");
59+
} else if (base.compare("structured") == 0) {
60+
if (structure.size() != 2) {
61+
parser.emitError(loc, "expected exactly 2 structure sizes");
6262
return failure();
6363
}
6464
properties |= static_cast<uint64_t>(LevelFormat::NOutOfM);
65-
properties |= nToBits(blockSizes[0]) | mToBits(blockSizes[1]);
65+
properties |= nToBits(structure[0]) | mToBits(structure[1]);
6666
} else if (base.compare("loose_compressed") == 0) {
6767
properties |= static_cast<uint64_t>(LevelFormat::LooseCompressed);
6868
} else if (base.compare("singleton") == 0) {
@@ -95,8 +95,8 @@ ParseResult LvlTypeParser::parseProperty(AsmParser &parser,
9595
}
9696

9797
ParseResult
98-
LvlTypeParser::parseBlockSizes(AsmParser &parser,
99-
SmallVector<unsigned> *blockSizes) const {
98+
LvlTypeParser::parseStructure(AsmParser &parser,
99+
SmallVector<unsigned> *structure) const {
100100
int intVal;
101101
auto loc = parser.getCurrentLocation();
102102
OptionalParseResult intValParseResult = parser.parseOptionalInteger(intVal);
@@ -105,7 +105,7 @@ LvlTypeParser::parseBlockSizes(AsmParser &parser,
105105
parser.emitError(loc, "failed to parse block size");
106106
return failure();
107107
}
108-
blockSizes->push_back(intVal);
108+
structure->push_back(intVal);
109109
return success();
110110
}
111111
parser.emitError(loc, "expected valid integer for block size");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ class LvlTypeParser {
2222

2323
private:
2424
ParseResult parseProperty(AsmParser &parser, uint64_t *properties) const;
25-
ParseResult parseBlockSizes(AsmParser &parser,
26-
SmallVector<unsigned> *blockSizes) const;
25+
ParseResult parseStructure(AsmParser &parser,
26+
SmallVector<unsigned> *structure) const;
2727
};
2828

2929
} // namespace ir_detail

mlir/test/CAPI/sparse_tensor.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static int testRoundtripEncoding(MlirContext ctx) {
4747
malloc(sizeof(enum MlirSparseTensorLevelType) * lvlRank);
4848
for (int l = 0; l < lvlRank; ++l) {
4949
lvlTypes[l] = mlirSparseTensorEncodingAttrGetLvlType(originalAttr, l);
50-
fprintf(stderr, "level_type: %d\n", lvlTypes[l]);
50+
fprintf(stderr, "level_type: %u\n", lvlTypes[l]);
5151
}
5252
// CHECK: posWidth: 32
5353
int posWidth = mlirSparseTensorEncodingAttrGetPosWidth(originalAttr);

mlir/test/Dialect/SparseTensor/GPU/gpu_matmul24_lib.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
map = ( i, j ) ->
55
( i : dense,
66
j floordiv 4 : dense,
7-
j mod 4 : block[2, 4]
7+
j mod 4 : structured[2, 4]
88
)
99
}>
1010

mlir/test/Dialect/SparseTensor/roundtrip_encoding.mlir

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,12 @@ func.func private @BSR_explicit(%arg0: tensor<?x?xf64, #BSR_explicit>) {
207207
map = ( i, j ) ->
208208
( i : dense,
209209
j floordiv 4 : dense,
210-
j mod 4 : block[2, 4]
210+
j mod 4 : structured[2, 4]
211211
),
212212
crdWidth = 8 // we would even like just 2-bits
213213
}>
214214

215-
// CHECK-DAG: #[[$NV_24:.*]] = #sparse_tensor.encoding<{ map = (d0, d1) -> (d0 : dense, d1 floordiv 4 : dense, d1 mod 4 : block[2, 4]), crdWidth = 8 }>
215+
// CHECK-DAG: #[[$NV_24:.*]] = #sparse_tensor.encoding<{ map = (d0, d1) -> (d0 : dense, d1 floordiv 4 : dense, d1 mod 4 : structured[2, 4]), crdWidth = 8 }>
216216
// CHECK-LABEL: func private @NV_24(
217217
// CHECK-SAME: tensor<?x?xf64, #[[$NV_24]]>
218218
func.func private @NV_24(%arg0: tensor<?x?xf64, #NV_24>) {
@@ -226,11 +226,11 @@ func.func private @NV_24(%arg0: tensor<?x?xf64, #NV_24>) {
226226
( i : dense,
227227
j : dense,
228228
k floordiv 4 : dense,
229-
k mod 4 : block[2, 4]
229+
k mod 4 : structured[2, 4]
230230
)
231231
}>
232232

233-
// CHECK-DAG: #[[$NV_24:.*]] = #sparse_tensor.encoding<{ map = (d0, d1, d2) -> (d0 : dense, d1 : dense, d2 floordiv 4 : dense, d2 mod 4 : block[2, 4]) }>
233+
// CHECK-DAG: #[[$NV_24:.*]] = #sparse_tensor.encoding<{ map = (d0, d1, d2) -> (d0 : dense, d1 : dense, d2 floordiv 4 : dense, d2 mod 4 : structured[2, 4]) }>
234234
// CHECK-LABEL: func private @NV_24(
235235
// CHECK-SAME: tensor<?x?x?xf64, #[[$NV_24]]>
236236
func.func private @NV_24(%arg0: tensor<?x?x?xf64, #NV_24>) {
@@ -244,11 +244,11 @@ func.func private @NV_24(%arg0: tensor<?x?x?xf64, #NV_24>) {
244244
( i : dense,
245245
k floordiv 4 : dense,
246246
j : dense,
247-
k mod 4 : block[2, 4]
247+
k mod 4 : structured[2, 4]
248248
)
249249
}>
250250

251-
// CHECK-DAG: #[[$NV_24:.*]] = #sparse_tensor.encoding<{ map = (d0, d1, d2) -> (d0 : dense, d2 floordiv 4 : dense, d1 : dense, d2 mod 4 : block[2, 4]) }>
251+
// CHECK-DAG: #[[$NV_24:.*]] = #sparse_tensor.encoding<{ map = (d0, d1, d2) -> (d0 : dense, d2 floordiv 4 : dense, d1 : dense, d2 mod 4 : structured[2, 4]) }>
252252
// CHECK-LABEL: func private @NV_24(
253253
// CHECK-SAME: tensor<?x?x?xf64, #[[$NV_24]]>
254254
func.func private @NV_24(%arg0: tensor<?x?x?xf64, #NV_24>) {
@@ -262,11 +262,11 @@ func.func private @NV_24(%arg0: tensor<?x?x?xf64, #NV_24>) {
262262
( i : dense,
263263
k floordiv 8 : dense,
264264
j : dense,
265-
k mod 8 : block[5, 8]
265+
k mod 8 : structured[5, 8]
266266
)
267267
}>
268268

269-
// CHECK-DAG: #[[$NOutOfM:.*]] = #sparse_tensor.encoding<{ map = (d0, d1, d2) -> (d0 : dense, d2 floordiv 8 : dense, d1 : dense, d2 mod 8 : block[5, 8]) }>
269+
// CHECK-DAG: #[[$NOutOfM:.*]] = #sparse_tensor.encoding<{ map = (d0, d1, d2) -> (d0 : dense, d2 floordiv 8 : dense, d1 : dense, d2 mod 8 : structured[5, 8]) }>
270270
// CHECK-LABEL: func private @NOutOfM(
271271
// CHECK-SAME: tensor<?x?x?xf64, #[[$NOutOfM]]>
272272
func.func private @NOutOfM(%arg0: tensor<?x?x?xf64, #NOutOfM>) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
map = ( i, j ) ->
6060
( i : dense,
6161
j floordiv 4 : dense,
62-
j mod 4 : block[2, 4]
62+
j mod 4 : structured[2, 4]
6363
),
6464
}>
6565

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
#NV_24 = #sparse_tensor.encoding<{
4242
map = ( i, j ) -> ( i : dense,
4343
j floordiv 4 : dense,
44-
j mod 4 : block[2, 4]),
44+
j mod 4 : structured[2, 4]),
4545
crdWidth = 8
4646
}>
4747

mlir/test/Integration/Dialect/SparseTensor/GPU/CUDA/sm80-lt/sparse-matmul-2-4-lib.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
map = ( i, j ) ->
2121
( i : dense,
2222
j floordiv 4 : dense,
23-
j mod 4 : block[2, 4]
23+
j mod 4 : structured[2, 4]
2424
)
2525
}>
2626

mlir/test/Integration/Dialect/SparseTensor/GPU/CUDA/sm80-lt/sparse-matmul-2-4-prune.mlir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
map = ( i, j ) ->
2121
( i : dense,
2222
j floordiv 4 : dense,
23-
j mod 4 : block[2, 4]
23+
j mod 4 : structured[2, 4]
2424
)
2525
}>
2626

0 commit comments

Comments
 (0)