Skip to content

Commit 9662efe

Browse files
committed
refactor: release in spgemm
1 parent 02fa1ff commit 9662efe

File tree

2 files changed

+15
-16
lines changed
  • src/GraphBLAS-sharp.Backend/Matrix/SpGeMM
  • tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM

2 files changed

+15
-16
lines changed

src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ module Expand =
7777

7878
assignValues processor firstValues secondValues positions resultValues
7979

80+
positions.Free processor
81+
8082
Some(resultValues, resultColumns, resultRows)
8183

8284
let expand (clContext: ClContext) workGroupSize =
@@ -238,8 +240,7 @@ module Expand =
238240

239241
offsets.Free processor
240242

241-
// reducedValues, reducedColumns, reducedRows
242-
243+
// reducedValues, reducedColumns, reducedRows option
243244
reduceResult
244245

245246
let runCOO opAdd opMul (clContext: ClContext) workGroupSize =
@@ -270,6 +271,8 @@ module Expand =
270271
let leftMatrixValues, rightMatrixValues, columns, rows =
271272
expand processor length segmentPointers leftMatrix rightMatrix
272273

274+
segmentPointers.Free processor
275+
273276
// multiply
274277
let mulResult =
275278
multiply processor leftMatrixValues rightMatrixValues columns rows
@@ -294,15 +297,11 @@ module Expand =
294297
let reduceResult =
295298
reduce processor allocationMode sortedValues sortedColumns sortedRows
296299

297-
reduceResult
298-
|> Option.map
299-
(fun (reducedValues, reducedColumns, reducedRows) ->
300-
301-
sortedValues.Free processor
302-
sortedColumns.Free processor
303-
sortedRows.Free processor
300+
sortedValues.Free processor
301+
sortedColumns.Free processor
302+
sortedRows.Free processor
304303

305-
reducedValues, reducedColumns, reducedRows))
304+
reduceResult)
306305

307306
let runOneStep opAdd opMul (clContext: ClContext) workGroupSize =
308307

@@ -398,7 +397,6 @@ module Expand =
398397
let result = helper 0 0 [] |> List.rev
399398

400399
segmentPointersByLeftMatrixRows.Free processor
401-
rightMatrixRowsNNZ.Free processor
402400

403401
result
404402

@@ -429,6 +427,8 @@ module Expand =
429427
getSegmentPointers processor leftMatrix.Columns rightMatrixRowsNNZ
430428

431429
if length < maxAllocSize then
430+
segmentLengths.Free processor
431+
432432
runOneStep processor allocationMode leftMatrix rightMatrixRowsNNZ rightMatrix
433433
else
434434
let result =
@@ -441,6 +441,9 @@ module Expand =
441441
rightMatrixRowsNNZ
442442
rightMatrix
443443

444+
rightMatrixRowsNNZ.Free processor
445+
segmentLengths.Free processor
446+
444447
match result with
445448
| _ :: _ ->
446449
let valuesList, columnsList, rowsList = result |> List.unzip3

tests/GraphBLAS-sharp.Tests/Backend/Matrix/SpGeMM/Expand.fs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ let expandTests =
181181

182182
let makeGeneralTest zero isEqual opAdd opMul testFun (leftArray: 'a [,], rightArray: 'a [,]) =
183183

184-
printfn "run test"
185-
186184
let leftMatrix =
187185
Utils.createMatrixFromArray2D CSR leftArray (isEqual zero)
188186

@@ -214,9 +212,7 @@ let makeGeneralTest zero isEqual opAdd opMul testFun (leftArray: 'a [,], rightAr
214212
let createGeneralTest (zero: 'a) isEqual (opAddQ, opAdd) (opMulQ, opMul) testFun =
215213
testFun opAddQ opMulQ context Utils.defaultWorkGroupSize
216214
|> makeGeneralTest zero isEqual opAdd opMul
217-
|> testPropertyWithConfig
218-
{ config with endSize = 100; maxTest = 10 }
219-
$"test on %A{typeof<'a>}"
215+
|> testPropertyWithConfig config $"test on %A{typeof<'a>}"
220216

221217
let generalTests =
222218
[ createGeneralTest 0 (=) ArithmeticOperations.intAdd ArithmeticOperations.intMul Matrix.SpGeMM.expand

0 commit comments

Comments
 (0)