Skip to content

Commit b278b7a

Browse files
committed
BFS on bool
1 parent faf242c commit b278b7a

File tree

4 files changed

+40
-38
lines changed
  • benchmarks/GraphBLAS-sharp.Benchmarks
  • src/GraphBLAS-sharp.Backend/Algorithms
  • tests/GraphBLAS-sharp.Tests/Backend/Algorithms

4 files changed

+40
-38
lines changed

benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Benchmarks<'elem when 'elem : struct>(
2727
let mutable matrix = Unchecked.defaultof<ClMatrix<'elem>>
2828
let mutable matrixHost = Unchecked.defaultof<_>
2929

30-
member val ResultLevels = Unchecked.defaultof<ClVector<'elem>> with get,set
30+
member val ResultLevels = Unchecked.defaultof<ClVector<int>> with get,set
3131

3232
[<ParamsSource("AvailableContexts")>]
3333
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
@@ -127,24 +127,24 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
127127
this.BFS()
128128
this.Processor.PostAndReply Msg.MsgNotifyMe
129129

130-
type BFSWithoutTransferBenchmarkInt32() =
130+
type BFSWithoutTransferBenchmarkBool() =
131131

132-
inherit WithoutTransferBenchmark<int>(
133-
(Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
134-
int32,
135-
(fun _ -> Utils.nextInt (System.Random())),
132+
inherit WithoutTransferBenchmark<bool>(
133+
(Algorithms.BFS.singleSource ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption),
134+
(fun _ -> true),
135+
(fun _ -> true),
136136
0,
137137
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
138138

139139
static member InputMatrixProvider =
140140
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
141141

142-
type BFSPushPullWithoutTransferBenchmarkInt32() =
142+
type BFSPushPullWithoutTransferBenchmarkBool() =
143143

144-
inherit WithoutTransferBenchmark<int>(
145-
(Algorithms.BFS.singleSourcePushPull ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
146-
int32,
147-
(fun _ -> Utils.nextInt (System.Random())),
144+
inherit WithoutTransferBenchmark<bool>(
145+
(Algorithms.BFS.singleSourcePushPull ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption),
146+
(fun _ -> true),
147+
(fun _ -> true),
148148
0,
149149
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
150150

@@ -200,12 +200,12 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
200200
this.Processor.PostAndReply Msg.MsgNotifyMe
201201
| _ -> failwith "Impossible"
202202

203-
type BFSWithTransferBenchmarkInt32() =
203+
type BFSWithTransferBenchmarkBool() =
204204

205-
inherit WithTransferBenchmark<int>(
206-
(Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
207-
int32,
208-
(fun _ -> Utils.nextInt (System.Random())),
205+
inherit WithTransferBenchmark<bool>(
206+
(Algorithms.BFS.singleSource ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption),
207+
(fun _ -> true),
208+
(fun _ -> true),
209209
0,
210210
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
211211

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ open BenchmarkDotNet.Running
44
[<EntryPoint>]
55
let main argv =
66
let benchmarks =
7-
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkInt32>
8-
typeof<Algorithms.BFS.BFSPushPullWithoutTransferBenchmarkInt32>
7+
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkBool>
8+
typeof<Algorithms.BFS.BFSPushPullWithoutTransferBenchmarkBool>
99
typeof<Algorithms.PageRank.PageRankWithoutTransferBenchmarkFloat32> |]
1010

1111
benchmarks.Run argv |> ignore

src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ open GraphBLAS.FSharp.Objects.ClCellExtensions
1111

1212
module internal BFS =
1313
let singleSource
14-
(add: Expr<int option -> int option -> int option>)
15-
(mul: Expr<'a option -> int option -> int option>)
14+
(add: Expr<bool option -> bool option -> bool option>)
15+
(mul: Expr<bool option -> bool option -> bool option>)
1616
(clContext: ClContext)
1717
workGroupSize
1818
=
@@ -41,7 +41,7 @@ module internal BFS =
4141
zeroCreate queue DeviceOnly vertexCount Dense
4242

4343
let front =
44-
ofList queue DeviceOnly Dense vertexCount [ source, 1 ]
44+
ofList queue DeviceOnly Dense vertexCount [ source, true ]
4545

4646
let mutable level = 0
4747
let mutable stop = false
@@ -67,14 +67,14 @@ module internal BFS =
6767
levels
6868

6969
let singleSourceSparse
70-
(add: Expr<int option -> int option -> int option>)
71-
(mul: Expr<'a option -> int option -> int option>)
70+
(add: Expr<bool option -> bool option -> bool option>)
71+
(mul: Expr<bool option -> bool option -> bool option>)
7272
(clContext: ClContext)
7373
workGroupSize
7474
=
7575

7676
let spMSpV =
77-
Operations.SpMSpV add mul clContext workGroupSize
77+
Operations.SpMSpVBool add mul clContext workGroupSize
7878

7979
let zeroCreate =
8080
Vector.zeroCreate clContext workGroupSize
@@ -94,7 +94,7 @@ module internal BFS =
9494
zeroCreate queue DeviceOnly vertexCount Dense
9595

9696
let mutable front =
97-
ofList queue DeviceOnly Sparse vertexCount [ source, 1 ]
97+
ofList queue DeviceOnly Sparse vertexCount [ source, true ]
9898

9999
let mutable level = 0
100100
let mutable stop = false
@@ -125,8 +125,8 @@ module internal BFS =
125125

126126

127127
let singleSourcePushPull
128-
(add: Expr<int option -> int option -> int option>)
129-
(mul: Expr<'a option -> int option -> int option>)
128+
(add: Expr<bool option -> bool option -> bool option>)
129+
(mul: Expr<bool option -> bool option -> bool option>)
130130
(clContext: ClContext)
131131
workGroupSize
132132
=
@@ -135,7 +135,7 @@ module internal BFS =
135135
Operations.SpMVInPlace add mul clContext workGroupSize
136136

137137
let spMSpV =
138-
Operations.SpMSpV add mul clContext workGroupSize
138+
Operations.SpMSpVBool add mul clContext workGroupSize
139139

140140
let zeroCreate =
141141
Vector.zeroCreate clContext workGroupSize
@@ -159,7 +159,7 @@ module internal BFS =
159159
ClArray.count Predicates.isSome clContext workGroupSize
160160

161161
//Push or pull functions
162-
let getNNZ (queue: MailboxProcessor<Msg>) (v: ClVector<int>) =
162+
let getNNZ (queue: MailboxProcessor<Msg>) (v: ClVector<bool>) =
163163
match v with
164164
| ClVector.Sparse v -> v.NNZ
165165
| ClVector.Dense v -> countNNZ queue v
@@ -169,14 +169,14 @@ module internal BFS =
169169
let push nnz size =
170170
(float32 nnz) / (float32 size) <= SPARSITY
171171

172-
fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix<'a>) (source: int) ->
172+
fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix<bool>) (source: int) ->
173173
let vertexCount = matrix.RowCount
174174

175175
let levels =
176176
zeroCreate queue DeviceOnly vertexCount Dense
177177

178178
let mutable frontier =
179-
ofList queue DeviceOnly Sparse vertexCount [ source, 1 ]
179+
ofList queue DeviceOnly Sparse vertexCount [ source, true ]
180180

181181
let mutable level = 0
182182
let mutable stop = false

tests/GraphBLAS-sharp.Tests/Backend/Algorithms/BFS.fs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,30 @@ let testFixtures (testContext: TestContext) =
2121

2222
let bfs =
2323
Algorithms.BFS.singleSource
24-
ArithmeticOperations.intSumOption
25-
ArithmeticOperations.intMulOption
24+
ArithmeticOperations.boolSumOption
25+
ArithmeticOperations.boolMulOption
2626
context
2727
workGroupSize
2828

2929
let bfsSparse =
3030
Algorithms.BFS.singleSourceSparse
31-
ArithmeticOperations.intSumOption
32-
ArithmeticOperations.intMulOption
31+
ArithmeticOperations.boolSumOption
32+
ArithmeticOperations.boolMulOption
3333
context
3434
workGroupSize
3535

3636
let bfsPushPull =
3737
Algorithms.BFS.singleSourcePushPull
38-
ArithmeticOperations.intSumOption
39-
ArithmeticOperations.intMulOption
38+
ArithmeticOperations.boolSumOption
39+
ArithmeticOperations.boolMulOption
4040
context
4141
workGroupSize
4242

4343
testPropertyWithConfig config testName
4444
<| fun (matrix: int [,]) ->
4545

46+
let matrixBool = Array2D.map (fun x -> x <> 0) matrix
47+
4648
let graph = undirectedFromArray2D matrix 0
4749

4850
let largestComponent =
@@ -56,7 +58,7 @@ let testFixtures (testContext: TestContext) =
5658
|> Utils.createArrayFromDictionary (Array2D.length1 matrix) 0
5759

5860
let matrixHost =
59-
Utils.createMatrixFromArray2D CSR matrix ((=) 0)
61+
Utils.createMatrixFromArray2D CSR matrixBool ((=) false)
6062

6163
let matrix = matrixHost.ToDevice context
6264

0 commit comments

Comments
 (0)