Skip to content

Commit 9e8b9bc

Browse files
committed
refactor: benchmarks
1 parent 9cc2155 commit 9e8b9bc

File tree

13 files changed

+437
-1707
lines changed

13 files changed

+437
-1707
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,41 @@
11
namespace GraphBLAS.FSharp.Benchmarks
22

33
open System.IO
4+
open BenchmarkDotNet.Attributes
5+
open GraphBLAS.FSharp
46
open GraphBLAS.FSharp.Backend.Quotes
57
open GraphBLAS.FSharp.IO
6-
open BenchmarkDotNet.Attributes
7-
open BenchmarkDotNet.Configs
8-
open BenchmarkDotNet.Columns
98
open Brahma.FSharp
10-
open GraphBLAS.FSharp.Objects
9+
open Backend.Algorithms.BFS
10+
open Microsoft.FSharp.Core
11+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
12+
open GraphBLAS.FSharp.Benchmarks
1113
open GraphBLAS.FSharp.Backend.Objects
12-
open GraphBLAS.FSharp.Backend.Algorithms
13-
open MatrixExtensions
14-
open ArraysExtensions
1514

1615
[<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) =
16+
[<IterationCount(100)>]
17+
[<WarmupCount(10)>]
18+
[<Config(typeof<Configs.SingleMatrixConfig>)>]
19+
type BFSBenchmarks<'elem when 'elem : struct>(
20+
buildFunToBenchmark,
21+
converter: string -> 'elem,
22+
binaryConverter,
23+
vertex: int)
24+
=
2525

2626
let mutable funToBenchmark = None
27-
let mutable matrix = Unchecked.defaultof<'matrixT>
27+
let mutable matrix = Unchecked.defaultof<ClMatrix.CSR<'elem>>
2828
let mutable matrixHost = Unchecked.defaultof<_>
2929

30-
let source = 0
31-
32-
member val ResultVector = Unchecked.defaultof<ClArray<'elem option>> with get,set
30+
member val ResultLevels = Unchecked.defaultof<ClArray<'elem option>> with get,set
3331

3432
[<ParamsSource("AvailableContexts")>]
3533
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
3634

37-
[<ParamsSource("InputMatricesProvider")>]
35+
[<ParamsSource("InputMatrixProvider")>]
3836
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
3937

40-
member this.OclContext:ClContext = (fst this.OclContextInfo).ClContext
38+
member this.OclContext = (fst this.OclContextInfo).ClContext
4139
member this.WorkGroupSize = snd this.OclContextInfo
4240

4341
member this.Processor =
@@ -47,17 +45,16 @@ type BFSBenchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem :
4745

4846
static member AvailableContexts = Utils.avaliableContexts
4947

50-
static member InputMatricesProviderBuilder pathToConfig =
51-
let datasetFolder = ""
48+
static member InputMatrixProviderBuilder pathToConfig =
49+
let datasetFolder = "BFS"
5250
pathToConfig
5351
|> Utils.getMatricesFilenames
5452
|> Seq.map
5553
(fun matrixFilename ->
5654
printfn "%A" matrixFilename
5755

5856
match Path.GetExtension matrixFilename with
59-
| ".mtx" ->
60-
MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename)
57+
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename)
6158
| _ -> failwith "Unsupported matrix format")
6259

6360
member this.FunToBenchmark =
@@ -68,29 +65,24 @@ type BFSBenchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem :
6865
x
6966
| Some x -> x
7067

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-
7968
member this.BFS() =
80-
this.ResultVector <- this.FunToBenchmark this.Processor matrix source
69+
this.ResultLevels <- this.FunToBenchmark this.Processor matrix vertex
8170

8271
member this.ClearInputMatrix() =
8372
(matrix :> IDeviceMemObject).Dispose this.Processor
8473

85-
member this.ClearResult() =
86-
this.ResultVector.FreeAndWait this.Processor
74+
member this.ClearResult() = this.ResultLevels.FreeAndWait this.Processor
8775

