@@ -224,6 +224,67 @@ module SpMSpV =
224224
225225 result
226226
227+ let run
228+ ( add : Expr < 'c option -> 'c option -> 'c option >)
229+ ( mul : Expr < 'a option -> 'b option -> 'c option >)
230+ ( clContext : ClContext )
231+ workGroupSize
232+ =
233+
234+ //TODO: Common.Gather?
235+ let gather = gather clContext workGroupSize
236+
237+ //TODO: Radix sort
238+ let sort =
239+ Sort.Bitonic.sortKeyValuesInplace clContext workGroupSize
240+
241+ let multiplyScalar =
242+ multiplyScalar clContext mul workGroupSize
243+
244+ let segReduce =
245+ Reduce.ByKey.Option.segmentSequential add clContext workGroupSize
246+
247+ fun ( queue : MailboxProcessor < _ >) ( matrix : ClMatrix.CSR < 'a >) ( vector : ClVector.Sparse < 'b >) ->
248+
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
260+ sort queue gatherIndices gatherRows gatherValues
261+
262+ let sortedRows , sortedIndices , sortedValues = gatherRows, gatherIndices, gatherValues
263+
264+ let multipliedValues =
265+ multiplyScalar queue sortedRows sortedValues vector
266+
267+ sortedValues.Free queue
268+ sortedRows.Free queue
269+
270+ match segReduce queue DeviceOnly sortedIndices multipliedValues with
271+ | Some ( reducedValues, reducedKeys) ->
272+ multipliedValues.Free queue
273+ sortedIndices.Free queue
274+
275+ { Context = clContext
276+ Indices = reducedKeys
277+ Values = reducedValues
278+ Size = matrix.ColumnCount }
279+ | None ->
280+ multipliedValues.Free queue
281+ sortedIndices.Free queue
282+
283+ { Context = clContext
284+ Indices = clContext.CreateClArray 0
285+ Values = clContext.CreateClArray 0
286+ Size = matrix.ColumnCount }
287+
227288 let runBoolStandard
228289 ( add : Expr < 'c option -> 'c option -> 'c option >)
229290 ( mul : Expr < 'a option -> 'b option -> 'c option >)
0 commit comments