File tree Expand file tree Collapse file tree
src/GraphBLAS-sharp.Backend Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -820,43 +820,21 @@ module ClArray =
820820 processor.Post( Msg.MsgSetArguments( fun () -> kernel.KernelFunc ndRange index array value))
821821 processor.Post( Msg.CreateRunMsg<_, _> kernel)
822822
823- let count ( predicate : Expr < 'a -> bool >) ( clContext : ClContext ) workGroupSize =
823+ let count < 'a > ( predicate : Expr < 'a -> bool >) ( clContext : ClContext ) workGroupSize =
824824
825825 let sum =
826826 PrefixSum.standardExcludeInPlace clContext workGroupSize
827827
828828 let getBitmap =
829- <@ fun ( ndRange : Range1D ) length ( vector : ClArray < 'a >) ( bitmap : ClArray < int >) ->
830-
831- let gid = ndRange.GlobalID0
832-
833- if gid < length then
834- let isTrue = (% predicate) vector.[ gid]
835-
836- if isTrue then
837- bitmap.[ gid] <- 1
838- else
839- bitmap.[ gid] <- 0 @>
840-
841- let kernel = clContext.Compile getBitmap
829+ map< 'a, int> ( Map.predicateBitmap predicate) clContext workGroupSize
842830
843831 fun ( processor : MailboxProcessor < _ >) ( array : ClArray < 'a >) ->
844832
845- let bitmap =
846- clContext.CreateClArrayWithSpecificAllocationMode( DeviceOnly, array.Length)
847-
848- let ndRange =
849- Range1D.CreateValid( array.Length, workGroupSize)
850-
851- let kernel = kernel.GetKernel()
852-
853- processor.Post( Msg.MsgSetArguments( fun () -> kernel.KernelFunc ndRange array.Length array bitmap))
854-
855- processor.Post( Msg.CreateRunMsg<_, _>( kernel))
833+ let bitmap = getBitmap processor DeviceOnly array
856834
857835 let result =
858836 ( sum processor bitmap) .ToHostAndFree processor
859837
860- processor.Post ( Msg.CreateFreeMsg bitmap )
838+ bitmap.Free processor
861839
862840 result
Original file line number Diff line number Diff line change @@ -28,6 +28,11 @@ module Map =
2828 | Some _ -> 1
2929 | None -> 0 @>
3030
31+ let predicateBitmap < 'a > ( predicate : Expr < 'a -> bool >) =
32+ <@ fun ( x : 'a ) ->
33+ let res = (% predicate) x
34+ if res then 1 else 0 @>
35+
3136 let inc = <@ fun item -> item + 1 @>
3237
3338 let subtraction = <@ fun first second -> first - second @>
You can’t perform that action at this time.
0 commit comments