xref: /llvm-project/mlir/test/Dialect/SparseTensor/convert_sparse2sparse.mlir (revision ef100c228a5913c6c54bfed8e80fd265ce8beca2)
1f82bee13SPeiming Liu// RUN: mlir-opt %s --stage-sparse-ops --lower-sparse-ops-to-foreach --canonicalize --cse | FileCheck %s
2eb877006Sbixia1
30d600002Sbixia1#SparseVector64 = #sparse_tensor.encoding<{
4dbe1be9aSYinying Li  map = (d0) -> (d0 : compressed),
584cd51bbSwren romano  posWidth = 64,
684cd51bbSwren romano  crdWidth = 64
70d600002Sbixia1}>
80d600002Sbixia1
90d600002Sbixia1#SparseVector32 = #sparse_tensor.encoding<{
10dbe1be9aSYinying Li  map = (d0) -> (d0 : compressed),
1184cd51bbSwren romano  posWidth = 32,
1284cd51bbSwren romano  crdWidth = 32
130d600002Sbixia1}>
140d600002Sbixia1
150d600002Sbixia1#SparseVector = #sparse_tensor.encoding<{
16dbe1be9aSYinying Li  map = (d0) -> (d0 : compressed)
170d600002Sbixia1}>
180d600002Sbixia1
1933267f40SPeiming Liu#SortedCOO2D = #sparse_tensor.encoding<{
203dc62112SYinying Li  map = (d0, d1) -> (d0 : compressed(nonunique), d1 : singleton),
2133267f40SPeiming Liu}>
2233267f40SPeiming Liu
23dfcb6719Sbixia1#SortedCOO3D = #sparse_tensor.encoding<{
243dc62112SYinying Li  map = (d0, d1, d2) -> (d0 : compressed(nonunique), d1 : singleton(nonunique), d2 : singleton)
2557416d87Sbixia1
2657416d87Sbixia1}>
2757416d87Sbixia1
2857416d87Sbixia1#TsssPermuted = #sparse_tensor.encoding<{
293dc62112SYinying Li  map = (d0, d1, d2) -> (d2 : compressed, d0 : compressed, d1 : compressed)
3057416d87Sbixia1}>
3157416d87Sbixia1
3233267f40SPeiming Liu#COOSlice = #sparse_tensor.encoding<{
33256ac461SYinying Li  map = (d0 : #sparse_tensor<slice(2, 2, 1)>, d1 : #sparse_tensor<slice(12, 13, 1)>) -> (d0 : compressed(nonunique), d1 : singleton)
3433267f40SPeiming Liu}>
3533267f40SPeiming Liu
36f248d0b2SPeiming Liu// CHECK-LABEL:   func.func @sparse_nop_convert
37f248d0b2SPeiming Liu// CHECK-NEXT:       return
380d600002Sbixia1func.func @sparse_nop_convert(%arg0: tensor<64xf32, #SparseVector>) -> tensor<64xf32, #SparseVector> {
390d600002Sbixia1  %0 = sparse_tensor.convert %arg0 : tensor<64xf32, #SparseVector> to tensor<64xf32, #SparseVector>
400d600002Sbixia1  return %0 : tensor<64xf32, #SparseVector>
410d600002Sbixia1}
420d600002Sbixia1
43f248d0b2SPeiming Liu// CHECK-LABEL:   func.func @sparse_hidden_nop_cast
440cbaff81SAart Bik// CHECK-NEXT:      sparse_tensor.convert
450cbaff81SAart Bik// CHECK-NEXT:      return
460d600002Sbixia1func.func @sparse_hidden_nop_cast(%arg0: tensor<32xf32, #SparseVector>) -> tensor<?xf32, #SparseVector> {
470d600002Sbixia1  %0 = sparse_tensor.convert %arg0 : tensor<32xf32, #SparseVector> to tensor<?xf32, #SparseVector>
480d600002Sbixia1  return %0 : tensor<?xf32, #SparseVector>
490d600002Sbixia1}
500d600002Sbixia1
51b7188d28SAart Bik// CHECK-LABEL:   func.func @sparse_convert_1d_ss(
520cbaff81SAart Bik// CHECK-NEXT:      sparse_tensor.convert
530cbaff81SAart Bik// CHECK-NEXT:      return
540d600002Sbixia1func.func @sparse_convert_1d_ss(%arg0: tensor<?xf32, #SparseVector64>) -> tensor<?xf32, #SparseVector32> {
550d600002Sbixia1  %0 = sparse_tensor.convert %arg0 : tensor<?xf32, #SparseVector64> to tensor<?xf32, #SparseVector32>
560d600002Sbixia1  return %0 : tensor<?xf32, #SparseVector32>
570d600002Sbixia1}
580d600002Sbixia1
59b7188d28SAart Bik// CHECK-LABEL:   func.func @sparse_convert(
600cbaff81SAart Bik// CHECK-NEXT:      sparse_tensor.convert
610cbaff81SAart Bik// CHECK-NEXT:      return
620d600002Sbixia1func.func @sparse_convert(%arg0: tensor<?xf32, #SparseVector64>) -> tensor<?xf32, #SparseVector32> {
630d600002Sbixia1  %0 = sparse_tensor.convert %arg0 : tensor<?xf32, #SparseVector64> to tensor<?xf32, #SparseVector32>
640d600002Sbixia1  return %0 : tensor<?xf32, #SparseVector32>
650d600002Sbixia1}
660d600002Sbixia1
67f248d0b2SPeiming Liu// CHECK-LABEL:   func.func @sparse_convert_permuted
68f248d0b2SPeiming Liu// CHECK:           sparse_tensor.foreach
69*ef100c22SPeiming Liu// CHECK:             tensor.insert
70f248d0b2SPeiming Liu// CHECK:           sparse_tensor.load
71f248d0b2SPeiming Liu// CHECK:           sparse_tensor.reorder_coo
72f248d0b2SPeiming Liu// CHECK:           sparse_tensor.foreach
73*ef100c22SPeiming Liu// CHECK:             tensor.insert
74f248d0b2SPeiming Liu// CHECK:           sparse_tensor.load
750cbaff81SAart Bik// CHECK:           return
7657416d87Sbixia1func.func @sparse_convert_permuted(%arg0: tensor<?x?x?xf32, #SortedCOO3D>) -> tensor<?x?x?xf32, #TsssPermuted> {
7757416d87Sbixia1  %0 = sparse_tensor.convert %arg0 : tensor<?x?x?xf32, #SortedCOO3D> to tensor<?x?x?xf32, #TsssPermuted>
7857416d87Sbixia1  return %0 : tensor<?x?x?xf32, #TsssPermuted>
7957416d87Sbixia1}
8033267f40SPeiming Liu
81f248d0b2SPeiming Liu// CHECK-LABEL:   func.func @sparse_convert_slice
82f248d0b2SPeiming Liu// CHECK:           sparse_tensor.foreach
83*ef100c22SPeiming Liu// CHECK:             tensor.insert
84f248d0b2SPeiming Liu// CHECK:           sparse_tensor.load
85f248d0b2SPeiming Liu// CHECK-NOT:       sparse_tensor.reorder_coo
860cbaff81SAart Bik// CHECK:           return
8733267f40SPeiming Liufunc.func @sparse_convert_slice(%arg0: tensor<2x13xi32, #COOSlice>) -> (tensor<2x13xi32, #SortedCOO2D>)  {
8833267f40SPeiming Liu  %0 = sparse_tensor.convert %arg0 : tensor<2x13xi32, #COOSlice> to tensor<2x13xi32, #SortedCOO2D>
8933267f40SPeiming Liu  return %0 : tensor<2x13xi32, #SortedCOO2D>
9033267f40SPeiming Liu}
91