Skip to content

Commit 4cb5a96

Browse files
[mlir][sparse] Migrate more tests to sparse_tensor.print (#84249)
Continuous efforts following #83946.
1 parent 6e692e7 commit 4cb5a96

20 files changed

+478
-560
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
1111
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
1212
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
13-
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
13+
// DEFINE: %{run_opts} = -e main -entry-point-result=void
1414
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
1515
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
1616
//
@@ -65,7 +65,7 @@ module {
6565
// and then calls the sparse scaling kernel with the sparse tensor
6666
// as input argument.
6767
//
68-
func.func @entry() {
68+
func.func @main() {
6969
%c0 = arith.constant 0 : index
7070
%f0 = arith.constant 0.0 : f32
7171

@@ -88,11 +88,16 @@ module {
8888

8989
// Print the resulting compacted values for verification.
9090
//
91-
// CHECK: ( 2, 2, 2, 4, 6, 8, 2, 10, 2, 2, 12, 2, 14, 2, 2, 16 )
91+
// CHECK: ---- Sparse Tensor ----
92+
// CHECK-NEXT: nse = 16
93+
// CHECK-NEXT: dim = ( 8, 8 )
94+
// CHECK-NEXT: lvl = ( 8, 8 )
95+
// CHECK-NEXT: pos[1] : ( 0, 3, 4, 5, 6, 8, 11, 14, 16
96+
// CHECK-NEXT: crd[1] : ( 0, 2, 7, 1, 2, 3, 1, 4, 1, 2, 5, 2, 6, 7, 2, 7
97+
// CHECK-NEXT: values : ( 2, 2, 2, 4, 6, 8, 2, 10, 2, 2, 12, 2, 14, 2, 2, 16
98+
// CHECK-NEXT: ----
9299
//
93-
%m = sparse_tensor.values %2 : tensor<8x8xf32, #CSR> to memref<?xf32>
94-
%v = vector.transfer_read %m[%c0], %f0: memref<?xf32>, vector<16xf32>
95-
vector.print %v : vector<16xf32>
100+
sparse_tensor.print %2 : tensor<8x8xf32, #CSR>
96101

97102
// Release the resources.
98103
bufferization.dealloc_tensor %1 : tensor<8x8xf32, #CSR>

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
1111
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
1212
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
13-
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
13+
// DEFINE: %{run_opts} = -e main -entry-point-result=void
1414
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
1515
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
1616
//
@@ -68,17 +68,7 @@ module @func_sparse.2 {
6868
return %1 : tensor<2x3x4xf64, #SparseMatrix>
6969
}
7070

71-
func.func @dump(%arg0: tensor<2x3x4xf64, #SparseMatrix>) {
72-
%d0 = arith.constant 0.0 : f64
73-
%c0 = arith.constant 0 : index
74-
%dm = sparse_tensor.convert %arg0 : tensor<2x3x4xf64, #SparseMatrix> to tensor<2x3x4xf64>
75-
%0 = vector.transfer_read %dm[%c0, %c0, %c0], %d0: tensor<2x3x4xf64>, vector<2x3x4xf64>
76-
vector.print %0 : vector<2x3x4xf64>
77-
bufferization.dealloc_tensor %dm : tensor<2x3x4xf64>
78-
return
79-
}
80-
81-
func.func public @entry() {
71+
func.func public @main() {
8272
%src = arith.constant dense<[
8373
[ [ 1.0, 2.0, 3.0, 4.0 ],
8474
[ 5.0, 6.0, 7.0, 8.0 ],
@@ -96,10 +86,34 @@ module @func_sparse.2 {
9686
%sm_t = call @condition(%t, %sm) : (i1, tensor<2x3x4xf64, #SparseMatrix>) -> tensor<2x3x4xf64, #SparseMatrix>
9787
%sm_f = call @condition(%f, %sm) : (i1, tensor<2x3x4xf64, #SparseMatrix>) -> tensor<2x3x4xf64, #SparseMatrix>
9888

99-
// CHECK: ( ( ( 0, 1, 2, 3 ), ( 4, 5, 6, 7 ), ( 8, 9, 10, 11 ) ), ( ( 12, 13, 14, 15 ), ( 16, 17, 18, 19 ), ( 20, 21, 22, 23 ) ) )
100-
// CHECK-NEXT: ( ( ( 2, 3, 4, 5 ), ( 6, 7, 8, 9 ), ( 10, 11, 12, 13 ) ), ( ( 14, 15, 16, 17 ), ( 18, 19, 20, 21 ), ( 22, 23, 24, 25 ) ) )
101-
call @dump(%sm_t) : (tensor<2x3x4xf64, #SparseMatrix>) -> ()
102-
call @dump(%sm_f) : (tensor<2x3x4xf64, #SparseMatrix>) -> ()
89+
//
90+
// CHECK: ---- Sparse Tensor ----
91+
// CHECK-NEXT: nse = 24
92+
// CHECK-NEXT: dim = ( 2, 3, 4 )
93+
// CHECK-NEXT: lvl = ( 2, 3, 4 )
94+
// CHECK-NEXT: pos[0] : ( 0, 2
95+
// CHECK-NEXT: crd[0] : ( 0, 1
96+
// CHECK-NEXT: pos[1] : ( 0, 3, 6
97+
// CHECK-NEXT: crd[1] : ( 0, 1, 2, 0, 1, 2
98+
// CHECK-NEXT: pos[2] : ( 0, 4, 8, 12, 16, 20, 24
99+
// CHECK-NEXT: crd[2] : ( 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3
100+
// CHECK-NEXT: values : ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23
101+
// CHECK-NEXT: ----
102+
// CHECK: ---- Sparse Tensor ----
103+
// CHECK-NEXT: nse = 24
104+
// CHECK-NEXT: dim = ( 2, 3, 4 )
105+
// CHECK-NEXT: lvl = ( 2, 3, 4 )
106+
// CHECK-NEXT: pos[0] : ( 0, 2
107+
// CHECK-NEXT: crd[0] : ( 0, 1
108+
// CHECK-NEXT: pos[1] : ( 0, 3, 6
109+
// CHECK-NEXT: crd[1] : ( 0, 1, 2, 0, 1, 2
110+
// CHECK-NEXT: pos[2] : ( 0, 4, 8, 12, 16, 20, 24
111+
// CHECK-NEXT: crd[2] : ( 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3
112+
// CHECK-NEXT: values : ( 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25
113+
// CHECK-NEXT: ----
114+
//
115+
sparse_tensor.print %sm_t : tensor<2x3x4xf64, #SparseMatrix>
116+
sparse_tensor.print %sm_f : tensor<2x3x4xf64, #SparseMatrix>
103117

104118
bufferization.dealloc_tensor %sm : tensor<2x3x4xf64, #SparseMatrix>
105119
bufferization.dealloc_tensor %sm_t : tensor<2x3x4xf64, #SparseMatrix>

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

Lines changed: 38 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
1111
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
1212
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
13-
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
13+
// DEFINE: %{run_opts} = -e main -entry-point-result=void
1414
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
1515
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
1616
//
@@ -97,39 +97,8 @@ module {
9797
return %0 : tensor<?x?xf64, #CSR>
9898
}
9999

100-
// Dumps a sparse vector of type f64.
101-
func.func @dump_vec(%arg0: tensor<?xf64, #SparseVector>) {
102-
// Dump the values array to verify only sparse contents are stored.
103-
%c0 = arith.constant 0 : index
104-
%d0 = arith.constant 0.0 : f64
105-
%0 = sparse_tensor.values %arg0 : tensor<?xf64, #SparseVector> to memref<?xf64>
106-
%1 = vector.transfer_read %0[%c0], %d0: memref<?xf64>, vector<8xf64>
107-
vector.print %1 : vector<8xf64>
108-
// Dump the dense vector to verify structure is correct.
109-
%dv = sparse_tensor.convert %arg0 : tensor<?xf64, #SparseVector> to tensor<?xf64>
110-
%2 = vector.transfer_read %dv[%c0], %d0: tensor<?xf64>, vector<16xf64>
111-
vector.print %2 : vector<16xf64>
112-
bufferization.dealloc_tensor %dv : tensor<?xf64>
113-
return
114-
}
115-
116-
// Dump a sparse matrix.
117-
func.func @dump_mat(%arg0: tensor<?x?xf64, #CSR>) {
118-
// Dump the values array to verify only sparse contents are stored.
119-
%c0 = arith.constant 0 : index
120-
%d0 = arith.constant 0.0 : f64
121-
%0 = sparse_tensor.values %arg0 : tensor<?x?xf64, #CSR> to memref<?xf64>
122-
%1 = vector.transfer_read %0[%c0], %d0: memref<?xf64>, vector<16xf64>
123-
vector.print %1 : vector<16xf64>
124-
%dm = sparse_tensor.convert %arg0 : tensor<?x?xf64, #CSR> to tensor<?x?xf64>
125-
%2 = vector.transfer_read %dm[%c0, %c0], %d0: tensor<?x?xf64>, vector<5x5xf64>
126-
vector.print %2 : vector<5x5xf64>
127-
bufferization.dealloc_tensor %dm : tensor<?x?xf64>
128-
return
129-
}
130-
131100
// Driver method to call and verify vector kernels.
132-
func.func @entry() {
101+
func.func @main() {
133102
%c0 = arith.constant 0 : index
134103

135104
// Setup sparse matrices.
@@ -151,19 +120,43 @@ module {
151120
//
152121
// Verify the results.
153122
//
154-
// CHECK: ( 1, 2, -4, 0, 5, 0, 0, 0 )
155-
// CHECK-NEXT: ( 0, 1, 0, 2, 0, -4, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0 )
156-
// CHECK-NEXT: ( 1, 2, 3, 4, 5, 6, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
157-
// CHECK-NEXT: ( ( 0, 0, 0, 1, 0 ), ( 0, 0, 0, 0, 2 ), ( 0, 3, 0, 4, 0 ), ( 0, 0, 0, 5, 6 ), ( 0, 0, 7, 0, 0 ) )
158-
// CHECK-NEXT: ( 1, 2, 5, 0, 0, 0, 0, 0 )
159-
// CHECK-NEXT: ( 0, 1, 0, 2, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0 )
160-
// CHECK-NEXT: ( 1, 2, 4, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 )
161-
// CHECK-NEXT: ( ( 0, 0, 0, 1, 0 ), ( 0, 0, 0, 0, 2 ), ( 0, 0, 0, 4, 0 ), ( 0, 0, 0, 0, 6 ), ( 0, 0, 0, 0, 0 ) )
123+
// CHECK: ---- Sparse Tensor ----
124+
// CHECK-NEXT: nse = 5
125+
// CHECK-NEXT: dim = ( 10 )
126+
// CHECK-NEXT: lvl = ( 10 )
127+
// CHECK-NEXT: pos[0] : ( 0, 5
128+
// CHECK-NEXT: crd[0] : ( 1, 3, 5, 7, 9
129+
// CHECK-NEXT: values : ( 1, 2, -4, 0, 5
130+
// CHECK-NEXT: ----
131+
// CHECK: ---- Sparse Tensor ----
132+
// CHECK-NEXT: nse = 7
133+
// CHECK-NEXT: dim = ( 5, 5 )
134+
// CHECK-NEXT: lvl = ( 5, 5 )
135+
// CHECK-NEXT: pos[1] : ( 0, 1, 2, 4, 6, 7
136+
// CHECK-NEXT: crd[1] : ( 3, 4, 1, 3, 3, 4, 2
137+
// CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7
138+
// CHECK-NEXT: ----
139+
// CHECK: ---- Sparse Tensor ----
140+
// CHECK-NEXT: nse = 3
141+
// CHECK-NEXT: dim = ( 10 )
142+
// CHECK-NEXT: lvl = ( 10 )
143+
// CHECK-NEXT: pos[0] : ( 0, 3
144+
// CHECK-NEXT: crd[0] : ( 1, 3, 9
145+
// CHECK-NEXT: values : ( 1, 2, 5
146+
// CHECK-NEXT: ----
147+
// CHECK: ---- Sparse Tensor ----
148+
// CHECK-NEXT: nse = 4
149+
// CHECK-NEXT: dim = ( 5, 5 )
150+
// CHECK-NEXT: lvl = ( 5, 5 )
151+
// CHECK-NEXT: pos[1] : ( 0, 1, 2, 3, 4, 4
152+
// CHECK-NEXT: crd[1] : ( 3, 4, 3, 4
153+
// CHECK-NEXT: values : ( 1, 2, 4, 6
154+
// CHECK-NEXT: ----
162155
//
163-
call @dump_vec(%sv1) : (tensor<?xf64, #SparseVector>) -> ()
164-
call @dump_mat(%sm1) : (tensor<?x?xf64, #CSR>) -> ()
165-
call @dump_vec(%1) : (tensor<?xf64, #SparseVector>) -> ()
166-
call @dump_mat(%2) : (tensor<?x?xf64, #CSR>) -> ()
156+
sparse_tensor.print %sv1 : tensor<?xf64, #SparseVector>
157+
sparse_tensor.print %sm1 : tensor<?x?xf64, #CSR>
158+
sparse_tensor.print %1 : tensor<?xf64, #SparseVector>
159+
sparse_tensor.print %2 : tensor<?x?xf64, #CSR>
167160

168161
// Release the resources.
169162
bufferization.dealloc_tensor %sv1 : tensor<?xf64, #SparseVector>

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
1111
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
1212
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
13-
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
13+
// DEFINE: %{run_opts} = -e main -entry-point-result=void
1414
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
1515
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
1616
//
@@ -60,7 +60,7 @@ module {
6060
}
6161

6262
// Driver method to call and verify vector kernels.
63-
func.func @entry() {
63+
func.func @main() {
6464
%c0 = arith.constant 0 : index
6565
%f0 = arith.constant 0.0 : f64
6666

@@ -86,20 +86,24 @@ module {
8686
tensor<5x5xf64, #DCSR>) -> tensor<5x5xf64, #DCSR>
8787

8888

89-
// CHECK: ( ( 0.1, 1.1, 0, 0, 0 ),
90-
// CHECK-SAME: ( 0, 1.1, 2.2, 0, 0 ),
91-
// CHECK-SAME: ( 0, 0, 2.1, 3.3, 0 ),
92-
// CHECK-SAME: ( 0, 0, 0, 3.1, 4.4 ),
93-
// CHECK-SAME: ( 0, 0, 0, 0, 4.1 ) )
94-
%r = sparse_tensor.convert %1 : tensor<5x5xf64, #DCSR> to tensor<5x5xf64>
95-
%v2 = vector.transfer_read %r[%c0, %c0], %f0 : tensor<5x5xf64>, vector<5x5xf64>
96-
vector.print %v2 : vector<5x5xf64>
89+
//
90+
// CHECK: ---- Sparse Tensor ----
91+
// CHECK-NEXT: nse = 9
92+
// CHECK-NEXT: dim = ( 5, 5 )
93+
// CHECK-NEXT: lvl = ( 5, 5 )
94+
// CHECK-NEXT: pos[0] : ( 0, 5
95+
// CHECK-NEXT: crd[0] : ( 0, 1, 2, 3, 4
96+
// CHECK-NEXT: pos[1] : ( 0, 2, 4, 6, 8, 9
97+
// CHECK-NEXT: crd[1] : ( 0, 1, 1, 2, 2, 3, 3, 4, 4
98+
// CHECK-NEXT: values : ( 0.1, 1.1, 1.1, 2.2, 2.1, 3.3, 3.1, 4.4, 4.1
99+
// CHECK-NEXT: ----
100+
//
101+
sparse_tensor.print %1 : tensor<5x5xf64, #DCSR>
97102

98103
// Release the resources.
99104
bufferization.dealloc_tensor %sl: tensor<5x5xf64, #DCSR>
100105
bufferization.dealloc_tensor %sr: tensor<5x5xf64, #DCSR>
101106
bufferization.dealloc_tensor %1: tensor<5x5xf64, #DCSR>
102-
bufferization.dealloc_tensor %r : tensor<5x5xf64>
103107

104108
return
105109
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
1111
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
1212
// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
13-
// DEFINE: %{run_opts} = -e entry -entry-point-result=void
13+
// DEFINE: %{run_opts} = -e main -entry-point-result=void
1414
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
1515
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
1616
//
@@ -79,7 +79,7 @@ module {
7979
}
8080

8181
// Driver method to call and verify sign kernel.
82-
func.func @entry() {
82+
func.func @main() {
8383
%c0 = arith.constant 0 : index
8484
%du = arith.constant 0.0 : f64
8585

@@ -110,11 +110,16 @@ module {
110110
//
111111
// Verify the results.
112112
//
113-
// CHECK: ( -1, 1, -1, 1, 1, -1, nan, -nan, 1, -1, -0, 0, 0 )
113+
// CHECK: ---- Sparse Tensor ----
114+
// CHECK-NEXT: nse = 12
115+
// CHECK-NEXT: dim = ( 32 )
116+
// CHECK-NEXT: lvl = ( 32 )
117+
// CHECK-NEXT: pos[0] : ( 0, 12
118+
// CHECK-NEXT: crd[0] : ( 0, 3, 5, 11, 13, 17, 18, 20, 21, 28, 29, 31
119+
// CHECK-NEXT: values : ( -1, 1, -1, 1, 1, -1, nan, -nan, 1, -1, -0, 0
120+
// CHECK-NEXT: ----
114121
//
115-
%1 = sparse_tensor.values %0 : tensor<?xf64, #SparseVector> to memref<?xf64>
116-
%2 = vector.transfer_read %1[%c0], %du: memref<?xf64>, vector<13xf64>
117-
vector.print %2 : vector<13xf64>
122+
sparse_tensor.print %0 : tensor<?xf64, #SparseVector>
118123

119124
// Release the resources.
120125
bufferization.dealloc_tensor %sv1 : tensor<?xf64, #SparseVector>

0 commit comments

Comments
 (0)