Skip to content

Commit 988672e

Browse files
committed
BFS, SSSP, PR benchmarks
1 parent 735f064 commit 988672e

4 files changed

Lines changed: 160 additions & 4 deletions

File tree

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ open GraphBLAS.FSharp.Objects.ArraysExtensions
1212
open GraphBLAS.FSharp.Backend.Quotes
1313

1414
[<AbstractClass>]
15-
[<IterationCount(100)>]
16-
[<WarmupCount(10)>]
15+
[<IterationCount(10)>]
16+
[<WarmupCount(3)>]
1717
[<Config(typeof<Configs.Matrix>)>]
1818
type Benchmarks<'elem when 'elem : struct>(
1919
buildFunToBenchmark,
@@ -139,6 +139,30 @@ type BFSWithoutTransferBenchmarkInt32() =
139139
static member InputMatrixProvider =
140140
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
141141

142+
type BFSPushPullWithoutTransferBenchmarkInt32() =
143+
144+
inherit WithoutTransferBenchmark<int>(
145+
(Algorithms.BFS.singleSourcePushPull ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
146+
int32,
147+
(fun _ -> Utils.nextInt (System.Random())),
148+
0,
149+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
150+
151+
static member InputMatrixProvider =
152+
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
153+
154+
type SSSPWithoutTransferBenchmarkInt32() =
155+
156+
inherit WithoutTransferBenchmark<int>(
157+
Algorithms.SSSP.singleSource,
158+
int32,
159+
(fun _ -> Utils.nextInt (System.Random())),
160+
0,
161+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
162+
163+
static member InputMatrixProvider =
164+
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
165+
142166
type WithTransferBenchmark<'elem when 'elem : struct>(
143167
buildFunToBenchmark,
144168
converter: string -> 'elem,
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
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.Benchmarks
11+
open GraphBLAS.FSharp.Objects
12+
13+
[<AbstractClass>]
14+
[<IterationCount(10)>]
15+
[<WarmupCount(3)>]
16+
[<Config(typeof<Configs.Matrix>)>]
17+
type Benchmarks(
18+
buildFunToBenchmark,
19+
converter: string -> float32,
20+
binaryConverter)
21+
=
22+
23+
let mutable funToBenchmark = None
24+
let mutable matrix = Unchecked.defaultof<ClMatrix.CSR<float32>>
25+
let mutable matrixPrepared = Unchecked.defaultof<ClMatrix.CSR<float32>>
26+
let mutable matrixHost = Unchecked.defaultof<_>
27+
28+
member val Result = Unchecked.defaultof<ClArray<float32 option>> with get,set
29+
30+
[<ParamsSource("AvailableContexts")>]
31+
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
32+
33+
[<ParamsSource("InputMatrixProvider")>]
34+
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
35+
36+
member this.OclContext = (fst this.OclContextInfo).ClContext
37+
member this.WorkGroupSize = snd this.OclContextInfo
38+
39+
member this.Processor =
40+
let p = (fst this.OclContextInfo).Queue
41+
p.Error.Add(fun e -> failwithf "%A" e)
42+
p
43+
44+
static member AvailableContexts = Utils.availableContexts
45+
46+
static member InputMatrixProviderBuilder pathToConfig =
47+
let datasetFolder = ""
48+
pathToConfig
49+
|> Utils.getMatricesFilenames
50+
|> Seq.map
51+
(fun matrixFilename ->
52+
printfn "%A" matrixFilename
53+
54+
match Path.GetExtension matrixFilename with
55+
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename)
56+
| _ -> failwith "Unsupported matrix format")
57+
58+
member this.FunToBenchmark =
59+
match funToBenchmark with
60+
| None ->
61+
let x = buildFunToBenchmark this.OclContext this.WorkGroupSize
62+
funToBenchmark <- Some x
63+
x
64+
| Some x -> x
65+
66+
member this.PageRank() =
67+
this.Result <- this.FunToBenchmark this.Processor matrixPrepared
68+
69+
member this.ClearInputMatrix() =
70+
(matrix :> IDeviceMemObject).Dispose this.Processor
71+
72+
member this.ClearPreparedMatrix() =
73+
(matrixPrepared :> IDeviceMemObject).Dispose this.Processor
74+
75+
member this.ClearResult() = this.Result.FreeAndWait this.Processor
76+
77+
member this.ReadMatrix() =
78+
let converter =
79+
match this.InputMatrixReader.Field with
80+
| Pattern -> binaryConverter
81+
| _ -> converter
82+
83+
matrixHost <- this.InputMatrixReader.ReadMatrix converter
84+
85+
member this.LoadMatrixToGPU() =
86+
matrix <- matrixHost.ToCSR.ToDevice this.OclContext
87+
88+
member this.PrepareMatrix() =
89+
matrixPrepared <- Algorithms.PageRank.prepareMatrix this.OclContext this.WorkGroupSize this.Processor matrix
90+
91+
abstract member GlobalSetup : unit -> unit
92+
93+
abstract member IterationCleanup : unit -> unit
94+
95+
abstract member GlobalCleanup : unit -> unit
96+
97+
abstract member Benchmark : unit -> unit
98+
99+
type PageRankWithoutTransferBenchmarkFloat32() =
100+
101+
inherit Benchmarks(
102+
Algorithms.PageRank.run,
103+
float32,
104+
(fun _ -> float32 <| Utils.nextInt (System.Random()))
105+
)
106+
107+
static member InputMatrixProvider =
108+
Benchmarks.InputMatrixProviderBuilder "BFSBenchmarks.txt"
109+
110+
[<GlobalSetup>]
111+
override this.GlobalSetup() =
112+
this.ReadMatrix()
113+
this.LoadMatrixToGPU()
114+
this.Processor.PostAndReply(Msg.MsgNotifyMe)
115+
this.PrepareMatrix()
116+
this.ClearInputMatrix()
117+
118+
[<IterationCleanup>]
119+
override this.IterationCleanup() =
120+
this.ClearResult()
121+
122+
[<GlobalCleanup>]
123+
override this.GlobalCleanup() =
124+
this.ClearPreparedMatrix()
125+
126+
[<Benchmark>]
127+
override this.Benchmark() =
128+
this.PageRank()
129+
this.Processor.PostAndReply(Msg.MsgNotifyMe)

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -25,6 +25,7 @@
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>

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ open BenchmarkDotNet.Running
44
[<EntryPoint>]
55
let main argv =
66
let benchmarks =
7-
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkInt32> |]
7+
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkInt32>
8+
typeof<Algorithms.BFS.BFSPushPullWithoutTransferBenchmarkInt32>
9+
typeof<Algorithms.PageRank.PageRankWithoutTransferBenchmarkFloat32> |]
810

911
benchmarks.Run argv |> ignore
1012
0

0 commit comments

Comments
 (0)