|
| 1 | +namespace GraphBLAS.FSharp.Benchmarks.Algorithms.PageRank |
| 2 | + |
| 3 | +open System.IO |
| 4 | +open BenchmarkDotNet.Attributes |
| 5 | +open GraphBLAS.FSharp |
| 6 | +open GraphBLAS.FSharp.IO |
| 7 | +open Brahma.FSharp |
| 8 | +open Microsoft.FSharp.Core |
| 9 | +open GraphBLAS.FSharp.Objects.ArraysExtensions |
| 10 | +open GraphBLAS.FSharp.Benchmarks |
| 11 | +open GraphBLAS.FSharp.Objects |
| 12 | + |
| 13 | +[<AbstractClass>] |
| 14 | +[<IterationCount(10)>] |
| 15 | +[<WarmupCount(3)>] |
| 16 | +[<Config(typeof<Configs.Matrix>)>] |
| 17 | +type Benchmarks( |
| 18 | + buildFunToBenchmark, |
| 19 | + converter: string -> float32, |
| 20 | + binaryConverter) |
| 21 | + = |
| 22 | + |
| 23 | + let mutable funToBenchmark = None |
| 24 | + let mutable matrix = Unchecked.defaultof<ClMatrix.CSR<float32>> |
| 25 | + let mutable matrixPrepared = Unchecked.defaultof<ClMatrix.CSR<float32>> |
| 26 | + let mutable matrixHost = Unchecked.defaultof<_> |
| 27 | + |
| 28 | + member val Result = Unchecked.defaultof<ClArray<float32 option>> with get,set |
| 29 | + |
| 30 | + [<ParamsSource("AvailableContexts")>] |
| 31 | + member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set |
| 32 | + |
| 33 | + [<ParamsSource("InputMatrixProvider")>] |
| 34 | + member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set |
| 35 | + |
| 36 | + member this.OclContext = (fst this.OclContextInfo).ClContext |
| 37 | + member this.WorkGroupSize = snd this.OclContextInfo |
| 38 | + |
| 39 | + member this.Processor = |
| 40 | + let p = (fst this.OclContextInfo).Queue |
| 41 | + p.Error.Add(fun e -> failwithf "%A" e) |
| 42 | + p |
| 43 | + |
| 44 | + static member AvailableContexts = Utils.availableContexts |
| 45 | + |
| 46 | + static member InputMatrixProviderBuilder pathToConfig = |
| 47 | + let datasetFolder = "" |
| 48 | + pathToConfig |
| 49 | + |> Utils.getMatricesFilenames |
| 50 | + |> Seq.map |
| 51 | + (fun matrixFilename -> |
| 52 | + printfn "%A" matrixFilename |
| 53 | + |
| 54 | + match Path.GetExtension matrixFilename with |
| 55 | + | ".mtx" -> MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename) |
| 56 | + | _ -> failwith "Unsupported matrix format") |
| 57 | + |
| 58 | + member this.FunToBenchmark = |
| 59 | + match funToBenchmark with |
| 60 | + | None -> |
| 61 | + let x = buildFunToBenchmark this.OclContext this.WorkGroupSize |
| 62 | + funToBenchmark <- Some x |
| 63 | + x |
| 64 | + | Some x -> x |
| 65 | + |
| 66 | + member this.PageRank() = |
| 67 | + this.Result <- this.FunToBenchmark this.Processor matrixPrepared |
| 68 | + |
| 69 | + member this.ClearInputMatrix() = |
| 70 | + (matrix :> IDeviceMemObject).Dispose this.Processor |
| 71 | + |
| 72 | + member this.ClearPreparedMatrix() = |
| 73 | + (matrixPrepared :> IDeviceMemObject).Dispose this.Processor |
| 74 | + |
| 75 | + member this.ClearResult() = this.Result.FreeAndWait this.Processor |
| 76 | + |
| 77 | + member this.ReadMatrix() = |
| 78 | + let converter = |
| 79 | + match this.InputMatrixReader.Field with |
| 80 | + | Pattern -> binaryConverter |
| 81 | + | _ -> converter |
| 82 | + |
| 83 | + matrixHost <- this.InputMatrixReader.ReadMatrix converter |
| 84 | + |
| 85 | + member this.LoadMatrixToGPU() = |
| 86 | + matrix <- matrixHost.ToCSR.ToDevice this.OclContext |
| 87 | + |
| 88 | + member this.PrepareMatrix() = |
| 89 | + matrixPrepared <- Algorithms.PageRank.prepareMatrix this.OclContext this.WorkGroupSize this.Processor matrix |
| 90 | + |
| 91 | + abstract member GlobalSetup : unit -> unit |
| 92 | + |
| 93 | + abstract member IterationCleanup : unit -> unit |
| 94 | + |
| 95 | + abstract member GlobalCleanup : unit -> unit |
| 96 | + |
| 97 | + abstract member Benchmark : unit -> unit |
| 98 | + |
| 99 | +type PageRankWithoutTransferBenchmarkFloat32() = |
| 100 | + |
| 101 | + inherit Benchmarks( |
| 102 | + Algorithms.PageRank.run, |
| 103 | + float32, |
| 104 | + (fun _ -> float32 <| Utils.nextInt (System.Random())) |
| 105 | + ) |
| 106 | + |
| 107 | + static member InputMatrixProvider = |
| 108 | + Benchmarks.InputMatrixProviderBuilder "BFSBenchmarks.txt" |
| 109 | + |
| 110 | + [<GlobalSetup>] |
| 111 | + override this.GlobalSetup() = |
| 112 | + this.ReadMatrix() |
| 113 | + this.LoadMatrixToGPU() |
| 114 | + this.Processor.PostAndReply(Msg.MsgNotifyMe) |
| 115 | + this.PrepareMatrix() |
| 116 | + this.ClearInputMatrix() |
| 117 | + |
| 118 | + [<IterationCleanup>] |
| 119 | + override this.IterationCleanup() = |
| 120 | + this.ClearResult() |
| 121 | + |
| 122 | + [<GlobalCleanup>] |
| 123 | + override this.GlobalCleanup() = |
| 124 | + this.ClearPreparedMatrix() |
| 125 | + |
| 126 | + [<Benchmark>] |
| 127 | + override this.Benchmark() = |
| 128 | + this.PageRank() |
| 129 | + this.Processor.PostAndReply(Msg.MsgNotifyMe) |
0 commit comments