@@ -7,28 +7,85 @@ open BenchmarkDotNet.Configs
77open BenchmarkDotNet.Columns
88open System.IO
99open System
10+ open System.Text .RegularExpressions
11+ open Brahma.FSharp .OpenCL .WorkflowBuilder .Evaluation
12+ open OpenCL.Net
13+ open GraphBLAS.FSharp .IO
14+ open QuickGraph
1015
11- [<SimpleJob ( targetCount = 10 ) >]
12- type BFSBenchmark4CSRMatrix () =
16+ [<Config ( typeof < CommonConfig > ) >]
17+ type BFSBenchmarks () =
1318 let random = Random()
1419
15- let mutable matrix = Unchecked.defaultof< Matrix< bool>>
1620 let mutable source = 0
1721
18- [<ParamsSource( " GraphPaths" ) >]
19- member val PathToGraph = " " with get, set
22+ // gb
23+ let mutable matrix = Unchecked.defaultof< Matrix< int>>
24+
25+ // qg
26+ let graph = AdjacencyGraph< int, Edge< int>>( false )
27+ let mutable bfs = Unchecked.defaultof< Algorithms.Search.BreadthFirstSearchAlgorithm< int, Edge< int>>>
28+
29+ [<ParamsSource( " AvaliableContextsProvider" ) >]
30+ member val OclContext = Unchecked.defaultof< ClContext> with get, set
31+ member this.Context =
32+ let ( ClContext context ) = this.OclContext
33+ context
34+
35+ [<ParamsSource( " InputMatricesProvider" ) >]
36+ member val InputMatrixReader = Unchecked.defaultof< MtxReader> with get, set
2037
2138 [<GlobalSetup>]
22- member this.BuildMatrix () =
23- matrix <- MatrixCSR <| CSRMatrix.FromFile this.PathToGraph
39+ member this.BuildGraph () =
40+ let inputMatrix = this.InputMatrixReader.ReadMatrix( fun _ -> 1 )
41+
42+ matrix <-
43+ graphblas {
44+ return ! Matrix.switch CSR inputMatrix
45+ >>= Matrix.synchronizeAndReturn
46+ }
47+ |> EvalGB.withClContext this.Context
48+ |> EvalGB.runSync
49+
50+ match inputMatrix with
51+ | MatrixCSR csr -> failwith " Not implemented"
52+ | MatrixCOO coo ->
53+ for i = 0 to coo.Values.Length - 1 do
54+ graph.AddVerticesAndEdge( Edge( coo.Rows.[ i], coo.Columns.[ i])) |> ignore
55+
56+ bfs <- Algorithms.Search.BreadthFirstSearchAlgorithm( graph)
57+
58+ [<IterationSetup>]
59+ member this.SetSource () =
2460 source <- random.Next <| Matrix.rowCount matrix
2561
2662 [<Benchmark>]
27- member this.LevelBFS () =
63+ member this.GraphblasLevelBFS () =
2864 BFS.levelSingleSource matrix source
65+ |> EvalGB.withClContext this.Context
66+ |> EvalGB.runSync
67+
68+ [<Benchmark>]
69+ member this.QuickGraphBFS () =
70+ bfs.Compute( source)
71+
72+ [<IterationCleanup>]
73+ member this.ClearBuffers () =
74+ this.Context.Provider.CloseAllBuffers()
75+
76+ [<GlobalCleanup>]
77+ member this.ClearContext () =
78+ let ( ClContext context ) = this.OclContext
79+ context.Provider.Dispose()
80+
81+ static member AvaliableContextsProvider = Utils.avaliableContexts
2982
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- }
83+ static member InputMatricesProvider =
84+ " Common.txt"
85+ |> Utils.getMatricesFilenames
86+ |> Seq.map
87+ ( fun matrixFilename ->
88+ match Path.GetExtension matrixFilename with
89+ | " .mtx" -> MtxReader( Utils.getFullPathToMatrix " Common" matrixFilename)
90+ | _ -> failwith " Unsupported matrix format"
91+ )
0 commit comments