Skip to content

Commit 8a79b41

Browse files
authored
Merge pull request #84 from artemiipatov/refactor
Refactor
2 parents f02ef72 + 441a2f9 commit 8a79b41

111 files changed

Lines changed: 2228 additions & 1137 deletions

Some content is hidden

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ GraphBLAS# is a GPGPU-based [GraphBLAS](https://graphblas.org/)-like API impleme
3030
- [x] COO-COO `map2`
3131
- [x] COO-COO `map2AtLeastOne`
3232
- [x] CSR-CSR multiplication
33+
- [x] CSR-CSR Kronecker product
3334
- **Vector-Matrix**
3435
- [x] Dense-CSR multiplication
3536
- [ ] Sparse-CSR multiplication

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

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
open System.IO
44
open BenchmarkDotNet.Attributes
5+
open Microsoft.FSharp.Core
6+
open Brahma.FSharp
57
open GraphBLAS.FSharp
6-
open GraphBLAS.FSharp.Backend.Quotes
78
open GraphBLAS.FSharp.IO
8-
open Brahma.FSharp
9-
open Backend.Algorithms.BFS
10-
open Microsoft.FSharp.Core
11-
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
129
open GraphBLAS.FSharp.Benchmarks
13-
open GraphBLAS.FSharp.Backend.Objects
10+
open GraphBLAS.FSharp.Objects
11+
open GraphBLAS.FSharp.Objects.ArraysExtensions
12+
open GraphBLAS.FSharp.Backend.Quotes
1413

1514
[<AbstractClass>]
1615
[<IterationCount(100)>]
@@ -20,11 +19,12 @@ type Benchmarks<'elem when 'elem : struct>(
2019
buildFunToBenchmark,
2120
converter: string -> 'elem,
2221
binaryConverter,
23-
vertex: int)
22+
vertex: int,
23+
buildMatrix)
2424
=
2525

2626
let mutable funToBenchmark = None
27-
let mutable matrix = Unchecked.defaultof<ClMatrix.CSR<'elem>>
27+
let mutable matrix = Unchecked.defaultof<ClMatrix<'elem>>
2828
let mutable matrixHost = Unchecked.defaultof<_>
2929

3030
member val ResultLevels = Unchecked.defaultof<ClArray<'elem option>> with get,set
@@ -69,7 +69,7 @@ type Benchmarks<'elem when 'elem : struct>(
6969
this.ResultLevels <- this.FunToBenchmark this.Processor matrix vertex
7070

7171
member this.ClearInputMatrix() =
72-
(matrix :> IDeviceMemObject).Dispose this.Processor
72+
matrix.Dispose this.Processor
7373

7474
member this.ClearResult() = this.ResultLevels.FreeAndWait this.Processor
7575

@@ -82,7 +82,7 @@ type Benchmarks<'elem when 'elem : struct>(
8282
matrixHost <- this.InputMatrixReader.ReadMatrix converter
8383

8484
member this.LoadMatrixToGPU() =
85-
matrix <- matrixHost.ToCSR.ToDevice this.OclContext
85+
matrix <- buildMatrix this.OclContext matrixHost
8686

8787
abstract member GlobalSetup : unit -> unit
8888

@@ -96,13 +96,15 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
9696
buildFunToBenchmark,
9797
converter: string -> 'elem,
9898
boolConverter,
99-
vertex) =
99+
vertex,
100+
buildMatrix) =
100101

101102
inherit Benchmarks<'elem>(
102103
buildFunToBenchmark,
103104
converter,
104105
boolConverter,
105-
vertex)
106+
vertex,
107+
buildMatrix)
106108

107109
[<GlobalSetup>]
108110
override this.GlobalSetup() =
@@ -125,10 +127,11 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
125127
type BFSWithoutTransferBenchmarkInt32() =
126128

127129
inherit WithoutTransferBenchmark<int>(
128-
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
130+
(Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
129131
int32,
130132
(fun _ -> Utils.nextInt (System.Random())),
131-
0)
133+
0,
134+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
132135

133136
static member InputMatrixProvider =
134137
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
@@ -137,13 +140,15 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
137140
buildFunToBenchmark,
138141
converter: string -> 'elem,
139142
boolConverter,
140-
vertex) =
143+
vertex,
144+
buildMatrix) =
141145

142146
inherit Benchmarks<'elem>(
143147
buildFunToBenchmark,
144148
converter,
145149
boolConverter,
146-
vertex)
150+
vertex,
151+
buildMatrix)
147152

148153
[<GlobalSetup>]
149154
override this.GlobalSetup() =
@@ -168,10 +173,11 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
168173
type BFSWithTransferBenchmarkInt32() =
169174

