Skip to content

Commit

Permalink
Merge pull request #88 from kirillgarbar/dev
Browse files Browse the repository at this point in the history
PageRank
  • Loading branch information
gsvgit authored Mar 18, 2024
2 parents 4a70218 + 6de410f commit 7fe8ff3
Show file tree
Hide file tree
Showing 75 changed files with 736 additions and 137 deletions.
51 changes: 40 additions & 11 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GraphBLAS.FSharp.Benchmarks.Algorithms.BFS
namespace GraphBLAS.FSharp.Benchmarks.Algorithms.BFS

open System.IO
open BenchmarkDotNet.Attributes
Expand All @@ -9,11 +9,12 @@ open GraphBLAS.FSharp.IO
open GraphBLAS.FSharp.Benchmarks
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Objects.ArraysExtensions
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
open GraphBLAS.FSharp.Backend.Quotes

[<AbstractClass>]
[<IterationCount(100)>]
[<WarmupCount(10)>]
[<IterationCount(10)>]
[<WarmupCount(3)>]
[<Config(typeof<Configs.Matrix>)>]
type Benchmarks<'elem when 'elem : struct>(
buildFunToBenchmark,
Expand All @@ -27,7 +28,7 @@ type Benchmarks<'elem when 'elem : struct>(
let mutable matrix = Unchecked.defaultof<ClMatrix<'elem>>
let mutable matrixHost = Unchecked.defaultof<_>

member val ResultLevels = Unchecked.defaultof<ClVector<'elem>> with get,set
member val ResultLevels = Unchecked.defaultof<ClVector<int>> with get,set

[<ParamsSource("AvailableContexts")>]
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
Expand Down Expand Up @@ -113,10 +114,12 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
override this.GlobalSetup() =
this.ReadMatrix()
this.LoadMatrixToGPU()
finish this.Processor

[<IterationCleanup>]
override this.IterationCleanup() =
this.ClearResult()
finish this.Processor

[<GlobalCleanup>]
override this.GlobalCleanup() =
Expand All @@ -127,10 +130,34 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
this.BFS()
this.Processor.PostAndReply Msg.MsgNotifyMe

type BFSWithoutTransferBenchmarkInt32() =
type BFSWithoutTransferBenchmarkBool() =

inherit WithoutTransferBenchmark<bool>(
(Algorithms.BFS.singleSource ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption),
(fun _ -> true),
(fun _ -> true),
0,
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))

static member InputMatrixProvider =
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"

type BFSPushPullWithoutTransferBenchmarkBool() =

inherit WithoutTransferBenchmark<bool>(
(Algorithms.BFS.singleSourcePushPull ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption),
(fun _ -> true),
(fun _ -> true),
0,
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))

static member InputMatrixProvider =
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"

type SSSPWithoutTransferBenchmarkInt32() =

