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
2016type Config () =
2117 inherit ManualConfig()
@@ -36,13 +32,12 @@ type Config() =
3632
3733 base .AddFilter(
3834 DisjunctionFilter(
39- NameFilter( fun name -> name.Contains " COO" ) :> IFilter,
40- NameFilter( fun name -> name.Contains " ToHost" ) :> IFilter
35+ NameFilter( fun name -> name.Contains " COO" ) :> IFilter
4136 )
4237 ) |> ignore
4338
44- [<IterationCount( 1 ) >]
45- [<WarmupCount( 1 ) >]
39+ [<IterationCount( 5 ) >]
40+ [<WarmupCount( 3 ) >]
4641[<Config( typeof< Config>) >]
4742type EWiseAddBenchmarks () =
4843 [<ParamsSource( " AvaliableContexts" ) >]
@@ -108,7 +103,7 @@ type EWiseAddBenchmarks4Float32() =
108103
109104 [<GlobalSetup>]
110105 member this.FormInputData () =
111- let mtxFormat = GraphReader .readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
106+ let mtxFormat = MtxReader .readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
112107 let cooMatrix =
113108 match mtxFormat.Shape.Format, mtxFormat.Shape.Field with
114109 | " coordinate" , " real" -> Utils.makeCOO mtxFormat <| FromString float32
@@ -169,121 +164,12 @@ type EWiseAddBenchmarks4Float32() =
169164 |> context.RunSync
170165
171166 static member InputMatricesProvider =
172- let matricesFilenames =
173- let pathToConfig =
174- Path.Combine [|
175- __ SOURCE_ DIRECTORY__
176- " Configs"
177- " EWiseAddBenchmarks4Float32.txt"
178- |] |> Path.GetFullPath
179-
180- File.ReadAllLines pathToConfig
181- |> Seq.ofArray
182- |> Seq.filter ( fun line -> not <| line.StartsWith " !" )
183-
184- matricesFilenames
185- |> Seq.map
186- ( fun matrixFilename ->
187- match Path.GetExtension matrixFilename with
188- | " .mtx" -> GraphReader.readShapeMtx <| Utils.getFullPathToMatrix matrixFilename
189- | _ -> failwith " Unsupported matrix format"
190- )
191-
192- type ToHostBenchmarks4Float32 () =
193- inherit EWiseAddBenchmarks()
194-
195- let mutable leftCOO = Unchecked.defaultof< Matrix< float32>>
196- let mutable rightCOO = Unchecked.defaultof< Matrix< float32>>
197- let mutable resultCOO = Unchecked.defaultof< Matrix< float32>>
198-
199- member val FirstMatrix = Unchecked.defaultof< COOFormat< float32>> with get, set
200- member val SecondMatrix = Unchecked.defaultof< COOFormat< float32>> with get, set
201-
202- [<GlobalSetup>]
203- member this.FormInputData () =
204- let mtxFormat = GraphReader.readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
205- let cooMatrix =
206- match mtxFormat.Shape.Format, mtxFormat.Shape.Field with
207- | " coordinate" , " real" -> Utils.makeCOO mtxFormat <| FromString float32
208- | " coordinate" , " integer" -> Utils.makeCOO mtxFormat <| FromString float32
209- | " coordinate" , " pattern" ->
210- let rand = System.Random()
211- let nextSingle ( random : System.Random ) =
212- let buffer = Array.zeroCreate< byte> 4
213- random.NextBytes buffer
214- System.BitConverter.ToSingle( buffer, 0 )
215-
216- Utils.makeCOO mtxFormat <| FromUnit ( fun () -> nextSingle rand)
217- | _ -> failwith " Unsupported matrix format"
218-
219- this.FirstMatrix <- cooMatrix
220- this.SecondMatrix <- cooMatrix |> Utils.transposeCOO
221-
222- [<IterationSetup>]
223- member this.BuildCOO () =
224- let leftRows = Array.zeroCreate< int> this.FirstMatrix.Rows.Length
225- let leftCols = Array.zeroCreate< int> this.FirstMatrix.Columns.Length
226- let leftVals = Array.zeroCreate< float32> this.FirstMatrix.Values.Length
227- Array.blit this.FirstMatrix.Rows 0 leftRows 0 this.FirstMatrix.Rows.Length
228- Array.blit this.FirstMatrix.Columns 0 leftCols 0 this.FirstMatrix.Columns.Length
229- Array.blit this.FirstMatrix.Values 0 leftVals 0 this.FirstMatrix.Values.Length
230-
231- leftCOO <-
232- Matrix.Build< float32>(
233- this.FirstMatrix.RowCount,
234- this.FirstMatrix.ColumnCount,
235- leftRows,
236- leftCols,
237- leftVals,
238- COO
239- )
240-
241- let rightRows = Array.zeroCreate< int> this.SecondMatrix.Rows.Length
242- let rightCols = Array.zeroCreate< int> this.SecondMatrix.Columns.Length
243- let rightVals = Array.zeroCreate< float32> this.SecondMatrix.Values.Length
244- Array.blit this.SecondMatrix.Rows 0 rightRows 0 this.SecondMatrix.Rows.Length
245- Array.blit this.SecondMatrix.Columns 0 rightCols 0 this.SecondMatrix.Columns.Length
246- Array.blit this.SecondMatrix.Values 0 rightVals 0 this.SecondMatrix.Values.Length
247-
248- rightCOO <-
249- Matrix.Build< float32>(
250- this.SecondMatrix.RowCount,
251- this.SecondMatrix.ColumnCount,
252- rightRows,
253- rightCols,
254- rightVals,
255- COO
256- )
257-
258- let ( ClContext context ) = this.OclContext
259- resultCOO <-
260- leftCOO.EWiseAdd rightCOO None Float32Semiring.addMult
261- |> context.RunSync
262-
263- [<Benchmark>]
264- member this.ToHostFloat32 () =
265- let ( ClContext context ) = this.OclContext
266- resultCOO.ToHost()
267- |> context.RunSync
268-
269- static member InputMatricesProvider =
270- let matricesFilenames =
271- let pathToConfig =
272- Path.Combine [|
273- __ SOURCE_ DIRECTORY__
274- " Configs"
275- " EWiseAddBenchmarks4Float32.txt"
276- |] |> Path.GetFullPath
277-
278- File.ReadAllLines pathToConfig
279- |> Seq.ofArray
280- |> Seq.filter ( fun line -> not <| line.StartsWith " !" )
281-
282- matricesFilenames
167+ " EWiseAddBenchmarks4Float32.txt"
168+ |> Utils.getMatricesFilenames
283169 |> Seq.map
284170 ( fun matrixFilename ->
285171 match Path.GetExtension matrixFilename with
286- | " .mtx" -> GraphReader.readShapeMtx <| Utils.getFullPathToMatrix matrixFilename
172+ | " .mtx" -> MtxReader.readShape <| Utils.getFullPathToMatrix matrixFilename
287173 | _ -> failwith " Unsupported matrix format"
288174 )
289175
@@ -298,7 +184,7 @@ type EWiseAddBenchmarks4Bool() =
298184
299185 [<GlobalSetup>]
300186 member this.FormInputData () =
301- let mtxFormat = GraphReader .readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
187+ let mtxFormat = MtxReader .readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
302188 let cooMatrix =
303189 match mtxFormat.Shape.Format, mtxFormat.Shape.Field with
304190 | " coordinate" , " real" -> Utils.makeCOO mtxFormat <| FromString ( fun _ -> true )
@@ -350,22 +236,11 @@ type EWiseAddBenchmarks4Bool() =
350236 |> context.RunSync
351237
352238 static member InputMatricesProvider =
353- let matricesFilenames =
354- let pathToConfig =
355- Path.Combine [|
356- __ SOURCE_ DIRECTORY__
357- " Configs"
358- " EWiseAddBenchmarks4Bool.txt"
359- |] |> Path.GetFullPath
360-
361- File.ReadAllLines pathToConfig
362- |> Seq.ofArray
363- |> Seq.filter ( fun line -> not <| line.StartsWith " !" )
364-
365- matricesFilenames
239+ " EWiseAddBenchmarks4Bool.txt"
240+ |> Utils.getMatricesFilenames
366241 |> Seq.map
367242 ( fun matrixFilename ->
368243 match Path.GetExtension matrixFilename with
369- | " .mtx" -> GraphReader.readShapeMtx <| Utils.getFullPathToMatrix matrixFilename
244+ | " .mtx" -> MtxReader.readShape <| Utils.getFullPathToMatrix matrixFilename
370245 | _ -> failwith " Unsupported matrix format"
371246 )
0 commit comments