11namespace GraphBLAS.FSharp.Benchmarks
22
33open GraphBLAS.FSharp
4- open GraphBLAS.FSharp .Algorithms
54open BenchmarkDotNet.Attributes
65open BenchmarkDotNet.Configs
76open BenchmarkDotNet.Columns
87open 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
218open GraphBLAS.FSharp .IO
229
2310type 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+ )
0 commit comments