Skip to content

Commit e0ba1c8

Browse files
committed
Move qg bench to bfs bench
1 parent d74458c commit e0ba1c8

7 files changed

Lines changed: 159 additions & 95 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksBFS.fs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,13 @@ open BenchmarkDotNet.Configs
77
open BenchmarkDotNet.Columns
88
open System.IO
99
open System
10-
open System.IO
1110
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
1911
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
2012
open OpenCL.Net
2113
open GraphBLAS.FSharp.IO
14+
open QuickGraph
2215

23-
type Config() =
16+
type BFSConfig() =
2417
inherit ManualConfig()
2518

2619
do
@@ -35,13 +28,19 @@ type Config() =
3528

3629
[<IterationCount(5)>]
3730
[<WarmupCount(3)>]
38-
[<Config(typeof<Config>)>]
31+
[<Config(typeof<BFSConfig>)>]
3932
type BFSBenchmarks() =
4033
let random = Random()
4134

42-
let mutable matrix = Unchecked.defaultof<Matrix<bool>>
4335
let mutable source = 0
4436

37+
// gb
38+
let mutable matrix = Unchecked.defaultof<Matrix<int>>
39+
40+
// qg
41+
let graph = AdjacencyGraph<int, Edge<int>>(false)
42+
let mutable bfs = Unchecked.defaultof<Algorithms.Search.BreadthFirstSearchAlgorithm<int, Edge<int>>>
43+
4544
[<ParamsSource("AvaliableContextsProvider")>]
4645
member val OclContext = Unchecked.defaultof<ClContext> with get, set
4746
member this.Context =
@@ -52,25 +51,39 @@ type BFSBenchmarks() =
5251
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
5352

5453
[<GlobalSetup>]
55-
member this.BuildMatrixAndSetSource() =
54+
member this.BuildGraph() =
55+
let inputMatrix = this.InputMatrixReader.ReadMatrix(fun _ -> 1)
56+
5657
matrix <-
5758
graphblas {
58-
let matrix = this.InputMatrixReader.ReadMatrix(fun _ -> true)
59-
60-
return! Matrix.switch CSR matrix
59+
return! Matrix.switch CSR inputMatrix
6160
>>= Matrix.synchronizeAndReturn
6261
}
6362
|> EvalGB.withClContext this.Context
6463
|> EvalGB.runSync
6564

65+
match inputMatrix with
66+
| MatrixCSR csr -> failwith "Not implemented"
67+
| MatrixCOO coo ->
68+
for i = 0 to coo.Values.Length - 1 do
69+
graph.AddVerticesAndEdge(Edge(coo.Rows.[i], coo.Columns.[i])) |> ignore
70+
71+
bfs <- Algorithms.Search.BreadthFirstSearchAlgorithm(graph)
72+
73+
[<IterationSetup>]
74+
member this.SetSource() =
6675
source <- random.Next <| Matrix.rowCount matrix
6776

6877
[<Benchmark>]
69-
member this.LevelBFS() =
78+
member this.GraphblasLevelBFS() =
7079
BFS.levelSingleSource matrix source
7180
|> EvalGB.withClContext this.Context
7281
|> EvalGB.runSync
7382

