10
10
// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
11
11
// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
12
12
// 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
14
14
// DEFINE: %{run} = mlir-cpu-runner %{run_opts} %{run_libs}
15
15
// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs}
16
16
//
32
32
}>
33
33
34
34
#SortedCOO = #sparse_tensor.encoding <{
35
- map = (d0 , d1 ) -> (d0 : compressed(nonunique), d1 : singleton)
35
+ map = (d0 , d1 ) -> (d0 : compressed(nonunique), d1 : singleton(soa) )
36
36
}>
37
37
38
38
#CSR = #sparse_tensor.encoding <{
48
48
}>
49
49
50
50
module {
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
-
134
51
//
135
52
// Main driver. We test the contents of various sparse tensor
136
53
// schemes when they are still empty and after a few insertions.
137
54
//
138
- func.func @entry () {
55
+ func.func @main () {
139
56
%c0 = arith.constant 0 : index
140
57
%c2 = arith.constant 2 : index
141
58
%c3 = arith.constant 3 : index
@@ -147,98 +64,103 @@ module {
147
64
//
148
65
// Dense case.
149
66
//
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: ----
151
73
//
152
74
%densea = tensor.empty () : tensor <4 x3 xf64 , #Dense >
153
75
%dense1 = sparse_tensor.insert %f1 into %densea [%c0 , %c0 ] : tensor <4 x3 xf64 , #Dense >
154
76
%dense2 = sparse_tensor.insert %f2 into %dense1 [%c2 , %c2 ] : tensor <4 x3 xf64 , #Dense >
155
77
%dense3 = sparse_tensor.insert %f3 into %dense2 [%c3 , %c0 ] : tensor <4 x3 xf64 , #Dense >
156
78
%dense4 = sparse_tensor.insert %f4 into %dense3 [%c3 , %c2 ] : tensor <4 x3 xf64 , #Dense >
157
79
%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 >
159
81
160
82
//
161
83
// COO case.
162
84
//
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: ----
167
94
//
168
95
%cooa = tensor.empty () : tensor <4 x3 xf64 , #SortedCOO >
169
96
%coo1 = sparse_tensor.insert %f1 into %cooa [%c0 , %c0 ] : tensor <4 x3 xf64 , #SortedCOO >
170
97
%coo2 = sparse_tensor.insert %f2 into %coo1 [%c2 , %c2 ] : tensor <4 x3 xf64 , #SortedCOO >
171
98
%coo3 = sparse_tensor.insert %f3 into %coo2 [%c3 , %c0 ] : tensor <4 x3 xf64 , #SortedCOO >
172
99
%coo4 = sparse_tensor.insert %f4 into %coo3 [%c3 , %c2 ] : tensor <4 x3 xf64 , #SortedCOO >
173
100
%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 >
175
102
176
103
//
177
104
// CSR case.
178
105
//
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: ----
182
114
//
183
115
%csra = tensor.empty () : tensor <4 x3 xf64 , #CSR >
184
116
%csr1 = sparse_tensor.insert %f1 into %csra [%c0 , %c0 ] : tensor <4 x3 xf64 , #CSR >
185
117
%csr2 = sparse_tensor.insert %f2 into %csr1 [%c2 , %c2 ] : tensor <4 x3 xf64 , #CSR >
186
118
%csr3 = sparse_tensor.insert %f3 into %csr2 [%c3 , %c0 ] : tensor <4 x3 xf64 , #CSR >
187
119
%csr4 = sparse_tensor.insert %f4 into %csr3 [%c3 , %c2 ] : tensor <4 x3 xf64 , #CSR >
188
120
%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 >
190
122
191
123
//
192
124
// DCSR case.
193
125
//
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: ----
199
136
//
200
137
%dcsra = tensor.empty () : tensor <4 x3 xf64 , #DCSR >
201
138
%dcsr1 = sparse_tensor.insert %f1 into %dcsra [%c0 , %c0 ] : tensor <4 x3 xf64 , #DCSR >
202
139
%dcsr2 = sparse_tensor.insert %f2 into %dcsr1 [%c2 , %c2 ] : tensor <4 x3 xf64 , #DCSR >
203
140
%dcsr3 = sparse_tensor.insert %f3 into %dcsr2 [%c3 , %c0 ] : tensor <4 x3 xf64 , #DCSR >
204
141
%dcsr4 = sparse_tensor.insert %f4 into %dcsr3 [%c3 , %c2 ] : tensor <4 x3 xf64 , #DCSR >
205
142
%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 >
207
144
208
145
//
209
146
// Row case.
210
147
//
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: ----
214
156
//
215
157
%rowa = tensor.empty () : tensor <4 x3 xf64 , #Row >
216
158
%row1 = sparse_tensor.insert %f1 into %rowa [%c0 , %c0 ] : tensor <4 x3 xf64 , #Row >
217
159
%row2 = sparse_tensor.insert %f2 into %row1 [%c2 , %c2 ] : tensor <4 x3 xf64 , #Row >
218
160
%row3 = sparse_tensor.insert %f3 into %row2 [%c3 , %c0 ] : tensor <4 x3 xf64 , #Row >
219
161
%row4 = sparse_tensor.insert %f4 into %row3 [%c3 , %c2 ] : tensor <4 x3 xf64 , #Row >
220
162
%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 >
242
164
243
165
// Release resources.
244
166
bufferization.dealloc_tensor %densem : tensor <4 x3 xf64 , #Dense >
0 commit comments