170175
inherit WithTransferBenchmark<int>(
171-
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
176+
(Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
172177
int32,
173178
(fun _ -> Utils.nextInt (System.Random())),
174-
0)
179+
0,
180+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))
175181

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

benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ namespace GraphBLAS.FSharp.Benchmarks
55
open Brahma.FSharp
66
open Brahma.FSharp.OpenCL.Translator
77
open Brahma.FSharp.OpenCL.Translator.QuotationTransformers
8-
open GraphBLAS.FSharp.Backend.Objects
98
open OpenCL.Net
109
open System.IO
1110
open System.Text.RegularExpressions
1211
open GraphBLAS.FSharp.Tests
1312
open FsCheck
1413
open Expecto
15-
open GraphBLAS.FSharp.Test
1614

1715
module Utils =
1816
type BenchmarkContext =

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

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

33
open System.IO
4-
open GraphBLAS.FSharp.Backend.Quotes
5-
open GraphBLAS.FSharp.IO
64
open BenchmarkDotNet.Attributes
75
open Brahma.FSharp
6+
open GraphBLAS.FSharp
7+
open GraphBLAS.FSharp.IO
88
open GraphBLAS.FSharp.Objects
9-
open GraphBLAS.FSharp.Backend.Objects
109
open GraphBLAS.FSharp.Objects.MatrixExtensions
11-
open GraphBLAS.FSharp.Backend.Objects.ClContext
12-
open GraphBLAS.FSharp.Backend.Matrix
10+
open GraphBLAS.FSharp.Objects.ClContextExtensions
11+
open GraphBLAS.FSharp.Backend.Quotes
1312
open GraphBLAS.FSharp.Benchmarks
1413

1514
[<AbstractClass>]
@@ -138,7 +137,7 @@ module WithoutTransfer =
138137
type Float32() =
139138

