Skip to content

Commit a8166d8

Browse files
committed
[mlir][sparse] move sparse2sparse conversion to own test file
Rationale: We were running *all* conversion tests two times, just to check the difference of one indidivual test in that file. By splitting that test out, we have a much more focused testing setup. Reviewed By: bixia Differential Revision: https://reviews.llvm.org/D132757
1 parent 59d246e commit a8166d8

File tree

2 files changed

+52
-23
lines changed

2 files changed

+52
-23
lines changed

mlir/test/Dialect/SparseTensor/conversion.mlir

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
// First use with `kViaCOO` for sparse2sparse conversion (the old way).
2-
// RUN: mlir-opt %s --sparse-tensor-conversion="s2s-strategy=1" \
3-
// RUN: --canonicalize --cse | FileCheck %s
4-
//
5-
// Now again with `kAuto` (the new default).
6-
// RUN: mlir-opt %s --sparse-tensor-conversion="s2s-strategy=0" \
7-
// RUN: --canonicalize --cse | FileCheck %s -check-prefix=CHECKAUTO
1+
// RUN: mlir-opt %s --sparse-tensor-conversion --canonicalize --cse | FileCheck %s
82

93
#SparseVector = #sparse_tensor.encoding<{
104
dimLevelType = ["compressed"]
@@ -233,29 +227,15 @@ func.func @sparse_convert_complex(%arg0: tensor<100xcomplex<f64>>) -> tensor<100
233227

