Skip to content

Commit 5124eed

Browse files
[mlir][sparse] Fix memory leaks (part 3) (#85184)
This commit fixes memory leaks in sparse tensor integration tests by adding `bufferization.dealloc_tensor` ops. Note: Buffer deallocation will be automated in the future with the ownership-based buffer deallocation pass, making `dealloc_tensor` obsolete (only codegen path, not when using the runtime library).
1 parent 6ed4d15 commit 5124eed

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ module {
222222
bufferization.dealloc_tensor %sparse_filter_CD : tensor<3x3xi32, #CDR>
223223
bufferization.dealloc_tensor %sparse_filter_CSC : tensor<3x3xi32, #CSC>
224224

225+
bufferization.dealloc_tensor %0 : tensor<6x6xi32>
225226
bufferization.dealloc_tensor %2 : tensor<6x6xi32, #DCSR>
226227
bufferization.dealloc_tensor %3 : tensor<6x6xi32, #CSR>
227228
bufferization.dealloc_tensor %4 : tensor<6x6xi32, #CDR>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,14 @@ module {
273273
bufferization.dealloc_tensor %sparse_input_CSC : tensor<8x8xi32, #CSC>
274274
bufferization.dealloc_tensor %sparse_input_CD : tensor<8x8xi32, #CDR>
275275

276+
bufferization.dealloc_tensor %0 : tensor<6x6xi32>
276277
bufferization.dealloc_tensor %1 : tensor<6x6xi32, #DCSR>
277278
bufferization.dealloc_tensor %2 : tensor<6x6xi32, #DCSR>
278279
bufferization.dealloc_tensor %3 : tensor<6x6xi32, #CSR>
279280
bufferization.dealloc_tensor %4 : tensor<6x6xi32, #CDR>
280281
bufferization.dealloc_tensor %5 : tensor<6x6xi32, #CSC>
282+
bufferization.dealloc_tensor %6 : tensor<6x6xi32>
283+
281284
return
282285
}
283286
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,19 @@ module {
233233
// bufferization.dealloc_tensor %s2pp4 : tensor<2x?x?xf64, #Tensor4>
234234
// bufferization.dealloc_tensor %s2pp5 : tensor<2x?x?xf64, #Tensor5>
235235
// bufferization.dealloc_tensor %s2pp6 : tensor<2x?x?xf64, #Tensor6>
236+
237+
bufferization.dealloc_tensor %d2341 : tensor<2x3x4xf64>
238+
bufferization.dealloc_tensor %d2342 : tensor<2x3x4xf64>
239+
bufferization.dealloc_tensor %d2343 : tensor<2x3x4xf64>
240+
bufferization.dealloc_tensor %d2344 : tensor<2x3x4xf64>
241+
bufferization.dealloc_tensor %d2345 : tensor<2x3x4xf64>
242+
bufferization.dealloc_tensor %d2346 : tensor<2x3x4xf64>
243+
bufferization.dealloc_tensor %dp344 : tensor<?x3x4xf64>
244+
bufferization.dealloc_tensor %d2p45 : tensor<2x?x4xf64>
245+
bufferization.dealloc_tensor %d23p6 : tensor<2x3x?xf64>
246+
bufferization.dealloc_tensor %dp3p4 : tensor<?x3x?xf64>
247+
bufferization.dealloc_tensor %dpp45 : tensor<?x?x4xf64>
248+
236249
return
237250
}
238251
}

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,14 @@ module {
114114
call @dump(%d31) : (tensor<2x3x4xf64>) -> ()
115115

116116
//
117-
// Release sparse tensors.
117+
// Release the resources.
118118
//
119119
bufferization.dealloc_tensor %t13 : tensor<2x3x4xf64, #Tensor3>
120120
bufferization.dealloc_tensor %t31 : tensor<2x3x4xf64, #Tensor1>
121121
bufferization.dealloc_tensor %s1 : tensor<2x3x4xf64, #Tensor1>
122122
bufferization.dealloc_tensor %s3 : tensor<2x3x4xf64, #Tensor3>
123+
bufferization.dealloc_tensor %d13 : tensor<2x3x4xf64>
124+
bufferization.dealloc_tensor %d31 : tensor<2x3x4xf64>
123125

124126
return
125127
}
@@ -167,12 +169,14 @@ module {
167169
call @dump(%d31) : (tensor<2x3x4xf64>) -> ()
168170

169171
//
170-
// Release sparse tensors.
172+
// Release the resources.
171173
//
172174
bufferization.dealloc_tensor %t13 : tensor<2x3x4xf64, #SingletonTensor3>
173175
bufferization.dealloc_tensor %t31 : tensor<2x3x4xf64, #SingletonTensor1>
174176
bufferization.dealloc_tensor %s1 : tensor<2x3x4xf64, #SingletonTensor1>
175177
bufferization.dealloc_tensor %s3 : tensor<2x3x4xf64, #SingletonTensor3>
178+
bufferization.dealloc_tensor %d13 : tensor<2x3x4xf64>
179+
bufferization.dealloc_tensor %d31 : tensor<2x3x4xf64>
176180

177181
return
178182
}

0 commit comments

Comments
 (0)