Skip to content

Commit 108c45c

Browse files
authored
Merge pull request #93 from kirillgarbar/scan
Improved scan performance
2 parents 2f5ba61 + b5ea523 commit 108c45c

File tree

9 files changed

+330
-41
lines changed

9 files changed

+330
-41
lines changed

src/GraphBLAS-sharp.Backend/Common/ClArray.fs

+5-5
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,15 @@ module ClArray =
202202
Bitmap.lastOccurrence clContext workGroupSize
203203

204204
let prefixSumExclude =
205-
PrefixSum.runExcludeInPlace <@ (+) @> clContext workGroupSize
205+
ScanInternal.standardExcludeInPlace clContext workGroupSize
206206

207207
fun (processor: MailboxProcessor<_>) (inputArray: ClArray<'a>) ->
208208

209209
let bitmap =
210210
getUniqueBitmap processor DeviceOnly inputArray
211211

212212
let resultLength =
213-
(prefixSumExclude processor bitmap 0)
213+
(prefixSumExclude processor bitmap)
214214
.ToHostAndFree(processor)
215215

216216
let outputArray =
@@ -314,7 +314,7 @@ module ClArray =
314314
Map.map<'a, int> (Map.chooseBitmap predicate) clContext workGroupSize
315315

316316
let prefixSum =
317-
PrefixSum.standardExcludeInPlace clContext workGroupSize
317+
ScanInternal.standardExcludeInPlace clContext workGroupSize
318318

319319
let assignValues =
320320
assignOption predicate clContext workGroupSize
@@ -410,7 +410,7 @@ module ClArray =
410410
Map.map2<'a, 'b, int> (Map.choose2Bitmap predicate) clContext workGroupSize
411411

412412
let prefixSum =
413-
PrefixSum.standardExcludeInPlace clContext workGroupSize
413+
ScanInternal.standardExcludeInPlace clContext workGroupSize
414414

415415
let assignValues =
416416
assignOption2 predicate clContext workGroupSize
@@ -878,7 +878,7 @@ module ClArray =
878878
mapInPlace ArithmeticOperations.intNotQ clContext workGroupSize
879879

880880
let prefixSum =
881-
PrefixSum.standardExcludeInPlace clContext workGroupSize
881+
ScanInternal.standardExcludeInPlace clContext workGroupSize
882882

883883
let scatter =
884884
Scatter.lastOccurrence clContext workGroupSize

src/GraphBLAS-sharp.Backend/Common/Common.fs

+11-8
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ module Common =
211211
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
212212
/// <param name="plus">Associative binary operation.</param>
213213
/// <param name="zero">Zero element for binary operation.</param>
214-
let runExcludeInPlace plus = PrefixSum.runExcludeInPlace plus
214+
let runExcludeInPlace plus = ScanInternal.runExcludeInPlace plus
215215

216216
/// <summary>
217217
/// Include in-place prefix sum.
@@ -231,7 +231,8 @@ module Common =
231231
/// <param name="clContext">ClContext.</param>
232232
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
233233
/// <param name="zero">Zero element for binary operation.</param>
234-
let runIncludeInPlace plus = PrefixSum.runIncludeInPlace plus
234+
let runIncludeInPlace plus =
235+
PrefixSumInternal.runIncludeInPlace plus
235236

236237
/// <summary>
237238
/// Exclude in-place prefix sum. Array is scanned starting from the end.
@@ -241,7 +242,7 @@ module Common =
241242
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
242243
/// <param name="zero">Zero element for binary operation.</param>
243244
let runBackwardsExcludeInPlace plus =
244-
PrefixSum.runBackwardsExcludeInPlace plus
245+
PrefixSumInternal.runBackwardsExcludeInPlace plus
245246

246247
/// <summary>
247248
/// Include in-place prefix sum. Array is scanned starting from the end.
@@ -251,7 +252,7 @@ module Common =
251252
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
252253
/// <param name="zero">Zero element for binary operation.</param>
253254
let runBackwardsIncludeInPlace plus =
254-
PrefixSum.runBackwardsIncludeInPlace plus
255+
PrefixSumInternal.runBackwardsIncludeInPlace plus
255256

256257
/// <summary>
257258
/// Exclude in-place prefix sum of integer array with addition operation and start value that is equal to 0.
@@ -267,7 +268,7 @@ module Common =
267268
/// > val sum = [| 4 |]
268269
/// </code>
269270
/// </example>
270-
let standardExcludeInPlace = PrefixSum.standardExcludeInPlace
271+
let standardExcludeInPlace = ScanInternal.standardExcludeInPlace
271272

272273
/// <summary>
273274
/// Include in-place prefix sum of integer array with addition operation and start value that is equal to 0.
@@ -285,7 +286,7 @@ module Common =
285286
/// </example>
286287
/// <param name="clContext">ClContext.</param>
287288
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
288-
let standardIncludeInPlace = PrefixSum.standardIncludeInPlace
289+
let standardIncludeInPlace = PrefixSumInternal.standardIncludeInPlace
289290

290291
module ByKey =
291292
/// <summary>
@@ -299,7 +300,8 @@ module Common =
299300
/// > val result = [| 0; 0; 1; 2; 0; 1 |]
300301
/// </code>
301302
/// </example>
302-
let sequentialExclude op = PrefixSum.ByKey.sequentialExclude op
303+
let sequentialExclude op =
304+
PrefixSumInternal.ByKey.sequentialExclude op
303305

304306
/// <summary>
305307
/// Include scan by key.
@@ -312,7 +314,8 @@ module Common =
312314
/// > val result = [| 1; 1; 2; 3; 1; 2 |]
313315
/// </code>
314316
/// </example>
315-
let sequentialInclude op = PrefixSum.ByKey.sequentialInclude op
317+
let sequentialInclude op =
318+
PrefixSumInternal.ByKey.sequentialInclude op
316319

317320
module Reduce =
318321
/// <summary>

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open GraphBLAS.FSharp.Backend.Quotes
66
open GraphBLAS.FSharp.Objects.ArraysExtensions
77
open GraphBLAS.FSharp.Objects.ClCellExtensions
88

9-
module PrefixSum =
9+
module internal PrefixSumInternal =
1010
let private update (opAdd: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize =
1111

1212
let update =
@@ -224,6 +224,8 @@ module PrefixSum =
224224
/// </example>
225225
/// <param name="clContext">ClContext.</param>
226226
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
227+
[<System.ObsoleteAttribute("This method is deprecated due to bad perfomance. Use method from Scan module instead.",
228+
false)>]
227229
let standardExcludeInPlace (clContext: ClContext) workGroupSize =
228230

229231
let scan =

0 commit comments

Comments
 (0)