Skip to content

Commit 7d1ee0e

Browse files
committed
add: Reduce.ByKey.Option.sequintialSegments
1 parent 4b7c3ed commit 7d1ee0e

File tree

12 files changed

+757
-495
lines changed

12 files changed

+757
-495
lines changed

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

Lines changed: 178 additions & 171 deletions
Large diffs are not rendered by default.

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

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ module Matrix =
9999
let transposeInPlace =
100100
CSR.Matrix.transposeInPlace clContext workGroupSize
101101

102-
let rowsToCSR =
103-
Rows.Matrix.toCSR clContext workGroupSize
104-
105102
fun (processor: MailboxProcessor<_>) allocationMode (matrix: ClMatrix<'a>) ->
106103
match matrix with
107104
| ClMatrix.COO m ->
@@ -112,7 +109,7 @@ module Matrix =
112109
m.ToCSR
113110
|> transposeInPlace processor allocationMode
114111
|> ClMatrix.CSR
115-
| _ -> failwith "not yet supported"
112+
| _ -> failwith "Not yet implemented"
116113

117114
/// <summary>
118115
/// Creates a new matrix, represented in COO format, that is equal to the given one.
@@ -156,9 +153,6 @@ module Matrix =
156153
let transposeInPlace =
157154
COO.Matrix.transposeInplace clContext workGroupSize
158155

159-
let rowsToCOO =
160-
Rows.Matrix.toCOO clContext workGroupSize
161-
162156
fun (processor: MailboxProcessor<_>) allocationMode (matrix: ClMatrix<'a>) ->
163157
match matrix with
164158
| ClMatrix.COO _ -> matrix
@@ -170,7 +164,7 @@ module Matrix =
170164
|> toCOOInPlace processor allocationMode
171165
|> transposeInPlace processor
172166
|> ClMatrix.COO
173-
| _ -> failwith "not yet supported"
167+
| _ -> failwith "Not yet implemented"
174168

175169
/// <summary>
176170
/// Creates a new matrix, represented in CSC format, that is equal to the given one.
@@ -199,7 +193,7 @@ module Matrix =
199193
|> COOtoCSR processor allocationMode)
200194
.ToCSC
201195
|> ClMatrix.CSC
202-
| _ -> failwith "not yet supported"
196+
| _ -> failwith "Not yet implemented"
203197

204198
/// <summary>
205199
/// Returns the matrix, represented in CSC format, that is equal to the given one.
@@ -245,6 +239,7 @@ module Matrix =
245239
| ClMatrix.CSC m ->
246240
(mapCSR processor allocationMode m.ToCSR).ToCSC
247241
|> ClMatrix.CSC
242+
| _ -> failwith "Not yet implemented"
248243

249244
let map2 (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize = // TODO()
250245
let map2COO =
@@ -395,19 +390,19 @@ module Matrix =
395390
| ClMatrix.CSR m1, ClMatrix.CSC m2, ClMatrix.COO mask -> runCSRnCSC queue m1 m2 mask |> ClMatrix.COO
396391
| _ -> failwith "Matrix formats are not matching"
397392

398-
let expand
399-
(clContext: ClContext)
400-
workGroupSize
401-
(opAdd: Expr<'c -> 'c -> 'c option>)
402-
(opMul: Expr<'a -> 'b -> 'c option>)
403-
=
404-
405-
let run =
406-
SpGeMM.Expand.run clContext workGroupSize opAdd opMul
407-
408-
fun (processor: MailboxProcessor<_>) allocationMode (leftMatrix: ClMatrix<'a>) (rightMatrix: ClMatrix<'b>) ->
409-
match leftMatrix, rightMatrix with
410-
| ClMatrix.CSR leftMatrix, ClMatrix.CSR rightMatrix ->
411-
run processor allocationMode leftMatrix rightMatrix
412-
|> ClMatrix.COO
413-
| _ -> failwith "Matrix formats are not matching"
393+
// let expand // TODO()
394+
// (clContext: ClContext)
395+
// workGroupSize
396+
// (opAdd: Expr<'c -> 'c -> 'c option>)
397+
// (opMul: Expr<'a -> 'b -> 'c option>)
398+
// =
399+
//
400+
// let run =
401+
// SpGeMM.Expand.run clContext workGroupSize opAdd opMul
402+
//
403+
// fun (processor: MailboxProcessor<_>) allocationMode (leftMatrix: ClMatrix<'a>) (rightMatrix: ClMatrix<'b>) ->
404+
// match leftMatrix, rightMatrix with
405+
// | ClMatrix.CSR leftMatrix, ClMatrix.CSR rightMatrix ->
406+
// run processor allocationMode leftMatrix rightMatrix
407+
// |> ClMatrix.COO
408+
// | _ -> failwith "Matrix formats are not matching"

src/GraphBLAS-sharp.Backend/Matrix/SpGeMM/Expand.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ module Expand =
200200
let reduce (clContext: ClContext) workGroupSize opAdd =
201201

202202
let reduce =
203-
Reduce.ByKey.segmentSequentialOption clContext workGroupSize opAdd // TODO(tests)
203+
Reduce.ByKey.Option.segmentSequential clContext workGroupSize opAdd
204204

205205
let getUniqueBitmap =
206206
ClArray.getUniqueBitmapLastOccurrence clContext workGroupSize

src/GraphBLAS-sharp/Objects/MatrixExtensions.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,4 @@ module MatrixExtensions =
6868
Values = values }
6969

7070
Matrix.CSC result
71+
| _ -> failwith "Not yet implemented"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
module GraphBLAS.FSharp.Tests.Backend.Common.ClArray.Fill
2+
3+
open Expecto
4+
open Brahma.FSharp
5+
open GraphBLAS.FSharp.Backend.Common
6+
open GraphBLAS.FSharp.Test
7+
open GraphBLAS.FSharp.Tests
8+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
9+
open GraphBLAS.FSharp.Backend.Objects.ClContext
10+
11+
let context = Context.defaultContext.ClContext
12+
13+
let processor = Context.defaultContext.Queue
14+
15+
let config =
16+
{ Utils.defaultConfig with
17+
arbitrary = [ typeof<Generators.ArrayAndChunkPositions> ] }
18+
19+
let makeTest<'a> isEqual testFun (value: 'a, targetIndex, count, target: 'a [] ) =
20+
21+
if target.Length > 0 then
22+
23+
let clTarget = context.CreateClArray target
24+
let clValue = context.CreateClCell value
25+
26+
testFun processor clValue 0 0 clTarget
27+
28+
// release
29+
let actual = clTarget.ToHostAndFree processor
30+
31+
// write to target
32+
Array.fill target targetIndex count value
33+
34+
"Results must be the same"
35+
|> Utils.compareArrays isEqual actual target
36+
37+
let createTest<'a> isEqual =
38+
ClArray.fill context Utils.defaultWorkGroupSize
39+
|> makeTest isEqual
40+
|> testPropertyWithConfig config $"test on %A{typeof<'a>}"
41+
42+
let tests =
43+
[ createTest<int> (=)
44+
45+
if Utils.isFloat64Available context.ClDevice then
46+
createTest<float> (=)
47+
48+
createTest<float32> (=)
49+
createTest<bool> (=) ]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module GraphBLAS.FSharp.Tests.Common.Backend.ClArray.Pairwise
2+
3+
open Expecto
4+
open Brahma.FSharp
5+
open GraphBLAS.FSharp.Backend.Common
6+
open GraphBLAS.FSharp.Test
7+
open GraphBLAS.FSharp.Tests
8+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
9+
open GraphBLAS.FSharp.Backend.Objects.ClContext
10+
11+
let context = Context.defaultContext.ClContext
12+
13+
let processor = Context.defaultContext.Queue
14+
15+
let config =
16+
{ Utils.defaultConfig with
17+
arbitrary = [ typeof<Generators.ArrayAndChunkPositions> ] }
18+
19+
let makeTest<'a> isEqual testFun (array: 'a [] ) =
20+
if array.Length > 0 then
21+
22+
let clArray = context.CreateClArray array
23+
24+
let (clFirstActual: ClArray<_>), (clSecondActual: ClArray<_>)
25+
= testFun processor HostInterop clArray
26+
27+
let firstActual = clFirstActual.ToHostAndFree processor
28+
let secondActual = clSecondActual.ToHostAndFree processor
29+
30+
let firstExpected, secondExpected =
31+
Array.pairwise array
32+
|> Array.unzip
33+
34+
"First results must be the same"
35+
|> Utils.compareArrays isEqual firstActual firstExpected
36+
37+
"Second results must be the same"
38+
|> Utils.compareArrays isEqual secondActual secondExpected
39+
40+
let createTest<'a> isEqual =
41+
ClArray.pairwise context Utils.defaultWorkGroupSize
42+
|> makeTest isEqual
43+
|> testPropertyWithConfig config $"test on %A{typeof<'a>}"
44+
45+
let tests =
46+
[ createTest<int> (=)
47+
48+
if Utils.isFloat64Available context.ClDevice then
49+
createTest<float> (=)
50+
51+
createTest<float32> (=)
52+
createTest<bool> (=) ]

0 commit comments

Comments
 (0)