Skip to content

Commit 8b2df22

Browse files
authored
Merge pull request #57 from IgorErin/refactor
Refactor
2 parents 517a200 + d58a9ee commit 8b2df22

75 files changed

Lines changed: 1649 additions & 1697 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: 44 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
namespace GraphBLAS.FSharp.Benchmarks
22

33
open System.IO
4-
open System.Text.RegularExpressions
5-
open GraphBLAS.FSharp
4+
open GraphBLAS.FSharp.Backend.Quotes
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.Objects
11+
open GraphBLAS.FSharp.Backend.Objects
12+
open GraphBLAS.FSharp.Backend.Matrix.COO
13+
open GraphBLAS.FSharp.Backend.Matrix.CSR
14+
open GraphBLAS.FSharp.Objects.Matrix
15+
open GraphBLAS.FSharp.Benchmarks.MatrixExtensions
1216

1317
type Config() =
1418
inherit ManualConfig()
@@ -43,7 +47,7 @@ type Config() =
4347
[<IterationCount(100)>]
4448
[<WarmupCount(10)>]
4549
[<Config(typeof<Config>)>]
46-
type EWiseAddBenchmarks<'matrixT, 'elem when 'matrixT :> Backend.IDeviceMemObject and 'elem : struct>(
50+
type EWiseAddBenchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : struct>(
4751
buildFunToBenchmark,
4852
converter: string -> 'elem,
4953
converterBool,
@@ -107,11 +111,11 @@ type EWiseAddBenchmarks<'matrixT, 'elem when 'matrixT :> Backend.IDeviceMemObjec
107111
this.ResultMatrix <- this.FunToBenchmark this.Processor firstMatrix secondMatrix
108112

109113
member this.ClearInputMatrices() =
110-
(firstMatrix :> Backend.IDeviceMemObject).Dispose this.Processor
111-
(secondMatrix :> Backend.IDeviceMemObject).Dispose this.Processor
114+
(firstMatrix :> IDeviceMemObject).Dispose this.Processor
115+
(secondMatrix :> IDeviceMemObject).Dispose this.Processor
112116

113117
member this.ClearResult() =
114-
(this.ResultMatrix :> Backend.IDeviceMemObject).Dispose this.Processor
118+
(this.ResultMatrix :> IDeviceMemObject).Dispose this.Processor
115119

116120
member this.ReadMatrices() =
117121
let leftMatrixReader = fst this.InputMatrixReader
@@ -131,7 +135,7 @@ type EWiseAddBenchmarks<'matrixT, 'elem when 'matrixT :> Backend.IDeviceMemObjec
131135

132136
abstract member Benchmark : unit -> unit
133137

134-
type EWiseAddBenchmarksWithoutDataTransfer<'matrixT, 'elem when 'matrixT :> Backend.IDeviceMemObject and 'elem : struct>(
138+
type EWiseAddBenchmarksWithoutDataTransfer<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : struct>(
135139
buildFunToBenchmark,
136140
converter: string -> 'elem,
137141
converterBool,
@@ -161,7 +165,7 @@ type EWiseAddBenchmarksWithoutDataTransfer<'matrixT, 'elem when 'matrixT :> Back
161165
this.EWiseAddition()
162166
this.Processor.PostAndReply(Msg.MsgNotifyMe)
163167

164-
type EWiseAddBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> Backend.IDeviceMemObject and 'elem : struct>(
168+
type EWiseAddBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : struct>(
165169
buildFunToBenchmark,
166170
converter: string -> 'elem,
167171
converterBool,
@@ -195,18 +199,18 @@ type EWiseAddBenchmarksWithDataTransfer<'matrixT, 'elem when 'matrixT :> Backend
195199
this.Processor.PostAndReply Msg.MsgNotifyMe
196200

197201
module M =
198-
let resultToHostCOO (resultMatrix:Backend.COOMatrix<'a>) (procesor:MailboxProcessor<_>) =
202+
let resultToHostCOO (resultMatrix: ClMatrix.COO<'a>) (processor :MailboxProcessor<_>) =
199203
let cols =
200204
let a = Array.zeroCreate resultMatrix.ColumnCount
201-
procesor.Post(Msg.CreateToHostMsg<_>(resultMatrix.Columns,a))
205+
processor.Post(Msg.CreateToHostMsg<_>(resultMatrix.Columns,a))
202206
a
203207
let rows =
204208
let a = Array.zeroCreate resultMatrix.RowCount
205-
procesor.Post(Msg.CreateToHostMsg(resultMatrix.Rows,a))
209+
processor.Post(Msg.CreateToHostMsg(resultMatrix.Rows,a))
206210
a
207211
let vals =
208212
let a = Array.zeroCreate resultMatrix.Values.Length
209-
procesor.Post(Msg.CreateToHostMsg(resultMatrix.Values,a))
213+
processor.Post(Msg.CreateToHostMsg(resultMatrix.Values,a))
210214
a
211215
{
212216
RowCount = resultMatrix.RowCount
@@ -219,23 +223,23 @@ module M =
219223

220224
type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
221225

222-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.COOMatrix<float32>,float32>(
223-
(fun context wgSize -> Backend.COOMatrix.elementwise context Backend.Common.StandardOperations.float32Sum wgSize),
226+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<float32>,float32>(
227+
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
224228
float32,
225229
(fun _ -> Utils.nextSingle (System.Random())),
226-
COOMatrix<float32>.ToBackend
230+
Matrix.ToBackendCOO
227231
)
228232

229233
static member InputMatricesProvider =
230234
EWiseAddBenchmarks<_,_>.InputMatricesProviderBuilder "EWiseAddBenchmarks4Float32COO.txt"
231235

232236
type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
233237

234-
inherit EWiseAddBenchmarksWithDataTransfer<Backend.COOMatrix<float32>,float32>(
235-
(fun context wgSize -> Backend.COOMatrix.elementwise context Backend.Common.StandardOperations.float32Sum wgSize),
238+
inherit EWiseAddBenchmarksWithDataTransfer<ClMatrix.COO<float32>,float32>(
239+
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
236240
float32,
237241
(fun _ -> Utils.nextSingle (System.Random())),
238-
COOMatrix<float32>.ToBackend,
242+
Matrix.ToBackendCOO<float32>,
239243
M.resultToHostCOO
240244
)
241245

@@ -245,11 +249,11 @@ type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
245249

246250
type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
247251

248-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.COOMatrix<bool>,bool>(
249-
(fun context wgSize -> Backend.COOMatrix.elementwise context Backend.Common.StandardOperations.boolSum wgSize),
252+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<bool>,bool>(
253+
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.boolSum wgSize),
250254
(fun _ -> true),
251255
(fun _ -> true),
252-
COOMatrix<bool>.ToBackend
256+
Matrix.ToBackendCOO<bool>
253257
)
254258

255259
static member InputMatricesProvider =
@@ -258,11 +262,11 @@ type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
258262

259263
type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
260264

261-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.CSRMatrix<float32>,float32>(
262-
(fun context wgSize -> Backend.CSRMatrix.elementwise context Backend.Common.StandardOperations.float32Sum wgSize),
265+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<float32>,float32>(
266+
(fun context wgSize -> CSRMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
263267
float32,
264268
(fun _ -> Utils.nextSingle (System.Random())),
265-
CSRMatrix<float32>.ToBackend
269+
Matrix.ToBackendCSR
266270
)
267271

268272
static member InputMatricesProvider =
@@ -271,11 +275,11 @@ type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
271275

272276
type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
273277

274-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.CSRMatrix<bool>,bool>(
275-
(fun context wgSize -> Backend.CSRMatrix.elementwise context Backend.Common.StandardOperations.boolSum wgSize),
278+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<bool>,bool>(
279+
(fun context wgSize -> CSRMatrix.elementwise context ArithmeticOperations.boolSum wgSize),
276280
(fun _ -> true),
277281
(fun _ -> true),
278-
CSRMatrix<bool>.ToBackend
282+
Matrix.ToBackendCSR
279283
)
280284

281285
static member InputMatricesProvider =
@@ -285,47 +289,47 @@ type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
285289

286290
type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
287291

288-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.COOMatrix<bool>,bool>(
289-
(fun context wgSize -> Backend.COOMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.boolSumAtLeastOne wgSize),
292+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<bool>,bool>(
293+
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
290294
(fun _ -> true),
291295
(fun _ -> true),
292-
COOMatrix<bool>.ToBackend
296+
Matrix.ToBackendCOO<bool>
293297
)
294298

295299
static member InputMatricesProvider =
296300
EWiseAddBenchmarks<_, _>.InputMatricesProviderBuilder "EWiseAddBenchmarks4BoolCSR.txt"
297301

298302
type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
299303

300-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.CSRMatrix<bool>,bool>(
301-
(fun context wgSize -> Backend.CSRMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.boolSumAtLeastOne wgSize),
304+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<bool>,bool>(
305+
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
302306
(fun _ -> true),
303307
(fun _ -> true),
304-
CSRMatrix<bool>.ToBackend
308+
Matrix.ToBackendCSR
305309
)
306310

307311
static member InputMatricesProvider =
308312
EWiseAddBenchmarks<_, _>.InputMatricesProviderBuilder "EWiseAddBenchmarks4BoolCSR.txt"
309313

310314
type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
311315

312-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.COOMatrix<float32>,float32>(
313-
(fun context wgSize -> Backend.COOMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.float32SumAtLeastOne wgSize),
316+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<float32>,float32>(
317+
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
314318
float32,
315319
(fun _ -> Utils.nextSingle (System.Random())),
316-
COOMatrix<float32>.ToBackend
320+
Matrix.ToBackendCOO<float32>
317321
)
318322

319323
static member InputMatricesProvider =
320324
EWiseAddBenchmarks<_,_>.InputMatricesProviderBuilder "EWiseAddBenchmarks4Float32COO.txt"
321325

322326
type EWiseAddAtLeastOneBenchmarks4Float32CSRWithoutDataTransfer() =
323327

324-
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.CSRMatrix<float32>,float32>(
325-
(fun context wgSize -> Backend.CSRMatrix.elementwiseAtLeastOne context Backend.Common.StandardOperations.float32SumAtLeastOne wgSize),
328+
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<float32>,float32>(
329+
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
326330
float32,
327331
(fun _ -> Utils.nextSingle (System.Random())),
328-
CSRMatrix<float32>.ToBackend
332+
Matrix.ToBackendCSR<float32>
329333
)
330334

331335
static member InputMatricesProvider =

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksMathNET.fs

Lines changed: 2 additions & 7 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
5-
open GraphBLAS.FSharp
4+
open GraphBLAS.FSharp.Objects
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)>]
@@ -23,7 +18,7 @@ type MathNETBenchmark<'elem when 'elem: struct and 'elem :> System.IEquatable<'e
2318

2419
static member COOMatrixToMathNETSparse matrix =
2520
match matrix with
26-
| MatrixCOO matrix ->
21+
| Matrix.COO matrix ->
2722
Matrix.Build.SparseFromCoordinateFormat(
2823
matrix.RowCount,
2924
matrix.ColumnCount,

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksMxm.fs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
namespace GraphBLAS.FSharp.Benchmarks
22

33
open System.IO
4-
open GraphBLAS.FSharp
54
open GraphBLAS.FSharp.IO
65
open BenchmarkDotNet.Attributes
76
open Brahma.FSharp
7+
open GraphBLAS.FSharp.Objects
8+
open GraphBLAS.FSharp.Backend.Objects
9+
open GraphBLAS.FSharp.Backend.Matrix
10+
open GraphBLAS.FSharp.Benchmarks.MatrixExtensions
811

912
[<AbstractClass>]
1013
[<IterationCount(100)>]
@@ -20,15 +23,15 @@ type MxmBenchmarks<'elem when 'elem : struct>(
2023
let mutable funCSR2CSC = None
2124
let mutable funCSC2CSR = None
2225

23-
let mutable firstMatrix = Unchecked.defaultof<Backend.Matrix<'elem>>
24-
let mutable secondMatrix = Unchecked.defaultof<Backend.Matrix<'elem>>
25-
let mutable mask = Unchecked.defaultof<Backend.Mask2D>
26+
let mutable firstMatrix = Unchecked.defaultof<ClMatrix<'elem>>
27+
let mutable secondMatrix = Unchecked.defaultof<ClMatrix<'elem>>
28+
let mutable mask = Unchecked.defaultof<ClMask2D>
2629

2730
let mutable firstMatrixHost = Unchecked.defaultof<_>
2831
let mutable secondMatrixHost = Unchecked.defaultof<_>
2932
let mutable maskHost = Unchecked.defaultof<Mask2D>
3033

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

3336
[<ParamsSource("AvaliableContexts")>]
3437
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
@@ -71,15 +74,15 @@ type MxmBenchmarks<'elem when 'elem : struct>(
7174
member this.FunCSR2CSC =
7275
match funCSR2CSC with
7376
| None ->
74-
let x = Backend.Matrix.toCSCInplace this.OclContext this.WorkGroupSize
77+
let x = Matrix.toCSCInplace this.OclContext this.WorkGroupSize
7578
funCSR2CSC <- Some x
7679
x
7780
| Some x -> x
7881

7982
member this.FunCSC2CSR =
8083
match funCSC2CSR with
8184
| None ->
82-
let x = Backend.Matrix.toCSRInplace this.OclContext this.WorkGroupSize
85+
let x = Matrix.toCSRInplace this.OclContext this.WorkGroupSize
8386
funCSC2CSR <- Some x
8487
x
8588
| Some x -> x
@@ -105,7 +108,7 @@ type MxmBenchmarks<'elem when 'elem : struct>(
105108

106109
member this.ReadMask(maskReader) =
107110
match this.ReadMatrix maskReader with
108-
| MatrixCOO m ->
111+
| Matrix.COO m ->
109112
maskHost <-
110113
{ IsComplemented = false
111114
RowCount = m.RowCount
@@ -233,10 +236,10 @@ module Operations =
233236
type MxmBenchmarks4Float32MultiplicationOnly() =
234237

235238
inherit MxmBenchmarksMultiplicationOnly<float32>(
236-
(Backend.Matrix.mxm Operations.add Operations.mult),
239+
(Matrix.mxm Operations.add Operations.mult),
237240
float32,
238241
(fun _ -> Utils.nextSingle (System.Random())),
239-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
242+
(fun context matrix -> ClMatrix.CSR (Matrix.ToBackendCSR context matrix))
240243
)
241244

242245
static member InputMatrixProvider =
@@ -245,10 +248,10 @@ type MxmBenchmarks4Float32MultiplicationOnly() =
245248
type MxmBenchmarks4Float32WithTransposing() =
246249

247250
inherit MxmBenchmarksWithTransposing<float32>(
248-
(Backend.Matrix.mxm Operations.add Operations.mult),
251+
(Matrix.mxm Operations.add Operations.mult),
249252
float32,
250253
(fun _ -> Utils.nextSingle (System.Random())),
251-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
254+
(fun context matrix -> ClMatrix.CSR (Matrix.ToBackendCSR context matrix))
252255
)
253256

254257
static member InputMatrixProvider =
@@ -257,10 +260,10 @@ type MxmBenchmarks4Float32WithTransposing() =
257260
type MxmBenchmarks4BoolMultiplicationOnly() =
258261

259262
inherit MxmBenchmarksMultiplicationOnly<bool>(
260-
(Backend.Matrix.mxm Operations.logicalOr Operations.logicalAnd),
263+
(Matrix.mxm Operations.logicalOr Operations.logicalAnd),
261264
(fun _ -> true),
262265
(fun _ -> true),
263-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<bool>.ToBackend context matrix))
266+
(fun context matrix -> ClMatrix.CSR (Matrix.ToBackendCSR context matrix))
264267
)
265268

266269
static member InputMatrixProvider =
@@ -269,10 +272,10 @@ type MxmBenchmarks4BoolMultiplicationOnly() =
269272
type MxmBenchmarks4BoolWithTransposing() =
270273

271274
inherit MxmBenchmarksWithTransposing<bool>(
272-
(Backend.Matrix.mxm Operations.logicalOr Operations.logicalAnd),
275+
(Matrix.mxm Operations.logicalOr Operations.logicalAnd),
273276
(fun _ -> true),
274277
(fun _ -> true),
275-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<bool>.ToBackend context matrix))
278+
(fun context matrix -> ClMatrix.CSR (Matrix.ToBackendCSR context matrix))
276279
)
277280

278281
static member InputMatrixProvider =
@@ -281,10 +284,10 @@ type MxmBenchmarks4BoolWithTransposing() =
281284
type MxmBenchmarks4Float32MultiplicationOnlyWithZerosFilter() =
282285

283286
inherit MxmBenchmarksMultiplicationOnly<float32>(
284-
(Backend.Matrix.mxm Operations.addWithFilter Operations.mult),
287+
(Matrix.mxm Operations.addWithFilter Operations.mult),
285288
float32,
286289
(fun _ -> Utils.nextSingle (System.Random())),
287-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
290+
(fun context matrix -> ClMatrix.CSR (Matrix.ToBackendCSR context matrix))
288291
)
289292

290293
static member InputMatrixProvider =
@@ -293,10 +296,10 @@ type MxmBenchmarks4Float32MultiplicationOnlyWithZerosFilter() =
293296
type MxmBenchmarks4Float32WithTransposingWithZerosFilter() =
294297

295298
inherit MxmBenchmarksWithTransposing<float32>(
296-
(Backend.Matrix.mxm Operations.addWithFilter Operations.mult),
299+
(Matrix.mxm Operations.addWithFilter Operations.mult),
297300
float32,
298301
(fun _ -> Utils.nextSingle (System.Random())),
299-
(fun context matrix -> Backend.MatrixCSR (CSRMatrix<float32>.ToBackend context matrix))
302+
(fun context matrix -> ClMatrix.CSR (Matrix.ToBackendCSR context matrix))
300303
)
301304

302305
static member InputMatrixProvider =

0 commit comments

Comments
 (0)