|
| 1 | +namespace GraphBLAS.FSharp.Benchmarks |
| 2 | + |
| 3 | +open GraphBLAS.FSharp |
| 4 | +open GraphBLAS.FSharp.Algorithms |
| 5 | +open BenchmarkDotNet.Attributes |
| 6 | +open BenchmarkDotNet.Configs |
| 7 | +open BenchmarkDotNet.Columns |
| 8 | +open 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 |
| 21 | +open GraphBLAS.FSharp.IO |
| 22 | + |
| 23 | +type MxvConfig() = |
| 24 | + inherit ManualConfig() |
| 25 | + |
| 26 | + do |
| 27 | + base.AddColumn( |
| 28 | + MatrixShapeColumn("RowCount", fun mtxReader -> mtxReader.ReadMatrixShape().RowCount) :> IColumn, |
| 29 | + MatrixShapeColumn("ColumnCount", fun mtxReader -> mtxReader.ReadMatrixShape().ColumnCount) :> IColumn, |
| 30 | + MatrixShapeColumn("NNZ", fun mtxReader -> mtxReader.ReadMatrixShape().Nnz) :> IColumn, |
| 31 | + TEPSColumn() :> IColumn, |
| 32 | + StatisticColumn.Min, |
| 33 | + StatisticColumn.Max |
| 34 | + ) |> ignore |
| 35 | + |
| 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 | +// ) |
0 commit comments