Skip to content

Commit dd9a49b

Browse files
committed
refactor: tests, benchmarks
1 parent 0af7b00 commit dd9a49b

41 files changed

Lines changed: 285 additions & 280 deletions

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/BenchmarksEWiseAdd.fs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
namespace GraphBLAS.FSharp.Benchmarks
22

33
open System.IO
4-
open System.Text.RegularExpressions
54
open GraphBLAS.FSharp
65
open GraphBLAS.FSharp.IO
76
open BenchmarkDotNet.Attributes
87
open BenchmarkDotNet.Configs
98
open BenchmarkDotNet.Columns
109
open Brahma.FSharp
11-
open OpenCL.Net
10+
open GraphBLAS.FSharp.Backend.Objects
11+
open GraphBLAS.FSharp.Backend.Matrix.COO
12+
open GraphBLAS.FSharp.Backend.Matrix.CSR
1213

1314
type Config() =
1415
inherit ManualConfig()
@@ -43,7 +44,7 @@ type Config() =
4344
[<IterationCount(100)>]
4445
[<WarmupCount(10)>]
4546
[<Config(typeof<Config>)>]
46-
type EWiseAddBenchmarks<'matrixT, 'elem when 'matrixT :> Backend.IDeviceMemObject and 'elem : struct>(
47+
type EWiseAddBenchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : struct>(
4748
buildFunToBenchmark,
4849
converter: string -> 'elem,
4950
converterBool,
@@ -107,11 +108,11 @@ type EWiseAddBenchmarks<'matrixT, 'elem when 'matrixT :> Backend.IDeviceMemObjec
107108
this.ResultMatrix <- this.FunToBenchmark this.Processor firstMatrix secondMatrix
108109

109110
member this.ClearInputMatrices() =
110-
(firstMatrix :> Backend.IDeviceMemObject).Dispose this.Processor
111-
(secondMatrix :> Backend.IDeviceMemObject).Dispose this.Processor
111+
(firstMatrix :> IDeviceMemObject).Dispose this.Processor
112+
(secondMatrix :> IDeviceMemObject).Dispose this.Processor
112113

113114
member this.ClearResult() =
114-
(this.ResultMatrix :> Backend.IDeviceMemObject).Dispose this.Processor
115+
(this.ResultMatrix :> IDeviceMemObject).Dispose this.Processor
115116

116117
member this.ReadMatrices() =
117118
let leftMatrixReader = fst this.InputMatrixReader
@@ -131,7 +132,7 @@ type EWiseAddBenchmarks<'matrixT, 'elem when 'matrixT :> Backend.IDeviceMemObjec
131132

132133
abstract member Benchmark : unit -> unit
133134

134-
type EWiseAddBenchmarksWithoutDataTransfer<'matrixT, 'elem when 'matrixT :> Backend.IDeviceMemObject and 'elem : struct>(
135+
type EWiseAddBenchmarksWithoutDataTransfer<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : struct>(
135136
buildFunToBenchmark,
136137
converter: string -> 'elem,
137138
converterBool,
@@ -161,7 +162,7 @@ type EWiseAddBenchmarksWithoutDataTransfer<'matrixT, 'elem when 'matrixT :> Back
161162
this.EWiseAddition()
162163
this.Processor.PostAndReply(Msg.MsgNotifyMe)
163164

164-
type EWiseAddBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> Backend.IDeviceMemObject and 'elem : struct>(
165+
type EWiseAddBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : struct>(
165166
buildFunToBenchmark,
166167
converter: string -> 'elem,
167168
converterBool,
@@ -195,18 +196,18 @@ type EWiseAddBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> Backend
195196
this.Processor.PostAndReply Msg.MsgNotifyMe
196197

197198
module M =
198-
let resultToHostCOO (resultMatrix:Backend.ClCOOMatrix<'a>) (procesor:MailboxProcessor<_>) =
199+
let resultToHostCOO (resultMatrix: ClCOOMatrix<'a>) (processor :MailboxProcessor<_>) =
199200
let cols =
200201
let a = Array.zeroCreate resultMatrix.ColumnCount
201-
procesor.Post(Msg.CreateToHostMsg<_>(resultMatrix.Columns,a))
202+
processor.Post(Msg.CreateToHostMsg<_>(resultMatrix.Columns,a))
202203
a
203204
let rows =
204205
let a = Array.zeroCreate resultMatrix.RowCount
205-
procesor.Post(Msg.CreateToHostMsg(resultMatrix.Rows,a))
206+
processor.Post(Msg.CreateToHostMsg(resultMatrix.Rows,a))
206207
a
207208
let vals =
208209
let a = Array.zeroCreate resultMatrix.Values.Length
209-
procesor.Post(Msg.CreateToHostMsg(resultMatrix.Values,a))
210+
processor.Post(Msg.CreateToHostMsg(resultMatrix.Values,a))
210211
a
211212
{
212213
RowCount = resultMatrix.RowCount
@@ -219,8 +220,8 @@ module M =
219220

220221
type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
221222

222-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.ClCOOMatrix<float32>,float32>(
223-
(fun context wgSize -> Backend.COOMatrix.elementwise context Backend.Common.StandardOperations.float32Sum wgSize),
223+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<float32>,float32>(
224+
(fun context wgSize -> COOMatrix.elementwise context Backend.Common.StandardOperations.float32Sum wgSize),
224225
float32,
225226
(fun _ -> Utils.nextSingle (System.Random())),
226227
COOMatrix<float32>.ToBackend
@@ -231,8 +232,8 @@ type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
231232

232233
type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
233234

234-
inherit EWiseAddBenchmarksWithDataTransfer<Backend.ClCOOMatrix<float32>,float32>(
235-
(fun context wgSize -> Backend.COOMatrix.elementwise context Backend.Common.StandardOperations.float32Sum wgSize),
235+
inherit EWiseAddBenchmarksWithDataTransfer<ClCOOMatrix<float32>,float32>(
236+
(fun context wgSize -> COOMatrix.elementwise context Backend.Common.StandardOperations.float32Sum wgSize),
236237
float32,
237238
(fun _ -> Utils.nextSingle (System.Random())),
238239
COOMatrix<float32>.ToBackend,
@@ -245,8 +246,8 @@ type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
245246

246247
type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
247248

248-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.ClCOOMatrix<bool>,bool>(
249-
(fun context wgSize -> Backend.COOMatrix.elementwise context Backend.Common.StandardOperations.boolSum wgSize),
249+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<bool>,bool>(
250+
(fun context wgSize -> COOMatrix.elementwise context Backend.Common.StandardOperations.boolSum wgSize),
250251
(fun _ -> true),
251252
(fun _ -> true),
252253
COOMatrix<bool>.ToBackend
@@ -258,8 +259,8 @@ type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
258259

259260
type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
260261

261-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.ClCSRMatrix<float32>,float32>(
262-
(fun context wgSize -> Backend.CSRMatrix.elementwise context Backend.Common.StandardOperations.float32Sum wgSize),
262+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<float32>,float32>(
263+
(fun context wgSize -> CSRMatrix.elementwise context Backend.Common.StandardOperations.float32Sum wgSize),
263264
float32,
264265
(fun _ -> Utils.nextSingle (System.Random())),
265266
CSRMatrix<float32>.ToBackend
@@ -271,8 +272,8 @@ type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
271272

272273
type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
273274

274-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.ClCSRMatrix<bool>,bool>(
275-
(fun context wgSize -> Backend.CSRMatrix.elementwise context Backend.Common.StandardOperations.boolSum wgSize),
275+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<bool>,bool>(
276+
(fun context wgSize -> CSRMatrix.elementwise context Backend.Common.StandardOperations.boolSum wgSize),
276277
(fun _ -> true),
277278
(fun _ -> true),
278279
CSRMatrix<bool>.ToBackend
@@ -285,8 +286,8 @@ type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
285286

286287
type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
287288

288-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.ClCOOMatrix<bool>,bool>(
289-
(fun context wgSize -> Backend.COOMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.boolSumAtLeastOne wgSize),
289+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<bool>,bool>(
290+
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.boolSumAtLeastOne wgSize),
290291
(fun _ -> true),
291292
(fun _ -> true),
292293
COOMatrix<bool>.ToBackend
@@ -297,8 +298,8 @@ type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
297298

298299
type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
299300

300-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.ClCSRMatrix<bool>,bool>(
301-
(fun context wgSize -> Backend.CSRMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.boolSumAtLeastOne wgSize),
301+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<bool>,bool>(
302+
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.boolSumAtLeastOne wgSize),
302303
(fun _ -> true),
303304
(fun _ -> true),
304305
CSRMatrix<bool>.ToBackend
@@ -309,8 +310,8 @@ type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
309310

310311
type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
311312

312-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.ClCOOMatrix<float32>,float32>(
313-
(fun context wgSize -> Backend.COOMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.float32SumAtLeastOne wgSize),
313+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCOOMatrix<float32>,float32>(
314+
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.float32SumAtLeastOne wgSize),
314315
float32,
315316
(fun _ -> Utils.nextSingle (System.Random())),
316317
COOMatrix<float32>.ToBackend
@@ -321,8 +322,8 @@ type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
321322

322323
type EWiseAddAtLeastOneBenchmarks4Float32CSRWithoutDataTransfer() =
323324

324-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.ClCSRMatrix<float32>,float32>(
325-
(fun context wgSize -> Backend.CSRMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.float32SumAtLeastOne wgSize),
325+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClCSRMatrix<float32>,float32>(
326+
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.float32SumAtLeastOne wgSize),
326327
float32,
327328
(fun _ -> Utils.nextSingle (System.Random())),
328329
CSRMatrix<float32>.ToBackend

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksMathNET.fs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
11
namespace GraphBLAS.FSharp.Benchmarks
22

33
open System.IO
4-
open System.Text.RegularExpressions
54
open GraphBLAS.FSharp
65
open GraphBLAS.FSharp.IO
76
open BenchmarkDotNet.Attributes
8-
open BenchmarkDotNet.Configs
9-
open BenchmarkDotNet.Columns
107
open MathNet.Numerics.LinearAlgebra
118
open MathNet.Numerics
12-
open Brahma.FSharp.OpenCL
139
open Microsoft.FSharp.Core
14-
open OpenCL.Net
1510

1611
[<AbstractClass>]
1712
[<IterationCount(100)>]

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksMxm.fs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ open GraphBLAS.FSharp
55
open GraphBLAS.FSharp.IO
66
open BenchmarkDotNet.Attributes
77
open Brahma.FSharp
8+
open GraphBLAS.FSharp.Backend.Objects
9+
open GraphBLAS.FSharp.Backend.Matrix
810

911
[<AbstractClass>]
1012
[<IterationCount(100)>]
@@ -20,15 +22,15 @@ type MxmBenchmarks<'elem when 'elem : struct>(
2022
let mutable funCSR2CSC = None
2123
let mutable funCSC2CSR = None
2224

23-
let mutable firstMatrix = Unchecked.defaultof<Backend.ClMatrix<'elem>>
24-
let mutable secondMatrix = Unchecked.defaultof<Backend.ClMatrix<'elem>>
25+
let mutable firstMatrix = Unchecked.defaultof<ClMatrix<'elem>>
26+
let mutable secondMatrix = Unchecked.defaultof<ClMatrix<'elem>>
2527
let mutable mask = Unchecked.defaultof<Backend.Mask2D>
2628

2729
let mutable firstMatrixHost = Unchecked.defaultof<_>
2830
let mutable secondMatrixHost = Unchecked.defaultof<_>
2931
let mutable maskHost = Unchecked.defaultof<Mask2D>
3032

31-
member val ResultMatrix = Unchecked.defaultof<Backend.ClMatrix<'elem>> with get, set
33+
member val ResultMatrix = Unchecked.defaultof<ClMatrix<'elem>> with get, set
3234

3335
[<ParamsSource("AvaliableContexts")>]
3436
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
@@ -71,15 +73,15 @@ type MxmBenchmarks<'elem when 'elem : struct>(
7173
member this.FunCSR2CSC =
7274
match funCSR2CSC with
7375
| None ->
74-
let x = Backend.Matrix.toCSCInplace this.OclContext this.WorkGroupSize
76+
let x = Matrix.toCSCInplace this.OclContext this.WorkGroupSize
7577
funCSR2CSC <- Some x
7678
x
7779
| Some x -> x
7880

7981
member this.FunCSC2CSR =
8082
match funCSC2CSR with
8183
| None ->
82-
let x = Backend.Matrix.toCSRInplace this.OclContext this.WorkGroupSize
84+
let x = Matrix.toCSRInplace this.OclContext this.WorkGroupSize
8385
funCSC2CSR <- Some x
8486
x
8587
| Some x -> x
@@ -233,10 +235,10 @@ module Operations =
233235
type MxmBenchmarks4Float32MultiplicationOnly() =
234236

235237
inherit MxmBenchmarksMultiplicationOnly<float32>(
236-
(Backend.Matrix.mxm Operations.add Operations.mult),
238+
(Matrix.mxm Operations.add Operations.mult),
237239
float32,
238240
(fun _ -> Utils.nextSingle (System.Random())),
239-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
241+
(fun context matrix -> ClMatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
240242
)
241243

242244
static member InputMatrixProvider =
@@ -245,10 +247,10 @@ type MxmBenchmarks4Float32MultiplicationOnly() =
245247
type MxmBenchmarks4Float32WithTransposing() =
246248

247249
inherit MxmBenchmarksWithTransposing<float32>(
248-
(Backend.Matrix.mxm Operations.add Operations.mult),
250+
(Matrix.mxm Operations.add Operations.mult),
249251
float32,
250252
(fun _ -> Utils.nextSingle (System.Random())),
251-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
253+
(fun context matrix -> ClMatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
252254
)
253255

254256
static member InputMatrixProvider =
@@ -257,10 +259,10 @@ type MxmBenchmarks4Float32WithTransposing() =
257259
type MxmBenchmarks4BoolMultiplicationOnly() =
258260

259261
inherit MxmBenchmarksMultiplicationOnly<bool>(
260-
(Backend.Matrix.mxm Operations.logicalOr Operations.logicalAnd),
262+
(Matrix.mxm Operations.logicalOr Operations.logicalAnd),
261263
(fun _ -> true),
262264
(fun _ -> true),
263-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<bool>.ToBackend context matrix))
265+
(fun context matrix -> ClMatrixCSR (CSRMatrix<bool>.ToBackend context matrix))
264266
)
265267

266268
static member InputMatrixProvider =
@@ -269,10 +271,10 @@ type MxmBenchmarks4BoolMultiplicationOnly() =
269271
type MxmBenchmarks4BoolWithTransposing() =
270272

271273
inherit MxmBenchmarksWithTransposing<bool>(
272-
(Backend.Matrix.mxm Operations.logicalOr Operations.logicalAnd),
274+
(Matrix.mxm Operations.logicalOr Operations.logicalAnd),
273275
(fun _ -> true),
274276
(fun _ -> true),
275-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<bool>.ToBackend context matrix))
277+
(fun context matrix -> ClMatrixCSR (CSRMatrix<bool>.ToBackend context matrix))
276278
)
277279

278280
static member InputMatrixProvider =
@@ -281,10 +283,10 @@ type MxmBenchmarks4BoolWithTransposing() =
281283
type MxmBenchmarks4Float32MultiplicationOnlyWithZerosFilter() =
282284

283285
inherit MxmBenchmarksMultiplicationOnly<float32>(
284-
(Backend.Matrix.mxm Operations.addWithFilter Operations.mult),
286+
(Matrix.mxm Operations.addWithFilter Operations.mult),
285287
float32,
286288
(fun _ -> Utils.nextSingle (System.Random())),
287-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
289+
(fun context matrix -> ClMatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
288290
)
289291

290292
static member InputMatrixProvider =
@@ -293,10 +295,10 @@ type MxmBenchmarks4Float32MultiplicationOnlyWithZerosFilter() =
293295
type MxmBenchmarks4Float32WithTransposingWithZerosFilter() =
294296

295297
inherit MxmBenchmarksWithTransposing<float32>(
296-
(Backend.Matrix.mxm Operations.addWithFilter Operations.mult),
298+
(Matrix.mxm Operations.addWithFilter Operations.mult),
297299
float32,
298300
(fun _ -> Utils.nextSingle (System.Random())),
299-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
301+
(fun context matrix -> ClMatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
300302
)
301303

302304
static member InputMatrixProvider =

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksMxv.fs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ namespace GraphBLAS.FSharp.Benchmarks
33
open GraphBLAS.FSharp
44
open GraphBLAS.FSharp.Backend
55
open BenchmarkDotNet.Attributes
6-
open BenchmarkDotNet.Configs
7-
open BenchmarkDotNet.Columns
8-
open System.IO
9-
open GraphBLAS.FSharp.IO
6+
open GraphBLAS.FSharp.Backend.Objects
107

118
[<Config(typeof<CommonConfig>)>]
129
type MxvBenchmarks() =

benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,13 @@ open BenchmarkDotNet.Columns
44
open BenchmarkDotNet.Reports
55
open BenchmarkDotNet.Running
66
open Brahma.FSharp
7-
open Brahma.FSharp.OpenCL.Shared
87
open Brahma.FSharp.OpenCL.Translator
98
open OpenCL.Net
109
open GraphBLAS.FSharp.IO
1110
open System.IO
1211
open System.Text.RegularExpressions
1312
open BenchmarkDotNet.Configs
1413
open BenchmarkDotNet.Jobs
15-
open GraphBLAS.FSharp
16-
17-
open System.IO
18-
open GraphBLAS.FSharp
19-
open System
2014

2115
type CommonConfig() =
2216
inherit ManualConfig()

src/GraphBLAS-sharp.Backend/Algorithms/BFS.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ namespace GraphBLAS.FSharp.Backend.Algorithms
33
open GraphBLAS.FSharp.Backend
44
open Brahma.FSharp
55
open FSharp.Quotations
6-
open GraphBLAS.FSharp.Backend.ArraysExtensions
6+
open GraphBLAS.FSharp.Backend.Objects
77
open GraphBLAS.FSharp.Backend.Common
88
open GraphBLAS.FSharp.Backend.Vector
99
open GraphBLAS.FSharp.Backend.Vector.Dense
10+
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
1011

1112
module BFS =
1213
let singleSource

0 commit comments

Comments
 (0)