@@ -127,16 +127,7 @@ module SpMSpV =
127127 computeOffsetsInplace queue ( vector.NNZ * 2 + 1 ) collectedRows
128128
129129 if gatherArraySize = 0 then
130- let resultRows =
131- clContext.CreateClArrayWithSpecificAllocationMode( DeviceOnly, 1 )
132-
133- let resultValues =
134- clContext.CreateClArrayWithSpecificAllocationMode( DeviceOnly, 1 )
135-
136- let resultColumns =
137- clContext.CreateClArrayWithSpecificAllocationMode( DeviceOnly, 1 )
138-
139- resultRows, resultColumns, resultValues, gatherArraySize
130+ None
140131 else
141132 let ndRange =
142133 Range1D.CreateValid( vector.NNZ, workGroupSize)
@@ -173,7 +164,7 @@ module SpMSpV =
173164
174165 collectedRows.Free queue
175166
176- resultRows, resultIndices, resultValues, gatherArraySize
167+ Some ( resultRows, resultIndices, resultValues)
177168
178169
179170 let private multiplyScalar ( clContext : ClContext ) ( mul : Expr < 'a option -> 'b option -> 'c option >) workGroupSize =
@@ -246,17 +237,9 @@ module SpMSpV =
246237
247238 fun ( queue : MailboxProcessor < _ >) ( matrix : ClMatrix.CSR < 'a >) ( vector : ClVector.Sparse < 'b >) ->
248239
249- let gatherRows , gatherIndices , gatherValues , gatherLength = gather queue matrix vector
250-
251- if gatherLength <= 0 then
252- gatherRows.Free queue
253- gatherValues.Free queue
254-
255- { Context = clContext
256- Indices = gatherIndices
257- Values = clContext.CreateClArray 0
258- Size = matrix.ColumnCount }
259- else
240+ match gather queue matrix vector with
241+ | None -> None
242+ | Some ( gatherRows, gatherIndices, gatherValues) ->
260243 sort queue gatherIndices gatherRows gatherValues
261244
262245 let sortedRows , sortedIndices , sortedValues = gatherRows, gatherIndices, gatherValues
@@ -272,18 +255,17 @@ module SpMSpV =
272255 multipliedValues.Free queue
273256 sortedIndices.Free queue
274257
275- { Context = clContext
276- Indices = reducedKeys
277- Values = reducedValues
278- Size = matrix.ColumnCount }
258+ Some(
259+ { Context = clContext
260+ Indices = reducedKeys
261+ Values = reducedValues
262+ Size = matrix.ColumnCount }
263+ )
279264 | None ->
280265 multipliedValues.Free queue
281266 sortedIndices.Free queue
282267
283- { Context = clContext
284- Indices = clContext.CreateClArray 0
285- Values = clContext.CreateClArray 0
286- Size = matrix.ColumnCount }
268+ None
287269
288270 let runBoolStandard
289271 ( add : Expr < 'c option -> 'c option -> 'c option >)
@@ -304,25 +286,22 @@ module SpMSpV =
304286
305287 fun ( queue : MailboxProcessor < _ >) ( matrix : ClMatrix.CSR < 'a >) ( vector : ClVector.Sparse < 'b >) ->
306288
307- let gatherRows , gatherIndices , gatherValues , gatherLength = gather queue matrix vector
308-
309- gatherRows.Free queue
310- gatherValues.Free queue
289+ match gather queue matrix vector with
290+ | None -> None
291+ | Some ( gatherRows, gatherIndices, gatherValues) ->
292+ gatherRows.Free queue
293+ gatherValues.Free queue
311294
312- if gatherLength <= 0 then
313- { Context = clContext
314- Indices = gatherIndices
315- Values = clContext.CreateClArray [| false |]
316- Size = matrix.ColumnCount }
317- else
318295 let sortedIndices = sort queue gatherIndices
319296
320297 let resultIndices = removeDuplicates queue sortedIndices
321298
322299 gatherIndices.Free queue
323300 sortedIndices.Free queue
324301
325- { Context = clContext
326- Indices = resultIndices
327- Values = create queue DeviceOnly resultIndices.Length true
328- Size = matrix.ColumnCount }
302+ Some(
303+ { Context = clContext
304+ Indices = resultIndices
305+ Values = create queue DeviceOnly resultIndices.Length true
306+ Size = matrix.ColumnCount }
307+ )
0 commit comments