Skip to content

Commit ff9022a

Browse files
committed
Add benchs refactorig; remove toHost bench
1 parent 7ef2108 commit ff9022a

4 files changed

Lines changed: 96 additions & 206 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksEWiseAdd.fs

Lines changed: 12 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
namespace GraphBLAS.FSharp.Benchmarks
22

33
open System.IO
4+
open System.Text.RegularExpressions
45
open GraphBLAS.FSharp
56
open GraphBLAS.FSharp.Predefined
67
open GraphBLAS.FSharp.MatrixBackend
78
open BenchmarkDotNet.Attributes
8-
open BenchmarkDotNet.Engines
99
open BenchmarkDotNet.Configs
1010
open BenchmarkDotNet.Columns
1111
open BenchmarkDotNet.Filters
12-
open BenchmarkDotNet.Jobs
13-
open BenchmarkDotNet.Order
1412
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
1513
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
1614
open OpenCL.Net
17-
open Brahma.OpenCL
18-
open System.Text.RegularExpressions
1915

2016
type Config() =
2117
inherit ManualConfig()
@@ -36,13 +32,12 @@ type Config() =
3632

3733
base.AddFilter(
3834
DisjunctionFilter(
39-
NameFilter(fun name -> name.Contains "COO") :> IFilter,
40-
NameFilter(fun name -> name.Contains "ToHost") :> IFilter
35+
NameFilter(fun name -> name.Contains "COO") :> IFilter
4136
)
4237
) |> ignore
4338

44-
[<IterationCount(1)>]
45-
[<WarmupCount(1)>]
39+
[<IterationCount(5)>]
40+
[<WarmupCount(3)>]
4641
[<Config(typeof<Config>)>]
4742
type EWiseAddBenchmarks() =
4843
[<ParamsSource("AvaliableContexts")>]
@@ -108,7 +103,7 @@ type EWiseAddBenchmarks4Float32() =
108103

109104
[<GlobalSetup>]
110105
member this.FormInputData() =
111-
let mtxFormat = GraphReader.readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
106+
let mtxFormat = MtxReader.readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
112107
let cooMatrix =
113108
match mtxFormat.Shape.Format, mtxFormat.Shape.Field with
114109
| "coordinate", "real" -> Utils.makeCOO mtxFormat <| FromString float32
@@ -169,121 +164,12 @@ type EWiseAddBenchmarks4Float32() =
169164
|> context.RunSync
170165

