Skip to content

Commit 33554ed

Browse files
committed
Add bfs benchmark
1 parent 5bbb3c2 commit 33554ed

12 files changed

Lines changed: 1960 additions & 471 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksBFS.fs

Lines changed: 104 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,121 @@ open BenchmarkDotNet.Configs
77
open BenchmarkDotNet.Columns
88
open System.IO
99
open System
10+
open System.IO
11+
open System.Text.RegularExpressions
12+
open GraphBLAS.FSharp
13+
open GraphBLAS.FSharp.Predefined
14+
open BenchmarkDotNet.Attributes
15+
open BenchmarkDotNet.Configs
16+
open BenchmarkDotNet.Columns
17+
open BenchmarkDotNet.Filters
18+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
19+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
20+
open OpenCL.Net
21+
open GraphBLAS.FSharp.IO
22+
23+
type Config() =
24+
inherit ManualConfig()
1025

11-
[<SimpleJob(targetCount=10)>]
12-
type BFSBenchmark4CSRMatrix() =
26+
do
27+
base.AddColumn(
28+
MatrixShapeColumn("RowCount", fun mtxReader -> mtxReader.ReadMatrixShape().RowCount) :> IColumn,
29+
MatrixShapeColumn("ColumnCount", fun mtxReader -> mtxReader.ReadMatrixShape().ColumnCount) :> IColumn,
30+
MatrixShapeColumn("NNZ", fun mtxReader -> mtxReader.ReadMatrixShape().Nnz) :> IColumn,
31+
TEPSColumn() :> IColumn,
32+
StatisticColumn.Min,
33+
StatisticColumn.Max
34+
) |> ignore
35+
36+
[<IterationCount(5)>]
37+
[<WarmupCount(3)>]
38+
[<Config(typeof<Config>)>]
39+
type BFSBenchmarks() =
1340
let random = Random()
1441

1542
let mutable matrix = Unchecked.defaultof<Matrix<bool>>
1643
let mutable source = 0
1744

18-
[<ParamsSource("GraphPaths")>]
19-
member val PathToGraph = "" with get, set
45+
[<ParamsSource("AvaliableContextsProvider")>]
46+
member val OclContext = Unchecked.defaultof<ClContext> with get, set
47+
member this.Context =
48+
let (ClContext context) = this.OclContext
49+
context
50+
51+
[<ParamsSource("InputMatricesProvider")>]
52+
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
2053

2154
[<GlobalSetup>]
22-
member this.BuildMatrix() =
23-
matrix <- MatrixCSR <| CSRMatrix.FromFile this.PathToGraph
55+
member this.BuildMatrixAndSetSource() =
56+
matrix <-
57+
graphblas {
58+
let matrix = this.InputMatrixReader.ReadMatrixBoolean(fun _ -> true)
59+
60+
return! Matrix.switch CSR matrix
61+
>>= Matrix.synchronizeAndReturn
62+
}
63+
|> EvalGB.withClContext this.Context
64+
|> EvalGB.runSync
65+
2466
source <- random.Next <| Matrix.rowCount matrix
2567

2668
[<Benchmark>]
2769
member this.LevelBFS() =
2870
BFS.levelSingleSource matrix source
71+
|> EvalGB.withClContext this.Context
72+
|> EvalGB.runSync
73+
74+
[<IterationCleanup>]
75+
member this.ClearBuffers() =
76+
this.Context.Provider.CloseAllBuffers()
77+
78+
[<GlobalCleanup>]
79+
member this.ClearContext() =
80+
let (ClContext context) = this.OclContext
81+
context.Provider.Dispose()
82+
83+
static member AvaliableContextsProvider =
84+
let pathToConfig =
85+
Path.Combine [|
86+
__SOURCE_DIRECTORY__
87+
"Configs"
88+
"Context.txt"
89+
|] |> Path.GetFullPath
90+
91+
use reader = new StreamReader(pathToConfig)
92+
let platformRegex = Regex <| reader.ReadLine()
93+
let deviceType =
94+
match reader.ReadLine() with
95+
| "Cpu" -> DeviceType.Cpu
96+
| "Gpu" -> DeviceType.Gpu
97+
| "All" -> DeviceType.All
98+
| _ -> failwith "Unsupported"
99+
100+
let mutable e = ErrorCode.Unknown
101+
Cl.GetPlatformIDs &e
102+
|> Array.collect (fun platform -> Cl.GetDeviceIDs(platform, deviceType, &e))
103+
|> Seq.ofArray
104+
|> Seq.distinctBy (fun device -> Cl.GetDeviceInfo(device, DeviceInfo.Name, &e).ToString())
105+
|> Seq.filter
106+
(fun device ->
107+
let platform = Cl.GetDeviceInfo(device, DeviceInfo.Platform, &e).CastTo<Platform>()
108+
let platformName = Cl.GetPlatformInfo(platform, PlatformInfo.Name, &e).ToString()
109+
platformRegex.IsMatch platformName
110+
)
111+
|> Seq.map
112+
(fun device ->
113+
let platform = Cl.GetDeviceInfo(device, DeviceInfo.Platform, &e).CastTo<Platform>()
114+
let platformName = Cl.GetPlatformInfo(platform, PlatformInfo.Name, &e).ToString()
115+
let deviceType = Cl.GetDeviceInfo(device, DeviceInfo.Type, &e).CastTo<DeviceType>()
116+
OpenCLEvaluationContext(platformName, deviceType) |> ClContext
117+
)
29118

30-
/// Sequence of paths to files where data for benchmarking will be taken from
31-
static member GraphPaths = seq {
32-
// Gets all mtx files from following directory
33-
yield! Directory.EnumerateFiles(Path.Combine [|"Datasets"; "1"|], "*.mtx")
34-
}
119+
static member InputMatricesProvider =
120+
"BFSBenchmarks.txt"
121+
|> Utils.getMatricesFilenames
122+
|> Seq.map
123+
(fun matrixFilename ->
124+
match Path.GetExtension matrixFilename with
125+
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix "BFSDatasets" matrixFilename)
126+
| _ -> failwith "Unsupported matrix format"
127+
)

0 commit comments

Comments
 (0)