Skip to content

Commit 541d5f1

Browse files
committed
Add benchmarks for EWiseAdd
1 parent e5c9ed5 commit 541d5f1

6 files changed

Lines changed: 170 additions & 7 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/Config.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ type TEPSColumn() =
2121
use streamReader = new StreamReader(pathToGraph)
2222
while streamReader.Peek() = int '%' do
2323
streamReader.ReadLine() |> ignore
24-
let matrixInfo = streamReader.ReadLine().Split(' ')
25-
let (nrows, ncols, nnz) = float matrixInfo.[0], float matrixInfo.[1], float matrixInfo.[2]
24+
let matrixInfo = streamReader.ReadLine().Split(' ') |> Array.map int
25+
let (nrows, ncols, nnz) = matrixInfo.[0], matrixInfo.[1], matrixInfo.[2]
2626
let (vertices, edges) = if nrows = ncols then (nrows, nnz) else (ncols, nrows)
27-
sprintf "%f" (edges / meanTime)
27+
sprintf "%f" (float edges / meanTime)
2828
| another -> sprintf "%s files not supported" another
2929
member this.GetValue(summary: Summary, benchmarkCase: BenchmarkCase, style: SummaryStyle): string =
3030
(this :> IColumn).GetValue(summary, benchmarkCase)
Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
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 BenchmarkDotNet.Engines
9+
open System.IO
10+
open System
11+
open MatrixBackend
12+
open GraphBLAS.FSharp.Predefined
13+
open MathNet.Numerics
14+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic
15+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
16+
17+
type COOFormat<'a> =
18+
{ Rows: int []
19+
Columns: int []
20+
Values: 'a []
21+
RowCount: int
22+
ColumnCount: int }
23+
24+
[<MinColumn; MaxColumn>]
25+
[<Config(typeof<Config>)>]
26+
[<SimpleJob(RunStrategy.Throughput)>]
27+
type EWiseAddBenchmarks() =
28+
let mutable leftCOO = Unchecked.defaultof<Matrix<float>>
29+
let mutable rightCOO = Unchecked.defaultof<Matrix<float>>
30+
31+
let mutable leftCSR = Unchecked.defaultof<Matrix<float>>
32+
let mutable rightCSR = Unchecked.defaultof<Matrix<float>>
33+
34+
let mutable leftMathNetSparse =
35+
Unchecked.defaultof<LinearAlgebra.Matrix<float>>
36+
37+
let mutable rightMathNetSparse =
38+
Unchecked.defaultof<LinearAlgebra.Matrix<float>>
39+
40+
let mutable firstGraph = Unchecked.defaultof<COOFormat<float>>
41+
let mutable secondGraph = Unchecked.defaultof<COOFormat<float>>
42+
43+
[<ParamsSource("GraphPaths")>]
44+
member val PathToGraph = Unchecked.defaultof<string * string> with get, set
45+
46+
[<GlobalSetup>]
47+
member this.ReadMatrices() =
48+
let getCOO(pathToGraph: string) =
49+
use streamReader = new StreamReader(pathToGraph)
50+
51+
while streamReader.Peek() = int '%' do
52+
streamReader.ReadLine() |> ignore
53+
54+
let matrixInfo =
55+
streamReader.ReadLine().Split(' ')
56+
|> Array.map int
57+
58+
let (nrows, ncols, nnz) =
59+
matrixInfo.[0], matrixInfo.[1], matrixInfo.[2]
60+
61+
[ 0 .. nnz - 1 ]
62+
|> List.map
63+
(fun _ ->
64+
streamReader.ReadLine().Split(' ')
65+
|> (fun line -> int line.[0], int line.[1], float line.[2]))
66+
|> List.toArray
67+
|> Array.unzip3
68+
|> fun (rows, cols, values) ->
69+
{ Rows = rows
70+
Columns = cols
71+
Values = values
72+
RowCount = nrows
73+
ColumnCount = ncols }
74+
75+
firstGraph <- fst this.PathToGraph |> getCOO
76+
secondGraph <- snd this.PathToGraph |> getCOO
77+
78+
[<IterationSetup(Target = "EWiseAdditionCOO")>]
79+
member this.BuildCOO() =
80+
leftCOO <-
81+
Matrix.Build<float>(
82+
firstGraph.RowCount,
83+
firstGraph.ColumnCount,
84+
firstGraph.Rows,
85+
firstGraph.Columns,
86+
firstGraph.Values,
87+
COO
88+
)
89+
90+
rightCOO <-
91+
Matrix.Build<float>(
92+
secondGraph.RowCount,
93+
secondGraph.ColumnCount,
94+
secondGraph.Rows,
95+
secondGraph.Columns,
96+
secondGraph.Values,
97+
COO
98+
)
99+
100+
[<IterationSetup(Target = "EWiseAdditionCSR")>]
101+
member this.BuildCSR() =
102+
leftCSR <-
103+
Matrix.Build<float>(
104+
firstGraph.RowCount,
105+
firstGraph.ColumnCount,
106+
firstGraph.Rows,
107+
firstGraph.Columns,
108+
firstGraph.Values,
109+
CSR
110+
)
111+
112+
rightCSR <-
113+
Matrix.Build<float>(
114+
secondGraph.RowCount,
115+
secondGraph.ColumnCount,
116+
secondGraph.Rows,
117+
secondGraph.Columns,
118+
secondGraph.Values,
119+
CSR
120+
)
121+
122+
[<IterationSetup(Target = "EWiseAdditionMathNetSparse")>]
123+
member this.BuildMathNetSparse() =
124+
leftMathNetSparse <-
125+
LinearAlgebra.SparseMatrix.ofListi
126+
firstGraph.RowCount
127+
firstGraph.ColumnCount
128+
(List.ofArray <| Array.zip3 firstGraph.Rows firstGraph.Columns firstGraph.Values)
129+
130+
rightMathNetSparse <-
131+
LinearAlgebra.SparseMatrix.ofListi
132+
secondGraph.RowCount
133+
secondGraph.ColumnCount
134+
(List.ofArray <| Array.zip3 secondGraph.Rows secondGraph.Columns secondGraph.Values)
135+
136+
[<Benchmark>]
137+
member this.EWiseAdditionCOO() =
138+
leftCOO.EWiseAdd rightCOO None FloatSemiring.addMult
139+
|> oclContext.RunSync
140+
141+
[<Benchmark>]
142+
member this.EWiseAdditionCSR() =
143+
leftCSR.EWiseAdd rightCOO None FloatSemiring.addMult
144+
|> oclContext.RunSync
145+
146+
[<Benchmark>]
147+
member this.EWiseAdditionMathNetSparse() = leftMathNetSparse + rightMathNetSparse
148+
149+
/// Sequence of paths to files where data for benchmarking will be taken from
150+
static member GraphPaths =
151+
seq {
152+
let getPathToFile filename =
153+
Path.Join [| "Datasets"
154+
"EWiseAddDatasets"
155+
filename |]
156+
157+
let map f (x, y) = f x, f y
158+
159+
// data filenames
160+
yield ("", "") |> map getPathToFile
161+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<Compile Include="AssemblyInfo.fs" />
1717
<Compile Include="Config.fs" />
1818
<Compile Include="BfsBenchmark.fs" />
19+
<Compile Include="EWiseAddBenchmark.fs" />
1920
<Compile Include="Program.fs" />
2021
</ItemGroup>
2122
<Import Project="..\..\.paket\Paket.Restore.targets" />

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open GraphBLAS.FSharp.Benchmarks
44
[<EntryPoint>]
55
let main argv =
66
let benchmarks = BenchmarkSwitcher [|
7-
typeof<BFSBenchmark4CSRMatrix>
7+
typeof<EWiseAddBenchmarks>
88
|]
99

1010
benchmarks.Run argv |> ignore
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
FSharp.Core
22
Microsoft.NETFramework.ReferenceAssemblies
33
BenchmarkDotNet
4+
MathNet.Numerics.FSharp

src/GraphBLAS-sharp/Matrix.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module MatrixBackend =
55
static member Build(denseMatrix: 'T[,], zero: 'T, matrixType: MatrixBackendFormat) : Matrix<'T> =
66
failwith "Not Implemented"
77

8-
static member Build(rows: int[], columns: int[], values: 'T[], matrixType: MatrixBackendFormat) : Matrix<'T> =
8+
static member Build(rowCount: int, columnCount: int, rows: int[], columns: int[], values: 'T[], matrixType: MatrixBackendFormat) : Matrix<'T> =
99
match matrixType with
1010
| CSR -> upcast CSRMatrix(rows, columns, values)
1111
| _ -> failwith "Not Implemented"
@@ -26,8 +26,8 @@ module MatrixExtensions =
2626
static member Build(denseMatrix: 'T[,], zero: 'T) : Matrix<'T> =
2727
Matrix.Build(denseMatrix, zero, matrixBackendFormat)
2828

29-
static member Build(rows: int[], columns: int[], values: 'T[]) : Matrix<'T> =
30-
Matrix.Build(rows, columns, values)
29+
static member Build(rowCount: int, columnCount: int, rows: int[], columns: int[], values: 'T[]) : Matrix<'T> =
30+
Matrix.Build(rowCount, columnCount, rows, columns, values)
3131

3232
static member Build(pathToMatrix: string) : Matrix<'T> =
3333
Matrix.Build(pathToMatrix, matrixBackendFormat)

0 commit comments

Comments
 (0)