171166
static member InputMatricesProvider =
172-
let matricesFilenames =
173-
let pathToConfig =
174-
Path.Combine [|
175-
__SOURCE_DIRECTORY__
176-
"Configs"
177-
"EWiseAddBenchmarks4Float32.txt"
178-
|] |> Path.GetFullPath
179-
180-
File.ReadAllLines pathToConfig
181-
|> Seq.ofArray
182-
|> Seq.filter (fun line -> not <| line.StartsWith "!")
183-
184-
matricesFilenames
185-
|> Seq.map
186-
(fun matrixFilename ->
187-
match Path.GetExtension matrixFilename with
188-
| ".mtx" -> GraphReader.readShapeMtx <| Utils.getFullPathToMatrix matrixFilename
189-
| _ -> failwith "Unsupported matrix format"
190-
)
191-
192-
type ToHostBenchmarks4Float32() =
193-
inherit EWiseAddBenchmarks()
194-
195-
let mutable leftCOO = Unchecked.defaultof<Matrix<float32>>
196-
let mutable rightCOO = Unchecked.defaultof<Matrix<float32>>
197-
let mutable resultCOO = Unchecked.defaultof<Matrix<float32>>
198-
199-
member val FirstMatrix = Unchecked.defaultof<COOFormat<float32>> with get, set
200-
member val SecondMatrix = Unchecked.defaultof<COOFormat<float32>> with get, set
201-
202-
[<GlobalSetup>]
203-
member this.FormInputData() =
204-
let mtxFormat = GraphReader.readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
205-
let cooMatrix =
206-
match mtxFormat.Shape.Format, mtxFormat.Shape.Field with
207-
| "coordinate", "real" -> Utils.makeCOO mtxFormat <| FromString float32
208-
| "coordinate", "integer" -> Utils.makeCOO mtxFormat <| FromString float32
209-
| "coordinate", "pattern" ->
210-
let rand = System.Random()
211-
let nextSingle (random: System.Random) =
212-
let buffer = Array.zeroCreate<byte> 4
213-
random.NextBytes buffer
214-
System.BitConverter.ToSingle(buffer, 0)
215-
216-
Utils.makeCOO mtxFormat <| FromUnit (fun () -> nextSingle rand)
217-
| _ -> failwith "Unsupported matrix format"
218-
219-
this.FirstMatrix <- cooMatrix
220-
this.SecondMatrix <- cooMatrix |> Utils.transposeCOO
221-
222-
[<IterationSetup>]
223-
member this.BuildCOO() =
224-
let leftRows = Array.zeroCreate<int> this.FirstMatrix.Rows.Length
225-
let leftCols = Array.zeroCreate<int> this.FirstMatrix.Columns.Length
226-
let leftVals = Array.zeroCreate<float32> this.FirstMatrix.Values.Length
227-
Array.blit this.FirstMatrix.Rows 0 leftRows 0 this.FirstMatrix.Rows.Length
228-
Array.blit this.FirstMatrix.Columns 0 leftCols 0 this.FirstMatrix.Columns.Length
229-
Array.blit this.FirstMatrix.Values 0 leftVals 0 this.FirstMatrix.Values.Length
230-
231-
leftCOO <-
232-
Matrix.Build<float32>(
233-
this.FirstMatrix.RowCount,
234-
this.FirstMatrix.ColumnCount,
235-
leftRows,
236-
leftCols,
237-
leftVals,
238-
COO
239-
)
240-
241-
let rightRows = Array.zeroCreate<int> this.SecondMatrix.Rows.Length
242-
let rightCols = Array.zeroCreate<int> this.SecondMatrix.Columns.Length
243-
let rightVals = Array.zeroCreate<float32> this.SecondMatrix.Values.Length
244-
Array.blit this.SecondMatrix.Rows 0 rightRows 0 this.SecondMatrix.Rows.Length
245-
Array.blit this.SecondMatrix.Columns 0 rightCols 0 this.SecondMatrix.Columns.Length
246-
Array.blit this.SecondMatrix.Values 0 rightVals 0 this.SecondMatrix.Values.Length
247-
248-
rightCOO <-
249-
Matrix.Build<float32>(
250-
this.SecondMatrix.RowCount,
251-
this.SecondMatrix.ColumnCount,
252-
rightRows,
253-
rightCols,
254-
rightVals,
255-
COO
256-
)
257-
258-
let (ClContext context) = this.OclContext
259-
resultCOO <-
260-
leftCOO.EWiseAdd rightCOO None Float32Semiring.addMult
261-
|> context.RunSync
262-
263-
[<Benchmark>]
264-
member this.ToHostFloat32() =
265-
let (ClContext context) = this.OclContext
266-
resultCOO.ToHost()
267-
|> context.RunSync
268-
269-
static member InputMatricesProvider =
270-
let matricesFilenames =
271-
let pathToConfig =
272-
Path.Combine [|
273-
__SOURCE_DIRECTORY__
274-
"Configs"
275-
"EWiseAddBenchmarks4Float32.txt"
276-
|] |> Path.GetFullPath
277-
278-
File.ReadAllLines pathToConfig
279-
|> Seq.ofArray
280-
|> Seq.filter (fun line -> not <| line.StartsWith "!")
281-
282-
matricesFilenames
167+
"EWiseAddBenchmarks4Float32.txt"
168+
|> Utils.getMatricesFilenames
283169
|> Seq.map
284170
(fun matrixFilename ->
285171
match Path.GetExtension matrixFilename with
286-
| ".mtx" -> GraphReader.readShapeMtx <| Utils.getFullPathToMatrix matrixFilename
172+
| ".mtx" -> MtxReader.readShape <| Utils.getFullPathToMatrix matrixFilename
287173
| _ -> failwith "Unsupported matrix format"
288174
)
289175

@@ -298,7 +184,7 @@ type EWiseAddBenchmarks4Bool() =
298184

299185
[<GlobalSetup>]
300186
member this.FormInputData() =
301-
let mtxFormat = GraphReader.readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
187+
let mtxFormat = MtxReader.readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
302188
let cooMatrix =
303189
match mtxFormat.Shape.Format, mtxFormat.Shape.Field with
304190
| "coordinate", "real" -> Utils.makeCOO mtxFormat <| FromString (fun _ -> true)
@@ -350,22 +236,11 @@ type EWiseAddBenchmarks4Bool() =
350236
|> context.RunSync
351237

