@@ -3,6 +3,7 @@ namespace GraphBLAS.FSharp.Backend.Common
33open Brahma.FSharp
44open Microsoft.FSharp .Quotations
55open GraphBLAS.FSharp .Backend .Objects .ClContext
6+ open GraphBLAS.FSharp .Backend .Objects .ClCell
67
78module ClArray =
89 let init ( clContext : ClContext ) workGroupSize ( initializer : Expr < int -> 'a >) =
@@ -172,11 +173,13 @@ module ClArray =
172173
173174 let copy = copy clContext workGroupSize
174175
175- fun ( processor : MailboxProcessor < _ >) allocationMode ( inputArray : ClArray < 'a >) ( totalSum : ClCell < 'a >) ( zero : 'a ) ->
176+ fun ( processor : MailboxProcessor < _ >) allocationMode ( inputArray : ClArray < 'a >) ( zero : 'a ) ->
176177
177178 let outputArray = copy processor allocationMode inputArray
178179
179- runExcludeInplace processor outputArray totalSum zero
180+ let totalSum = runExcludeInplace processor outputArray zero
181+
182+ outputArray, totalSum
180183
181184 let prefixSumInclude plus ( clContext : ClContext ) workGroupSize =
182185
@@ -185,11 +188,13 @@ module ClArray =
185188
186189 let copy = copy clContext workGroupSize
187190
188- fun ( processor : MailboxProcessor < _ >) allocationMode ( inputArray : ClArray < 'a >) ( totalSum : ClCell < 'a >) ( zero : 'a ) ->
191+ fun ( processor : MailboxProcessor < _ >) allocationMode ( inputArray : ClArray < 'a >) ( zero : 'a ) ->
189192
190193 let outputArray = copy processor allocationMode inputArray
191194
192- runIncludeInplace processor outputArray totalSum zero
195+ let totalSum = runIncludeInplace processor outputArray zero
196+
197+ outputArray, totalSum
193198
194199 let prefixSumBackwardsExcludeInplace plus =
195200 PrefixSum.runBackwardsExcludeInplace plus
@@ -242,32 +247,23 @@ module ClArray =
242247 let getUniqueBitmap = getUniqueBitmap clContext workGroupSize
243248
244249 let prefixSumExclude =
245- prefixSumExclude <@ (+) @> clContext workGroupSize
250+ prefixSumExcludeInplace <@ (+) @> clContext workGroupSize
246251
247252 fun ( processor : MailboxProcessor < _ >) ( inputArray : ClArray < 'a >) ->
248253
249254 let bitmap =
250255 getUniqueBitmap processor DeviceOnly inputArray
251256
252- let sum = clContext.CreateClCell 0
253-
254- let positions , sum =
255- prefixSumExclude processor DeviceOnly bitmap sum 0
256-
257257 let resultLength =
258- let a = [| 0 |]
259-
260- processor.PostAndReply( fun ch -> Msg.CreateToHostMsg( sum, a, ch))
261- |> ignore
262-
263- processor.Post( Msg.CreateFreeMsg<_>( sum))
264-
265- a.[ 0 ]
258+ ( prefixSumExclude processor bitmap 0 )
259+ .ToHostAndFree( processor)
266260
267261 let outputArray =
268262 clContext.CreateClArrayWithSpecificAllocationMode( DeviceOnly, resultLength)
269263
270- scatter processor positions inputArray outputArray
264+ scatter processor bitmap inputArray outputArray
265+
266+ processor.Post <| Msg.CreateFreeMsg<_>( bitmap)
271267
272268 outputArray
273269
@@ -360,3 +356,5 @@ module ClArray =
360356 clContext.CreateClArrayWithSpecificAllocationMode( allocationMode, leftArray.Length)
361357
362358 map2 processor leftArray rightArray resultArray
359+
360+ resultArray
0 commit comments