Skip to content

Commit 9cc2155

Browse files
committed
wip: benchmarks
1 parent 5b94160 commit 9cc2155

File tree

23 files changed

+1117
-1205
lines changed

23 files changed

+1117
-1205
lines changed
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
namespace GraphBLAS.FSharp.Benchmarks
2+
3+
open System.IO
4+
open GraphBLAS.FSharp.Backend.Quotes
5+
open GraphBLAS.FSharp.IO
6+
open BenchmarkDotNet.Attributes
7+
open BenchmarkDotNet.Configs
8+
open BenchmarkDotNet.Columns
9+
open Brahma.FSharp
10+
open GraphBLAS.FSharp.Objects
11+
open GraphBLAS.FSharp.Backend.Objects
12+
open GraphBLAS.FSharp.Backend.Algorithms
13+
open MatrixExtensions
14+
open ArraysExtensions
15+
16+
[<AbstractClass>]
17+
[<IterationCount(10)>]
18+
[<WarmupCount(5)>]
19+
[<Config(typeof<AlgorithmConfig>)>]
20+
type BFSBenchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : struct>(
21+
buildFunToBenchmark,
22+
converter: string -> 'elem,
23+
converterBool,
24+
buildMatrix) =
25+
26+
let mutable funToBenchmark = None
27+
let mutable matrix = Unchecked.defaultof<'matrixT>
28+
let mutable matrixHost = Unchecked.defaultof<_>
29+
30+
let source = 0
31+
32+
member val ResultVector = Unchecked.defaultof<ClArray<'elem option>> with get,set
33+
34+
[<ParamsSource("AvaliableContexts")>]
35+
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
36+
37+
[<ParamsSource("InputMatricesProvider")>]
38+
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
39+
40+
member this.OclContext:ClContext = (fst this.OclContextInfo).ClContext
41+
member this.WorkGroupSize = snd this.OclContextInfo
42+
43+
member this.Processor =
44+
let p = (fst this.OclContextInfo).Queue
45+
p.Error.Add(fun e -> failwithf "%A" e)
46+
p
47+
48+
static member AvaliableContexts = Utils.avaliableContexts
49+
50+
static member InputMatricesProviderBuilder pathToConfig =
51+
let datasetFolder = ""
52+
pathToConfig
53+
|> Utils.getMatricesFilenames
54+
|> Seq.map
55+
(fun matrixFilename ->
56+
printfn "%A" matrixFilename
57+
58+
match Path.GetExtension matrixFilename with
59+
| ".mtx" ->
60+
MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename)
61+
| _ -> failwith "Unsupported matrix format")
62+
63+
member this.FunToBenchmark =
64+
match funToBenchmark with
65+
| None ->
66+
let x = buildFunToBenchmark this.OclContext this.WorkGroupSize
67+
funToBenchmark <- Some x
68+
x
69+
| Some x -> x
70+
71+
member this.ReadMatrix (reader:MtxReader) =
72+
let converter =
73+
match reader.Field with
74+
| Pattern -> converterBool
75+
| _ -> converter
76+
77+
reader.ReadMatrix converter
78+
79+
member this.BFS() =
80+
this.ResultVector <- this.FunToBenchmark this.Processor matrix source
81+
82+
member this.ClearInputMatrix() =
83+
(matrix :> IDeviceMemObject).Dispose this.Processor
84+
85+
member this.ClearResult() =
86+
this.ResultVector.FreeAndWait this.Processor
87+
88+
member this.ReadMatrix() =
89+
let matrixReader = this.InputMatrixReader
90+
matrixHost <- this.ReadMatrix matrixReader
91+
92+
member this.LoadMatrixToGPU() =
93+
matrix <- buildMatrix this.OclContext matrixHost
94+
95+
abstract member GlobalSetup : unit -> unit
96+
97+
abstract member IterationCleanup : unit -> unit
98+
99+
abstract member GlobalCleanup : unit -> unit
100+
101+
abstract member Benchmark : unit -> unit
102+
103+
type BFSBenchmarksWithoutDataTransfer() =
104+
105+
inherit BFSBenchmarks<ClMatrix.CSR<int>, int>(
106+
(fun context wgSize -> BFS.singleSource context ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption wgSize),
107+
int,
108+
(fun _ -> Utils.nextInt (System.Random())),
109+
Matrix.ToBackendCSR)
110+
111+
static member InputMatricesProvider =
112+
BFSBenchmarks<_,_>.InputMatricesProviderBuilder "BFSBenchmarks.txt"
113+
114+
[<GlobalSetup>]
115+
override this.GlobalSetup() =
116+
this.ReadMatrix ()
117+
this.LoadMatrixToGPU ()
118+
119+
[<IterationCleanup>]
120+
override this.IterationCleanup() =
121+
this.ClearResult()
122+
123+
[<GlobalCleanup>]
124+
override this.GlobalCleanup() =
125+
this.ClearInputMatrix()
126+
127+
[<Benchmark>]
128+
override this.Benchmark() =
129+
this.BFS()
130+
this.Processor.PostAndReply(Msg.MsgNotifyMe)
131+
132+
type BFSBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : struct>(
133+
buildFunToBenchmark,
134+
converter: string -> 'elem,
135+
converterBool,
136+
buildMatrix,
137+
resultToHost) =
138+
139+
inherit BFSBenchmarks<'matrixT, 'elem>(
140+
buildFunToBenchmark,
141+
converter,
142+
converterBool,
143+
buildMatrix)
144+
145+
[<GlobalSetup>]
146+
override this.GlobalSetup() =
147+
this.ReadMatrix()
148+
149+
[<GlobalCleanup>]
150+
override this.GlobalCleanup() = ()
151+
152+
[<IterationCleanup>]
153+
override this.IterationCleanup() =
154+
this.ClearInputMatrix()
155+
this.ClearResult()
156+
157+
[<Benchmark>]
158+
override this.Benchmark() =
159+
this.LoadMatrixToGPU()
160+
this.BFS()
161+
this.Processor.PostAndReply Msg.MsgNotifyMe
162+
let res = resultToHost this.ResultVector this.Processor
163+
this.Processor.PostAndReply Msg.MsgNotifyMe
164+

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksBFS.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type BFSBenchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem :
3131

3232
member val ResultVector = Unchecked.defaultof<ClArray<'elem option>> with get,set
3333

34-
[<ParamsSource("AvaliableContexts")>]
34+
[<ParamsSource("AvailableContexts")>]
3535
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
3636

3737
[<ParamsSource("InputMatricesProvider")>]
@@ -45,7 +45,7 @@ type BFSBenchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem :
4545
p.Error.Add(fun e -> failwithf "%A" e)
4646
p
4747

48-
static member AvaliableContexts = Utils.avaliableContexts
48+
static member AvailableContexts = Utils.avaliableContexts
4949

5050
static member InputMatricesProviderBuilder pathToConfig =
5151
let datasetFolder = ""
@@ -159,6 +159,6 @@ type BFSBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> IDeviceMemOb
159159
this.LoadMatrixToGPU()
160160
this.BFS()
161161
this.Processor.PostAndReply Msg.MsgNotifyMe
162-
let res = resultToHost this.ResultVector this.Processor
162+
resultToHost this.ResultVector this.Processor
163163
this.Processor.PostAndReply Msg.MsgNotifyMe
164164

0 commit comments

Comments
 (0)