Skip to content

Commit d748b66

Browse files
committed
Add mxv and transpose benchs
1 parent e0ba1c8 commit d748b66

10 files changed

Lines changed: 223 additions & 169 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksBFS.fs

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -93,41 +93,7 @@ type BFSBenchmarks() =
9393
let (ClContext context) = this.OclContext
9494
context.Provider.Dispose()
9595

96-
static member AvaliableContextsProvider =
97-
let pathToConfig =
98-
Path.Combine [|
99-
__SOURCE_DIRECTORY__
100-
"Configs"
101-
"Context.txt"
102-
|] |> Path.GetFullPath
103-
104-
use reader = new StreamReader(pathToConfig)
105-
let platformRegex = Regex <| reader.ReadLine()
106-
let deviceType =
107-
match reader.ReadLine() with
108-
| "Cpu" -> DeviceType.Cpu
109-
| "Gpu" -> DeviceType.Gpu
110-
| "All" -> DeviceType.All
111-
| _ -> failwith "Unsupported"
112-
113-
let mutable e = ErrorCode.Unknown
114-
Cl.GetPlatformIDs &e
115-
|> Array.collect (fun platform -> Cl.GetDeviceIDs(platform, deviceType, &e))
116-
|> Seq.ofArray
117-
|> Seq.distinctBy (fun device -> Cl.GetDeviceInfo(device, DeviceInfo.Name, &e).ToString())
118-
|> Seq.filter
119-
(fun device ->
120-
let platform = Cl.GetDeviceInfo(device, DeviceInfo.Platform, &e).CastTo<Platform>()
121-
let platformName = Cl.GetPlatformInfo(platform, PlatformInfo.Name, &e).ToString()
122-
platformRegex.IsMatch platformName
123-
)
124-
|> Seq.map
125-
(fun device ->
126-
let platform = Cl.GetDeviceInfo(device, DeviceInfo.Platform, &e).CastTo<Platform>()
127-
let platformName = Cl.GetPlatformInfo(platform, PlatformInfo.Name, &e).ToString()
128-
let deviceType = Cl.GetDeviceInfo(device, DeviceInfo.Type, &e).CastTo<DeviceType>()
129-
OpenCLEvaluationContext(platformName, deviceType) |> ClContext
130-
)
96+
static member AvaliableContextsProvider = Utils.avaliableContexts
13197

13298
static member InputMatricesProvider =
13399
"BFSBenchmarks.txt"
Lines changed: 69 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
namespace GraphBLAS.FSharp.Benchmarks
22

33
open GraphBLAS.FSharp
4-
open GraphBLAS.FSharp.Algorithms
54
open BenchmarkDotNet.Attributes
65
open BenchmarkDotNet.Configs
76
open BenchmarkDotNet.Columns
87
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
218
open GraphBLAS.FSharp.IO
229

