xref: /llvm-project/mlir/test/Integration/Dialect/SparseTensor/CPU/sparse_matmul.mlir (revision eb206e9ea84eff0a0596fed2de8316d924f946d1)
1//--------------------------------------------------------------------------------------------------
2// WHEN CREATING A NEW TEST, PLEASE JUST COPY & PASTE WITHOUT EDITS.
3//
4// Set-up that's shared across all tests in this directory. In principle, this
5// config could be moved to lit.local.cfg. However, there are downstream users that
6//  do not use these LIT config files. Hence why this is kept inline.
7//
8// DEFINE: %{sparsifier_opts} = enable-runtime-library=true
9// DEFINE: %{sparsifier_opts_sve} = enable-arm-sve=true %{sparsifier_opts}
10// DEFINE: %{compile} = mlir-opt %s --sparsifier="%{sparsifier_opts}"
11// DEFINE: %{compile_sve} = mlir-opt %s --sparsifier="%{sparsifier_opts_sve}"
12// DEFINE: %{run_libs} = -shared-libs=%mlir_c_runner_utils,%mlir_runner_utils
13// DEFINE: %{run_libs_sve} = -shared-libs=%native_mlir_runner_utils,%native_mlir_c_runner_utils
14// DEFINE: %{run_opts} = -e main -entry-point-result=void
15// DEFINE: %{run} = mlir-runner %{run_opts} %{run_libs}
16// DEFINE: %{run_sve} = %mcr_aarch64_cmd --march=aarch64 --mattr="+sve" %{run_opts} %{run_libs_sve}
17//
18// DEFINE: %{env} =
19//--------------------------------------------------------------------------------------------------
20
21// RUN: %{compile} | %{run} | FileCheck %s
22//
23// Do the same run, but now with direct IR generation.
24// REDEFINE: %{sparsifier_opts} = enable-runtime-library=false enable-buffer-initialization=true
25// RUN: %{compile} | %{run} | FileCheck %s
26//
27// Do the same run, but now with parallelization strategy.
28// REDEFINE: %{sparsifier_opts} = enable-runtime-library=true parallelization-strategy=any-storage-any-loop
29// RUN: %{compile} | %{run} | FileCheck %s
30//
31// Do the same run, but now with direct IR generation and parallelization strategy.
32// REDEFINE: %{sparsifier_opts} = enable-runtime-library=false enable-buffer-initialization=true parallelization-strategy=any-storage-any-loop
33// RUN: %{compile} | %{run} | FileCheck %s
34//
35// Do the same run, but now with direct IR generation and vectorization.
36// REDEFINE: %{sparsifier_opts} = enable-runtime-library=false enable-buffer-initialization=true vl=2 reassociate-fp-reductions=true enable-index-optimizations=true
37// RUN: %{compile} | %{run} | FileCheck %s
38//
39// Do the same run, but now with direct IR generation and VLA vectorization.
40// RUN: %if mlir_arm_sve_tests %{ %{compile_sve} | %{run_sve} | FileCheck %s %}
41
42// TODO: Investigate the output generated for SVE, see https://github.com/llvm/llvm-project/issues/60626
43
44#CSR = #sparse_tensor.encoding<{
45  map = (d0, d1) -> (d0 : dense, d1 : compressed)
46}>
47
48#DCSR = #sparse_tensor.encoding<{
49  map = (d0, d1) -> (d0 : compressed, d1 : compressed)
50}>
51
52module {
53  func.func private @printMemrefF64(%ptr : tensor<*xf64>)
54  func.func private @printMemref1dF64(%ptr : memref<?xf64>) attributes { llvm.emit_c_interface }
55
56  //
57  // Computes C = A x B with all matrices dense.
58  //
59  func.func @matmul1(%A: tensor<4x8xf64>, %B: tensor<8x4xf64>,
60                     %C: tensor<4x4xf64>) -> tensor<4x4xf64> {
61    %D = linalg.matmul
62      ins(%A, %B: tensor<4x8xf64>, tensor<8x4xf64>)
63      outs(%C: tensor<4x4xf64>) -> tensor<4x4xf64>
64    return %D: tensor<4x4xf64>
65  }
66
67  //
68  // Computes C = A x B with all matrices sparse (SpMSpM) in CSR.
69  //
70  func.func @matmul2(%A: tensor<4x8xf64, #CSR>,
71                     %B: tensor<8x4xf64, #CSR>) -> tensor<4x4xf64, #CSR> {
72    %C = tensor.empty() : tensor<4x4xf64, #CSR>
73    %D = linalg.matmul
74      ins(%A, %B: tensor<4x8xf64, #CSR>, tensor<8x4xf64, #CSR>)
75         outs(%C: tensor<4x4xf64, #CSR>) -> tensor<4x4xf64, #CSR>
76    return %D: tensor<4x4xf64, #CSR>
77  }
78
79  //
80  // Computes C = A x B with all matrices sparse (SpMSpM) in DCSR.
81  //
82  func.func @matmul3(%A: tensor<4x8xf64, #DCSR>,
83                     %B: tensor<8x4xf64, #DCSR>) -> tensor<4x4xf64, #DCSR> {
84    %C = tensor.empty() : tensor<4x4xf64, #DCSR>
85    %D = linalg.matmul
86      ins(%A, %B: tensor<4x8xf64, #DCSR>, tensor<8x4xf64, #DCSR>)
87         outs(%C: tensor<4x4xf64, #DCSR>) -> tensor<4x4xf64, #DCSR>
88    return %D: tensor<4x4xf64, #DCSR>
89  }
90
91  //
92  // Main driver.
93  //
94  func.func @main() {
95    %c0 = arith.constant 0 : index
96
97    // Initialize various matrices, dense for stress testing,
98    // and sparse to verify correct nonzero structure.
99    %da = arith.constant dense<[
100        [ 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1 ],
101        [ 1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2, 8.2 ],
102        [ 1.3, 2.3, 3.3, 4.3, 5.3, 6.3, 7.3, 8.3 ],
103        [ 1.4, 2.4, 3.4, 4.4, 5.4, 6.4, 7.4, 8.4 ]
104    ]> : tensor<4x8xf64>
105    %db = arith.constant dense<[
106        [ 10.1, 11.1, 12.1, 13.1 ],
107        [ 10.2, 11.2, 12.2, 13.2 ],
108        [ 10.3, 11.3, 12.3, 13.3 ],
109        [ 10.4, 11.4, 12.4, 13.4 ],
110        [ 10.5, 11.5, 12.5, 13.5 ],
111        [ 10.6, 11.6, 12.6, 13.6 ],
112        [ 10.7, 11.7, 12.7, 13.7 ],
113        [ 10.8, 11.8, 12.8, 13.8 ]
114    ]> : tensor<8x4xf64>
115    %sa = arith.constant dense<[
116        [ 0.0, 2.1, 0.0, 0.0, 0.0, 6.1, 0.0, 0.0 ],
117        [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ],
118        [ 0.0, 2.3, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ],
119        [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 ]
120    ]> : tensor<4x8xf64>
121    %sb = arith.constant dense<[
122        [ 0.0, 0.0, 0.0, 1.0 ],
123        [ 0.0, 0.0, 2.0, 0.0 ],
124        [ 0.0, 3.0, 0.0, 0.0 ],
125        [ 4.0, 0.0, 0.0, 0.0 ],
126        [ 0.0, 0.0, 0.0, 0.0 ],
127        [ 0.0, 5.0, 0.0, 0.0 ],
128        [ 0.0, 0.0, 6.0, 0.0 ],
129        [ 0.0, 0.0, 7.0, 8.0 ]
130    ]> : tensor<8x4xf64>
131    %zero = arith.constant dense<0.0> : tensor<4x4xf64>
132
133    // Convert all these matrices to sparse format.
134    %a1 = sparse_tensor.convert %da : tensor<4x8xf64> to tensor<4x8xf64, #CSR>
135    %a2 = sparse_tensor.convert %da : tensor<4x8xf64> to tensor<4x8xf64, #DCSR>
136    %a3 = sparse_tensor.convert %sa : tensor<4x8xf64> to tensor<4x8xf64, #CSR>
137    %a4 = sparse_tensor.convert %sa : tensor<4x8xf64> to tensor<4x8xf64, #DCSR>
138    %b1 = sparse_tensor.convert %db : tensor<8x4xf64> to tensor<8x4xf64, #CSR>
139    %b2 = sparse_tensor.convert %db : tensor<8x4xf64> to tensor<8x4xf64, #DCSR>
140    %b3 = sparse_tensor.convert %sb : tensor<8x4xf64> to tensor<8x4xf64, #CSR>
141    %b4 = sparse_tensor.convert %sb : tensor<8x4xf64> to tensor<8x4xf64, #DCSR>
142
143    //
144    // Sanity check before going into the computations.
145    //
146    // CHECK:      ---- Sparse Tensor ----
147    // CHECK-NEXT: nse = 32
148    // CHECK-NEXT: dim = ( 4, 8 )
149    // CHECK-NEXT: lvl = ( 4, 8 )
150    // CHECK-NEXT: pos[1] : ( 0, 8, 16, 24, 32 )
151    // CHECK-NEXT: crd[1] : ( 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 )
152    // CHECK-NEXT: values : ( 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2, 8.2, 1.3, 2.3, 3.3, 4.3, 5.3, 6.3, 7.3, 8.3, 1.4, 2.4, 3.4, 4.4, 5.4, 6.4, 7.4, 8.4 )
153    // CHECK-NEXT: ----
154    //
155    sparse_tensor.print %a1 : tensor<4x8xf64, #CSR>
156
157    //
158    // CHECK:      ---- Sparse Tensor ----
159    // CHECK-NEXT: nse = 32
160    // CHECK-NEXT: dim = ( 4, 8 )
161    // CHECK-NEXT: lvl = ( 4, 8 )
162    // CHECK-NEXT: pos[0] : ( 0, 4 )
163    // CHECK-NEXT: crd[0] : ( 0, 1, 2, 3 )
164    // CHECK-NEXT: pos[1] : ( 0, 8, 16, 24, 32 )
165    // CHECK-NEXT: crd[1] : ( 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 )
166    // CHECK-NEXT: values : ( 1.1, 2.1, 3.1, 4.1, 5.1, 6.1, 7.1, 8.1, 1.2, 2.2, 3.2, 4.2, 5.2, 6.2, 7.2, 8.2, 1.3, 2.3, 3.3, 4.3, 5.3, 6.3, 7.3, 8.3, 1.4, 2.4, 3.4, 4.4, 5.4, 6.4, 7.4, 8.4 )
167    // CHECK-NEXT: ----
168    //
169    sparse_tensor.print %a2 : tensor<4x8xf64, #DCSR>
170
171    //
172    // CHECK:      ---- Sparse Tensor ----
173    // CHECK-NEXT: nse = 4
174    // CHECK-NEXT: dim = ( 4, 8 )
175    // CHECK-NEXT: lvl = ( 4, 8 )
176    // CHECK-NEXT: pos[1] : ( 0, 2, 2, 3, 4 )
177    // CHECK-NEXT: crd[1] : ( 1, 5, 1, 7 )
178    // CHECK-NEXT: values : ( 2.1, 6.1, 2.3, 1 )
179    // CHECK-NEXT: ----
180    //
181    sparse_tensor.print %a3 : tensor<4x8xf64, #CSR>
182
183    //
184    // CHECK:      ---- Sparse Tensor ----
185    // CHECK-NEXT: nse = 4
186    // CHECK-NEXT: dim = ( 4, 8 )
187    // CHECK-NEXT: lvl = ( 4, 8 )
188    // CHECK-NEXT: pos[0] : ( 0, 3 )
189    // CHECK-NEXT: crd[0] : ( 0, 2, 3 )
190    // CHECK-NEXT: pos[1] : ( 0, 2, 3, 4 )
191    // CHECK-NEXT: crd[1] : ( 1, 5, 1, 7 )
192    // CHECK-NEXT: values : ( 2.1, 6.1, 2.3, 1 )
193    // CHECK-NEXT: ----
194    //
195    sparse_tensor.print %a4 : tensor<4x8xf64, #DCSR>
196
197    //
198    // CHECK:      ---- Sparse Tensor ----
199    // CHECK-NEXT: nse = 32
200    // CHECK-NEXT: dim = ( 8, 4 )
201    // CHECK-NEXT: lvl = ( 8, 4 )
202    // CHECK-NEXT: pos[1] : ( 0, 4, 8, 12, 16, 20, 24, 28, 32 )
203    // CHECK-NEXT: crd[1] : ( 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 )
204    // CHECK-NEXT: values : ( 10.1, 11.1, 12.1, 13.1, 10.2, 11.2, 12.2, 13.2, 10.3, 11.3, 12.3, 13.3, 10.4, 11.4, 12.4, 13.4, 10.5, 11.5, 12.5, 13.5, 10.6, 11.6, 12.6, 13.6, 10.7, 11.7, 12.7, 13.7, 10.8, 11.8, 12.8, 13.8 )
205    // CHECK-NEXT: ----
206    //
207    sparse_tensor.print %b1 : tensor<8x4xf64, #CSR>
208
209    //
210    // CHECK:      ---- Sparse Tensor ----
211    // CHECK-NEXT: nse = 32
212    // CHECK-NEXT: dim = ( 8, 4 )
213    // CHECK-NEXT: lvl = ( 8, 4 )
214    // CHECK-NEXT: pos[0] : ( 0, 8 )
215    // CHECK-NEXT: crd[0] : ( 0, 1, 2, 3, 4, 5, 6, 7 )
216    // CHECK-NEXT: pos[1] : ( 0, 4, 8, 12, 16, 20, 24, 28, 32 )
217    // CHECK-NEXT: crd[1] : ( 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 )
218    // CHECK-NEXT: values : ( 10.1, 11.1, 12.1, 13.1, 10.2, 11.2, 12.2, 13.2, 10.3, 11.3, 12.3, 13.3, 10.4, 11.4, 12.4, 13.4, 10.5, 11.5, 12.5, 13.5, 10.6, 11.6, 12.6, 13.6, 10.7, 11.7, 12.7, 13.7, 10.8, 11.8, 12.8, 13.8 )
219    // CHECK-NEXT: ----
220    //
221    sparse_tensor.print %b2 : tensor<8x4xf64, #DCSR>
222
223    //
224    // CHECK:      ---- Sparse Tensor ----
225    // CHECK-NEXT: nse = 8
226    // CHECK-NEXT: dim = ( 8, 4 )
227    // CHECK-NEXT: lvl = ( 8, 4 )
228    // CHECK-NEXT: pos[1] : ( 0, 1, 2, 3, 4, 4, 5, 6, 8 )
229    // CHECK-NEXT: crd[1] : ( 3, 2, 1, 0, 1, 2, 2, 3 )
230    // CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7, 8 )
231    // CHECK-NEXT: ----
232    //
233    sparse_tensor.print %b3 : tensor<8x4xf64, #CSR>
234
235    //
236    // CHECK:      ---- Sparse Tensor ----
237    // CHECK-NEXT: nse = 8
238    // CHECK-NEXT: dim = ( 8, 4 )
239    // CHECK-NEXT: lvl = ( 8, 4 )
240    // CHECK-NEXT: pos[0] : ( 0, 7 )
241    // CHECK-NEXT: crd[0] : ( 0, 1, 2, 3, 5, 6, 7 )
242    // CHECK-NEXT: pos[1] : ( 0, 1, 2, 3, 4, 5, 6, 8 )
243    // CHECK-NEXT: crd[1] : ( 3, 2, 1, 0, 1, 2, 2, 3 )
244    // CHECK-NEXT: values : ( 1, 2, 3, 4, 5, 6, 7, 8 )
245    // CHECK-NEXT: ----
246    //
247    sparse_tensor.print %b4 : tensor<8x4xf64, #DCSR>
248
249    // Call kernels with dense.
250    %0 = call @matmul1(%da, %db, %zero)
251       : (tensor<4x8xf64>, tensor<8x4xf64>, tensor<4x4xf64>) -> tensor<4x4xf64>
252    %1 = call @matmul2(%a1, %b1)
253       : (tensor<4x8xf64, #CSR>,
254          tensor<8x4xf64, #CSR>) -> tensor<4x4xf64, #CSR>
255    %2 = call @matmul3(%a2, %b2)
256       : (tensor<4x8xf64, #DCSR>,
257          tensor<8x4xf64, #DCSR>) -> tensor<4x4xf64, #DCSR>
258
259    // Call kernels with one sparse.
260    %3 = call @matmul1(%sa, %db, %zero)
261       : (tensor<4x8xf64>, tensor<8x4xf64>, tensor<4x4xf64>) -> tensor<4x4xf64>
262    %4 = call @matmul2(%a3, %b1)
263       : (tensor<4x8xf64, #CSR>,
264          tensor<8x4xf64, #CSR>) -> tensor<4x4xf64, #CSR>
265    %5 = call @matmul3(%a4, %b2)
266       : (tensor<4x8xf64, #DCSR>,
267          tensor<8x4xf64, #DCSR>) -> tensor<4x4xf64, #DCSR>
268
269    // Call kernels with sparse.
270    %6 = call @matmul1(%sa, %sb, %zero)
271       : (tensor<4x8xf64>, tensor<8x4xf64>, tensor<4x4xf64>) -> tensor<4x4xf64>
272    %7 = call @matmul2(%a3, %b3)
273       : (tensor<4x8xf64, #CSR>,
274          tensor<8x4xf64, #CSR>) -> tensor<4x4xf64, #CSR>
275    %8 = call @matmul3(%a4, %b4)
276       : (tensor<4x8xf64, #DCSR>,
277          tensor<8x4xf64, #DCSR>) -> tensor<4x4xf64, #DCSR>
278
279    //
280    // CHECK:      {{\[}}[388.76,   425.56,   462.36,   499.16],
281    // CHECK-NEXT: [397.12,   434.72,   472.32,   509.92],
282    // CHECK-NEXT: [405.48,   443.88,   482.28,   520.68],
283    // CHECK-NEXT: [413.84,   453.04,   492.24,   531.44]]
284    //
285    %u0 = tensor.cast %0 : tensor<4x4xf64> to tensor<*xf64>
286    call @printMemrefF64(%u0) : (tensor<*xf64>) -> ()
287
288    //
289    // CHECK:      ---- Sparse Tensor ----
290    // CHECK-NEXT: nse = 16
291    // CHECK-NEXT: dim = ( 4, 4 )
292    // CHECK-NEXT: lvl = ( 4, 4 )
293    // CHECK-NEXT: pos[1] : ( 0, 4, 8, 12, 16 )
294    // CHECK-NEXT: crd[1] : ( 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 )
295    // CHECK-NEXT: values : ( 388.76, 425.56, 462.36, 499.16, 397.12, 434.72, 472.32, 509.92, 405.48, 443.88, 482.28, 520.68, 413.84, 453.04, 492.24, 531.44 )
296    // CHECK-NEXT: ----
297    //
298    sparse_tensor.print %1 : tensor<4x4xf64, #CSR>
299
300    //
301    // CHECK:      ---- Sparse Tensor ----
302    // CHECK-NEXT: nse = 16
303    // CHECK-NEXT: dim = ( 4, 4 )
304    // CHECK-NEXT: lvl = ( 4, 4 )
305    // CHECK-NEXT: pos[0] : ( 0, 4 )
306    // CHECK-NEXT: crd[0] : ( 0, 1, 2, 3 )
307    // CHECK-NEXT: pos[1] : ( 0, 4, 8, 12, 16 )
308    // CHECK-NEXT: crd[1] : ( 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 )
309    // CHECK-NEXT: values : ( 388.76, 425.56, 462.36, 499.16, 397.12, 434.72, 472.32, 509.92, 405.48, 443.88, 482.28, 520.68, 413.84, 453.04, 492.24, 531.44 )
310    // CHECK-NEXT: ----
311    //
312    sparse_tensor.print %2 : tensor<4x4xf64, #DCSR>
313
314    //
315    // CHECK:      {{\[}}[86.08,   94.28,   102.48,   110.68],
316    // CHECK-NEXT: [0,   0,   0,   0],
317    // CHECK-NEXT: [23.46,   25.76,   28.06,   30.36],
318    // CHECK-NEXT: [10.8,   11.8,   12.8,   13.8]]
319    //
320    %u3 = tensor.cast %3 : tensor<4x4xf64> to tensor<*xf64>
321    call @printMemrefF64(%u3) : (tensor<*xf64>) -> ()
322
323    //
324    // CHECK:      ---- Sparse Tensor ----
325    // CHECK-NEXT: nse = 12
326    // CHECK-NEXT: dim = ( 4, 4 )
327    // CHECK-NEXT: lvl = ( 4, 4 )
328    // CHECK-NEXT: pos[1] : ( 0, 4, 4, 8, 12 )
329    // CHECK-NEXT: crd[1] : ( 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 )
330    // CHECK-NEXT: values : ( 86.08, 94.28, 102.48, 110.68, 23.46, 25.76, 28.06, 30.36, 10.8, 11.8, 12.8, 13.8 )
331    // CHECK-NEXT: ----
332    //
333    sparse_tensor.print %4 : tensor<4x4xf64, #CSR>
334
335    //
336    // CHECK:      ---- Sparse Tensor ----
337    // CHECK-NEXT: nse = 12
338    // CHECK-NEXT: dim = ( 4, 4 )
339    // CHECK-NEXT: lvl = ( 4, 4 )
340    // CHECK-NEXT: pos[0] : ( 0, 3 )
341    // CHECK-NEXT: crd[0] : ( 0, 2, 3 )
342    // CHECK-NEXT: pos[1] : ( 0, 4, 8, 12 )
343    // CHECK-NEXT: crd[1] : ( 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3 )
344    // CHECK-NEXT: values : ( 86.08, 94.28, 102.48, 110.68, 23.46, 25.76, 28.06, 30.36, 10.8, 11.8, 12.8, 13.8 )
345    // CHECK-NEXT: ----
346    //
347    sparse_tensor.print %5 : tensor<4x4xf64, #DCSR>
348
349    //
350    // CHECK:      {{\[}}[0,   30.5,   4.2,   0],
351    // CHECK-NEXT: [0,   0,   0,   0],
352    // CHECK-NEXT: [0,   0,   4.6,   0],
353    // CHECK-NEXT: [0,   0,   7,   8]]
354    //
355    %u6 = tensor.cast %6 : tensor<4x4xf64> to tensor<*xf64>
356    call @printMemrefF64(%u6) : (tensor<*xf64>) -> ()
357
358    //
359    // CHECK:      ---- Sparse Tensor ----
360    // CHECK-NEXT: nse = 5
361    // CHECK-NEXT: dim = ( 4, 4 )
362    // CHECK-NEXT: lvl = ( 4, 4 )
363    // CHECK-NEXT: pos[1] : ( 0, 2, 2, 3, 5 )
364    // CHECK-NEXT: crd[1] : ( 1, 2, 2, 2, 3 )
365    // CHECK-NEXT: values : ( 30.5, 4.2, 4.6, 7, 8 )
366    // CHECK-NEXT: ----
367    //
368    sparse_tensor.print %7 : tensor<4x4xf64, #CSR>
369
370    //
371    // CHECK:      ---- Sparse Tensor ----
372    // CHECK-NEXT: nse = 5
373    // CHECK-NEXT: dim = ( 4, 4 )
374    // CHECK-NEXT: lvl = ( 4, 4 )
375    // CHECK-NEXT: pos[0] : ( 0, 3 )
376    // CHECK-NEXT: crd[0] : ( 0, 2, 3 )
377    // CHECK-NEXT: pos[1] : ( 0, 2, 3, 5 )
378    // CHECK-NEXT: crd[1] : ( 1, 2, 2, 2, 3 )
379    // CHECK-NEXT: values : ( 30.5, 4.2, 4.6, 7, 8 )
380    // CHECK-NEXT: ----
381    //
382    sparse_tensor.print %8 : tensor<4x4xf64, #DCSR>
383
384    // Release the resources.
385    bufferization.dealloc_tensor %a1 : tensor<4x8xf64, #CSR>
386    bufferization.dealloc_tensor %a2 : tensor<4x8xf64, #DCSR>
387    bufferization.dealloc_tensor %a3 : tensor<4x8xf64, #CSR>
388    bufferization.dealloc_tensor %a4 : tensor<4x8xf64, #DCSR>
389    bufferization.dealloc_tensor %b1 : tensor<8x4xf64, #CSR>
390    bufferization.dealloc_tensor %b2 : tensor<8x4xf64, #DCSR>
391    bufferization.dealloc_tensor %b3 : tensor<8x4xf64, #CSR>
392    bufferization.dealloc_tensor %b4 : tensor<8x4xf64, #DCSR>
393    bufferization.dealloc_tensor %0 : tensor<4x4xf64>
394    bufferization.dealloc_tensor %1 : tensor<4x4xf64, #CSR>
395    bufferization.dealloc_tensor %2 : tensor<4x4xf64, #DCSR>
396    bufferization.dealloc_tensor %3 : tensor<4x4xf64>
397    bufferization.dealloc_tensor %4 : tensor<4x4xf64, #CSR>
398    bufferization.dealloc_tensor %5 : tensor<4x4xf64, #DCSR>
399    bufferization.dealloc_tensor %6 : tensor<4x4xf64>
400    bufferization.dealloc_tensor %7 : tensor<4x4xf64, #CSR>
401    bufferization.dealloc_tensor %8 : tensor<4x4xf64, #DCSR>
402
403    return
404  }
405}
406