@@ -17,15 +17,19 @@ open OpenCL.Net
1717open Brahma.OpenCL
1818open System.Text .RegularExpressions
1919
20- type Config < 'a > () =
20+ type Config () =
2121 inherit ManualConfig()
2222
2323 do
2424 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,
25+ MatrixShapeColumn( " RowCount" , fun matrix -> matrix.RowCount) :> IColumn,
26+ MatrixShapeColumn( " ColumnCount" , fun matrix -> matrix.ColumnCount) :> IColumn,
27+ MatrixShapeColumn( " NNZ" , fun matrix ->
28+ match matrix.Format with
29+ | " coordinate" -> matrix.Size.[ 2 ]
30+ | " array" -> 0
31+ | _ -> failwith " Unsupported" ) :> IColumn,
32+ TEPSColumn() :> IColumn,
2933 StatisticColumn.Min,
3034 StatisticColumn.Max
3135 ) |> ignore
@@ -36,19 +40,26 @@ type Config<'a>() =
3640 )
3741 ) |> ignore
3842
39- type Float32Config = Config< float32>
40- type BoolConfig = Config< bool>
41-
42- [<SimpleJob( RunStrategy.Monitoring, targetCount= 2 ) >]
43+ [<IterationCount( 1 ) >]
44+ [<WarmupCount( 1 ) >]
45+ [<Config( typeof< Config>) >]
4346type EWiseAddBenchmarks () =
4447 [<ParamsSource( " AvaliableContexts" ) >]
4548 member val OclContext = Unchecked.defaultof< ClContext> with get, set
4649
50+ [<ParamsSource( " InputMatricesProvider" ) >]
51+ member val InputMatrix = Unchecked.defaultof< MtxShape> with get, set
52+
4753 [<IterationCleanup>]
4854 member this.ClearBuffers () =
4955 let ( ClContext context ) = this.OclContext
5056 context.Provider.CloseAllBuffers()
5157
58+ [<GlobalCleanup>]
59+ member this.ClearContext () =
60+ let ( ClContext context ) = this.OclContext
61+ context.Provider.Dispose()
62+
5263 static member AvaliableContexts =
5364 let pathToConfig =
5465 Path.Combine [|
@@ -84,7 +95,6 @@ type EWiseAddBenchmarks() =
8495 OpenCLEvaluationContext( platformName, deviceType) |> ClContext
8596 )
8697
87- [<Config( typeof< Float32Config>) >]
8898type EWiseAddBenchmarks4Float32 () =
8999 inherit EWiseAddBenchmarks()
90100
@@ -94,13 +104,25 @@ type EWiseAddBenchmarks4Float32() =
94104 member val FirstMatrix = Unchecked.defaultof< COOFormat< float32>> with get, set
95105 member val SecondMatrix = Unchecked.defaultof< COOFormat< float32>> with get, set
96106
97- [<ParamsSource( " InputMatricesProvider" ) >]
98- member val InputMatrix = Unchecked.defaultof< InputMatrixFormat< float32>> with get, set
99-
100107 [<GlobalSetup>]
101108 member this.FormInputData () =
102- this.FirstMatrix <- this.InputMatrix.MatrixStructure
103- this.SecondMatrix <- this.InputMatrix.MatrixStructure |> Utils.transposeCOO
109+ let mtxFormat = GraphReader.readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
110+ let cooMatrix =
111+ match mtxFormat.Shape.Format, mtxFormat.Shape.Field with
112+ | " coordinate" , " real" -> Utils.makeCOO mtxFormat <| FromString float32
113+ | " coordinate" , " integer" -> Utils.makeCOO mtxFormat <| FromString float32
114+ | " coordinate" , " pattern" ->
115+ let rand = System.Random()
116+ let nextSingle ( random : System.Random ) =
117+ let buffer = Array.zeroCreate< byte> 4
118+ random.NextBytes buffer
119+ System.BitConverter.ToSingle( buffer, 0 )
120+
121+ Utils.makeCOO mtxFormat <| FromUnit ( fun () -> nextSingle rand)
122+ | _ -> failwith " Unsupported matrix format"
123+
124+ this.FirstMatrix <- cooMatrix
125+ this.SecondMatrix <- cooMatrix |> Utils.transposeCOO
104126
105127 [<IterationSetup>]
106128 member this.BuildCOO () =
@@ -157,32 +179,14 @@ type EWiseAddBenchmarks4Float32() =
157179 |> Seq.ofArray
158180 |> Seq.filter ( fun line -> not <| line.StartsWith " !" )
159181
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)
175- | _ -> failwith " Unsupported matrix format"
176- | _ -> failwith " Unsupported matrix format"
177-
178182 matricesFilenames
179- |> Seq.map ( fun filename ->
180- {
181- MatrixName = Path.GetFileNameWithoutExtension filename
182- MatrixStructure = matrixHandler filename
183- })
183+ |> Seq.map
184+ ( fun matrixFilename ->
185+ match Path.GetExtension matrixFilename with
186+ | " .mtx" -> GraphReader.readShapeMtx <| Utils.getFullPathToMatrix matrixFilename
187+ | _ -> failwith " Unsupported matrix format"
188+ )
184189
185- [<Config( typeof< BoolConfig>) >]
186190type EWiseAddBenchmarks4Bool () =
187191 inherit EWiseAddBenchmarks()
188192
@@ -192,13 +196,18 @@ type EWiseAddBenchmarks4Bool() =
192196 member val FirstMatrix = Unchecked.defaultof< COOFormat< bool>> with get, set
193197 member val SecondMatrix = Unchecked.defaultof< COOFormat< bool>> with get, set
194198
195- [<ParamsSource( " InputMatricesProvider" ) >]
196- member val InputMatrix = Unchecked.defaultof< InputMatrixFormat< bool>> with get, set
197-
198199 [<GlobalSetup>]
199200 member this.FormInputData () =
200- this.FirstMatrix <- this.InputMatrix.MatrixStructure
201- this.SecondMatrix <- this.InputMatrix.MatrixStructure |> Utils.transposeCOO
201+ let mtxFormat = GraphReader.readMtx <| Utils.getFullPathToMatrix this.InputMatrix.Filename
202+ let cooMatrix =
203+ match mtxFormat.Shape.Format, mtxFormat.Shape.Field with
204+ | " coordinate" , " real" -> Utils.makeCOO mtxFormat <| FromString ( fun _ -> true )
205+ | " coordinate" , " integer" -> Utils.makeCOO mtxFormat <| FromString ( fun _ -> true )
206+ | " coordinate" , " pattern" -> Utils.makeCOO mtxFormat <| FromUnit ( fun _ -> true )
207+ | _ -> failwith " Unsupported matrix format"
208+
209+ this.FirstMatrix <- cooMatrix
210+ this.SecondMatrix <- cooMatrix |> Utils.transposeCOO
202211
203212 [<IterationSetup>]
204213 member this.BuildCOO () =
@@ -253,20 +262,10 @@ type EWiseAddBenchmarks4Bool() =
253262 |> Seq.ofArray
254263 |> Seq.filter ( fun line -> not <| line.StartsWith " !" )
255264
256- let matrixHandler ( matrixFilename : string ) =
257- match Path.GetExtension matrixFilename with
258- | " .mtx" ->
259- let mtx = GraphReader.readMtx <| Utils.getFullPathToMatrix matrixFilename
260- match mtx.Format, mtx.Field with
261- | " coordinate" , " real" -> Utils.makeCOO mtx <| FromString ( fun _ -> true )
262- | " coordinate" , " integer" -> Utils.makeCOO mtx <| FromString ( fun _ -> true )
263- | " coordinate" , " pattern" -> Utils.makeCOO mtx <| FromUnit ( fun _ -> true )
264- | _ -> failwith " Unsupported matrix format"
265- | _ -> failwith " Unsupported matrix format"
266-
267265 matricesFilenames
268- |> Seq.map ( fun filename ->
269- {
270- MatrixName = Path.GetFileNameWithoutExtension filename
271- MatrixStructure = matrixHandler filename
272- })
266+ |> Seq.map
267+ ( fun matrixFilename ->
268+ match Path.GetExtension matrixFilename with
269+ | " .mtx" -> GraphReader.readShapeMtx <| Utils.getFullPathToMatrix matrixFilename
270+ | _ -> failwith " Unsupported matrix format"
271+ )
0 commit comments