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//
3232}>
3333
3434#SortedCOO = #sparse_tensor.encoding <{
35- map = (d0 , d1 ) -> (d0 : compressed(nonunique), d1 : singleton)
35+ map = (d0 , d1 ) -> (d0 : compressed(nonunique), d1 : singleton(soa) )
3636}>
3737
3838#CSR = #sparse_tensor.encoding <{
4848}>
4949
5050module {
51-
52- func.func @dump_dense (%arg0: tensor <4 x3 xf64 , #Dense >) {
53- %c0 = arith.constant 0 : index
54- %fu = arith.constant 99.0 : f64
55- %v = sparse_tensor.values %arg0 : tensor <4 x3 xf64 , #Dense > to memref <?xf64 >
56- %vv = vector.transfer_read %v [%c0 ], %fu: memref <?xf64 >, vector <12 xf64 >
57- vector.print %vv : vector <12 xf64 >
58- return
59- }
60-
61- func.func @dump_coo (%arg0: tensor <4 x3 xf64 , #SortedCOO >) {
62- %c0 = arith.constant 0 : index
63- %cu = arith.constant -1 : index
64- %fu = arith.constant 99.0 : f64
65- %p0 = sparse_tensor.positions %arg0 { level = 0 : index } : tensor <4 x3 xf64 , #SortedCOO > to memref <?xindex >
66- %i0 = sparse_tensor.coordinates %arg0 { level = 0 : index } : tensor <4 x3 xf64 , #SortedCOO > to memref <?xindex , strided <[?], offset : ?>>
67- %i1 = sparse_tensor.coordinates %arg0 { level = 1 : index } : tensor <4 x3 xf64 , #SortedCOO > to memref <?xindex , strided <[?], offset : ?>>
68- %v = sparse_tensor.values %arg0 : tensor <4 x3 xf64 , #SortedCOO > to memref <?xf64 >
69- %vp0 = vector.transfer_read %p0 [%c0 ], %cu: memref <?xindex >, vector <2 xindex >
70- vector.print %vp0 : vector <2 xindex >
71- %vi0 = vector.transfer_read %i0 [%c0 ], %cu: memref <?xindex , strided <[?], offset : ?>>, vector <4 xindex >
72- vector.print %vi0 : vector <4 xindex >
73- %vi1 = vector.transfer_read %i1 [%c0 ], %cu: memref <?xindex , strided <[?], offset : ?>>, vector <4 xindex >
74- vector.print %vi1 : vector <4 xindex >
75- %vv = vector.transfer_read %v [%c0 ], %fu: memref <?xf64 >, vector <4 xf64 >
76- vector.print %vv : vector <4 xf64 >
77- return
78- }
79-
80- func.func @dump_csr (%arg0: tensor <4 x3 xf64 , #CSR >) {
81- %c0 = arith.constant 0 : index
82- %cu = arith.constant -1 : index
83- %fu = arith.constant 99.0 : f64
84- %p1 = sparse_tensor.positions %arg0 { level = 1 : index } : tensor <4 x3 xf64 , #CSR > to memref <?xindex >
85- %i1 = sparse_tensor.coordinates %arg0 { level = 1 : index } : tensor <4 x3 xf64 , #CSR > to memref <?xindex >
86- %v = sparse_tensor.values %arg0 : tensor <4 x3 xf64 , #CSR > to memref <?xf64 >
87- %vp1 = vector.transfer_read %p1 [%c0 ], %cu: memref <?xindex >, vector <5 xindex >
88- vector.print %vp1 : vector <5 xindex >
89- %vi1 = vector.transfer_read %i1 [%c0 ], %cu: memref <?xindex >, vector <4 xindex >
90- vector.print %vi1 : vector <4 xindex >
91- %vv = vector.transfer_read %v [%c0 ], %fu: memref <?xf64 >, vector <4 xf64 >
92- vector.print %vv : vector <4 xf64 >
93- return
94- }
95-
96- func.func @dump_dcsr (%arg0: tensor <4 x3 xf64 , #DCSR >) {
97- %c0 = arith.constant 0 : index
98- %cu = arith.constant -1 : index
99- %fu = arith.constant 99.0 : f64
100- %p0 = sparse_tensor.positions %arg0 { level = 0 : index } : tensor <4 x3 xf64 , #DCSR > to memref <?xindex >
101- %i0 = sparse_tensor.coordinates %arg0 { level = 0 : index } : tensor <4 x3 xf64 , #DCSR > to memref <?xindex >
102- %p1 = sparse_tensor.positions %arg0 { level = 1 : index } : tensor <4 x3 xf64 , #DCSR > to memref <?xindex >
103- %i1 = sparse_tensor.coordinates %arg0 { level = 1 : index } : tensor <4 x3 xf64 , #DCSR > to memref <?xindex >
104- %v = sparse_tensor.values %arg0 : tensor <4 x3 xf64 , #DCSR > to memref <?xf64 >
105- %vp0 = vector.transfer_read %p0 [%c0 ], %cu: memref <?xindex >, vector <2 xindex >
106- vector.print %vp0 : vector <2 xindex >
107- %vi0 = vector.transfer_read %i0 [%c0 ], %cu: memref <?xindex >, vector <3 xindex >
108- vector.print %vi0 : vector <3 xindex >
109- %vp1 = vector.transfer_read %p1 [%c0 ], %cu: memref <?xindex >, vector <4 xindex >
110- vector.print %vp1 : vector <4 xindex >
111- %vi1 = vector.transfer_read %i1 [%c0 ], %cu: memref <?xindex >, vector <4 xindex >
112- vector.print %vi1 : vector <4 xindex >
113- %vv = vector.transfer_read %v [%c0 ], %fu: memref <?xf64 >, vector <4 xf64 >
114- vector.print %vv : vector <4 xf64 >
115- return
116- }
117-
118- func.func @dump_row (%arg0: tensor <4 x3 xf64 , #Row >) {
119- %c0 = arith.constant 0 : index
120- %cu = arith.constant -1 : index
121- %fu = arith.constant 99.0 : f64
122- %p0 = sparse_tensor.positions %arg0 { level = 0 : index } : tensor <4 x3 xf64 , #Row > to memref <?xindex >
123- %i0 = sparse_tensor.coordinates %arg0 { level = 0 : index } : tensor <4 x3 xf64 , #Row > to memref <?xindex >
124- %v = sparse_tensor.values %arg0 : tensor <4 x3 xf64 , #Row > to memref <?xf64 >
125- %vp0 = vector.transfer_read %p0 [%c0 ], %cu: memref <?xindex >, vector <2 xindex >
126- vector.print %vp0 : vector <2 xindex >
127- %vi0 = vector.transfer_read %i0 [%c0 ], %cu: memref <?xindex >, vector <3 xindex >
128- vector.print %vi0 : vector <3 xindex >
129- %vv = vector.transfer_read %v [%c0 ], %fu: memref <?xf64 >, vector <9 xf64 >
130- vector.print %vv : vector <9 xf64 >
131- return
132- }
133-
13451 //
13552 // Main driver. We test the contents of various sparse tensor
13653 // schemes when they are still empty and after a few insertions.
13754 //
138- func.func @entry () {
55+ func.func @main () {
13956 %c0 = arith.constant 0 : index
14057 %c2 = arith.constant 2 : index
14158 %c3 = arith.constant 3 : index
@@ -147,98 +64,103 @@ module {
14764 //
14865 // Dense case.
14966 //
150- // CHECK: ( 1, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 4 )
67+ // CHECK: ---- Sparse Tensor ----
68+ // CHECK-NEXT: nse = 12
69+ // CHECK-NEXT: dim = ( 4, 3 )
70+ // CHECK-NEXT: lvl = ( 4, 3 )
71+ // CHECK-NEXT: values : ( 1, 0, 0, 0, 0, 0, 0, 0, 2, 3, 0, 4,
72+ // CHECK-NEXT: ----
15173 //
15274 %densea = tensor.empty () : tensor <4 x3 xf64 , #Dense >
15375 %dense1 = sparse_tensor.insert %f1 into %densea [%c0 , %c0 ] : tensor <4 x3 xf64 , #Dense >
15476 %dense2 = sparse_tensor.insert %f2 into %dense1 [%c2 , %c2 ] : tensor <4 x3 xf64 , #Dense >
15577 %dense3 = sparse_tensor.insert %f3 into %dense2 [%c3 , %c0 ] : tensor <4 x3 xf64 , #Dense >
15678 %dense4 = sparse_tensor.insert %f4 into %dense3 [%c3 , %c2 ] : tensor <4 x3 xf64 , #Dense >
15779 %densem = sparse_tensor.load %dense4 hasInserts : tensor <4 x3 xf64 , #Dense >
158- call @dump_dense ( %densem ) : ( tensor <4 x3 xf64 , #Dense >) -> ()
80+ sparse_tensor.print %densem : tensor <4 x3 xf64 , #Dense >
15981
16082 //
16183 // COO case.
16284 //
163- // CHECK-NEXT: ( 0, 4 )
164- // CHECK-NEXT: ( 0, 2, 3, 3 )
165- // CHECK-NEXT: ( 0, 2, 0, 2 )
166- // CHECK-NEXT: ( 1, 2, 3, 4 )
85+ // CHECK-NEXT: ---- Sparse Tensor ----
86+ // CHECK-NEXT: nse = 4
87+ // CHECK-NEXT: dim = ( 4, 3 )
88+ // CHECK-NEXT: lvl = ( 4, 3 )
89+ // CHECK-NEXT: pos[0] : ( 0, 4,
90+ // CHECK-NEXT: crd[0] : ( 0, 2, 3, 3,
91+ // CHECK-NEXT: crd[1] : ( 0, 2, 0, 2,
92+ // CHECK-NEXT: values : ( 1, 2, 3, 4,
93+ // CHECK-NEXT: ----
16794 //
16895 %cooa = tensor.empty () : tensor <4 x3 xf64 , #SortedCOO >
16996 %coo1 = sparse_tensor.insert %f1 into %cooa [%c0 , %c0 ] : tensor <4 x3 xf64 , #SortedCOO >
17097 %coo2 = sparse_tensor.insert %f2 into %coo1 [%c2 , %c2 ] : tensor <4 x3 xf64 , #SortedCOO >
17198 %coo3 = sparse_tensor.insert %f3 into %coo2 [%c3 , %c0 ] : tensor <4 x3 xf64 , #SortedCOO >
17299 %coo4 = sparse_tensor.insert %f4 into %coo3 [%c3 , %c2 ] : tensor <4 x3 xf64 , #SortedCOO >
173100 %coom = sparse_tensor.load %coo4 hasInserts : tensor <4 x3 xf64 , #SortedCOO >
174- call @dump_coo ( %coom ) : ( tensor <4 x3 xf64 , #SortedCOO >) -> ()
101+ sparse_tensor.print %coom : tensor <4 x3 xf64 , #SortedCOO >
175102
176103 //
177104 // CSR case.
178105 //
179- // CHECK-NEXT: ( 0, 1, 1, 2, 4 )
180- // CHECK-NEXT: ( 0, 2, 0, 2 )
181- // CHECK-NEXT: ( 1, 2, 3, 4 )
106+ // CHECK-NEXT: ---- Sparse Tensor ----
107+ // CHECK-NEXT: nse = 4
108+ // CHECK-NEXT: dim = ( 4, 3 )
109+ // CHECK-NEXT: lvl = ( 4, 3 )
110+ // CHECK-NEXT: pos[1] : ( 0, 1, 1, 2, 4,
111+ // CHECK-NEXT: crd[1] : ( 0, 2, 0, 2,
112+ // CHECK-NEXT: values : ( 1, 2, 3, 4,
113+ // CHECK-NEXT: ----
182114 //
183115 %csra = tensor.empty () : tensor <4 x3 xf64 , #CSR >
184116 %csr1 = sparse_tensor.insert %f1 into %csra [%c0 , %c0 ] : tensor <4 x3 xf64 , #CSR >
185117 %csr2 = sparse_tensor.insert %f2 into %csr1 [%c2 , %c2 ] : tensor <4 x3 xf64 , #CSR >
186118 %csr3 = sparse_tensor.insert %f3 into %csr2 [%c3 , %c0 ] : tensor <4 x3 xf64 , #CSR >
187119 %csr4 = sparse_tensor.insert %f4 into %csr3 [%c3 , %c2 ] : tensor <4 x3 xf64 , #CSR >
188120 %csrm = sparse_tensor.load %csr4 hasInserts : tensor <4 x3 xf64 , #CSR >
189- call @dump_csr ( %csrm ) : ( tensor <4 x3 xf64 , #CSR >) -> ()
121+ sparse_tensor.print %csrm : tensor <4 x3 xf64 , #CSR >
190122
191123 //
192124 // DCSR case.
193125 //
194- // CHECK-NEXT: ( 0, 3 )
195- // CHECK-NEXT: ( 0, 2, 3 )
196- // CHECK-NEXT: ( 0, 1, 2, 4 )
197- // CHECK-NEXT: ( 0, 2, 0, 2 )
198- // CHECK-NEXT: ( 1, 2, 3, 4 )
126+ // CHECK-NEXT: ---- Sparse Tensor ----
127+ // CHECK-NEXT: nse = 4
128+ // CHECK-NEXT: dim = ( 4, 3 )
129+ // CHECK-NEXT: lvl = ( 4, 3 )
130+ // CHECK-NEXT: pos[0] : ( 0, 3,
131+ // CHECK-NEXT: crd[0] : ( 0, 2, 3,
132+ // CHECK-NEXT: pos[1] : ( 0, 1, 2, 4,
133+ // CHECK-NEXT: crd[1] : ( 0, 2, 0, 2,
134+ // CHECK-NEXT: values : ( 1, 2, 3, 4,
135+ // CHECK-NEXT: ----
199136 //
200137 %dcsra = tensor.empty () : tensor <4 x3 xf64 , #DCSR >
201138 %dcsr1 = sparse_tensor.insert %f1 into %dcsra [%c0 , %c0 ] : tensor <4 x3 xf64 , #DCSR >
202139 %dcsr2 = sparse_tensor.insert %f2 into %dcsr1 [%c2 , %c2 ] : tensor <4 x3 xf64 , #DCSR >
203140 %dcsr3 = sparse_tensor.insert %f3 into %dcsr2 [%c3 , %c0 ] : tensor <4 x3 xf64 , #DCSR >
204141 %dcsr4 = sparse_tensor.insert %f4 into %dcsr3 [%c3 , %c2 ] : tensor <4 x3 xf64 , #DCSR >
205142 %dcsrm = sparse_tensor.load %dcsr4 hasInserts : tensor <4 x3 xf64 , #DCSR >
206- call @dump_dcsr ( %dcsrm ) : ( tensor <4 x3 xf64 , #DCSR >) -> ()
143+ sparse_tensor.print %dcsrm : tensor <4 x3 xf64 , #DCSR >
207144
208145 //
209146 // Row case.
210147 //
211- // CHECK-NEXT: ( 0, 3 )
212- // CHECK-NEXT: ( 0, 2, 3 )
213- // CHECK-NEXT: ( 1, 0, 0, 0, 0, 2, 3, 0, 4 )
148+ // CHECK-NEXT: ---- Sparse Tensor ----
149+ // CHECK-NEXT: nse = 9
150+ // CHECK-NEXT: dim = ( 4, 3 )
151+ // CHECK-NEXT: lvl = ( 4, 3 )
152+ // CHECK-NEXT: pos[0] : ( 0, 3,
153+ // CHECK-NEXT: crd[0] : ( 0, 2, 3,
154+ // CHECK-NEXT: values : ( 1, 0, 0, 0, 0, 2, 3, 0, 4,
155+ // CHECK-NEXT: ----
214156 //
215157 %rowa = tensor.empty () : tensor <4 x3 xf64 , #Row >
216158 %row1 = sparse_tensor.insert %f1 into %rowa [%c0 , %c0 ] : tensor <4 x3 xf64 , #Row >
217159 %row2 = sparse_tensor.insert %f2 into %row1 [%c2 , %c2 ] : tensor <4 x3 xf64 , #Row >
218160 %row3 = sparse_tensor.insert %f3 into %row2 [%c3 , %c0 ] : tensor <4 x3 xf64 , #Row >
219161 %row4 = sparse_tensor.insert %f4 into %row3 [%c3 , %c2 ] : tensor <4 x3 xf64 , #Row >
220162 %rowm = sparse_tensor.load %row4 hasInserts : tensor <4 x3 xf64 , #Row >
221- call @dump_row (%rowm ) : (tensor <4 x3 xf64 , #Row >) -> ()
222-
223- //
224- // NOE sanity check.
225- //
226- // CHECK-NEXT: 12
227- // CHECK-NEXT: 4
228- // CHECK-NEXT: 4
229- // CHECK-NEXT: 4
230- // CHECK-NEXT: 9
231- //
232- %noe1 = sparse_tensor.number_of_entries %densem : tensor <4 x3 xf64 , #Dense >
233- %noe2 = sparse_tensor.number_of_entries %coom : tensor <4 x3 xf64 , #SortedCOO >
234- %noe3 = sparse_tensor.number_of_entries %csrm : tensor <4 x3 xf64 , #CSR >
235- %noe4 = sparse_tensor.number_of_entries %dcsrm : tensor <4 x3 xf64 , #DCSR >
236- %noe5 = sparse_tensor.number_of_entries %rowm : tensor <4 x3 xf64 , #Row >
237- vector.print %noe1 : index
238- vector.print %noe2 : index
239- vector.print %noe3 : index
240- vector.print %noe4 : index
241- vector.print %noe5 : index
163+ sparse_tensor.print %rowm : tensor <4 x3 xf64 , #Row >
242164
243165 // Release resources.
244166 bufferization.dealloc_tensor %densem : tensor <4 x3 xf64 , #Dense >
0 commit comments