@@ -10,64 +10,88 @@ open System.IO
1010open System.Text .RegularExpressions
1111open BenchmarkDotNet.Configs
1212open BenchmarkDotNet.Jobs
13+ open GraphBLAS.FSharp
1314
1415type CommonConfig () =
1516 inherit ManualConfig()
1617
1718 do
1819 base .AddColumn(
19- MatrixShapeColumn( " RowCount" , fun mtxReader -> mtxReader.ReadMatrixShape() .RowCount) :> IColumn,
20- MatrixShapeColumn( " ColumnCount" , fun mtxReader -> mtxReader.ReadMatrixShape() .ColumnCount) :> IColumn,
21- MatrixShapeColumn( " NNZ" , fun mtxReader -> mtxReader.ReadMatrixShape() .Nnz) :> IColumn,
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+ MatrixShapeColumn( " SqrNNZ" , ( fun ( _ , mtxReader ) -> mtxReader.ReadMatrixShape() .Nnz)) :> IColumn,
2224 TEPSColumn() :> IColumn,
2325 StatisticColumn.Min,
2426 StatisticColumn.Max
25- ) |> ignore
27+ )
28+ |> ignore
2629
2730 base .AddJob(
28- Job.Dry
31+ Job
32+ .Dry
2933 .WithWarmupCount( 3 )
3034 .WithIterationCount( 10 )
3135 .WithInvocationCount( 3 )
32- ) |> ignore
36+ )
37+ |> ignore
3338
34- type ClContext = ClContext of Brahma.FSharp.OpenCL.ClContext
35- with
39+ type ClContext =
40+ | ClContext of Brahma.FSharp.OpenCL.ClContext
3641 override this.ToString () =
3742 let mutable e = ErrorCode.Unknown
3843 let ( ClContext context ) = this
3944 let device = context.Device
40- let deviceName = Cl.GetDeviceInfo( device, DeviceInfo.Name, & e) .ToString()
45+
46+ let deviceName =
47+ Cl
48+ .GetDeviceInfo( device, DeviceInfo.Name, & e)
49+ .ToString()
50+
4151 if deviceName.Length < 20 then
4252 sprintf " %s " deviceName
4353 else
44- let platform = Cl.GetDeviceInfo( device, DeviceInfo.Platform, & e) .CastTo< Platform>()
45- let platformName = Cl.GetPlatformInfo( platform, PlatformInfo.Name, & e) .ToString()
54+ let platform =
55+ Cl
56+ .GetDeviceInfo( device, DeviceInfo.Platform, & e)
57+ .CastTo< Platform>()
58+
59+ let platformName =
60+ Cl
61+ .GetPlatformInfo( platform, PlatformInfo.Name, & e)
62+ .ToString()
63+
4664 let deviceType =
47- match Cl.GetDeviceInfo( device, DeviceInfo.Type, & e) .CastTo< DeviceType>() with
65+ match Cl
66+ .GetDeviceInfo( device, DeviceInfo.Type, & e)
67+ .CastTo< DeviceType>() with
4868 | DeviceType.Cpu -> " CPU"
4969 | DeviceType.Gpu -> " GPU"
5070 | DeviceType.Accelerator -> " Accelerator"
5171 | _ -> " another"
5272
5373 sprintf " %s , %s " platformName deviceType
5474
55- type MatrixShapeColumn ( columnName : string , getShape : MtxReader -> int ) =
75+ type MatrixShapeColumn ( columnName : string , getShape : ( MtxReader * MtxReader ) -> int ) =
5676 interface IColumn with
5777 member this.AlwaysShow : bool = true
5878 member this.Category : ColumnCategory = ColumnCategory.Params
5979 member this.ColumnName : string = columnName
6080
61- member this.GetValue ( summary : Summary , benchmarkCase : BenchmarkCase ): string =
62- let inputMatrix = benchmarkCase.Parameters.[ " InputMatrixReader" ] :?> MtxReader
81+ member this.GetValue ( summary : Summary , benchmarkCase : BenchmarkCase ) : string =
82+ let inputMatrix =
83+ benchmarkCase.Parameters.[ " InputMatrixReader" ] :?> MtxReader * MtxReader
84+
6385 sprintf " %i " <| getShape inputMatrix
6486
65- member this.GetValue ( summary : Summary , benchmarkCase : BenchmarkCase , style : SummaryStyle ): string =
87+ member this.GetValue ( summary : Summary , benchmarkCase : BenchmarkCase , style : SummaryStyle ) : string =
6688 ( this :> IColumn) .GetValue( summary, benchmarkCase)
6789
68- member this.Id : string = sprintf " %s .%s " " MatrixShapeColumn" columnName
69- member this.IsAvailable ( summary : Summary ): bool = true
70- member this.IsDefault ( summary : Summary , benchmarkCase : BenchmarkCase ): bool = false
90+ member this.Id : string =
91+ sprintf " %s .%s " " MatrixShapeColumn" columnName
92+
93+ member this.IsAvailable ( summary : Summary ) : bool = true
94+ member this.IsDefault ( summary : Summary , benchmarkCase : BenchmarkCase ) : bool = false
7195 member this.IsNumeric : bool = true
7296 member this.Legend : string = sprintf " %s of input matrix" columnName
7397 member this.PriorityInCategory : int = 1
@@ -79,28 +103,39 @@ type TEPSColumn() =
79103 member this.Category : ColumnCategory = ColumnCategory.Statistics
80104 member this.ColumnName : string = " TEPS"
81105
82- member this.GetValue ( summary : Summary , benchmarkCase : BenchmarkCase ): string =
83- let inputMatrixReader = benchmarkCase.Parameters.[ " InputMatrixReader" ] :?> MtxReader
106+ member this.GetValue ( summary : Summary , benchmarkCase : BenchmarkCase ) : string =
107+ let inputMatrixReader =
108+ benchmarkCase.Parameters.[ " InputMatrixReader" ] :?> MtxReader * MtxReader
109+ |> fst
110+
84111 let matrixShape = inputMatrixReader.ReadMatrixShape()
85112
86- let ( nrows , ncols ) = matrixShape.RowCount, matrixShape.ColumnCount
113+ let ( nrows , ncols ) =
114+ matrixShape.RowCount, matrixShape.ColumnCount
115+
87116 let ( vertices , edges ) =
88117 match inputMatrixReader.Format with
89- | Coordinate -> if nrows = ncols then ( nrows, matrixShape.Nnz) else ( ncols, nrows)
118+ | Coordinate ->
119+ if nrows = ncols then
120+ ( nrows, matrixShape.Nnz)
121+ else
122+ ( ncols, nrows)
90123 | _ -> failwith " Unsupported"
91124
92125 if isNull summary.[ benchmarkCase]. ResultStatistics then
93126 " NA"
94127 else
95- let meanTime = summary.[ benchmarkCase]. ResultStatistics.Mean
128+ let meanTime =
129+ summary.[ benchmarkCase]. ResultStatistics.Mean
130+
96131 sprintf " %f " <| float edges / ( meanTime * 1e-6 )
97132
98- member this.GetValue ( summary : Summary , benchmarkCase : BenchmarkCase , style : SummaryStyle ): string =
133+ member this.GetValue ( summary : Summary , benchmarkCase : BenchmarkCase , style : SummaryStyle ) : string =
99134 ( this :> IColumn) .GetValue( summary, benchmarkCase)
100135
101136 member this.Id : string = " TEPSColumn"
102- member this.IsAvailable ( summary : Summary ): bool = true
103- member this.IsDefault ( summary : Summary , benchmarkCase : BenchmarkCase ): bool = false
137+ member this.IsAvailable ( summary : Summary ) : bool = true
138+ member this.IsDefault ( summary : Summary , benchmarkCase : BenchmarkCase ) : bool = false
104139 member this.IsNumeric : bool = true
105140 member this.Legend : string = " Traversed edges per second"
106141 member this.PriorityInCategory : int = 0
@@ -109,59 +144,126 @@ type TEPSColumn() =
109144module Utils =
110145 let getMatricesFilenames configFilename =
111146 let getFullPathToConfig filename =
112- Path.Combine [|
113- __ SOURCE _ DIRECTORY __
114- " Configs "
115- filename
116- |] |> Path.GetFullPath
147+ Path.Combine [| __ SOURCE _ DIRECTORY __
148+ " Configs "
149+ filename |]
150+ |> Path.GetFullPath
151+
117152
118153 configFilename
119154 |> getFullPathToConfig
120155 |> File.ReadLines
121156 |> Seq.filter ( fun line -> not <| line.StartsWith " !" )
122157
123158 let getFullPathToMatrix datasetsFolder matrixFilename =
124- Path.Combine [|
125- __ SOURCE_ DIRECTORY__
126- " Datasets"
127- datasetsFolder
128- matrixFilename
129- |]
159+ Path.Combine [| __ SOURCE_ DIRECTORY__
160+ " Datasets"
161+ datasetsFolder
162+ matrixFilename |]
130163
131164 let avaliableContexts =
132165 let pathToConfig =
133- Path.Combine [|
134- __ SOURCE_ DIRECTORY__
135- " Configs"
136- " Context.txt"
137- |] |> Path.GetFullPath
166+ Path.Combine [| __ SOURCE_ DIRECTORY__
167+ " Configs"
168+ " Context.txt" |]
169+ |> Path.GetFullPath
138170
139171 use reader = new StreamReader( pathToConfig)
140172 let platformRegex = Regex <| reader.ReadLine()
173+
141174 let deviceType =
142175 match reader.ReadLine() with
143176 | " Cpu" -> DeviceType.Cpu
144177 | " Gpu" -> DeviceType.Gpu
145- | " All " -> DeviceType.All
178+ | " Default " -> DeviceType.Default
146179 | _ -> failwith " Unsupported"
147180
181+ let workGroupSizes =
182+ reader.ReadLine()
183+ |> ( fun s -> s.Split ' ' )
184+ |> Seq.map int
185+
148186 let mutable e = ErrorCode.Unknown
149- Cl.GetPlatformIDs & e
150- |> Array.collect ( fun platform -> Cl.GetDeviceIDs( platform, deviceType, & e))
151- |> Seq.ofArray
152- |> Seq.distinctBy ( fun device -> Cl.GetDeviceInfo( device, DeviceInfo.Name, & e) .ToString())
153- |> Seq.filter
154- ( fun device ->
155- let platform = Cl.GetDeviceInfo( device, DeviceInfo.Platform, & e) .CastTo< Platform>()
156- let platformName = Cl.GetPlatformInfo( platform, PlatformInfo.Name, & e) .ToString()
157- platformRegex.IsMatch platformName
158- )
159- |> Seq.map
160- ( fun device ->
161- let platform = Cl.GetDeviceInfo( device, DeviceInfo.Platform, & e) .CastTo< Platform>()
162- let platformName = Cl.GetPlatformInfo( platform, PlatformInfo.Name, & e) .ToString()
163- let deviceType = Cl.GetDeviceInfo( device, DeviceInfo.Type, & e) .CastTo< DeviceType>()
164- failwith " fix me"
165- //OpenCLEvaluationContext(platformName, deviceType) |> ClContext
166- Brahma.FSharp.OpenCL.ClContext () |> ClContext
167- )
187+
188+ let contexts =
189+ Cl.GetPlatformIDs & e
190+ |> Array.collect ( fun platform -> Cl.GetDeviceIDs( platform, deviceType, & e))
191+ |> Seq.ofArray
192+ |> Seq.distinctBy
193+ ( fun device ->
194+ Cl
195+ .GetDeviceInfo( device, DeviceInfo.Name, & e)
196+ .ToString())
197+ |> Seq.filter
198+ ( fun device ->
199+ let platform =
200+ Cl
201+ .GetDeviceInfo( device, DeviceInfo.Platform, & e)
202+ .CastTo< Platform>()
203+
204+ let platformName =
205+ Cl
206+ .GetPlatformInfo( platform, PlatformInfo.Name, & e)
207+ .ToString()
208+
209+ platformRegex.IsMatch platformName)
210+ |> Seq.map
211+ ( fun device ->
212+ let platform =
213+ Cl
214+ .GetDeviceInfo( device, DeviceInfo.Platform, & e)
215+ .CastTo< Platform>()
216+
217+ let clPlatform =
218+ Cl
219+ .GetPlatformInfo( platform, PlatformInfo.Name, & e)
220+ .ToString()
221+ |> ClPlatform.Custom
222+
223+ let deviceType =
224+ Cl
225+ .GetDeviceInfo( device, DeviceInfo.Type, & e)
226+ .CastTo< DeviceType>()
227+
228+ let clDeviceType =
229+ match deviceType with
230+ | DeviceType.Cpu -> ClDeviceType.CPU
231+ | DeviceType.Gpu -> ClDeviceType.GPU
232+ | DeviceType.Default -> ClDeviceType.Default
233+ | _ -> failwith " Unsupported"
234+
235+ Brahma.FSharp.OpenCL.ClContext( clPlatform, clDeviceType))
236+
237+ seq {
238+ for wgSize in workGroupSizes do
239+ for context in contexts do
240+ yield ( context, wgSize)
241+ }
242+
243+ let nextSingle ( random : System.Random ) =
244+ let buffer = Array.zeroCreate< byte> 4
245+ random.NextBytes buffer
246+ System.BitConverter.ToSingle( buffer, 0 )
247+
248+ let rowPointers2rowIndices ( rowPointers : int []) =
249+ let rowIndices =
250+ Array.zeroCreate rowPointers.[ rowPointers.Length - 1 ]
251+
252+ [| 0 .. rowPointers.Length - 2 |]
253+ |> Array.Parallel.iter
254+ ( fun i ->
255+ [| rowPointers.[ i] .. rowPointers.[ i + 1 ] - 1 |]
256+ |> Array.Parallel.iter ( fun j -> rowIndices.[ j] <- i))
257+
258+ rowIndices
259+
260+ let rowIndices2rowPointers ( rowIndices : int []) rowCount =
261+ let nnzPerRow = Array.zeroCreate rowCount
262+ let rowPointers = Array.zeroCreate rowCount
263+
264+ Array.iter ( fun rowIndex -> nnzPerRow.[ rowIndex] <- nnzPerRow.[ rowIndex] + 1 ) rowIndices
265+
266+ for i in 1 .. rowCount - 1 do
267+ rowPointers.[ i] <- rowPointers.[ i - 1 ] + nnzPerRow.[ i - 1 ]
268+
269+ rowPointers
0 commit comments