Skip to content

Commit b8c4244

Browse files
committed
Merge remote-tracking branch 'origin/command-queue'
2 parents 54c0c00 + 108c45c commit b8c4244

File tree

4 files changed

+47
-29
lines changed

4 files changed

+47
-29
lines changed

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ module Common =
250250
/// <param name="clContext">ClContext.</param>
251251
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
252252
/// <param name="zero">Zero element for binary operation.</param>
253-
let runIncludeInPlace plus = PrefixSum.runIncludeInPlace plus
253+
let runIncludeInPlace plus =
254+
PrefixSumInternal.runIncludeInPlace plus
254255

255256
/// <summary>
256257
/// Exclude in-place prefix sum. Array is scanned starting from the end.
@@ -260,7 +261,7 @@ module Common =
260261
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
261262
/// <param name="zero">Zero element for binary operation.</param>
262263
let runBackwardsExcludeInPlace plus =
263-
PrefixSum.runBackwardsExcludeInPlace plus
264+
PrefixSumInternal.runBackwardsExcludeInPlace plus
264265

265266
/// <summary>
266267
/// Include in-place prefix sum. Array is scanned starting from the end.
@@ -270,7 +271,7 @@ module Common =
270271
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
271272
/// <param name="zero">Zero element for binary operation.</param>
272273
let runBackwardsIncludeInPlace plus =
273-
PrefixSum.runBackwardsIncludeInPlace plus
274+
PrefixSumInternal.runBackwardsIncludeInPlace plus
274275

275276
/// <summary>
276277
/// Exclude in-place prefix sum of integer array with addition operation and start value that is equal to 0.
@@ -304,7 +305,7 @@ module Common =
304305
/// </example>
305306
/// <param name="clContext">ClContext.</param>
306307
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
307-
let standardIncludeInPlace = PrefixSum.standardIncludeInPlace
308+
let standardIncludeInPlace = PrefixSumInternal.standardIncludeInPlace
308309

309310
module ByKey =
310311
/// <summary>
@@ -318,7 +319,8 @@ module Common =
318319
/// > val result = [| 0; 0; 1; 2; 0; 1 |]
319320
/// </code>
320321
/// </example>
321-
let sequentialExclude op = PrefixSum.ByKey.sequentialExclude op
322+
let sequentialExclude op =
323+
PrefixSumInternal.ByKey.sequentialExclude op
322324

323325
/// <summary>
324326
/// Include scan by key.
@@ -331,7 +333,8 @@ module Common =
331333
/// > val result = [| 1; 1; 2; 3; 1; 2 |]
332334
/// </code>
333335
/// </example>
334-
let sequentialInclude op = PrefixSum.ByKey.sequentialInclude op
336+
let sequentialInclude op =
337+
PrefixSumInternal.ByKey.sequentialInclude op
335338

336339
module Reduce =
337340
/// <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 =
@@ -209,6 +209,8 @@ module PrefixSum =
209209
/// </example>
210210
/// <param name="clContext">ClContext.</param>
211211
/// <param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
212+
[<System.ObsoleteAttribute("This method is deprecated due to bad perfomance. Use method from Scan module instead.",
213+
false)>]
212214
let standardExcludeInPlace (clContext: ClContext) workGroupSize =
213215

214216
let scan =

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ module internal Radix =
247247
let count = count clContext workGroupSize mask
248248

249249
let prefixSum =
250-
PrefixSum.standardExcludeInPlace clContext workGroupSize
250+
ScanInternal.standardExcludeInPlace clContext workGroupSize
251251

252252
let scatterByKey =
253253
scatterByKey clContext workGroupSize mask

tests/GraphBLAS-sharp.Tests/Backend/Common/Scan/PrefixSum.fs

+34-21
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,51 @@ let logger = Log.create "ClArray.PrefixSum.Tests"
1313

1414
let context = defaultContext.ClContext
1515

16-
let config = Tests.Utils.defaultConfig
16+
let config =
17+
{ Tests.Utils.defaultConfig with
18+
maxTest = 20
19+
startSize = 1
20+
endSize = 1000000 }
1721

1822
let wgSize = 128
1923

2024
let q = defaultContext.Queue
2125

22-
let makeTest plus zero isEqual scan (array: 'a []) =
26+
let makeTest plus zero isEqual scanInclude scanExclude (array: 'a []) =
2327
if array.Length > 0 then
28+
// Exclude
29+
let actual, actualSum =
30+
let clArray = context.CreateClArray array
31+
let (total: ClCell<_>) = scanExclude q clArray
32+
33+
let actual = clArray.ToHostAndFree q
34+
let actualSum = total.ToHostAndFree q
35+
36+
actual, actualSum
37+
38+
let expected, expectedSum =
39+
array
40+
|> Array.mapFold
41+
(fun s t ->
42+
let a = plus s t
43+
s, a)
44+
zero
2445

25-
logger.debug (
26-
eventX $"Array is %A{array}\n"
27-
>> setField "array" (sprintf "%A" array)
28-
)
46+
"Arrays for exclude should be the same"
47+
|> Tests.Utils.compareArrays isEqual actual expected
48+
49+
"Total sums for exclude should be equal"
50+
|> Expect.equal actualSum expectedSum
2951

52+
// Include
3053
let actual, actualSum =
3154
let clArray = context.CreateClArray array
32-
let (total: ClCell<_>) = scan q clArray
55+
let (total: ClCell<_>) = scanInclude q clArray zero
3356

3457
let actual = clArray.ToHostAndFree q
3558
let actualSum = total.ToHostAndFree q
3659
actual, actualSum
3760

38-
logger.debug (
39-
eventX "Actual is {actual}\n"
40-
>> setField "actual" (sprintf "%A" actual)
41-
)
42-
4361
let expected, expectedSum =
4462
array
4563
|> Array.mapFold
@@ -48,20 +66,15 @@ let makeTest plus zero isEqual scan (array: 'a []) =
4866
s, a)
4967
zero
5068

51-
logger.debug (
52-
eventX "Expected is {expected}\n"
53-
>> setField "expected" (sprintf "%A" expected)
54-
)
55-
56-
"Total sums should be equal"
69+
"Total sums for include should be equal"
5770
|> Expect.equal actualSum expectedSum
5871

59-
"Arrays should be the same"
72+
"Arrays for include should be the same"
6073
|> Tests.Utils.compareArrays isEqual actual expected
6174

6275
let testFixtures plus plusQ zero isEqual name =
63-
Common.PrefixSum.runExcludeInPlace plusQ zero context wgSize
64-
|> makeTest plus zero isEqual
76+
(PrefixSum.runIncludeInPlace plusQ context wgSize, PrefixSum.runExcludeInPlace plusQ zero context wgSize)
77+
||> makeTest plus zero isEqual
6578
|> testPropertyWithConfig config $"Correctness on %s{name}"
6679

6780
let tests =

0 commit comments

Comments
 (0)