2310
type MxvConfig() =
@@ -33,94 +20,72 @@ type MxvConfig() =
3320
StatisticColumn.Max
3421
) |> ignore
3522

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-
// )
23+
[<IterationCount(5)>]
24+
[<WarmupCount(3)>]
25+
[<Config(typeof<MxvConfig>)>]
26+
type MxvBenchmarks() =
27+
let rand = System.Random()
28+
29+
let mutable matrix = Unchecked.defaultof<Matrix<float>>
30+
let mutable vector = Unchecked.defaultof<Vector<float>>
31+
let semiring = Predefined.AddMult.float
32+
33+
[<ParamsSource("AvaliableContextsProvider")>]
34+
member val OclContext = Unchecked.defaultof<ClContext> with get, set
35+
member this.Context =
36+
let (ClContext context) = this.OclContext
37+
context
38+
39+
[<ParamsSource("InputMatricesProvider")>]
40+
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
41+
42+
[<GlobalSetup>]
43+
member this.BuildMatrix() =
44+
let inputMatrix = this.InputMatrixReader.ReadMatrixReal(float)
45+
46+
matrix <-
47+
graphblas {
48+
return! Matrix.switch CSR inputMatrix
49+
>>= Matrix.synchronizeAndReturn
50+
}
51+
|> EvalGB.withClContext this.Context
52+
|> EvalGB.runSync
53+
54+
[<IterationSetup>]
55+
member this.BuildVector() =
56+
vector <-
57+
graphblas {
58+
return!
59+
[ for i = 0 to matrix.ColumnCount - 1 do if rand.Next() % 2 = 0 then yield (i, 1.) ]
60+
|> Vector.ofList matrix.ColumnCount
61+
// >>= Vector.synchronizeAndReturn
62+
}
63+
|> EvalGB.withClContext this.Context
64+
|> EvalGB.runSync
65+
66+
[<Benchmark>]
67+
member this.Mxv() =
68+
Matrix.mxv semiring matrix vector
69+
|> EvalGB.withClContext this.Context
70+
|> EvalGB.runSync
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
82+
83+
static member InputMatricesProvider =
84+
"MxvBenchmarks.txt"
85+
|> Utils.getMatricesFilenames
86+
|> Seq.map
87+
(fun matrixFilename ->
88+
match Path.GetExtension matrixFilename with
89+
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix "MxvDatasets" matrixFilename)
90+
| _ -> failwith "Unsupported matrix format"
91+
)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
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.Text.RegularExpressions
11+
open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
12+
open OpenCL.Net
13+
open GraphBLAS.FSharp.IO
14+
15+
type TransposeConfig() =
16+
inherit ManualConfig()
17+
18+
do
19+
base.AddColumn(
20+
MatrixShapeColumn("RowCount", fun mtxReader -> mtxReader.ReadMatrixShape().RowCount) :> IColumn,
21+
MatrixShapeColumn("ColumnCount", fun mtxReader -> mtxReader.ReadMatrixShape().ColumnCount) :> IColumn,
22+
MatrixShapeColumn("NNZ", fun mtxReader -> mtxReader.ReadMatrixShape().Nnz) :> IColumn,
23+
TEPSColumn() :> IColumn,
24+
StatisticColumn.Min,
25+
StatisticColumn.Max
26+
) |> ignore
27+
28+
[<IterationCount(5)>]
29+
[<WarmupCount(3)>]
30+
[<Config(typeof<MxvConfig>)>]
31+
type TransposeBenchmarks() =
32+
let mutable matrix = Unchecked.defaultof<Matrix<float>>
33+
34+
[<ParamsSource("AvaliableContextsProvider")>]
35+
member val OclContext = Unchecked.defaultof<ClContext> with get, set
36+
member this.Context =
37+
let (ClContext context) = this.OclContext
38+
context
39+
40+
[<ParamsSource("InputMatricesProvider")>]
41+
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
42+
43+
[<GlobalSetup>]
44+
member this.BuildMatrix() =
45+
let inputMatrix = this.InputMatrixReader.ReadMatrixReal(float)
46+
47+
matrix <-
48+
graphblas {
49+
return! Matrix.switch CSR inputMatrix
50+
>>= Matrix.synchronizeAndReturn
51+
}
52+
|> EvalGB.withClContext this.Context
53+
|> EvalGB.runSync
54+
55+
[<Benchmark>]
56+
member this.Transpose() =
57+
Matrix.transpose matrix
58+
|> EvalGB.withClContext this.Context
59+
|> EvalGB.runSync
60+
61+
[<IterationCleanup>]
62+
member this.ClearBuffers() =
63+
this.Context.Provider.CloseAllBuffers()
64+
65+
[<GlobalCleanup>]
66+
member this.ClearContext() =
67+
let (ClContext context) = this.OclContext
68+
context.Provider.Dispose()
69+
70+
static member AvaliableContextsProvider = Utils.avaliableContexts
71+
72+
static member InputMatricesProvider =
73+
"MxvBenchmarks.txt"
74+
|> Utils.getMatricesFilenames
75+
|> Seq.map
76+
(fun matrixFilename ->
77+
match Path.GetExtension matrixFilename with
78+
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix "MxvDatasets" matrixFilename)
79+
| _ -> failwith "Unsupported matrix format"
80+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
arc130.mtx
2+
webbase-1M.mtx
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
arc130.mtx
2+
webbase-1M.mtx

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<Compile Include="BenchmarksBFS.fs" />
1919
<Compile Include="BenchmarksMxv.fs" />
2020
<Compile Include="BenchmarksEWiseAdd.fs" />
21+
<Compile Include="BenchmarksTranspose.fs" />
2122
<Compile Include="Program.fs" />
2223
</ItemGroup>
2324
<Import Project="..\..\.paket\Paket.Restore.targets" />

benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation
77
open OpenCL.Net
88
open GraphBLAS.FSharp.IO
99
open System.IO
10+
open System.Text.RegularExpressions
1011

1112
type ClContext = ClContext of OpenCLEvaluationContext
1213
with
@@ -104,3 +105,39 @@ module Utils =
104105
datasetsFolder
105106
matrixFilename
106107
|]
108+
109+
let avaliableContexts =
110+
let pathToConfig =
111+
Path.Combine [|
112+
__SOURCE_DIRECTORY__
113+
"Configs"
114+
"Context.txt"
115+
|] |> Path.GetFullPath
116+
117+
use reader = new StreamReader(pathToConfig)
118+
let platformRegex = Regex <| reader.ReadLine()
119+
let deviceType =
120+
match reader.ReadLine() with
121+
| "Cpu" -> DeviceType.Cpu
122+
| "Gpu" -> DeviceType.Gpu
123+
| "All" -> DeviceType.All
124+
| _ -> failwith "Unsupported"
125+
126+
let mutable e = ErrorCode.Unknown
127+
Cl.GetPlatformIDs &e
128+
|> Array.collect (fun platform -> Cl.GetDeviceIDs(platform, deviceType, &e))
129+
|> Seq.ofArray
130+
|> Seq.distinctBy (fun device -> Cl.GetDeviceInfo(device, DeviceInfo.Name, &e).ToString())
131+
|> Seq.filter
132+
(fun device ->
133+
let platform = Cl.GetDeviceInfo(device, DeviceInfo.Platform, &e).CastTo<Platform>()
134+
let platformName = Cl.GetPlatformInfo(platform, PlatformInfo.Name, &e).ToString()
135+
platformRegex.IsMatch platformName
136+
)
137+
|> Seq.map
138+
(fun device ->
139+
let platform = Cl.GetDeviceInfo(device, DeviceInfo.Platform, &e).CastTo<Platform>()
140+
let platformName = Cl.GetPlatformInfo(platform, PlatformInfo.Name, &e).ToString()
141+
let deviceType = Cl.GetDeviceInfo(device, DeviceInfo.Type, &e).CastTo<DeviceType>()
142+
OpenCLEvaluationContext(platformName, deviceType) |> ClContext
143+
)

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ let main argv =
77
// typeof<EWiseAddBenchmarks4Float32>
88
// typeof<EWiseAddBenchmarks4Bool>
99
typeof<BFSBenchmarks>
10+
typeof<MxvBenchmarks>
11+
typeof<TransposeBenchmarks>
1012
|]
1113

1214
benchmarks.Run argv |> ignore

src/GraphBLAS-sharp/Backend/CSRMatrix/Convert.fs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ module internal rec Convert =
1919
else
2020
let! compressedRows = compressRows matrix.RowCount matrix.Rows
2121
let! cols = Copy.copyArray matrix.Columns
22-
// FIXME copy broken
23-
let vals = matrix.Values
22+
let! vals = Copy.copyArray matrix.Values
2423

2524
return {
2625
RowCount = matrix.RowCount

0 commit comments

Comments
 (0)