inherit WithoutTransferBenchmark<int>(
(Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
Algorithms.SSSP.run,
int32,
(fun _ -> Utils.nextInt (System.Random())),
0,
Expand All @@ -156,6 +183,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
[<GlobalSetup>]
override this.GlobalSetup() =
this.ReadMatrix()
finish this.Processor

[<GlobalCleanup>]
override this.GlobalCleanup() =
Expand All @@ -165,6 +193,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
override this.IterationCleanup() =
this.ClearInputMatrix()
this.ClearResult()
finish this.Processor

[<Benchmark>]
override this.Benchmark() =
Expand All @@ -176,12 +205,12 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
this.Processor.PostAndReply Msg.MsgNotifyMe
| _ -> failwith "Impossible"

type BFSWithTransferBenchmarkInt32() =
type BFSWithTransferBenchmarkBool() =

inherit WithTransferBenchmark<int>(
(Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
int32,
(fun _ -> Utils.nextInt (System.Random())),
inherit WithTransferBenchmark<bool>(
(Algorithms.BFS.singleSource ArithmeticOperations.boolSumOption ArithmeticOperations.boolMulOption),
(fun _ -> true),
(fun _ -> true),
0,
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))

Expand Down
133 changes: 133 additions & 0 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
<Compile Include="Matrix/Map2/MathNET.fs" />
<Compile Include="Vector/Map2.fs" />
<Compile Include="Algorithms/BFS.fs" />
<Compile Include="Algorithms/PageRank.fs" />
<Compile Include="Program.fs" />
<Folder Include="Datasets" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
</Project>
7 changes: 5 additions & 2 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open GraphBLAS.FSharp.IO
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Objects.MatrixExtensions
open GraphBLAS.FSharp.Objects.ClContextExtensions
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.Benchmarks

Expand Down Expand Up @@ -118,12 +119,12 @@ module WithoutTransfer =
override this.GlobalSetup() =
this.ReadMatrices ()
this.LoadMatricesToGPU ()
this.Processor.PostAndReply(Msg.MsgNotifyMe)
finish this.Processor

[<Benchmark>]
override this.Benchmark () =
this.EWiseAddition()
this.Processor.PostAndReply(Msg.MsgNotifyMe)
finish this.Processor

[<IterationCleanup>]
override this.IterationCleanup () =
Expand Down Expand Up @@ -251,6 +252,7 @@ module WithTransfer =
[<GlobalSetup>]
override this.GlobalSetup() =
this.ReadMatrices()
finish this.Processor

[<GlobalCleanup>]
override this.GlobalCleanup() = ()
Expand All @@ -259,6 +261,7 @@ module WithTransfer =
override this.IterationCleanup() =
this.ClearInputMatrices()
this.ClearResult()
finish this.Processor

[<Benchmark>]
override this.Benchmark() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open GraphBLAS.FSharp.IO
open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Objects.ClContextExtensions
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
open GraphBLAS.FSharp.Benchmarks

[<AbstractClass>]
Expand Down Expand Up @@ -115,15 +116,17 @@ module WithoutTransfer =
override this.GlobalSetup() =
this.ReadMatrices()
this.LoadMatricesToGPU()
finish this.Processor

[<Benchmark>]
override this.Benchmark() =
this.Mxm()
this.Processor.PostAndReply(Msg.MsgNotifyMe)
finish this.Processor

[<IterationCleanup>]
override this.IterationCleanup () =
this.ClearResult()
finish this.Processor

[<GlobalCleanup>]
override this.GlobalCleanup () =
Expand Down
9 changes: 7 additions & 2 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open Brahma.FSharp
open GraphBLAS.FSharp
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Objects.ClContextExtensions
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
open GraphBLAS.FSharp.Benchmarks

[<AbstractClass>]
Expand Down Expand Up @@ -152,15 +153,17 @@ type MxmBenchmarksMultiplicationOnly<'elem when 'elem : struct>(
this.ReadMatrices ()
this.LoadMatricesToGPU ()
this.ConvertSecondMatrixToCSC()
finish this.Processor

[<Benchmark>]
override this.Benchmark () =
this.Mxm()
this.Processor.PostAndReply(Msg.MsgNotifyMe)
finish this.Processor

[<IterationCleanup>]
override this.IterationCleanup () =
this.ClearResult()
finish this.Processor

[<GlobalCleanup>]
override this.GlobalCleanup () =
Expand All @@ -182,18 +185,20 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>(
override this.GlobalSetup() =
this.ReadMatrices()
this.LoadMatricesToGPU ()
finish this.Processor

[<Benchmark>]
override this.Benchmark() =
this.ConvertSecondMatrixToCSC()
this.Mxm()
this.Processor.PostAndReply(Msg.MsgNotifyMe)
finish this.Processor


[<IterationCleanup>]
override this.IterationCleanup() =
this.ClearResult()
this.ConvertSecondMatrixToCSR()
finish this.Processor

[<GlobalCleanup>]
override this.GlobalCleanup() =
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ open BenchmarkDotNet.Running
[<EntryPoint>]
let main argv =
let benchmarks =
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkInt32> |]
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkBool> |]

benchmarks.Run argv |> ignore
0
Loading

0 comments on commit 7fe8ff3

Please sign in to comment.