Skip to content

Commit d9dd757

Browse files
committed
wip: SpGeMM benchmark
1 parent 2a5617b commit d9dd757

10 files changed

Lines changed: 91 additions & 84 deletions

File tree

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

Lines changed: 70 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -92,89 +92,87 @@ type Benchmarks<'elem when 'elem : struct>(
9292

9393
abstract member Benchmark : unit -> unit
9494

95-
module WithoutTransfer =
96-
type Benchmark<'elem when 'elem : struct>(
95+
type WithoutTransferBenchmark<'elem when 'elem : struct>(
96+
buildFunToBenchmark,
97+
converter: string -> 'elem,
98+
boolConverter,
99+
vertex) =
100+
101+
inherit Benchmarks<'elem>(
97102
buildFunToBenchmark,
98-
converter: string -> 'elem,
103+
converter,
99104
boolConverter,
100-
vertex) =
105+
vertex)
101106

102-
inherit Benchmarks<'elem>(
103-
buildFunToBenchmark,
104-
converter,
105-
boolConverter,
106-
vertex)
107+
[<GlobalSetup>]
108+
override this.GlobalSetup() =
109+
this.ReadMatrix()
110+
this.LoadMatrixToGPU()
107111

108-
[<GlobalSetup>]
109-
override this.GlobalSetup() =
110-
this.ReadMatrix()
111-
this.LoadMatrixToGPU()
112+
[<IterationCleanup>]
113+
override this.IterationCleanup() =
114+
this.ClearResult()
112115

113-
[<IterationCleanup>]
114-
override this.IterationCleanup() =
115-
this.ClearResult()
116+
[<GlobalCleanup>]
117+
override this.GlobalCleanup() =
118+
this.ClearInputMatrix()
116119

117-
[<GlobalCleanup>]
118-
override this.GlobalCleanup() =
119-
this.ClearInputMatrix()
120+
[<Benchmark>]
121+
override this.Benchmark() =
122+
this.BFS()
123+
this.Processor.PostAndReply Msg.MsgNotifyMe
120124

121-
[<Benchmark>]
122-
override this.Benchmark() =
123-
this.BFS()
124-
this.Processor.PostAndReply Msg.MsgNotifyMe
125+
type BFSWithoutTransferBenchmarkInt32() =
125126

126-
type Int() =
127+
inherit WithoutTransferBenchmark<int>(
128+
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
129+
int32,
130+
(fun _ -> Utils.nextInt (System.Random())),
131+
0)
127132

128-
inherit Benchmark<int>(
129-
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
130-
int32,
131-
(fun _ -> Utils.nextInt (System.Random())),
132-
0)
133+
static member InputMatrixProvider =
134+
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
133135

134-
static member InputMatrixProvider =
135-
Benchmark<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
136+
type WithTransferBenchmark<'elem when 'elem : struct>(
137+
buildFunToBenchmark,
138+
converter: string -> 'elem,
139+
boolConverter,
140+
vertex) =
136141

137-
module WithTransfer =
138-
type Benchmark<'elem when 'elem : struct>(
142+
inherit Benchmarks<'elem>(
139143
buildFunToBenchmark,
140-
converter: string -> 'elem,
144+
converter,
141145
boolConverter,
142-
vertex) =
143-
144-
inherit Benchmarks<'elem>(
145-
buildFunToBenchmark,
146-
converter,
147-
boolConverter,
148-
vertex)
149-
150-
[<GlobalSetup>]
151-
override this.GlobalSetup() =
152-
this.ReadMatrix()
153-
154-
[<GlobalCleanup>]
155-
override this.GlobalCleanup() =
156-
this.ClearResult()
157-
158-
[<IterationCleanup>]
159-
override this.IterationCleanup() =
160-
this.ClearInputMatrix()
161-
this.ClearResult()
162-
163-
[<Benchmark>]
164-
override this.Benchmark() =
165-
this.LoadMatrixToGPU()
166-
this.BFS()
167-
this.ResultLevels.ToHost this.Processor |> ignore
168-
this.Processor.PostAndReply Msg.MsgNotifyMe
169-
170-
type Int() =
171-
172-
inherit Benchmark<int>(
173-
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
174-
int32,
175-
(fun _ -> Utils.nextInt (System.Random())),
176-
0)
177-
178-
static member InputMatrixProvider =
179-
Benchmark<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
146+
vertex)
147+
148+
[<GlobalSetup>]
149+
override this.GlobalSetup() =
150+
this.ReadMatrix()
151+
152+
[<GlobalCleanup>]
153+
override this.GlobalCleanup() =
154+
this.ClearResult()
155+
156+
[<IterationCleanup>]
157+
override this.IterationCleanup() =
158+
this.ClearInputMatrix()
159+
this.ClearResult()
160+
161+
[<Benchmark>]
162+
override this.Benchmark() =
163+
this.LoadMatrixToGPU()
164+
this.BFS()
165+
this.ResultLevels.ToHost this.Processor |> ignore
166+
this.Processor.PostAndReply Msg.MsgNotifyMe
167+
168+
type BFSWithTransferBenchmarkInt32() =
169+
170+
inherit WithTransferBenchmark<int>(
171+
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
172+
int32,
173+
(fun _ -> Utils.nextInt (System.Random())),
174+
0)
175+
176+
static member InputMatrixProvider =
177+
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
180178

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2+
Gpu
3+
32
4+
15
NVIDIA*
26
Gpu
37
32
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hollywood-2009.mtx

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
<Compile Include="Vector/Map2.fs" />
2727
<Compile Include="Algorithms/BFS.fs" />
2828
<Compile Include="Program.fs" />
29+
<Folder Include="Datasets" />
2930
</ItemGroup>
3031
<Import Project="..\..\.paket\Paket.Restore.targets" />
3132
</Project>

benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,16 @@ module Utils =
108108
let queue = context.QueueProvider.CreateQueue()
109109

110110
{ ClContext = context; Queue = queue })
111+
let result =
112+
seq {
113+
for wgSize in workGroupSizes do
114+
for context in contexts do
115+
yield (context, wgSize)
116+
}
111117

112-
seq {
113-
for wgSize in workGroupSizes do
114-
for context in contexts do
115-
yield (context, wgSize)
116-
}
118+
printfn "result length: %A" <| Seq.length result
117119

120+
result
118121
let nextSingle (random: System.Random) =
119122
let buffer = Array.zeroCreate<byte> 4
120123
random.NextBytes buffer

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type Benchmarks<'elem when 'elem : struct>(
4949
static member AvailableContexts = Utils.availableContexts
5050

5151
static member InputMatrixProviderBuilder pathToConfig =
52-
let datasetFolder = "Mxm"
52+
let datasetFolder = ""
5353
pathToConfig
5454
|> Utils.getMatricesFilenames
5555
|> Seq.map
@@ -59,7 +59,6 @@ type Benchmarks<'elem when 'elem : struct>(
5959
match Path.GetExtension matrixFilename with
6060
| ".mtx" ->
6161
MtxReader(Utils.getFullPathToMatrix datasetFolder matrixFilename)
62-
, MtxReader(Utils.getFullPathToMatrix datasetFolder (matrixFilename))
6362
| _ -> failwith "Unsupported matrix format")
6463

6564
member this.FunToBenchmark =
@@ -145,4 +144,4 @@ module WithoutTransfer =
145144
)
146145

147146
static member InputMatrixProvider =
148-
Benchmarks<_>.InputMatrixProviderBuilder "MxmBenchmarks4Float32.txt"
147+
Benchmarks<_>.InputMatrixProviderBuilder "SpGeMM.txt"

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ open BenchmarkDotNet.Running
44
[<EntryPoint>]
55
let main argv =
66
let benchmarks =
7-
BenchmarkSwitcher [| typeof<Algorithms.BFS.WithoutTransfer.Int> |]
7+
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSWithoutTransferBenchmarkInt32>
8+
typeof<Matrix.SpGeMM.Expand.WithoutTransfer.Float32> |]
89

910
benchmarks.Run argv |> ignore
1011
0

src/GraphBLAS-sharp.Backend/Matrix/CSR/Matrix.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ module Matrix =
167167
let pairwise = ClArray.pairwise clContext workGroupSize
168168

169169
let subtract =
170-
ClArray.map clContext workGroupSize <@ fun (fst, snd) -> snd - fst @>
170+
ClArray.map <@ fun (fst, snd) -> snd - fst @> clContext workGroupSize
171171

172172
fun (processor: MailboxProcessor<_>) allocationMode (matrix: ClMatrix.CSR<'b>) ->
173173
let pointerPairs =

src/GraphBLAS-sharp.Backend/Vector/Sparse/Vector.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,6 @@ module Vector =
6565
let reduce<'a when 'a: struct> (opAdd: Expr<'a -> 'a -> 'a>) (clContext: ClContext) workGroupSize =
6666

6767
let reduce =
68-
Reduce.reduce clContext workGroupSize opAdd
68+
Reduce.reduce opAdd clContext workGroupSize
6969

7070
fun (processor: MailboxProcessor<_>) (vector: ClVector.Sparse<'a>) -> reduce processor vector.Values

src/GraphBLAS-sharp.Backend/Vector/Vector.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ module Vector =
3939
ClArray.zeroCreate clContext workGroupSize
4040

4141
let map =
42-
ClArray.map clContext workGroupSize <@ Some @>
42+
ClArray.map <@ Some @> clContext workGroupSize
4343

4444
fun (processor: MailboxProcessor<_>) allocationMode format size (elements: (int * 'a) list) ->
4545
match format with

0 commit comments

Comments
 (0)