8876
member this.ReadMatrix() =
89-
let matrixReader = this.InputMatrixReader
90-
matrixHost <- this.ReadMatrix matrixReader
77+
let converter =
78+
match this.InputMatrixReader.Field with
79+
| Pattern -> binaryConverter
80+
| _ -> converter
81+
82+
matrixHost <- this.InputMatrixReader.ReadMatrix converter
9183

9284
member this.LoadMatrixToGPU() =
93-
matrix <- buildMatrix this.OclContext matrixHost
85+
matrix <- matrixHost.ToCSR.ToDevice this.OclContext
9486

9587
abstract member GlobalSetup : unit -> unit
9688

@@ -100,21 +92,22 @@ type BFSBenchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem :
10092

10193
abstract member Benchmark : unit -> unit
10294

103-
type BFSBenchmarksWithoutDataTransfer() =
95+
type BFSBenchmarksWithoutDataTransfer<'elem when 'elem : struct>(
96+
buildFunToBenchmark,
97+
converter: string -> 'elem,
98+
boolConverter,
99+
vertex) =
104100

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"
101+
inherit BFSBenchmarks<'elem>(
102+
buildFunToBenchmark,
103+
converter,
104+
boolConverter,
105+
vertex)
113106

114107
[<GlobalSetup>]
115108
override this.GlobalSetup() =
116-
this.ReadMatrix ()
117-
this.LoadMatrixToGPU ()
109+
this.ReadMatrix()
110+
this.LoadMatrixToGPU()
118111

119112
[<IterationCleanup>]
120113
override this.IterationCleanup() =
@@ -127,27 +120,27 @@ type BFSBenchmarksWithoutDataTransfer() =
127120
[<Benchmark>]
128121
override this.Benchmark() =
129122
this.BFS()
130-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
123+
this.Processor.PostAndReply Msg.MsgNotifyMe
131124

132-
type BFSBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : struct>(
133-
buildFunToBenchmark,
134-
converter: string -> 'elem,
135-
converterBool,
136-
buildMatrix,
137-
resultToHost) =
125+
type BFSBenchmarksWithTransfer<'elem when 'elem : struct>(
126+
buildFunToBenchmark,
127+
converter: string -> 'elem,
128+
boolConverter,
129+
vertex) =
138130

139-
inherit BFSBenchmarks<'matrixT, 'elem>(
131+
inherit BFSBenchmarks<'elem>(
140132
buildFunToBenchmark,
141133
converter,
142-
converterBool,
143-
buildMatrix)
134+
boolConverter,
135+
vertex)
144136

145137
[<GlobalSetup>]
146138
override this.GlobalSetup() =
147139
this.ReadMatrix()
148140

149141
[<GlobalCleanup>]
150-
override this.GlobalCleanup() = ()
142+
override this.GlobalCleanup() =
143+
this.ClearResult()
151144

152145
[<IterationCleanup>]
153146
override this.IterationCleanup() =
@@ -158,7 +151,28 @@ type BFSBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> IDeviceMemOb
158151
override this.Benchmark() =
159152
this.LoadMatrixToGPU()
160153
this.BFS()
154+
this.ResultLevels.ToHost this.Processor |> ignore
161155
this.Processor.PostAndReply Msg.MsgNotifyMe
162-
resultToHost this.ResultVector this.Processor
163-
this.Processor.PostAndReply Msg.MsgNotifyMe
156+
157+
type BFSIntWithoutTransferBenchmark() =
158+
159+
inherit BFSBenchmarksWithoutDataTransfer<int>(
160+
(fun context -> singleSource context ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
161+
int32,
162+
(fun _ -> Utils.nextInt (System.Random())),
163+
0)
164+
165+
static member InputMatrixProvider =
166+
BFSBenchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
167+
168+
type BFSIntWithTransferBenchmark() =
169+
170+
inherit BFSBenchmarksWithTransfer<int>(
171+
(fun context -> singleSource context ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
172+
int32,
173+
(fun _ -> Utils.nextInt (System.Random())),
174+
0)
175+
176+
static member InputMatrixProvider =
177+
BFSBenchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
164178

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

Lines changed: 0 additions & 164 deletions
This file was deleted.

0 commit comments

Comments
 (0)