Skip to content

Commit 483b644

Browse files
committed
merge: kirillgarbar/dev branch into msbfs
2 parents 2b23505 + e548294 commit 483b644

51 files changed

Lines changed: 2508 additions & 504 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ open GraphBLAS.FSharp.Objects.ArraysExtensions
1212
open GraphBLAS.FSharp.Backend.Quotes
1313

1414
[<AbstractClass>]
15-
[<IterationCount(100)>]
16-
[<WarmupCount(10)>]
15+
[<IterationCount(10)>]
16+
[<WarmupCount(3)>]
1717
[<Config(typeof<Configs.Matrix>)>]
1818
type Benchmarks<'elem when 'elem : struct>(
1919
buildFunToBenchmark,
@@ -27,7 +27,7 @@ type Benchmarks<'elem when 'elem : struct>(
2727
let mutable matrix = Unchecked.defaultof<ClMatrix<'elem>>
2828
let mutable matrixHost = Unchecked.defaultof<_>
2929

30-
member val ResultLevels = Unchecked.defaultof<ClArray<'elem option>> with get,set
30+
member val ResultLevels = Unchecked.defaultof<ClVector<'elem>> with get,set
3131

3232
[<ParamsSource("AvailableContexts")>]
3333
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
@@ -71,7 +71,10 @@ type Benchmarks<'elem when 'elem : struct>(
7171
member this.ClearInputMatrix() =
7272
matrix.Dispose this.Processor
7373

74-
member this.ClearResult() = this.ResultLevels.FreeAndWait this.Processor
74+
member this.ClearResult() =
75+
match this.ResultLevels with
76+
| ClVector.Dense result -> result.FreeAndWait this.Processor
77+
| _ -> failwith "Impossible"
7578

7679
member this.ReadMatrix() =
7780
let converter =
@@ -136,6 +139,30 @@ type BFSWithoutTransferBenchmarkInt32() =
136139
static member InputMatrixProvider =
137140
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
138141

142+
type BFSPushPullWithoutTransferBenchmarkInt32() =
143+
144+
inherit WithoutTransferBenchmark<int>(
145+
(Algorithms.BFS.singleSourcePushPull ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
146+
int32,
147+
(fun _ -> Utils.nextInt (System.Random())),
148+
0,
149+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
150+
151+
static member InputMatrixProvider =
152+
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
153+
154+
type SSSPWithoutTransferBenchmarkInt32() =
155+
156+
inherit WithoutTransferBenchmark<int>(
157+
Algorithms.SSSP.run,
158+
int32,
159+
(fun _ -> Utils.nextInt (System.Random())),
160+
0,
161+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
162+
163+
static member InputMatrixProvider =
164+
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
165+
139166
type WithTransferBenchmark<'elem when 'elem : struct>(
140167
buildFunToBenchmark,
141168
converter: string -> 'elem,
@@ -167,8 +194,11 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
167194
override this.Benchmark() =
168195
this.LoadMatrixToGPU()
169196
this.BFS()
170-
this.ResultLevels.ToHost this.Processor |> ignore
171-
this.Processor.PostAndReply Msg.MsgNotifyMe
197+
match this.ResultLevels with
198+
| ClVector.Dense result ->
199+
result.ToHost this.Processor |> ignore
200+
this.Processor.PostAndReply Msg.MsgNotifyMe
201+
| _ -> failwith "Impossible"
172202

173203
type BFSWithTransferBenchmarkInt32() =
174204

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
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+
buildMatrix)
22+
=
23+
24+
let mutable funToBenchmark = None
25+
let mutable matrix = Unchecked.defaultof<ClMatrix<float32>>
26+
let mutable matrixPrepared = Unchecked.defaultof<ClMatrix<float32>>
27+
let mutable matrixHost = Unchecked.defaultof<_>
28+
29+
let accuracy = 0.00000001f
30+
31+
member val Result = Unchecked.defaultof<ClVector<float32>> with get,set
32+
33+
[<ParamsSource("AvailableContexts")>]
34+
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
35+
36+
[<ParamsSource("InputMatrixProvider")>]
37+
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
38+
39+
member this.OclContext = (fst this.OclContextInfo).ClContext
40+
member this.WorkGroupSize = snd this.OclContextInfo
41+
42+
member this.Processor =
43+
let p = (fst this.OclContextInfo).Queue
44+
p.Error.Add(fun e -> failwithf "%A" e)
45+
p
46+
47+
static member AvailableContexts = Utils.availableContexts
48+
49+
static member InputMatrixProviderBuilder pathToConfig =
50+
let datasetFolder = ""
51+
pathToConfig
52+
|> Utils.getMatricesFilenames
53+
|> Seq.map
54+
(fun matrixFilename ->
55+
printfn "%A" matrixFilename
56+
57+
match Path.GetExtension matrixFilename with
58+
| ".mtx" -> MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename)
59+
| _ -> failwith "Unsupported matrix format")
60+
61+
member this.FunToBenchmark =
62+
match funToBenchmark with
63+
| None ->
64+
let x = buildFunToBenchmark this.OclContext this.WorkGroupSize
65+
funToBenchmark <- Some x
66+
x
67+
| Some x -> x
68+
69+
member this.PageRank() =
70+
this.Result <- this.FunToBenchmark this.Processor matrixPrepared accuracy
71+
72+
member this.ClearInputMatrix() =
73+
matrix.Dispose this.Processor
74+
75+
member this.ClearPreparedMatrix() =
76+
matrixPrepared.Dispose this.Processor
77+
78+
member this.ClearResult() = this.Result.Dispose this.Processor
79+
80+
member this.ReadMatrix() =
81+
let converter =
82+
match this.InputMatrixReader.Field with
83+
| Pattern -> binaryConverter
84+
| _ -> converter
85+
86+
matrixHost <- this.InputMatrixReader.ReadMatrix converter
87+
88+
member this.LoadMatrixToGPU() =
89+
matrix <- buildMatrix this.OclContext matrixHost
90+
91+
member this.PrepareMatrix() =
92+
matrixPrepared <- Algorithms.PageRank.prepareMatrix this.OclContext this.WorkGroupSize this.Processor matrix
93+
94+
abstract member GlobalSetup : unit -> unit
95+
96+
abstract member IterationCleanup : unit -> unit
97+
98+
abstract member GlobalCleanup : unit -> unit
99+
100+
abstract member Benchmark : unit -> unit
101+
102+
type PageRankWithoutTransferBenchmarkFloat32() =
103+
104+
inherit Benchmarks(
105+
Algorithms.PageRank.run,
106+
float32,
107+
(fun _ -> float32 <| Utils.nextInt (System.Random())),
108+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
109+
110+
static member InputMatrixProvider =
111+
Benchmarks.InputMatrixProviderBuilder "BFSBenchmarks.txt"
112+
113+
[<GlobalSetup>]
114+
override this.GlobalSetup() =
115+
this.ReadMatrix()
116+
this.LoadMatrixToGPU()
117+
this.Processor.PostAndReply(Msg.MsgNotifyMe)
118+
this.PrepareMatrix()
119+
this.ClearInputMatrix()
120+
121+
[<IterationCleanup>]
122+
override this.IterationCleanup() =
123+
this.ClearResult()
124+
125+
[<GlobalCleanup>]
126+
override this.GlobalCleanup() =
127+
this.ClearPreparedMatrix()
128+
129+
[<Benchmark>]
130+
override this.Benchmark() =
131+
this.PageRank()
132+
this.Processor.PostAndReply(Msg.MsgNotifyMe)

benchmarks/GraphBLAS-sharp.Benchmarks/GraphBLAS-sharp.Benchmarks.fsproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -25,6 +25,7 @@
2525
<Compile Include="Matrix/Map2/MathNET.fs" />
2626
<Compile Include="Vector/Map2.fs" />
2727
<Compile Include="Algorithms/BFS.fs" />
28+
<Compile Include="Algorithms/PageRank.fs" />
2829
<Compile Include="Program.fs" />
2930
<Folder Include="Datasets" />
3031
</ItemGroup>

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type Benchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : st
4646
static member AvailableContexts = Utils.availableContexts
4747

4848
static member InputMatricesProviderBuilder pathToConfig =
49-
let datasetFolder = "EWiseAdd"
49+
let datasetFolder = ""
5050
pathToConfig
5151
|> Utils.getMatricesFilenames
5252
|> Seq.map

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ open GraphBLAS.FSharp.Benchmarks
1313
[<AbstractClass>]
1414
[<IterationCount(100)>]
1515
[<WarmupCount(10)>]
16-
[<Config(typeof<Configs.Matrix2>)>]
16+
[<Config(typeof<Configs.Matrix>)>]
1717
type Benchmarks<'elem when 'elem : struct>(
1818
buildFunToBenchmark,
1919
converter: string -> 'elem,
@@ -22,11 +22,9 @@ type Benchmarks<'elem when 'elem : struct>(
2222

2323
let mutable funToBenchmark = None
2424

25-
let mutable firstMatrix = Unchecked.defaultof<ClMatrix<'elem>>
26-
let mutable secondMatrix = Unchecked.defaultof<ClMatrix<'elem>>
25+
let mutable matrix = Unchecked.defaultof<ClMatrix<'elem>>
2726

28-
let mutable firstMatrixHost = Unchecked.defaultof<_>
29-
let mutable secondMatrixHost = Unchecked.defaultof<_>
27+
let mutable matrixHost = Unchecked.defaultof<_>
3028

3129
member val ResultMatrix = Unchecked.defaultof<ClMatrix.COO<'elem> option> with get, set
3230

@@ -36,7 +34,7 @@ type Benchmarks<'elem when 'elem : struct>(
3634
[<ParamsSource("InputMatrixProvider")>]
3735
member val InputMatrixReader = Unchecked.defaultof<MtxReader> with get, set
3836

39-
member this.OclContext:ClContext = (fst this.OclContextInfo).ClContext
37+
member this.OclContext: ClContext = (fst this.OclContextInfo).ClContext
4038
member this.WorkGroupSize = snd this.OclContextInfo
4139

4240
member this.Processor =
@@ -76,24 +74,21 @@ type Benchmarks<'elem when 'elem : struct>(
7674
reader.ReadMatrix converter
7775

7876
member this.Mxm() =
79-
this.ResultMatrix <- this.FunToBenchmark this.Processor DeviceOnly firstMatrix secondMatrix
77+
this.ResultMatrix <- this.FunToBenchmark this.Processor DeviceOnly matrix matrix
8078

8179
member this.ClearInputMatrices() =
82-
firstMatrix.Dispose this.Processor
83-
secondMatrix.Dispose this.Processor
80+
matrix.Dispose this.Processor
8481

8582
member this.ClearResult() =
8683
match this.ResultMatrix with
8784
| Some matrix -> matrix.Dispose this.Processor
8885
| None -> ()
8986

9087
member this.ReadMatrices() =
91-
firstMatrixHost <- this.ReadMatrix this.InputMatrixReader
92-
secondMatrixHost <- this.ReadMatrix this.InputMatrixReader
88+
matrixHost <- this.ReadMatrix this.InputMatrixReader
9389

9490
member this.LoadMatricesToGPU () =
95-
firstMatrix <- buildMatrix this.OclContext firstMatrixHost
96-
secondMatrix <- buildMatrix this.OclContext secondMatrixHost
91+
matrix <- buildMatrix this.OclContext matrixHost
9792

9893
abstract member GlobalSetup : unit -> unit
9994

benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type Masked<'elem when 'elem : struct>(
5151
static member AvaliableContexts = Utils.availableContexts
5252

5353
static member InputMatrixProviderBuilder pathToConfig =
54-
let datasetFolder = "Mxm"
54+
let datasetFolder = ""
5555
pathToConfig
5656
|> Utils.getMatricesFilenames
5757
|> Seq.map

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ open BenchmarkDotNet.Running
44
[<EntryPoint>]
55
let main argv =
66
let benchmarks =
7-
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkInt32> |]
7+
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkInt32>
8+
typeof<Algorithms.BFS.BFSPushPullWithoutTransferBenchmarkInt32>
9+
typeof<Algorithms.PageRank.PageRankWithoutTransferBenchmarkFloat32> |]
810

911
benchmarks.Run argv |> ignore
1012
0

benchmarks/GraphBLAS-sharp.Benchmarks/Vector/Map2.fs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type Benchmarks<'elem when 'elem : struct>(
2727

2828
member val HostVectorPair = Unchecked.defaultof<Vector<'elem> * Vector<'elem>> with get, set
2929

30-
member val ResultVector = Unchecked.defaultof<ClVector<'elem>> with get,set
30+
member val ResultVector = Unchecked.defaultof<ClVector<'elem> option> with get,set
3131

3232
[<ParamsSource("AvailableContexts")>]
3333
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
@@ -67,7 +67,9 @@ type Benchmarks<'elem when 'elem : struct>(
6767
secondVector.Dispose this.Processor
6868

6969
member this.ClearResult() =
70-
this.ResultVector.Dispose this.Processor
70+
match this.ResultVector with
71+
| Some v -> v.Dispose this.Processor
72+
| None -> ()
7173

7274
member this.CreateVectors() =
7375
this.HostVectorPair <- List.last (Gen.sample this.Size 1 generator)
@@ -162,8 +164,12 @@ module WithTransfer =
162164
override this.Benchmark () =
163165
this.LoadVectorsToGPU()
164166
this.Map2()
165-
this.ResultVector.ToHost this.Processor |> ignore
166-
this.Processor.PostAndReply Msg.MsgNotifyMe
167+
match this.ResultVector with
168+
| Some v ->
169+
v.ToHost this.Processor |> ignore
170+
this.Processor.PostAndReply Msg.MsgNotifyMe
171+
| None -> ()
172+
167173

168174
[<IterationCleanup>]
169175
override this.IterationCleanup () =

0 commit comments

Comments
 (0)