Skip to content

Commit 7fe8ff3

Browse files
authored
Merge pull request SparseLinearAlgebra#88 from kirillgarbar/dev
PageRank
2 parents 4a70218 + 6de410f commit 7fe8ff3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+736
-137
lines changed

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

Lines changed: 40 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace GraphBLAS.FSharp.Benchmarks.Algorithms.BFS
1+
namespace GraphBLAS.FSharp.Benchmarks.Algorithms.BFS
22

33
open System.IO
44
open BenchmarkDotNet.Attributes
@@ -9,11 +9,12 @@ open GraphBLAS.FSharp.IO
99
open GraphBLAS.FSharp.Benchmarks
1010
open GraphBLAS.FSharp.Objects
1111
open GraphBLAS.FSharp.Objects.ArraysExtensions
12+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
1213
open GraphBLAS.FSharp.Backend.Quotes
1314

1415
[<AbstractClass>]
15-
[<IterationCount(100)>]
16-
[<WarmupCount(10)>]
16+
[<IterationCount(10)>]
17+
[<WarmupCount(3)>]
1718
[<Config(typeof<Configs.Matrix>)>]
1819
type Benchmarks<'elem when 'elem : struct>(
1920
buildFunToBenchmark,
@@ -27,7 +28,7 @@ type Benchmarks<'elem when 'elem : struct>(
2728
let mutable matrix = Unchecked.defaultof<ClMatrix<'elem>>
2829
let mutable matrixHost = Unchecked.defaultof<_>
2930

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

3233
[<ParamsSource("AvailableContexts")>]
3334
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
@@ -113,10 +114,12 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
113114
override this.GlobalSetup() =
114115
this.ReadMatrix()
115116
this.LoadMatrixToGPU()
117+
finish this.Processor
116118

117119
[<IterationCleanup>]
118120
override this.IterationCleanup() =
119121
this.ClearResult()
122+
finish this.Processor
120123

121124
[<GlobalCleanup>]
122125
override this.GlobalCleanup() =
@@ -127,10 +130,34 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
127130
this.BFS()
128131
this.Processor.PostAndReply Msg.MsgNotifyMe
129132

130-
type BFSWithoutTransferBenchmarkInt32() =
133+
type BFSWithoutTransferBenchmarkBool() =
134+
135+
inherit WithoutTransferBenchmark<bool>(
136+
(Algorithms.BFS.singleSource ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption),
137+
(fun _ -> true),
138+
(fun _ -> true),
139+
0,
140+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
141+
142+
static member InputMatrixProvider =
143+
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
144+
145+
type BFSPushPullWithoutTransferBenchmarkBool() =
146+
147+
inherit WithoutTransferBenchmark<bool>(
148+
(Algorithms.BFS.singleSourcePushPull ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption),
149+
(fun _ -> true),
150+
(fun _ -> true),
151+
0,
152+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
153+
154+
static member InputMatrixProvider =
155+
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
156+
157+
type SSSPWithoutTransferBenchmarkInt32() =
131158

132159
inherit WithoutTransferBenchmark<int>(
133-
(Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
160+
Algorithms.SSSP.run,
134161
int32,
135162
(fun _ -> Utils.nextInt (System.Random())),
136163
0,
@@ -156,6 +183,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
156183
[<GlobalSetup>]
157184
override this.GlobalSetup() =
158185
this.ReadMatrix()
186+
finish this.Processor
159187

160188
[<GlobalCleanup>]
161189
override this.GlobalCleanup() =
@@ -165,6 +193,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
165193
override this.IterationCleanup() =
166194
this.ClearInputMatrix()
167195
this.ClearResult()
196+
finish this.Processor
168197

169198
[<Benchmark>]
170199
override this.Benchmark() =
@@ -176,12 +205,12 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
176205
this.Processor.PostAndReply Msg.MsgNotifyMe
177206
| _ -> failwith "Impossible"
178207

179-
type BFSWithTransferBenchmarkInt32() =
208+
type BFSWithTransferBenchmarkBool() =
180209

181-
inherit WithTransferBenchmark<int>(
182-
(Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
183-
int32,
184-
(fun _ -> Utils.nextInt (System.Random())),
210+
inherit WithTransferBenchmark<bool>(
211+
(Algorithms.BFS.singleSource ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption),
212+
(fun _ -> true),
213+
(fun _ -> true),
185214
0,
186215
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
187216

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
namespace GraphBLAS.FSharp.Benchmarks.Algorithms.PageRank
2+
3+
open System.IO
4+
open BenchmarkDotNet.Attributes
5+
open GraphBLAS.FSharp
6+
open GraphBLAS.FSharp.IO
7+
open Brahma.FSharp
8+
open Microsoft.FSharp.Core
9+
open GraphBLAS.FSharp.Objects.ArraysExtensions
10+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
11+
open GraphBLAS.FSharp.Benchmarks
12+
open GraphBLAS.FSharp.Objects
13+
14+
[<AbstractClass>]
15+
[<IterationCount(10)>]
16+
[<WarmupCount(3)>]
17+
[<Config(typeof<Configs.Matrix>)>]
18+
type Benchmarks(
19+
buildFunToBenchmark,
20+
converter: string -> float32,
21+
binaryConverter,
22+
buildMatrix)
23+
=
24+
25+
let mutable funToBenchmark = None
26+
let mutable matrix = Unchecked.defaultof<ClMatrix<float32>>
27+
let mutable matrixPrepared = Unchecked.defaultof<Algorithms.PageRank.PageRankMatrix>
28+
let mutable matrixHost = Unchecked.defaultof<_>
29+
30+
member val Result = Unchecked.defaultof<ClVector<float32>> with get,set
31+
32+
[<ParamsSource("AvailableContexts")>]
33+
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
34+
35+
[<ParamsSource("InputMatrixProvider")>]
36+
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
37+
38+
member this.OclContext = (fst this.OclContextInfo).ClContext
39+
member this.WorkGroupSize = snd this.OclContextInfo
40+
41+
member this.Processor =
42+
let p = (fst this.OclContextInfo).Queue
43+
p.Error.Add(fun e -> failwithf "%A" e)
44+
p
45+
46+
static member AvailableContexts = Utils.availableContexts
47+
48+
static member InputMatrixProviderBuilder pathToConfig =
49+
let datasetFolder = ""
50+
pathToConfig
51+
|> Utils.getMatricesFilenames
52+
|> Seq.map
53+
(fun matrixFilename ->
54+
printfn "%A" matrixFilename
55+
56+
match Path.GetExtension matrixFilename with
57+
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename)
58+
| _ -> failwith "Unsupported matrix format")
59+
60+
member this.FunToBenchmark =
61+
match funToBenchmark with
62+
| None ->
63+
let x = buildFunToBenchmark this.OclContext this.WorkGroupSize
64+
funToBenchmark <- Some x
65+
x
66+
| Some x -> x
67+
68+
member this.PageRank() =
69+
this.Result <- this.FunToBenchmark this.Processor matrixPrepared Constants.PageRank.accuracy
70+
71+
member this.ClearInputMatrix() =
72+
matrix.Dispose this.Processor
73+
74+
member this.ClearPreparedMatrix() =
75+
matrixPrepared.Dispose this.Processor
76+
77+
member this.ClearResult() = this.Result.Dispose this.Processor
78+
79+
member this.ReadMatrix() =
80+
let converter =
81+
match this.InputMatrixReader.Field with
82+
| Pattern -> binaryConverter
83+
| _ -> converter
84+
85+
matrixHost <- this.InputMatrixReader.ReadMatrix converter
86+
87+
member this.LoadMatrixToGPU() =
88+
matrix <- buildMatrix this.OclContext matrixHost
89+
90+
member this.PrepareMatrix() =
91+
matrixPrepared <- Algorithms.PageRank.prepareMatrix this.OclContext this.WorkGroupSize this.Processor matrix
92+
93+
abstract member GlobalSetup : unit -> unit
94+
95+
abstract member IterationCleanup : unit -> unit
96+
97+
abstract member GlobalCleanup : unit -> unit
98+
99+
abstract member Benchmark : unit -> unit
100+
101+
type PageRankWithoutTransferBenchmarkFloat32() =
102+
103+
inherit Benchmarks(
104+
Algorithms.PageRank.run,
105+
float32,
106+
(fun _ -> float32 <| Utils.nextInt (System.Random())),
107+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
108+
109+
static member InputMatrixProvider =
110+
Benchmarks.InputMatrixProviderBuilder "BFSBenchmarks.txt"
111+
112+
[<GlobalSetup>]
113+
override this.GlobalSetup() =
114+
this.ReadMatrix()
115+
this.LoadMatrixToGPU()
116+
finish this.Processor
117+
this.PrepareMatrix()
118+
this.ClearInputMatrix()
119+
finish this.Processor
120+
121+
[<IterationCleanup>]
122+
override this.IterationCleanup() =
123+
this.ClearResult()
124+
finish this.Processor
125+
126+
[<GlobalCleanup>]
127+
override this.GlobalCleanup() =
128+
this.ClearPreparedMatrix()
129+
130+
[<Benchmark>]
131+
override this.Benchmark() =
132+
this.PageRank()
133+
finish this.Processor

benchmarks/GraphBLAS-sharp.Benchmarks/GraphBLAS-sharp.Benchmarks.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525
<Compile Include="Matrix/Map2/MathNET.fs" />
2626
<Compile Include="Vector/Map2.fs" />
2727
<Compile Include="Algorithms/BFS.fs" />
28+
<Compile Include="Algorithms/PageRank.fs" />
2829
<Compile Include="Program.fs" />
2930
<Folder Include="Datasets" />
3031
</ItemGroup>
3132
<Import Project="..\..\.paket\Paket.Restore.targets" />
32-
</Project>
33+
</Project>

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open GraphBLAS.FSharp.IO
88
open GraphBLAS.FSharp.Objects
99
open GraphBLAS.FSharp.Objects.MatrixExtensions
1010
open GraphBLAS.FSharp.Objects.ClContextExtensions
11+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
1112
open GraphBLAS.FSharp.Backend.Quotes
1213
open GraphBLAS.FSharp.Benchmarks
1314

@@ -118,12 +119,12 @@ module WithoutTransfer =
118119
override this.GlobalSetup() =
119120
this.ReadMatrices ()
120121
this.LoadMatricesToGPU ()
121-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
122+
finish this.Processor
122123

123124
[<Benchmark>]
124125
override this.Benchmark () =
125126
this.EWiseAddition()
126-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
127+
finish this.Processor
127128

128129
[<IterationCleanup>]
129130
override this.IterationCleanup () =
@@ -251,6 +252,7 @@ module WithTransfer =
251252
[<GlobalSetup>]
252253
override this.GlobalSetup() =
253254
this.ReadMatrices()
255+
finish this.Processor
254256

255257
[<GlobalCleanup>]
256258
override this.GlobalCleanup() = ()
@@ -259,6 +261,7 @@ module WithTransfer =
259261
override this.IterationCleanup() =
260262
this.ClearInputMatrices()
261263
this.ClearResult()
264+
finish this.Processor
262265

263266
[<Benchmark>]
264267
override this.Benchmark() =

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open GraphBLAS.FSharp.IO
88
open GraphBLAS.FSharp.Backend.Quotes
99
open GraphBLAS.FSharp.Objects
1010
open GraphBLAS.FSharp.Objects.ClContextExtensions
11+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
1112
open GraphBLAS.FSharp.Benchmarks
1213

1314
[<AbstractClass>]
@@ -115,15 +116,17 @@ module WithoutTransfer =
115116
override this.GlobalSetup() =
116117
this.ReadMatrices()
117118
this.LoadMatricesToGPU()
119+
finish this.Processor
118120

119121
[<Benchmark>]
120122
override this.Benchmark() =
121123
this.Mxm()
122-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
124+
finish this.Processor
123125

124126
[<IterationCleanup>]
125127
override this.IterationCleanup () =
126128
this.ClearResult()
129+
finish this.Processor
127130

128131
[<GlobalCleanup>]
129132
override this.GlobalCleanup () =

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ open Brahma.FSharp
88
open GraphBLAS.FSharp
99
open GraphBLAS.FSharp.Objects
1010
open GraphBLAS.FSharp.Objects.ClContextExtensions
11+
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
1112
open GraphBLAS.FSharp.Benchmarks
1213

1314
[<AbstractClass>]
@@ -152,15 +153,17 @@ type MxmBenchmarksMultiplicationOnly<'elem when 'elem : struct>(
152153
this.ReadMatrices ()
153154
this.LoadMatricesToGPU ()
154155
this.ConvertSecondMatrixToCSC()
156+
finish this.Processor
155157

156158
[<Benchmark>]
157159
override this.Benchmark () =
158160
this.Mxm()
159-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
161+
finish this.Processor
160162

161163
[<IterationCleanup>]
162164
override this.IterationCleanup () =
163165
this.ClearResult()
166+
finish this.Processor
164167

165168
[<GlobalCleanup>]
166169
override this.GlobalCleanup () =
@@ -182,18 +185,20 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>(
182185
override this.GlobalSetup() =
183186
this.ReadMatrices()
184187
this.LoadMatricesToGPU ()
188+
finish this.Processor
185189

186190
[<Benchmark>]
187191
override this.Benchmark() =
188192
this.ConvertSecondMatrixToCSC()
189193
this.Mxm()
190-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
194+
finish this.Processor
191195

192196

193197
[<IterationCleanup>]
194198
override this.IterationCleanup() =
195199
this.ClearResult()
196200
this.ConvertSecondMatrixToCSR()
201+
finish this.Processor
197202

198203
[<GlobalCleanup>]
199204
override this.GlobalCleanup() =

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open BenchmarkDotNet.Running
44
[<EntryPoint>]
55
let main argv =
66
let benchmarks =
7-
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkInt32> |]
7+
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkBool> |]
88

99
benchmarks.Run argv |> ignore
1010
0

0 commit comments

Comments
 (0)