Skip to content

Commit 4c7626a

Browse files
committed
add: Sum test
1 parent 86abbce commit 4c7626a

7 files changed

Lines changed: 80 additions & 13 deletions

File tree

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ module internal PrefixSum =
3939
processor.Post(Msg.CreateRunMsg<_, _> kernel)
4040
processor.Post(Msg.CreateFreeMsg(mirror))
4141

42-
4342
let private scanGeneral
4443
beforeLocalSumClear
4544
writeData

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ open GraphBLAS.FSharp.Backend
55
open Microsoft.FSharp.Quotations
66

77
module internal Sum =
8-
98
let private scan
109
(clContext: ClContext)
1110
(workGroupSize: int)

src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
<Compile Include="AssemblyInfo.fs" />
1414
<Compile Include="Common/CommonQuotes.fs" />
1515
<Compile Include="Common/Utils.fs" />
16-
<Compile Include="Common/ClArray.fs" />
1716
<Compile Include="Common/Sum.fs" />
18-
<Compile Include="Common/PrefixSum.fs" />
17+
<Compile Include="Common\ClArray.fs" />
18+
<Compile Include="Common\PrefixSum.fs" />
1919
<Compile Include="Common/BitonicSort.fs" />
2020
<Compile Include="Common/Scatter.fs" />
2121
<Compile Include="Common/StandardOperations.fs" />

src/GraphBLAS-sharp.Backend/Matrix/COOMatrix/COOMatrix.fs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,6 @@ module COOMatrix =
407407

408408
let resultValues = copyData processor matrix.Values
409409

410-
411410
{ Context = clContext
412411
RowIndices = resultRows
413412
ColumnIndices = resultColumns
@@ -500,13 +499,6 @@ module COOMatrix =
500499
if (i < length - 1
501500
&& allRowsBuffer.[i] = allRowsBuffer.[i + 1]
502501
&& allColumnsBuffer.[i] = allColumnsBuffer.[i + 1]) then
503-
rawPositionsBuffer.[i] <- 0
504-
505-
match (%opAdd) (Both(leftValuesBuffer.[i + 1], rightValuesBuffer.[i])) with
506-
| Some v ->
507-
allValuesBuffer.[i + 1] <- v
508-
rawPositionsBuffer.[i + 1] <- 1
509-
| None -> rawPositionsBuffer.[i + 1] <- 0
510502

511503
let result = (%opAdd) (Both(leftValuesBuffer.[i + 1], rightValuesBuffer.[i]))
512504

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
module Backend.Sum
2+
3+
open Expecto
4+
open Expecto.Logging
5+
open Expecto.Logging.Message
6+
open Brahma.FSharp
7+
open GraphBLAS.FSharp.Backend.Common
8+
open GraphBLAS.FSharp.Tests.Utils
9+
open FSharp.Quotations
10+
11+
let logger = Log.create "Sum.Test"
12+
13+
let context = defaultContext.ClContext
14+
15+
let makeTest (q: MailboxProcessor<_>) sum plus zero isEqual (filter: 'a [] -> 'a []) (array: 'a []) =
16+
if array.Length > 0 then
17+
let array = filter array
18+
19+
logger.debug (
20+
eventX "Filtered array is {array}\n"
21+
>> setField "array" (sprintf "%A" array)
22+
)
23+
24+
let actualSum =
25+
use clArray = context.CreateClArray array
26+
use total = sum q clArray
27+
28+
let actualSum = [| zero |]
29+
q.PostAndReply(fun ch -> Msg.CreateToHostMsg(total, actualSum, ch)).[0]
30+
31+
logger.debug (
32+
eventX "Actual is {actual}\n"
33+
>> setField "actual" (sprintf "%A" actualSum)
34+
)
35+
36+
let expectedSum =
37+
array
38+
|> Array.fold plus zero
39+
40+
logger.debug (
41+
eventX "Expected is {expected}\n"
42+
>> setField "expected" (sprintf "%A" expectedSum)
43+
)
44+
45+
"Total sums should be equal"
46+
|> Expect.equal actualSum expectedSum
47+
48+
let testFixtures config wgSize q plus (plusQ: Expr<'a -> 'a -> 'a>) zero isEqual filter name =
49+
let sum =
50+
Sum.run context wgSize plusQ zero
51+
52+
makeTest q sum plus zero isEqual filter
53+
|> testPropertyWithConfig config (sprintf "Correctness on %s" name)
54+
55+
let tests =
56+
let config = defaultConfig
57+
58+
let wgSize = 128
59+
let q = defaultContext.Queue
60+
q.Error.Add(fun e -> failwithf "%A" e)
61+
62+
let filterFloats =
63+
Array.filter (System.Double.IsNaN >> not)
64+
65+
[ testFixtures config wgSize q (+) <@ (+) @> 0 (=) id "int add"
66+
testFixtures config wgSize q (+) <@ (+) @> 0uy (=) id "byte add"
67+
testFixtures config wgSize q max <@ max @> 0 (=) id "int max"
68+
testFixtures config wgSize q max <@ max @> 0.0 (=) filterFloats "float max"
69+
testFixtures config wgSize q max <@ max @> 0uy (=) id "byte max"
70+
testFixtures config wgSize q min <@ min @> System.Int32.MaxValue (=) id "int min"
71+
testFixtures config wgSize q min <@ min @> System.Double.MaxValue (=) filterFloats "float min"
72+
testFixtures config wgSize q min <@ min @> System.Byte.MaxValue (=) id "byte min"
73+
testFixtures config wgSize q (||) <@ (||) @> false (=) id "bool logic-or"
74+
testFixtures config wgSize q (&&) <@ (&&) @> true (=) id "bool logic-and" ]
75+
|> testList "Backend.Common.Sum tests"
76+

tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<Compile Include="BackendCommonTests/ConvertTests.fs" />
2323
<Compile Include="BackendCommonTests/TransposeTests.fs" />
2424
<Compile Include="BackendCommonTests/MxmTests.fs" />
25+
<Compile Include="BackendCommonTests\SumTest.fs" />
2526
<!--Compile Include="MatrixOperationsTests/GetTuplesTests.fs" /-->
2627
<!--Compile Include="MatrixOperationsTests/MxvTests.fs" /-->
2728
<!--Compile Include="MatrixOperationsTests/VxmTests.fs" /-->

tests/GraphBLAS-sharp.Tests/Program.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let allTests =
2727
//Matrix.GetTuples.tests
2828
//Matrix.Mxv.tests
2929
//Algo.Bfs.tests
30-
]
30+
Backend.Sum.tests ]
3131
|> testSequenced
3232

3333
[<EntryPoint>]

0 commit comments

Comments
 (0)