|
| 1 | +namespace GraphBLAS.FSharp.Benchmarks |
| 2 | + |
| 3 | +open System.IO |
| 4 | +open GraphBLAS.FSharp |
| 5 | +open GraphBLAS.FSharp.Predefined |
| 6 | +open GraphBLAS.FSharp.MatrixBackend |
| 7 | +open BenchmarkDotNet.Attributes |
| 8 | +open BenchmarkDotNet.Engines |
| 9 | +open BenchmarkDotNet.Configs |
| 10 | +open BenchmarkDotNet.Columns |
| 11 | +open BenchmarkDotNet.Filters |
| 12 | +open BenchmarkDotNet.Jobs |
| 13 | +open BenchmarkDotNet.Order |
| 14 | +open Brahma.FSharp.OpenCL.WorkflowBuilder.Basic |
| 15 | +open Brahma.FSharp.OpenCL.WorkflowBuilder.Evaluation |
| 16 | +open OpenCL.Net |
| 17 | + |
| 18 | +type Config() = |
| 19 | + inherit ManualConfig() |
| 20 | + |
| 21 | + do |
| 22 | + base.AddColumn( |
| 23 | + MatrixShapeColumn("RowCount", fun matrix -> matrix.MatrixStructure.RowCount) :> IColumn, |
| 24 | + MatrixShapeColumn("ColumnCount", fun matrix -> matrix.MatrixStructure.ColumnCount) :> IColumn, |
| 25 | + MatrixShapeColumn("NNZ", fun matrix -> matrix.MatrixStructure.Values.Length) :> IColumn, |
| 26 | + TEPSColumn() :> IColumn, |
| 27 | + StatisticColumn.Min, |
| 28 | + StatisticColumn.Max |
| 29 | + ) |> ignore |
| 30 | + |
| 31 | + base.AddFilter( |
| 32 | + DisjunctionFilter( |
| 33 | + NameFilter(fun name -> name.Contains "COO") :> IFilter |
| 34 | + ) |
| 35 | + ) |> ignore |
| 36 | + |
| 37 | +[<Config(typeof<Config>)>] |
| 38 | +[<SimpleJob(RunStrategy.Monitoring, targetCount=2)>] |
| 39 | +type EWiseAddBenchmarks() = |
| 40 | + member val FirstMatrix = Unchecked.defaultof<COOFormat<float32>> with get, set |
| 41 | + member val SecondMatrix = Unchecked.defaultof<COOFormat<float32>> with get, set |
| 42 | + |
| 43 | + [<ParamsSource("InputMatricesProvider")>] |
| 44 | + member val InputMatrix = Unchecked.defaultof<InputMatrixFormat> with get, set |
| 45 | + |
| 46 | + [<ParamsSource("AvaliableContexts")>] |
| 47 | + member val OclContext = Unchecked.defaultof<ClContext> with get, set |
| 48 | + |
| 49 | + [<GlobalSetup>] |
| 50 | + member this.FormInputData() = |
| 51 | + let transposeCOO (matrix: COOFormat<float32>) = |
| 52 | + (matrix.Rows, matrix.Columns, matrix.Values) |
| 53 | + |||> Array.zip3 |
| 54 | + |> Array.sortBy (fun (row, col, value) -> row) |
| 55 | + |> Array.unzip3 |
| 56 | + |> |
| 57 | + fun (rows, cols, values) -> |
| 58 | + { |
| 59 | + Rows = cols |
| 60 | + Columns = rows |
| 61 | + Values = values |
| 62 | + RowCount = matrix.ColumnCount |
| 63 | + ColumnCount = matrix.RowCount |
| 64 | + } |
| 65 | + |
| 66 | + this.FirstMatrix <- this.InputMatrix.MatrixStructure |
| 67 | + this.SecondMatrix <- this.InputMatrix.MatrixStructure |> transposeCOO |
| 68 | + |
| 69 | + [<IterationCleanup>] |
| 70 | + member this.ClearBuffers() = |
| 71 | + let (ClContext context) = this.OclContext |
| 72 | + context.Provider.CloseAllBuffers() |
| 73 | + |
| 74 | + /// Sequence of paths to files where data for benchmarking will be taken from |
| 75 | + static member InputMatricesProvider = |
| 76 | + let matricesFilenames = |
| 77 | + seq { |
| 78 | + "arc130.mtx" |
| 79 | + "linux_call_graph.mtx" |
| 80 | + "webbase-1M.mtx" |
| 81 | + } |
| 82 | + |
| 83 | + matricesFilenames |
| 84 | + |> Seq.map |
| 85 | + (fun matrixFilename -> |
| 86 | + let getFullPathToMatrix filename = |
| 87 | + Path.Combine [| |
| 88 | + __SOURCE_DIRECTORY__ |
| 89 | + "Datasets" |
| 90 | + "EWiseAddDatasets" |
| 91 | + filename |
| 92 | + |] |
| 93 | + |
| 94 | + let fullPath = getFullPathToMatrix matrixFilename |
| 95 | + let matrixName = Path.GetFileNameWithoutExtension matrixFilename |
| 96 | + let matrixStructure = GraphReader.readMtx fullPath |
| 97 | + { |
| 98 | + MatrixName = matrixName |
| 99 | + MatrixStructure = matrixStructure |
| 100 | + } |
| 101 | + ) |
| 102 | + |
| 103 | + static member AvaliableContexts = |
| 104 | + let mutable e = ErrorCode.Unknown |
| 105 | + Cl.GetPlatformIDs &e |
| 106 | + |> Array.collect (fun platform -> Cl.GetDeviceIDs(platform, DeviceType.All, &e)) |
| 107 | + |> Seq.ofArray |
| 108 | + |> Seq.map |
| 109 | + (fun device -> |
| 110 | + let platform = Cl.GetDeviceInfo(device, DeviceInfo.Platform, &e).CastTo<Platform>() |
| 111 | + let platformName = Cl.GetPlatformInfo(platform, PlatformInfo.Name, &e).ToString() |
| 112 | + let deviceType = Cl.GetDeviceInfo(device, DeviceInfo.Type, &e).CastTo<DeviceType>() |
| 113 | + OpenCLEvaluationContext(platformName, deviceType) |> ClContext |
| 114 | + ) |
| 115 | + |
| 116 | +type EWiseAddBenchmarks4Float32() = |
| 117 | + inherit EWiseAddBenchmarks() |
| 118 | + |
| 119 | + let mutable leftCOO = Unchecked.defaultof<Matrix<float32>> |
| 120 | + let mutable rightCOO = Unchecked.defaultof<Matrix<float32>> |
| 121 | + |
| 122 | + [<IterationSetup>] |
| 123 | + member this.BuildCOO() = |
| 124 | + let leftRows = Array.zeroCreate<int> base.FirstMatrix.Rows.Length |
| 125 | + let leftCols = Array.zeroCreate<int> base.FirstMatrix.Columns.Length |
| 126 | + let leftVals = Array.zeroCreate<float32> base.FirstMatrix.Values.Length |
| 127 | + Array.blit base.FirstMatrix.Rows 0 leftRows 0 base.FirstMatrix.Rows.Length |
| 128 | + Array.blit base.FirstMatrix.Columns 0 leftCols 0 base.FirstMatrix.Columns.Length |
| 129 | + Array.blit base.FirstMatrix.Values 0 leftVals 0 base.FirstMatrix.Values.Length |
| 130 | + |
| 131 | + leftCOO <- |
| 132 | + Matrix.Build<float32>( |
| 133 | + base.FirstMatrix.RowCount, |
| 134 | + base.FirstMatrix.ColumnCount, |
| 135 | + leftRows, |
| 136 | + leftCols, |
| 137 | + leftVals, |
| 138 | + COO |
| 139 | + ) |
| 140 | + |
| 141 | + let rightRows = Array.zeroCreate<int> base.SecondMatrix.Rows.Length |
| 142 | + let rightCols = Array.zeroCreate<int> base.SecondMatrix.Columns.Length |
| 143 | + let rightVals = Array.zeroCreate<float32> base.SecondMatrix.Values.Length |
| 144 | + Array.blit base.SecondMatrix.Rows 0 rightRows 0 base.SecondMatrix.Rows.Length |
| 145 | + Array.blit base.SecondMatrix.Columns 0 rightCols 0 base.SecondMatrix.Columns.Length |
| 146 | + Array.blit base.SecondMatrix.Values 0 rightVals 0 base.SecondMatrix.Values.Length |
| 147 | + |
| 148 | + rightCOO <- |
| 149 | + Matrix.Build<float32>( |
| 150 | + base.SecondMatrix.RowCount, |
| 151 | + base.SecondMatrix.ColumnCount, |
| 152 | + rightRows, |
| 153 | + rightCols, |
| 154 | + rightVals, |
| 155 | + COO |
| 156 | + ) |
| 157 | + |
| 158 | + [<Benchmark>] |
| 159 | + member this.EWiseAdditionCOOFloat32() = |
| 160 | + let (ClContext context) = this.OclContext |
| 161 | + leftCOO.EWiseAdd rightCOO None Float32Semiring.addMult |
| 162 | + |> context.RunSync |
| 163 | + |
| 164 | +type EWiseAddBenchmarks4Bool() = |
| 165 | + inherit EWiseAddBenchmarks() |
| 166 | + |
| 167 | + let mutable leftCOO = Unchecked.defaultof<Matrix<bool>> |
| 168 | + let mutable rightCOO = Unchecked.defaultof<Matrix<bool>> |
| 169 | + |
| 170 | + [<IterationSetup>] |
| 171 | + member this.BuildCOO() = |
| 172 | + let leftRows = Array.zeroCreate<int> base.FirstMatrix.Rows.Length |
| 173 | + let leftCols = Array.zeroCreate<int> base.FirstMatrix.Columns.Length |
| 174 | + let leftVals = Array.create<bool> base.FirstMatrix.Values.Length true |
| 175 | + Array.blit base.FirstMatrix.Rows 0 leftRows 0 base.FirstMatrix.Rows.Length |
| 176 | + Array.blit base.FirstMatrix.Columns 0 leftCols 0 base.FirstMatrix.Columns.Length |
| 177 | + |
| 178 | + leftCOO <- |
| 179 | + Matrix.Build<bool>( |
| 180 | + base.FirstMatrix.RowCount, |
| 181 | + base.FirstMatrix.ColumnCount, |
| 182 | + leftRows, |
| 183 | + leftCols, |
| 184 | + leftVals, |
| 185 | + COO |
| 186 | + ) |
| 187 | + |
| 188 | + let rightRows = Array.zeroCreate<int> base.SecondMatrix.Rows.Length |
| 189 | + let rightCols = Array.zeroCreate<int> base.SecondMatrix.Columns.Length |
| 190 | + let rightVals = Array.create<bool> base.SecondMatrix.Values.Length true |
| 191 | + Array.blit base.SecondMatrix.Rows 0 rightRows 0 base.SecondMatrix.Rows.Length |
| 192 | + Array.blit base.SecondMatrix.Columns 0 rightCols 0 base.SecondMatrix.Columns.Length |
| 193 | + |
| 194 | + rightCOO <- |
| 195 | + Matrix.Build<bool>( |
| 196 | + base.SecondMatrix.RowCount, |
| 197 | + base.SecondMatrix.ColumnCount, |
| 198 | + rightRows, |
| 199 | + rightCols, |
| 200 | + rightVals, |
| 201 | + COO |
| 202 | + ) |
| 203 | + |
| 204 | + [<Benchmark>] |
| 205 | + member this.EWiseAdditionCOOBool() = |
| 206 | + let (ClContext context) = this.OclContext |
| 207 | + leftCOO.EWiseAdd rightCOO None BooleanSemiring.anyAll |
| 208 | + |> context.RunSync |
0 commit comments