-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PageRank #88
PageRank #88
Changes from 9 commits
faf242c
b278b7a
ebdb250
6f3819b
1ed601c
858cd82
0826562
b82fe68
c8f3042
0ab7361
97b6db4
f671a2e
6de410f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
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.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() = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've always thought about it. Don't you need to make the preparatory methods blocking? Then is it possible to avoid blocking in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is a good idea to block after preparotory methods in case some of them are not blocking by itself, but blocking in the |
||
this.ReadMatrix() | ||
this.LoadMatrixToGPU() | ||
this.Processor.PostAndReply(Msg.MsgNotifyMe) | ||
this.PrepareMatrix() | ||
this.ClearInputMatrix() | ||
this.Processor.PostAndReply(Msg.MsgNotifyMe) | ||
|
||
[<IterationCleanup>] | ||
override this.IterationCleanup() = | ||
this.ClearResult() | ||
this.Processor.PostAndReply(Msg.MsgNotifyMe) | ||
|
||
[<GlobalCleanup>] | ||
override this.GlobalCleanup() = | ||
this.ClearPreparedMatrix() | ||
|
||
[<Benchmark>] | ||
override this.Benchmark() = | ||
this.PageRank() | ||
this.Processor.PostAndReply(Msg.MsgNotifyMe) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,26 @@ module Algorithms = | |
|
||
module SSSP = | ||
let run = SSSP.run | ||
|
||
module PageRank = | ||
type PageRankMatrix = PageRank.PageRankMatrix | ||
|
||
/// <summary> | ||
/// Computes PageRank of the given matrix. | ||
/// Matrix should be prepared in advance using "PageRank.prepareMatrix" method. | ||
/// Accepts accuracy as a parameter which determines how many iterations will be performed. | ||
/// Values of accuracy higher than 1e-06 are not recommended since the process may never stop. | ||
/// </summary> | ||
/// <example> | ||
/// <code> | ||
/// let preparedMatrix = PageRank.prepareMatrix clContext workGroupSize queue matrix | ||
/// let accuracy = 1e-05 | ||
/// let pageRank = PageRank.run clContext workGroupSize queue preparedMatrix accuracy | ||
/// </code> | ||
/// </example> | ||
let run = PageRank.run | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think documentation is needed. At least we should say that matrix has to be prepared first by calling prepareMatrix method. |
||
|
||
/// <summary> | ||
/// Converts matrix representing a graph to a format suitable for PageRank algorithm. | ||
/// </summary> | ||
let prepareMatrix = PageRank.prepareMatrix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How much is it necessary to duplicate this? Is it possible to make an extension?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to make extension for specialization of generic
MailboxProcessor
and failed, as far as I know it is possible only for static members and static method would look not much better than thisThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Seems like that. Than maybe just
in GraphBlas-sharp.Backend.Objects
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was told that this may work.
We can choose!