Skip to content

Commit 83c860e

Browse files
committed
BFS sparse and push-pull on int32
1 parent 01c35d3 commit 83c860e

2 files changed

Lines changed: 18 additions & 23 deletions

File tree

  • src/GraphBLAS-sharp.Backend/Algorithms
  • tests/GraphBLAS-sharp.Tests/Backend/Algorithms

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ module internal BFS =
6767
levels
6868

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

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

7979
let zeroCreate =
8080
Vector.zeroCreate clContext workGroupSize
@@ -87,14 +87,14 @@ module internal BFS =
8787
let fillSubVectorTo =
8888
Vector.assignByMaskInPlace Mask.assign clContext workGroupSize
8989

90-
fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix<bool>) (source: int) ->
90+
fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix<'a>) (source: int) ->
9191
let vertexCount = matrix.RowCount
9292

9393
let levels =
9494
zeroCreate queue DeviceOnly vertexCount Dense
9595

9696
let mutable front =
97-
ofList queue DeviceOnly Sparse vertexCount [ source, true ]
97+
ofList queue DeviceOnly Sparse vertexCount [ source, 1 ]
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<bool option -> bool option -> bool option>)
129-
(mul: Expr<bool option -> bool option -> bool option>)
128+
(add: Expr<int option -> int option -> int option>)
129+
(mul: Expr<'a option -> int option -> int 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.SpMSpVBool add mul clContext workGroupSize
138+
Operations.SpMSpV add mul clContext workGroupSize
139139

140140
let zeroCreate =
141141
Vector.zeroCreate clContext workGroupSize
@@ -149,7 +149,7 @@ module internal BFS =
149149
Vector.map2Sparse Mask.complementedOp clContext workGroupSize
150150

151151
let fillSubVectorInPlace =
152-
Vector.assignByMaskInPlace (Mask.assign) clContext workGroupSize
152+
Vector.assignByMaskInPlace Mask.assign clContext workGroupSize
153153

154154
let toSparse = Vector.toSparse clContext workGroupSize
155155

@@ -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<bool>) =
162+
let getNNZ (queue: MailboxProcessor<Msg>) (v: ClVector<int>) =
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<bool>) (source: int) ->
172+
fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix<'a>) (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, true ]
179+
ofList queue DeviceOnly Sparse vertexCount [ source, 1 ]
180180

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

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ let testFixtures (testContext: TestContext) =
2828

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

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

@@ -58,24 +58,19 @@ let testFixtures (testContext: TestContext) =
5858
let matrixHost =
5959
Utils.createMatrixFromArray2D CSR matrix ((=) 0)
6060

61-
let matrixHostBool =
62-
Utils.createMatrixFromArray2D CSR (Array2D.map (fun x -> x <> 0) matrix) ((=) false)
63-
6461
let matrix = matrixHost.ToDevice context
65-
let matrixBool = matrixHostBool.ToDevice context
6662

6763
let res = bfs queue matrix source
6864

69-
let resSparse = bfsSparse queue matrixBool source
65+
let resSparse = bfsSparse queue matrix source
7066

71-
let resPushPull = bfsPushPull queue matrixBool source
67+
let resPushPull = bfsPushPull queue matrix source
7268

7369
let resHost = res.ToHost queue
7470
let resHostSparse = resSparse.ToHost queue
7571
let resHostPushPull = resPushPull.ToHost queue
7672

7773
matrix.Dispose queue
78-
matrixBool.Dispose queue
7974
res.Dispose queue
8075
resSparse.Dispose queue
8176
resPushPull.Dispose queue

0 commit comments

Comments
 (0)