-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from kirillgarbar/dev
PageRank
- Loading branch information
Showing
75 changed files
with
736 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
namespace GraphBLAS.FSharp.Benchmarks.Algorithms.PageRank | ||
|
||
open System.IO | ||
open BenchmarkDotNet.Attributes | ||
open GraphBLAS.FSharp | ||
open GraphBLAS.FSharp.IO | ||
open Brahma.FSharp | ||
open Microsoft.FSharp.Core | ||
open GraphBLAS.FSharp.Objects.ArraysExtensions | ||
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions | ||
open GraphBLAS.FSharp.Benchmarks | ||
open GraphBLAS.FSharp.Objects | ||
|
||
[<AbstractClass>] | ||
[<IterationCount(10)>] | ||
[<WarmupCount(3)>] | ||
[<Config(typeof<Configs.Matrix>)>] | ||
type Benchmarks( | ||
buildFunToBenchmark, | ||
converter: string -> float32, | ||
binaryConverter, | ||
buildMatrix) | ||
= | ||
|
||
let mutable funToBenchmark = None | ||
let mutable matrix = Unchecked.defaultof<ClMatrix<float32>> | ||
let mutable matrixPrepared = Unchecked.defaultof<Algorithms.PageRank.PageRankMatrix> | ||
let mutable matrixHost = Unchecked.defaultof<_> | ||
|
||
member val Result = Unchecked.defaultof<ClVector<float32>> with get,set | ||
|
||
[<ParamsSource("AvailableContexts")>] | ||
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set | ||
|
||
[<ParamsSource("InputMatrixProvider")>] | ||
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set | ||
|
||
member this.OclContext = (fst this.OclContextInfo).ClContext | ||
member this.WorkGroupSize = snd this.OclContextInfo | ||
|
||
member this.Processor = | ||
let p = (fst this.OclContextInfo).Queue | ||
p.Error.Add(fun e -> failwithf "%A" e) | ||
p | ||
|
||
static member AvailableContexts = Utils.availableContexts | ||
|
||
static member InputMatrixProviderBuilder pathToConfig = | ||
let datasetFolder = "" | ||
pathToConfig | ||
|> Utils.getMatricesFilenames | ||
|> Seq.map | ||
(fun matrixFilename -> | ||
printfn "%A" matrixFilename | ||
|
||
match Path.GetExtension matrixFilename with | ||
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename) | ||
| _ -> failwith "Unsupported matrix format") | ||
|
||
member this.FunToBenchmark = | ||
match funToBenchmark with | ||
| None -> | ||
let x = buildFunToBenchmark this.OclContext this.WorkGroupSize | ||
funToBenchmark <- Some x | ||
x | ||
| Some x -> x | ||
|
||
member this.PageRank() = | ||
this.Result <- this.FunToBenchmark this.Processor matrixPrepared Constants.PageRank.accuracy | ||
|
||
member this.ClearInputMatrix() = | ||
matrix.Dispose this.Processor | ||
|
||
member this.ClearPreparedMatrix() = | ||
matrixPrepared.Dispose this.Processor | ||
|
||
member this.ClearResult() = this.Result.Dispose this.Processor | ||
|
||
member this.ReadMatrix() = | ||
let converter = | ||
match this.InputMatrixReader.Field with | ||
| Pattern -> binaryConverter | ||
| _ -> converter | ||
|
||
matrixHost <- this.InputMatrixReader.ReadMatrix converter | ||
|
||
member this.LoadMatrixToGPU() = | ||
matrix <- buildMatrix this.OclContext matrixHost | ||
|
||
member this.PrepareMatrix() = | ||
matrixPrepared <- Algorithms.PageRank.prepareMatrix this.OclContext this.WorkGroupSize this.Processor matrix | ||
|
||
abstract member GlobalSetup : unit -> unit | ||
|
||
abstract member IterationCleanup : unit -> unit | ||
|
||
abstract member GlobalCleanup : unit -> unit | ||
|
||
abstract member Benchmark : unit -> unit | ||
|
||
type PageRankWithoutTransferBenchmarkFloat32() = | ||
|
||
inherit Benchmarks( | ||
Algorithms.PageRank.run, | ||
float32, | ||
(fun _ -> float32 <| Utils.nextInt (System.Random())), | ||
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)) | ||
|
||
static member InputMatrixProvider = | ||
Benchmarks.InputMatrixProviderBuilder "BFSBenchmarks.txt" | ||
|
||
[<GlobalSetup>] | ||
override this.GlobalSetup() = | ||
this.ReadMatrix() | ||
this.LoadMatrixToGPU() | ||
finish this.Processor | ||
this.PrepareMatrix() | ||
this.ClearInputMatrix() | ||
finish this.Processor | ||
|
||
[<IterationCleanup>] | ||
override this.IterationCleanup() = | ||
this.ClearResult() | ||
finish this.Processor | ||
|
||
[<GlobalCleanup>] | ||
override this.GlobalCleanup() = | ||
this.ClearPreparedMatrix() | ||
|
||
[<Benchmark>] | ||
override this.Benchmark() = | ||
this.PageRank() | ||
finish this.Processor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.