83+
[<Benchmark>]
84+
member this.QuickGraphBFS() =
85+
bfs.Compute(source)
86+
7487
[<IterationCleanup>]
7588
member this.ClearBuffers() =
7689
this.Context.Provider.CloseAllBuffers()
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
namespace GraphBLAS.FSharp.Benchmarks
2+
3+
open GraphBLAS.FSharp
4+
open GraphBLAS.FSharp.Algorithms
5+
open BenchmarkDotNet.Attributes
6+
open BenchmarkDotNet.Configs
7+
open BenchmarkDotNet.Columns
8+
open System.IO
9+
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 MxvConfig() =
24+
inherit ManualConfig()
25+
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+
// TODO (откуда то брать вектор)
37+
38+
// [<IterationCount(5)>]
39+
// [<WarmupCount(3)>]
40+
// [<Config(typeof<MxvConfig>)>]
41+
// type MxvBenchmarks() =
42+
// let mutable matrix = Unchecked.defaultof<Matrix<bool>>
43+
44+
// [<ParamsSource("AvaliableContextsProvider")>]
45+
// member val OclContext = Unchecked.defaultof<ClContext> with get, set
46+
// member this.Context =
47+
// let (ClContext context) = this.OclContext
48+
// context
49+
50+
// [<ParamsSource("InputMatricesProvider")>]
51+
// member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
52+
53+
// [<GlobalSetup>]
54+
// member this.BuildMatrixAndSetSource() =
55+
// matrix <-
56+
// graphblas {
57+
// let matrix = this.InputMatrixReader.ReadMatrix(fun _ -> true)
58+
59+
// return! Matrix.switch CSR matrix
60+
// >>= Matrix.synchronizeAndReturn
61+
// }
62+
// |> EvalGB.withClContext this.Context
63+
// |> EvalGB.runSync
64+
65+
// source <- random.Next <| Matrix.rowCount matrix
66+
67+
// [<Benchmark>]
68+
// member this.LevelBFS() =
69+
// BFS.levelSingleSource matrix source
70+
// |> EvalGB.withClContext this.Context
71+
// |> EvalGB.runSync
72+
73+
// [<IterationCleanup>]
74+
// member this.ClearBuffers() =
75+
// this.Context.Provider.CloseAllBuffers()
76+
77+
// [<GlobalCleanup>]
78+
// member this.ClearContext() =
79+
// let (ClContext context) = this.OclContext
80+
// context.Provider.Dispose()
81+
82+
// static member AvaliableContextsProvider =
83+
// let pathToConfig =
84+
// Path.Combine [|
85+
// __SOURCE_DIRECTORY__
86+
// "Configs"
87+
// "Context.txt"
88+
// |] |> Path.GetFullPath
89+
90+
// use reader = new StreamReader(pathToConfig)
91+
// let platformRegex = Regex <| reader.ReadLine()
92+
// let deviceType =
93+
// match reader.ReadLine() with
94+
// | "Cpu" -> DeviceType.Cpu
95+
// | "Gpu" -> DeviceType.Gpu
96+
// | "All" -> DeviceType.All
97+
// | _ -> failwith "Unsupported"
98+
99+
// let mutable e = ErrorCode.Unknown
100+
// Cl.GetPlatformIDs &e
101+
// |> Array.collect (fun platform -> Cl.GetDeviceIDs(platform, deviceType, &e))
102+
// |> Seq.ofArray
103+
// |> Seq.distinctBy (fun device -> Cl.GetDeviceInfo(device, DeviceInfo.Name, &e).ToString())
104+
// |> Seq.filter
105+
// (fun device ->
106+
// let platform = Cl.GetDeviceInfo(device, DeviceInfo.Platform, &e).CastTo<Platform>()
107+
// let platformName = Cl.GetPlatformInfo(platform, PlatformInfo.Name, &e).ToString()
108+
// platformRegex.IsMatch platformName
109+
// )
110+
// |> Seq.map
111+
// (fun device ->
112+
// let platform = Cl.GetDeviceInfo(device, DeviceInfo.Platform, &e).CastTo<Platform>()
113+
// let platformName = Cl.GetPlatformInfo(platform, PlatformInfo.Name, &e).ToString()
114+
// let deviceType = Cl.GetDeviceInfo(device, DeviceInfo.Type, &e).CastTo<DeviceType>()
115+
// OpenCLEvaluationContext(platformName, deviceType) |> ClContext
116+
// )
117+
118+
// static member InputMatricesProvider =
119+
// "BFSBenchmarks.txt"
120+
// |> Utils.getMatricesFilenames
121+
// |> Seq.map
122+
// (fun matrixFilename ->
123+
// match Path.GetExtension matrixFilename with
124+
// | ".mtx" -> MtxReader(Utils.getFullPathToMatrix "BFSDatasets" matrixFilename)
125+
// | _ -> failwith "Unsupported matrix format"
126+
// )

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksQG.fs

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

benchmarks/GraphBLAS-sharp.Benchmarks/GraphBLAS-sharp.Benchmarks.fsproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
<Compile Include="AssemblyInfo.fs" />
1717
<Compile Include="Helpers.fs" />
1818
<Compile Include="BenchmarksBFS.fs" />
19+
<Compile Include="BenchmarksMxv.fs" />
1920
<Compile Include="BenchmarksEWiseAdd.fs" />
20-
<Compile Include="BenchmarksQG.fs" />
2121
<Compile Include="Program.fs" />
2222
</ItemGroup>
2323
<Import Project="..\..\.paket\Paket.Restore.targets" />
24-
</Project>
24+
</Project>

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ let main argv =
77
// typeof<EWiseAddBenchmarks4Float32>
88
// typeof<EWiseAddBenchmarks4Bool>
99
typeof<BFSBenchmarks>
10-
typeof<QGBenchmarks>
1110
|]
1211

1312
benchmarks.Run argv |> ignore

tests/GraphBLAS-sharp.Tests/AlgorithmsTests/BfsTests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ let testCases = [
1717
let expected =
1818
graphblas {
1919
let! matrix =
20-
MtxReader("arc130.mtx").ReadMatrixReal(fun _ -> true)
20+
MtxReader("arc130.mtx").ReadMatrixReal(fun _ -> 1)
2121
|> Matrix.switch CSR
2222

2323
return!

tests/GraphBLAS-sharp.Tests/Helpers.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module Extensions =
2020
QuotationEvaluator.Evaluate f
2121

2222
module CustomDatatypes =
23+
// мб заменить рекорд на структуру (не помогает)
2324
[<Struct>]
2425
type WrappedInt = { InnerValue: int }
2526
with

0 commit comments

Comments
 (0)