11namespace GraphBLAS.FSharp.Benchmarks
22
33open System.IO
4+ open System.Text .RegularExpressions
45open GraphBLAS.FSharp
56open GraphBLAS.FSharp .Predefined
67open GraphBLAS.FSharp .MatrixBackend
78open BenchmarkDotNet.Attributes
8- open BenchmarkDotNet.Engines
99open BenchmarkDotNet.Configs
1010open BenchmarkDotNet.Columns
1111open BenchmarkDotNet.Filters
12- open BenchmarkDotNet.Jobs
13- open BenchmarkDotNet.Order
1412open Brahma.FSharp .OpenCL .WorkflowBuilder .Basic
1513open Brahma.FSharp .OpenCL .WorkflowBuilder .Evaluation
1614open OpenCL.Net
17- open Brahma.OpenCL
18- open System.Text .RegularExpressions
1915
20- type Config < 'a > () =
16+ type Config () =
2117 inherit ManualConfig()
2218
2319 do
2420 base .AddColumn(
25- MatrixShapeColumn< 'a>( " RowCount" , fun matrix -> matrix.MatrixStructure.RowCount) :> IColumn,
26- MatrixShapeColumn< 'a>( " ColumnCount" , fun matrix -> matrix.MatrixStructure.ColumnCount) :> IColumn,
27- MatrixShapeColumn< 'a>( " NNZ" , fun matrix -> matrix.MatrixStructure.Values.Length) :> IColumn,
28- TEPSColumn< 'a>() :> IColumn,
21+ MatrixShapeColumn( " RowCount" , fun matrix -> matrix.RowCount) :> IColumn,
22+ MatrixShapeColumn( " ColumnCount" , fun matrix -> matrix.ColumnCount) :> IColumn,
23+ MatrixShapeColumn( " NNZ" , fun matrix ->
24+ match matrix.Format with
25+ | " coordinate" -> matrix.Size.[ 2 ]
26+ | " array" -> 0
27+ | _ -> failwith " Unsupported" ) :> IColumn,
28+ TEPSColumn() :> IColumn,
2929 StatisticColumn.Min,
3030 StatisticColumn.Max
3131 ) |> ignore
@@ -36,19 +36,26 @@ type Config<'a>() =
3636 )
3737 ) |> ignore
3838
39- type Float32Config = Config< float32>
40- type BoolConfig = Config< bool>
41-
42- [<SimpleJob( RunStrategy.Monitoring, targetCount= 2 ) >]
39+ [<IterationCount( 5 ) >]
40+ [<WarmupCount( 3 ) >]
41+ [<Config( typeof< Config>) >]
4342type EWiseAddBenchmarks () =
4443 [<ParamsSource( " AvaliableContexts" ) >]
4544 member val OclContext = Unchecked.defaultof< ClContext> with get, set
46-
45+
46+ [<ParamsSource( " InputMatricesProvider" ) >]
47+ member val InputMatrix = Unchecked.defaultof< MtxShape> with get, set
48+
4749 [<IterationCleanup>]
4850 member this.ClearBuffers () =
4951 let ( ClContext context ) = this.OclContext
5052 context.Provider.CloseAllBuffers()
5153
54+ [<GlobalCleanup>]
55+ member this.ClearContext () =
56+ let ( ClContext context ) = this.OclContext
57+ context.Provider.Dispose()
58+
5259 static member AvaliableContexts =
5360 let pathToConfig =
5461 Path.Combine [|
@@ -70,6 +77,7 @@ type EWiseAddBenchmarks() =
7077 Cl.GetPlatformIDs & e
7178 |> Array.collect ( fun platform -> Cl.GetDeviceIDs( platform, deviceType, & e))
7279 |> Seq.ofArray
80+ |> Seq.distinctBy ( fun device -> Cl.GetDeviceInfo( device, DeviceInfo.Name, & e) .ToString())
7381 |> Seq.filter
7482 ( fun device ->
7583 let platform = Cl.GetDeviceInfo( device, DeviceInfo.Platform, & e) .CastTo< Platform>()
@@ -84,7 +92,6 @@ type EWiseAddBenchmarks() =
8492 OpenCLEvaluationContext( platformName, deviceType) |> ClContext
8593 )
8694
87- [<Config( typeof< Float32Config>) >]
8895type EWiseAddBenchmarks4Float32 () =
8996 inherit EWiseAddBenchmarks()
9097
@@ -94,13 +101,25 @@ type EWiseAddBenchmarks4Float32() =
94101 member val FirstMatrix = Unchecked.defaultof< COOFormat< float32>> with get, set
95102 member val SecondMatrix = Unchecked.defaultof< COOFormat< float32>> with get, set
96103
97- [<ParamsSource( " InputMatricesProvider" ) >]
98- member val InputMatrix = Unchecked.defaultof< InputMatrixFormat< float32>> with get, set
99-
100104 [<GlobalSetup>]
101105 member this.FormInputData () =
102- this.FirstMatrix <- this.InputMatrix.MatrixStructure
103- this.SecondMatrix <- this.InputMatrix.MatrixStructure |> Utils.transposeCOO
106+ let mtxFormat = MtxReader.readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
107+ let cooMatrix =
108+ match mtxFormat.Shape.Format, mtxFormat.Shape.Field with
109+ | " coordinate" , " real" -> Utils.makeCOO mtxFormat <| FromString float32
110+ | " coordinate" , " integer" -> Utils.makeCOO mtxFormat <| FromString float32
111+ | " coordinate" , " pattern" ->
112+ let rand = System.Random()
113+ let nextSingle ( random : System.Random ) =
114+ let buffer = Array.zeroCreate< byte> 4
115+ random.NextBytes buffer
116+ System.BitConverter.ToSingle( buffer, 0 )
117+
118+ Utils.makeCOO mtxFormat <| FromUnit ( fun () -> nextSingle rand)
119+ | _ -> failwith " Unsupported matrix format"
120+
121+ this.FirstMatrix <- cooMatrix
122+ this.SecondMatrix <- cooMatrix |> Utils.transposeCOO
104123
105124 [<IterationSetup>]
106125 member this.BuildCOO () =
@@ -115,9 +134,9 @@ type EWiseAddBenchmarks4Float32() =
115134 Matrix.Build< float32>(
116135 this.FirstMatrix.RowCount,
117136 this.FirstMatrix.ColumnCount,
118- this.FirstMatrix.Rows ,
119- this.FirstMatrix.Columns ,
120- this.FirstMatrix.Values ,
137+ leftRows ,
138+ leftCols ,
139+ leftVals ,
121140 COO
122141 )
123142
@@ -132,9 +151,9 @@ type EWiseAddBenchmarks4Float32() =
132151 Matrix.Build< float32>(
133152 this.SecondMatrix.RowCount,
134153 this.SecondMatrix.ColumnCount,
135- this.SecondMatrix.Rows ,
136- this.SecondMatrix.Columns ,
137- this.SecondMatrix.Values ,
154+ rightRows ,
155+ rightCols ,
156+ rightVals ,
138157 COO
139158 )
140159
@@ -145,44 +164,15 @@ type EWiseAddBenchmarks4Float32() =
145164 |> context.RunSync
146165
147166 static member InputMatricesProvider =
148- let matricesFilenames =
149- let pathToConfig =
150- Path.Combine [|
151- __ SOURCE_ DIRECTORY__
152- " Configs"
153- " EWiseAddBenchmarks4Float32.txt"
154- |] |> Path.GetFullPath
155-
156- File.ReadAllLines pathToConfig
157- |> Seq.ofArray
158- |> Seq.filter ( fun line -> not <| line.StartsWith " !" )
159-
160- let matrixHandler ( matrixFilename : string ) =
161- match Path.GetExtension matrixFilename with
162- | " .mtx" ->
163- let mtx = GraphReader.readMtx <| Utils.getFullPathToMatrix matrixFilename
164- match mtx.Format, mtx.Field with
165- | " coordinate" , " real" -> Utils.makeCOO mtx <| FromString float32
166- | " coordinate" , " integer" -> Utils.makeCOO mtx <| FromString float32
167- | " coordinate" , " pattern" ->
168- let rand = System.Random()
169- let nextSingle ( random : System.Random ) =
170- let buffer = Array.zeroCreate< byte> 4
171- random.NextBytes buffer
172- System.BitConverter.ToSingle( buffer, 0 )
173-
174- Utils.makeCOO mtx <| FromUnit ( fun () -> nextSingle rand)
167+ " EWiseAddBenchmarks4Float32.txt"
168+ |> Utils.getMatricesFilenames
169+ |> Seq.map
170+ ( fun matrixFilename ->
171+ match Path.GetExtension matrixFilename with
172+ | " .mtx" -> MtxReader.readShape <| Utils.getFullPathToMatrix matrixFilename
175173 | _ -> failwith " Unsupported matrix format"
176- | _ -> failwith " Unsupported matrix format"
177-
178- matricesFilenames
179- |> Seq.map ( fun filename ->
180- {
181- MatrixName = Path.GetFileNameWithoutExtension filename
182- MatrixStructure = matrixHandler filename
183- })
174+ )
184175
185- [<Config( typeof< BoolConfig>) >]
186176type EWiseAddBenchmarks4Bool () =
187177 inherit EWiseAddBenchmarks()
188178
@@ -192,8 +182,18 @@ type EWiseAddBenchmarks4Bool() =
192182 member val FirstMatrix = Unchecked.defaultof< COOFormat< bool>> with get, set
193183 member val SecondMatrix = Unchecked.defaultof< COOFormat< bool>> with get, set
194184
195- [<ParamsSource( " InputMatricesProvider" ) >]
196- member val InputMatrix = Unchecked.defaultof< InputMatrixFormat< bool>> with get, set
185+ [<GlobalSetup>]
186+ member this.FormInputData () =
187+ let mtxFormat = MtxReader.readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
188+ let cooMatrix =
189+ match mtxFormat.Shape.Format, mtxFormat.Shape.Field with
190+ | " coordinate" , " real" -> Utils.makeCOO mtxFormat <| FromString ( fun _ -> true )
191+ | " coordinate" , " integer" -> Utils.makeCOO mtxFormat <| FromString ( fun _ -> true )
192+ | " coordinate" , " pattern" -> Utils.makeCOO mtxFormat <| FromUnit ( fun _ -> true )
193+ | _ -> failwith " Unsupported matrix format"
194+
195+ this.FirstMatrix <- cooMatrix
196+ this.SecondMatrix <- cooMatrix |> Utils.transposeCOO
197197
198198 [<IterationSetup>]
199199 member this.BuildCOO () =
@@ -207,9 +207,9 @@ type EWiseAddBenchmarks4Bool() =
207207 Matrix.Build< bool>(
208208 this.FirstMatrix.RowCount,
209209 this.FirstMatrix.ColumnCount,
210- this.FirstMatrix.Rows ,
211- this.FirstMatrix.Columns ,
212- this.FirstMatrix.Values ,
210+ leftRows ,
211+ leftCols ,
212+ leftVals ,
213213 COO
214214 )
215215
@@ -223,9 +223,9 @@ type EWiseAddBenchmarks4Bool() =
223223 Matrix.Build< bool>(
224224 this.SecondMatrix.RowCount,
225225 this.SecondMatrix.ColumnCount,
226- this.SecondMatrix.Rows ,
227- this.SecondMatrix.Columns ,
228- this.SecondMatrix.Values ,
226+ rightRows ,
227+ rightCols ,
228+ rightVals ,
229229 COO
230230 )
231231
@@ -236,32 +236,11 @@ type EWiseAddBenchmarks4Bool() =
236236 |> context.RunSync
237237
238238 static member InputMatricesProvider =
239- let matricesFilenames =
240- let pathToConfig =
241- Path.Combine [|
242- __ SOURCE_ DIRECTORY__
243- " Configs"
244- " EWiseAddBenchmarks4Bool.txt"
245- |] |> Path.GetFullPath
246-
247- File.ReadAllLines pathToConfig
248- |> Seq.ofArray
249- |> Seq.filter ( fun line -> not <| line.StartsWith " !" )
250-
251- let matrixHandler ( matrixFilename : string ) =
252- match Path.GetExtension matrixFilename with
253- | " .mtx" ->
254- let mtx = GraphReader.readMtx <| Utils.getFullPathToMatrix matrixFilename
255- match mtx.Format, mtx.Field with
256- | " coordinate" , " real" -> Utils.makeCOO mtx <| FromString ( fun _ -> true )
257- | " coordinate" , " integer" -> Utils.makeCOO mtx <| FromString ( fun _ -> true )
258- | " coordinate" , " pattern" -> Utils.makeCOO mtx <| FromUnit ( fun _ -> true )
239+ " EWiseAddBenchmarks4Bool.txt"
240+ |> Utils.getMatricesFilenames
241+ |> Seq.map
242+ ( fun matrixFilename ->
243+ match Path.GetExtension matrixFilename with
244+ | " .mtx" -> MtxReader.readShape <| Utils.getFullPathToMatrix matrixFilename
259245 | _ -> failwith " Unsupported matrix format"
260- | _ -> failwith " Unsupported matrix format"
261-
262- matricesFilenames
263- |> Seq.map ( fun filename ->
264- {
265- MatrixName = Path.GetFileNameWithoutExtension filename
266- MatrixStructure = matrixHandler filename
267- })
246+ )
0 commit comments