Skip to content

Commit 087eef0

Browse files
committed
add: RrefixSum.*lengthToHost
1 parent 481f047 commit 087eef0

2 files changed

Lines changed: 26 additions & 17 deletions

File tree

src/GraphBLAS-sharp.Backend/Predefined/PrefixSum.fs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,25 @@ module internal PrefixSum =
3838
fun (processor: MailboxProcessor<_>) allocationMode (inputArray: ClArray<int>) (totalSum: ClCell<int>) ->
3939

4040
scan processor allocationMode inputArray totalSum 0
41+
42+
let standardExcludeInplaceLengthToHost clContext workGroupSize =
43+
44+
let scan = standardExcludeInplace clContext workGroupSize
45+
46+
let resultLength = Array.zeroCreate<int> 1
47+
48+
fun (processor: MailboxProcessor<_>) (positions: ClArray<int>) ->
49+
50+
let resultLengthGpu = clContext.CreateClCell 0
51+
52+
let _, r =
53+
scan processor positions resultLengthGpu
54+
55+
let res =
56+
processor.PostAndReply(fun ch -> Msg.CreateToHostMsg<_>(r, resultLength, ch))
57+
58+
processor.Post(Msg.CreateFreeMsg<_>(r))
59+
60+
res.[0]
61+
62+

src/GraphBLAS-sharp.Backend/Vector/DenseVector/DenseVector.fs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,30 +95,17 @@ module DenseVector =
9595
let getBitmap = ClArray.map clContext workGroupSize <| Map.option 1 0
9696

9797
let prefixSum =
98-
PrefixSum.standardExcludeInplace clContext workGroupSize
98+
PrefixSum.standardExcludeInplaceLengthToHost clContext workGroupSize
9999

100100
let allIndices = ClArray.init clContext workGroupSize <@ id @>
101101

102102
let allValues = ClArray.map clContext workGroupSize Map.optionToValueOrZero
103103

104-
let resultLength = Array.zeroCreate<int> 1
105-
106104
fun (processor: MailboxProcessor<_>) allocationMode (vector: ClArray<'a option>) ->
107105

108106
let positions = getBitmap processor DeviceOnly vector
109107

110-
let resultLengthGpu = clContext.CreateClCell 0
111-
112-
let _, r =
113-
prefixSum processor positions resultLengthGpu
114-
115-
let resultLength =
116-
let res =
117-
processor.PostAndReply(fun ch -> Msg.CreateToHostMsg<_>(r, resultLength, ch))
118-
119-
processor.Post(Msg.CreateFreeMsg<_>(r))
120-
121-
res.[0]
108+
let resultLength = prefixSum processor positions
122109

123110
// compute result indices
124111
let resultIndices =
@@ -131,11 +118,11 @@ module DenseVector =
131118
processor.Post <| Msg.CreateFreeMsg<_>(allIndices)
132119

133120
// compute result values
134-
let allValues = allValues processor DeviceOnly vector
135-
136121
let resultValues =
137122
clContext.CreateClArrayWithSpecificAllocationMode<'a>(allocationMode, resultLength)
138123

124+
let allValues = allValues processor DeviceOnly vector
125+
139126
scatterValues processor positions allValues resultValues
140127

141128
processor.Post <| Msg.CreateFreeMsg<_>(allValues)

0 commit comments

Comments
 (0)