234228
// CHECK-LABEL: func @sparse_convert_1d_ss(
235229
// CHECK-SAME: %[[A:.*]]: !llvm.ptr<i8>)
236-
// CHECK-DAG: %[[ToCOO:.*]] = arith.constant 5 : i32
237-
// CHECK-DAG: %[[FromCOO:.*]] = arith.constant 2 : i32
230+
// CHECK-DAG: %[[SparseToSparse:.*]] = arith.constant 3 : i32
238231
// CHECK-DAG: %[[P:.*]] = memref.alloca() : memref<1xi8>
239232
// CHECK-DAG: %[[Q:.*]] = memref.alloca() : memref<1xindex>
240233
// CHECK-DAG: %[[R:.*]] = memref.alloca() : memref<1xindex>
241234
// CHECK-DAG: %[[X:.*]] = memref.cast %[[P]] : memref<1xi8> to memref<?xi8>
242235
// CHECK-DAG: %[[Y:.*]] = memref.cast %[[Q]] : memref<1xindex> to memref<?xindex>
243236
// CHECK-DAG: %[[Z:.*]] = memref.cast %[[R]] : memref<1xindex> to memref<?xindex>
244-
// CHECK: %[[C:.*]] = call @newSparseTensor(%[[X]], %[[Y]], %[[Z]], %{{.*}}, %{{.*}}, %{{.*}}, %[[ToCOO]], %[[A]])
245-
// CHECK: %[[T:.*]] = call @newSparseTensor(%[[X]], %[[Y]], %[[Z]], %{{.*}}, %{{.*}}, %{{.*}}, %[[FromCOO]], %[[C]])
246-
// CHECK: call @delSparseTensorCOOF32(%[[C]])
237+
// CHECK: %[[T:.*]] = call @newSparseTensor(%[[X]], %[[Y]], %[[Z]], %{{.*}}, %{{.*}}, %{{.*}}, %[[SparseToSparse]], %[[A]])
247238
// CHECK: return %[[T]] : !llvm.ptr<i8>
248-
// CHECKAUTO-LABEL: func @sparse_convert_1d_ss(
249-
// CHECKAUTO-SAME: %[[A:.*]]: !llvm.ptr<i8>)
250-
// CHECKAUTO-DAG: %[[SparseToSparse:.*]] = arith.constant 3 : i32
251-
// CHECKAUTO-DAG: %[[P:.*]] = memref.alloca() : memref<1xi8>
252-
// CHECKAUTO-DAG: %[[Q:.*]] = memref.alloca() : memref<1xindex>
253-
// CHECKAUTO-DAG: %[[R:.*]] = memref.alloca() : memref<1xindex>
254-
// CHECKAUTO-DAG: %[[X:.*]] = memref.cast %[[P]] : memref<1xi8> to memref<?xi8>
255-
// CHECKAUTO-DAG: %[[Y:.*]] = memref.cast %[[Q]] : memref<1xindex> to memref<?xindex>
256-
// CHECKAUTO-DAG: %[[Z:.*]] = memref.cast %[[R]] : memref<1xindex> to memref<?xindex>
257-
// CHECKAUTO: %[[T:.*]] = call @newSparseTensor(%[[X]], %[[Y]], %[[Z]], %{{.*}}, %{{.*}}, %{{.*}}, %[[SparseToSparse]], %[[A]])
258-
// CHECKAUTO: return %[[T]] : !llvm.ptr<i8>
259239
func.func @sparse_convert_1d_ss(%arg0: tensor<?xf32, #SparseVector64>) -> tensor<?xf32, #SparseVector32> {
260240
%0 = sparse_tensor.convert %arg0 : tensor<?xf32, #SparseVector64> to tensor<?xf32, #SparseVector32>
261241
return %0 : tensor<?xf32, #SparseVector32>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// First use with `kViaCOO` for sparse2sparse conversion (the old way).
2+
// RUN: mlir-opt %s --sparse-tensor-conversion="s2s-strategy=1" \
3+
// RUN: --canonicalize --cse | FileCheck %s -check-prefix=CHECK-COO
4+
//
5+
// Now again with `kAuto` (the new default).
6+
// RUN: mlir-opt %s --sparse-tensor-conversion="s2s-strategy=0" \
7+
// RUN: --canonicalize --cse | FileCheck %s -check-prefix=CHECK-AUTO
8+
9+
#SparseVector64 = #sparse_tensor.encoding<{
10+
dimLevelType = ["compressed"],
11+
pointerBitWidth = 64,
12+
indexBitWidth = 64
13+
}>
14+
15+
#SparseVector32 = #sparse_tensor.encoding<{
16+
dimLevelType = ["compressed"],
17+
pointerBitWidth = 32,
18+
indexBitWidth = 32
19+
}>
20+
21+
// CHECK-COO-LABEL: func @sparse_convert(
22+
// CHECK-COO-SAME: %[[A:.*]]: !llvm.ptr<i8>)
23+
// CHECK-COO-DAG: %[[ToCOO:.*]] = arith.constant 5 : i32
24+
// CHECK-COO-DAG: %[[FromCOO:.*]] = arith.constant 2 : i32
25+
// CHECK-COO-DAG: %[[P:.*]] = memref.alloca() : memref<1xi8>
26+
// CHECK-COO-DAG: %[[Q:.*]] = memref.alloca() : memref<1xindex>
27+
// CHECK-COO-DAG: %[[R:.*]] = memref.alloca() : memref<1xindex>
28+
// CHECK-COO-DAG: %[[X:.*]] = memref.cast %[[P]] : memref<1xi8> to memref<?xi8>
29+
// CHECK-COO-DAG: %[[Y:.*]] = memref.cast %[[Q]] : memref<1xindex> to memref<?xindex>
30+
// CHECK-COO-DAG: %[[Z:.*]] = memref.cast %[[R]] : memref<1xindex> to memref<?xindex>
31+
// CHECK-COO: %[[C:.*]] = call @newSparseTensor(%[[X]], %[[Y]], %[[Z]], %{{.*}}, %{{.*}}, %{{.*}}, %[[ToCOO]], %[[A]])
32+
// CHECK-COO: %[[T:.*]] = call @newSparseTensor(%[[X]], %[[Y]], %[[Z]], %{{.*}}, %{{.*}}, %{{.*}}, %[[FromCOO]], %[[C]])
33+
// CHECK-COO: call @delSparseTensorCOOF32(%[[C]])
34+
// CHECK-COO: return %[[T]] : !llvm.ptr<i8>
35+
// CHECK-AUTO-LABEL: func @sparse_convert(
36+
// CHECK-AUTO-SAME: %[[A:.*]]: !llvm.ptr<i8>)
37+
// CHECK-AUTO-DAG: %[[SparseToSparse:.*]] = arith.constant 3 : i32
38+
// CHECK-AUTO-DAG: %[[P:.*]] = memref.alloca() : memref<1xi8>
39+
// CHECK-AUTO-DAG: %[[Q:.*]] = memref.alloca() : memref<1xindex>
40+
// CHECK-AUTO-DAG: %[[R:.*]] = memref.alloca() : memref<1xindex>
41+
// CHECK-AUTO-DAG: %[[X:.*]] = memref.cast %[[P]] : memref<1xi8> to memref<?xi8>
42+
// CHECK-AUTO-DAG: %[[Y:.*]] = memref.cast %[[Q]] : memref<1xindex> to memref<?xindex>
43+
// CHECK-AUTO-DAG: %[[Z:.*]] = memref.cast %[[R]] : memref<1xindex> to memref<?xindex>
44+
// CHECK-AUTO: %[[T:.*]] = call @newSparseTensor(%[[X]], %[[Y]], %[[Z]], %{{.*}}, %{{.*}}, %{{.*}}, %[[SparseToSparse]], %[[A]])
45+
// CHECK-AUTO: return %[[T]] : !llvm.ptr<i8>
46+
func.func @sparse_convert(%arg0: tensor<?xf32, #SparseVector64>) -> tensor<?xf32, #SparseVector32> {
47+
%0 = sparse_tensor.convert %arg0 : tensor<?xf32, #SparseVector64> to tensor<?xf32, #SparseVector32>
48+
return %0 : tensor<?xf32, #SparseVector32>
49+
}

0 commit comments

Comments
 (0)