@@ -127,6 +127,7 @@ module SpMSpV =
127127 computeOffsetsInplace queue ( vector.NNZ * 2 + 1 ) collectedRows
128128
129129 if gatherArraySize = 0 then
130+ collectedRows.Free queue
130131 None
131132 else
132133 let ndRange =
@@ -236,39 +237,34 @@ module SpMSpV =
236237 Reduce.ByKey.Option.segmentSequential add clContext workGroupSize
237238
238239 fun ( queue : MailboxProcessor < _ >) ( matrix : ClMatrix.CSR < 'a >) ( vector : ClVector.Sparse < 'b >) ->
239- let result =
240- gather queue matrix vector
241- |> Option.map
242- ( fun ( gatherRows , gatherIndices , gatherValues ) ->
243- sort queue gatherIndices gatherRows gatherValues
244-
245- let sortedRows , sortedIndices , sortedValues = gatherRows, gatherIndices, gatherValues
240+ gather queue matrix vector
241+ |> Option.map
242+ ( fun ( gatherRows , gatherIndices , gatherValues ) ->
243+ sort queue gatherIndices gatherRows gatherValues
246244
247- let multipliedValues =
248- multiplyScalar queue sortedRows sortedValues vector
245+ let sortedRows , sortedIndices , sortedValues = gatherRows, gatherIndices, gatherValues
249246
250- sortedValues.Free queue
251- sortedRows.Free queue
247+ let multipliedValues =
248+ multiplyScalar queue sortedRows sortedValues vector
252249
253- let result =
254- segReduce queue DeviceOnly sortedIndices multipliedValues
255- |> Option.map
256- ( fun ( reducedValues , reducedKeys ) ->
250+ sortedValues.Free queue
251+ sortedRows.Free queue
257252
258- { Context = clContext
259- Indices = reducedKeys
260- Values = reducedValues
261- Size = matrix.ColumnCount })
253+ let result =
254+ segReduce queue DeviceOnly sortedIndices multipliedValues
255+ |> Option.map
256+ ( fun ( reducedValues , reducedKeys ) ->
262257
263- multipliedValues.Free queue
264- sortedIndices.Free queue
258+ { Context = clContext
259+ Indices = reducedKeys
260+ Values = reducedValues
261+ Size = matrix.ColumnCount })
265262
266- result)
263+ multipliedValues.Free queue
264+ sortedIndices.Free queue
267265
268- //Unwrap 't option option to 't option
269- match result with
270- | Some result -> result
271- | None -> None
266+ result)
267+ |> Option.bind id
272268
273269
274270 let runBoolStandard
0 commit comments