140139
inherit Benchmark<ClMatrix.COO<float32>,float32>(
141-
(Matrix.map2 ArithmeticOperations.float32SumOption),
140+
(Operations.Matrix.map2 ArithmeticOperations.float32SumOption),
142141
float32,
143142
(fun _ -> Utils.nextSingle (System.Random())),
144143
Matrix.COO
@@ -150,7 +149,7 @@ module WithoutTransfer =
150149
type Bool() =
151150

152151
inherit Benchmark<ClMatrix.COO<bool>,bool>(
153-
(Matrix.map2 ArithmeticOperations.boolSumOption),
152+
(Operations.Matrix.map2 ArithmeticOperations.boolSumOption),
154153
(fun _ -> true),
155154
(fun _ -> true),
156155
Matrix.COO
@@ -163,7 +162,7 @@ module WithoutTransfer =
163162
type Float32() =
164163

165164
inherit Benchmark<ClMatrix.CSR<float32>,float32>(
166-
(Matrix.map2 ArithmeticOperations.float32SumOption),
165+
(Operations.Matrix.map2 ArithmeticOperations.float32SumOption),
167166
float32,
168167
(fun _ -> Utils.nextSingle (System.Random())),
169168
(fun matrix -> Matrix.CSR matrix.ToCSR)
@@ -175,7 +174,7 @@ module WithoutTransfer =
175174
type Bool() =
176175

177176
inherit Benchmark<ClMatrix.CSR<bool>,bool>(
178-
(Matrix.map2 ArithmeticOperations.boolSumOption),
177+
(Operations.Matrix.map2 ArithmeticOperations.boolSumOption),
179178
(fun _ -> true),
180179
(fun _ -> true),
181180
(fun matrix -> Matrix.CSR matrix.ToCSR)
@@ -189,7 +188,7 @@ module WithoutTransfer =
189188
type Bool() =
190189

191190
inherit Benchmark<ClMatrix.COO<bool>,bool>(
192-
(Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
191+
(Operations.Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
193192
(fun _ -> true),
194193
(fun _ -> true),
195194
Matrix.COO
@@ -201,7 +200,7 @@ module WithoutTransfer =
201200
type Float32() =
202201

203202
inherit Benchmark<ClMatrix.COO<float32>,float32>(
204-
(Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
203+
(Operations.Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
205204
float32,
206205
(fun _ -> Utils.nextSingle (System.Random())),
207206
Matrix.COO
@@ -214,7 +213,7 @@ module WithoutTransfer =
214213
type Bool() =
215214

216215
inherit Benchmark<ClMatrix.CSR<bool>,bool>(
217-
(Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
216+
(Operations.Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
218217
(fun _ -> true),
219218
(fun _ -> true),
220219
(fun matrix -> Matrix.CSR matrix.ToCSR)
@@ -226,7 +225,7 @@ module WithoutTransfer =
226225
type Float32() =
227226

228227
inherit Benchmark<ClMatrix.CSR<float32>,float32>(
229-
(Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
228+
(Operations.Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
230229
float32,
231230
(fun _ -> Utils.nextSingle (System.Random())),
232231
(fun matrix -> Matrix.CSR matrix.ToCSR)
@@ -273,7 +272,7 @@ module WithTransfer =
273272
type Float32() =
274273

275274
inherit Benchmark<ClMatrix.COO<float32>,float32>(
276-
(Matrix.map2 ArithmeticOperations.float32SumOption),
275+
(Operations.Matrix.map2 ArithmeticOperations.float32SumOption),
277276
float32,
278277
(fun _ -> Utils.nextSingle (System.Random())),
279278
Matrix.COO,

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
module GraphBLAS.FSharp.Benchmarks.Matrix.SpGeMM.Expand
22

33
open System.IO
4-
open GraphBLAS.FSharp.Backend.Quotes
5-
open GraphBLAS.FSharp.IO
64
open BenchmarkDotNet.Attributes
75
open Brahma.FSharp
6+
open GraphBLAS.FSharp
7+
open GraphBLAS.FSharp.IO
8+
open GraphBLAS.FSharp.Backend.Quotes
89
open GraphBLAS.FSharp.Objects
9-
open GraphBLAS.FSharp.Backend.Objects
10-
open GraphBLAS.FSharp.Backend.Matrix
11-
open GraphBLAS.FSharp.Backend.Objects.ClContext
10+
open GraphBLAS.FSharp.Objects.ClContextExtensions
1211
open GraphBLAS.FSharp.Benchmarks
13-
open GraphBLAS.FSharp.Backend
1412

1513
[<AbstractClass>]
1614
[<IterationCount(100)>]
@@ -139,7 +137,7 @@ module WithoutTransfer =
139137
type Float32() =
140138

141139
inherit Benchmark<float32>(
142-
Matrix.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
140+
Operations.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
143141
float32,
144142
(fun _ -> Utils.nextSingle (System.Random())),
145143
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ open GraphBLAS.FSharp.Backend.Quotes
55
open GraphBLAS.FSharp.IO
66
open BenchmarkDotNet.Attributes
77
open Brahma.FSharp
8+
open GraphBLAS.FSharp
89
open GraphBLAS.FSharp.Objects
9-
open GraphBLAS.FSharp.Backend.Objects
10-
open GraphBLAS.FSharp.Backend.Matrix
11-
open GraphBLAS.FSharp.Backend.Objects.ClContext
10+
open GraphBLAS.FSharp.Objects.ClContextExtensions
1211
open GraphBLAS.FSharp.Benchmarks
13-
open GraphBLAS.FSharp.Backend
1412

1513
[<AbstractClass>]
1614
[<IterationCount(100)>]
@@ -204,7 +202,7 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>(
204202
type Mxm4Float32MultiplicationOnlyBenchmark() =
205203

206204
inherit MxmBenchmarksMultiplicationOnly<float32>(
207-
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
205+
Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
208206
float32,
209207
(fun _ -> Utils.nextSingle (System.Random())),
210208
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -216,7 +214,7 @@ type Mxm4Float32MultiplicationOnlyBenchmark() =
216214
type Mxm4Float32WithTransposingBenchmark() =
217215

218216
inherit MxmBenchmarksWithTransposing<float32>(
219-
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
217+
Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
220218
float32,
221219
(fun _ -> Utils.nextSingle (System.Random())),
222220
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -228,7 +226,7 @@ type Mxm4Float32WithTransposingBenchmark() =
228226
type Mxm4BoolMultiplicationOnlyBenchmark() =
229227

230228
inherit MxmBenchmarksMultiplicationOnly<bool>(
231-
(Matrix.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
229+
(Operations.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
232230
(fun _ -> true),
233231
(fun _ -> true),
234232
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -240,7 +238,7 @@ type Mxm4BoolMultiplicationOnlyBenchmark() =
240238
type Mxm4BoolWithTransposingBenchmark() =
241239

242240
inherit MxmBenchmarksWithTransposing<bool>(
243-
(Matrix.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
241+
(Operations.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
244242
(fun _ -> true),
245243
(fun _ -> true),
246244
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -252,7 +250,7 @@ type Mxm4BoolWithTransposingBenchmark() =
252250
type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() =
253251

254252
inherit MxmBenchmarksMultiplicationOnly<float32>(
255-
(Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)),
253+
(Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)),
256254
float32,
257255
(fun _ -> Utils.nextSingle (System.Random())),
258256
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -264,7 +262,7 @@ type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() =
264262
type Mxm4Float32WithTransposingWithZerosFilterBenchmark() =
265263

266264
inherit MxmBenchmarksWithTransposing<float32>(
267-
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
265+
Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
268266
float32,
269267
(fun _ -> Utils.nextSingle (System.Random())),
270268
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)

0 commit comments

Comments
 (0)