352238
static member InputMatricesProvider =
353-
let matricesFilenames =
354-
let pathToConfig =
355-
Path.Combine [|
356-
__SOURCE_DIRECTORY__
357-
"Configs"
358-
"EWiseAddBenchmarks4Bool.txt"
359-
|] |> Path.GetFullPath
360-
361-
File.ReadAllLines pathToConfig
362-
|> Seq.ofArray
363-
|> Seq.filter (fun line -> not <| line.StartsWith "!")
364-
365-
matricesFilenames
239+
"EWiseAddBenchmarks4Bool.txt"
240+
|> Utils.getMatricesFilenames
366241
|> Seq.map
367242
(fun matrixFilename ->
368243
match Path.GetExtension matrixFilename with
369-
| ".mtx" -> GraphReader.readShapeMtx <| Utils.getFullPathToMatrix matrixFilename
244+
| ".mtx" -> MtxReader.readShape <| Utils.getFullPathToMatrix matrixFilename
370245
| _ -> failwith "Unsupported matrix format"
371246
)

benchmarks/GraphBLAS-sharp.Benchmarks/Common.fs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
namespace GraphBLAS.FSharp.Benchmarks
22

3-
open GraphBLAS.FSharp
43
open BenchmarkDotNet.Columns
54
open BenchmarkDotNet.Reports
65
open BenchmarkDotNet.Running
@@ -33,11 +32,14 @@ type MatrixShapeColumn(columnName: string, getShape: MtxShape -> int) =
3332
member this.AlwaysShow: bool = true
3433
member this.Category: ColumnCategory = ColumnCategory.Params
3534
member this.ColumnName: string = columnName
35+
3636
member this.GetValue(summary: Summary, benchmarkCase: BenchmarkCase): string =
3737
let inputMatrix = benchmarkCase.Parameters.["InputMatrix"] :?> MtxShape
3838
sprintf "%i" <| getShape inputMatrix
39+
3940
member this.GetValue(summary: Summary, benchmarkCase: BenchmarkCase, style: SummaryStyle): string =
4041
(this :> IColumn).GetValue(summary, benchmarkCase)
42+
4143
member this.Id: string = sprintf "%s.%s" "MatrixShapeColumn" columnName
4244
member this.IsAvailable(summary: Summary): bool = true
4345
member this.IsDefault(summary: Summary, benchmarkCase: BenchmarkCase): bool = false
@@ -51,20 +53,24 @@ type TEPSColumn() =
5153
member this.AlwaysShow: bool = true
5254
member this.Category: ColumnCategory = ColumnCategory.Statistics
5355
member this.ColumnName: string = "TEPS"
56+
5457
member this.GetValue(summary: Summary, benchmarkCase: BenchmarkCase): string =
5558
let inputMatrix = benchmarkCase.Parameters.["InputMatrix"] :?> MtxShape
56-
let (nrows, ncols) =
57-
inputMatrix.RowCount,
58-
inputMatrix.ColumnCount
59-
// !!!!!!!!!!!!
60-
let (vertices, edges) = (ncols, nrows)
59+
let (nrows, ncols) = inputMatrix.RowCount, inputMatrix.ColumnCount
60+
let (vertices, edges) =
61+
match inputMatrix.Format with
62+
| "coordinate" -> if nrows = ncols then (nrows, inputMatrix.Size.[2]) else (ncols, nrows)
63+
| _ -> failwith "Unsupported"
64+
6165
if isNull summary.[benchmarkCase].ResultStatistics then
6266
"NA"
6367
else
6468
let meanTime = summary.[benchmarkCase].ResultStatistics.Mean
6569
sprintf "%f" <| float edges / (meanTime * 1e-6)
70+
6671
member this.GetValue(summary: Summary, benchmarkCase: BenchmarkCase, style: SummaryStyle): string =
6772
(this :> IColumn).GetValue(summary, benchmarkCase)
73+
6874
member this.Id: string = "TEPSColumn"
6975
member this.IsAvailable(summary: Summary): bool = true
7076
member this.IsDefault(summary: Summary, benchmarkCase: BenchmarkCase): bool = false

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ let main argv =
88
let benchmarks = BenchmarkSwitcher [|
99
typeof<EWiseAddBenchmarks4Float32>
1010
typeof<EWiseAddBenchmarks4Bool>
11-
typeof<ToHostBenchmarks4Float32>
1211
|]
1312

1413
benchmarks.Run argv |> ignore

0 commit comments

Comments
 (0)