Skip to content

Commit 2a5617b

Browse files
committed
refactor: operations early binding
1 parent 1d45950 commit 2a5617b

File tree

48 files changed

+279
-312
lines changed

Some content is hidden

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

48 files changed

+279
-312
lines changed

benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/Benchmark.fs renamed to benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ module WithoutTransfer =
126126
type Int() =
127127

128128
inherit Benchmark<int>(
129-
(fun context -> singleSource context ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
129+
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
130130
int32,
131131
(fun _ -> Utils.nextInt (System.Random())),
132132
0)
@@ -170,7 +170,7 @@ module WithTransfer =
170170
type Int() =
171171

172172
inherit Benchmark<int>(
173-
(fun context -> singleSource context ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
173+
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
174174
int32,
175175
(fun _ -> Utils.nextInt (System.Random())),
176176
0)

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
<Compile Include="Helpers.fs" />
2020
<Compile Include="Columns.fs" />
2121
<Compile Include="Configs.fs" />
22-
<!--Compile Include="BenchmarksTranspose.fs" /-->
23-
<Compile Include="Matrix\SpGeMM\Masked.fs" />
24-
<Compile Include="Matrix\SpGeMM\Expand.fs" />
25-
<Compile Include="Matrix\Map2\Map2.fs" />
26-
<Compile Include="Matrix\Map2\MathNET.fs" />
27-
<Compile Include="Vector\Map2.fs" />
28-
<Compile Include="Algorithms\Benchmark.fs" />
22+
<Compile Include="Matrix/SpGeMM/Masked.fs" />
23+
<Compile Include="Matrix/SpGeMM/Expand.fs" />
24+
<Compile Include="Matrix/Map2/Map2.fs" />
25+
<Compile Include="Matrix/Map2/MathNET.fs" />
26+
<Compile Include="Vector/Map2.fs" />
27+
<Compile Include="Algorithms/BFS.fs" />
2928
<Compile Include="Program.fs" />
3029
</ItemGroup>
3130
<Import Project="..\..\.paket\Paket.Restore.targets" />

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ module WithoutTransfer =
138138
type Float32() =
139139

140140
inherit Benchmark<ClMatrix.COO<float32>,float32>(
141-
(fun context -> Matrix.map2 context ArithmeticOperations.float32SumOption),
141+
(Matrix.map2 ArithmeticOperations.float32SumOption),
142142
float32,
143143
(fun _ -> Utils.nextSingle (System.Random())),
144144
Matrix.COO
@@ -150,7 +150,7 @@ module WithoutTransfer =
150150
type Bool() =
151151

152152
inherit Benchmark<ClMatrix.COO<bool>,bool>(
153-
(fun context -> Matrix.map2 context ArithmeticOperations.boolSumOption),
153+
(Matrix.map2 ArithmeticOperations.boolSumOption),
154154
(fun _ -> true),
155155
(fun _ -> true),
156156
Matrix.COO
@@ -163,7 +163,7 @@ module WithoutTransfer =
163163
type Float32() =
164164

165165
inherit Benchmark<ClMatrix.CSR<float32>,float32>(
166-
(fun context -> Matrix.map2 context ArithmeticOperations.float32SumOption),
166+
(Matrix.map2 ArithmeticOperations.float32SumOption),
167167
float32,
168168
(fun _ -> Utils.nextSingle (System.Random())),
169169
(fun matrix -> Matrix.CSR matrix.ToCSR)
@@ -175,7 +175,7 @@ module WithoutTransfer =
175175
type Bool() =
176176

177177
inherit Benchmark<ClMatrix.CSR<bool>,bool>(
178-
(fun context -> Matrix.map2 context ArithmeticOperations.boolSumOption),
178+
(Matrix.map2 ArithmeticOperations.boolSumOption),
179179
(fun _ -> true),
180180
(fun _ -> true),
181181
(fun matrix -> Matrix.CSR matrix.ToCSR)
@@ -189,7 +189,7 @@ module WithoutTransfer =
189189
type Bool() =
190190

191191
inherit Benchmark<ClMatrix.COO<bool>,bool>(
192-
(fun context -> Matrix.map2AtLeastOne context ArithmeticOperations.boolSumAtLeastOne),
192+
(Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
193193
(fun _ -> true),
194194
(fun _ -> true),
195195
Matrix.COO
@@ -201,7 +201,7 @@ module WithoutTransfer =
201201
type Float32() =
202202

203203
inherit Benchmark<ClMatrix.COO<float32>,float32>(
204-
(fun context -> Matrix.map2AtLeastOne context ArithmeticOperations.float32SumAtLeastOne),
204+
(Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
205205
float32,
206206
(fun _ -> Utils.nextSingle (System.Random())),
207207
Matrix.COO
@@ -214,7 +214,7 @@ module WithoutTransfer =
214214
type Bool() =
215215

216216
inherit Benchmark<ClMatrix.CSR<bool>,bool>(
217-
(fun context -> Matrix.map2AtLeastOne context ArithmeticOperations.boolSumAtLeastOne),
217+
(Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
218218
(fun _ -> true),
219219
(fun _ -> true),
220220
(fun matrix -> Matrix.CSR matrix.ToCSR)
@@ -226,7 +226,7 @@ module WithoutTransfer =
226226
type Float32() =
227227

228228
inherit Benchmark<ClMatrix.CSR<float32>,float32>(
229-
(fun context -> Matrix.map2AtLeastOne context ArithmeticOperations.float32SumAtLeastOne),
229+
(Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
230230
float32,
231231
(fun _ -> Utils.nextSingle (System.Random())),
232232
(fun matrix -> Matrix.CSR matrix.ToCSR)
@@ -273,7 +273,7 @@ module WithTransfer =
273273
type Float32() =
274274

275275
inherit Benchmark<ClMatrix.COO<float32>,float32>(
276-
(fun context -> Matrix.map2 context ArithmeticOperations.float32SumOption),
276+
(Matrix.map2 ArithmeticOperations.float32SumOption),
277277
float32,
278278
(fun _ -> Utils.nextSingle (System.Random())),
279279
Matrix.COO,

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

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -104,45 +104,45 @@ type Benchmarks<'elem when 'elem : struct>(
104104

105105
abstract member GlobalCleanup : unit -> unit
106106

107-
type MxmBenchmarksMultiplicationOnly<'elem when 'elem : struct>(
108-
buildFunToBenchmark,
109-
converter: string -> 'elem,
110-
converterBool,
111-
buildMatrix) =
112-
113-
inherit Benchmarks<'elem>(
114-
buildFunToBenchmark,
115-
converter,
116-
converterBool,
117-
buildMatrix)
118-
119-
[<GlobalSetup>]
120-
override this.GlobalSetup() =
121-
this.ReadMatrices()
122-
this.LoadMatricesToGPU()
123-
124-
[<Benchmark>]
125-
override this.Benchmark() =
126-
this.Mxm()
127-
this.Processor.PostAndReply(Msg.MsgNotifyMe)
128-
129-
[<IterationCleanup>]
130-
override this.IterationCleanup () =
131-
this.ClearResult()
132-
133-
[<GlobalCleanup>]
134-
override this.GlobalCleanup () =
135-
this.ClearInputMatrices()
136-
137-
138-
// type Mxm4Float32WithTransposingWithZerosFilterBenchmark() =
139-
//
140-
// inherit MxmBenchmarksWithTransposing<float32>(
141-
// (fun context wgSize -> Matrix.SpGeMM.expand context wgSize (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)),
142-
// float32,
143-
// (fun _ -> Utils.nextSingle (System.Random())),
144-
// (fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
145-
// )
146-
//
147-
// static member InputMatrixProvider =
148-
// Benchmarks<_>.InputMatrixProviderBuilder "MxmBenchmarks4Float32.txt"
107+
module WithoutTransfer =
108+
type Benchmark<'elem when 'elem : struct>(
109+
buildFunToBenchmark,
110+
converter: string -> 'elem,
111+
converterBool,
112+
buildMatrix) =
113+
114+
inherit Benchmarks<'elem>(
115+
buildFunToBenchmark,
116+
converter,
117+
converterBool,
118+
buildMatrix)
119+
120+
[<GlobalSetup>]
121+
override this.GlobalSetup() =
122+
this.ReadMatrices()
123+
this.LoadMatricesToGPU()
124+
125+
[<Benchmark>]
126+
override this.Benchmark() =
127+
this.Mxm()
128+
this.Processor.PostAndReply(Msg.MsgNotifyMe)
129+
130+
[<IterationCleanup>]
131+
override this.IterationCleanup () =
132+
this.ClearResult()
133+
134+
[<GlobalCleanup>]
135+
override this.GlobalCleanup () =
136+
this.ClearInputMatrices()
137+
138+
type Float32() =
139+
140+
inherit Benchmark<float32>(
141+
Matrix.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
142+
float32,
143+
(fun _ -> Utils.nextSingle (System.Random())),
144+
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
145+
)
146+
147+
static member InputMatrixProvider =
148+
Benchmarks<_>.InputMatrixProviderBuilder "MxmBenchmarks4Float32.txt"

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace GraphBLAS.FSharp.Benchmarks.Matrix.SpGeMM
22

33
open System.IO
4+
open GraphBLAS.FSharp.Backend.Quotes
45
open GraphBLAS.FSharp.IO
56
open BenchmarkDotNet.Attributes
67
open Brahma.FSharp
@@ -203,7 +204,7 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>(
203204
type Mxm4Float32MultiplicationOnlyBenchmark() =
204205

205206
inherit MxmBenchmarksMultiplicationOnly<float32>(
206-
Matrix.SpGeMM.masked (Operations.add ()) (Operations.mult ()),
207+
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
207208
float32,
208209
(fun _ -> Utils.nextSingle (System.Random())),
209210
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -215,7 +216,7 @@ type Mxm4Float32MultiplicationOnlyBenchmark() =
215216
type Mxm4Float32WithTransposingBenchmark() =
216217

217218
inherit MxmBenchmarksWithTransposing<float32>(
218-
Matrix.SpGeMM.masked (Operations.add ()) (Operations.mult ()),
219+
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
219220
float32,
220221
(fun _ -> Utils.nextSingle (System.Random())),
221222
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -227,7 +228,7 @@ type Mxm4Float32WithTransposingBenchmark() =
227228
type Mxm4BoolMultiplicationOnlyBenchmark() =
228229

229230
inherit MxmBenchmarksMultiplicationOnly<bool>(
230-
(Matrix.SpGeMM.masked Operations.logicalOr Operations.logicalAnd),
231+
(Matrix.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
231232
(fun _ -> true),
232233
(fun _ -> true),
233234
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -239,7 +240,7 @@ type Mxm4BoolMultiplicationOnlyBenchmark() =
239240
type Mxm4BoolWithTransposingBenchmark() =
240241

241242
inherit MxmBenchmarksWithTransposing<bool>(
242-
(Matrix.SpGeMM.masked Operations.logicalOr Operations.logicalAnd),
243+
(Matrix.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
243244
(fun _ -> true),
244245
(fun _ -> true),
245246
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -251,7 +252,7 @@ type Mxm4BoolWithTransposingBenchmark() =
251252
type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() =
252253

253254
inherit MxmBenchmarksMultiplicationOnly<float32>(
254-
(Matrix.SpGeMM.masked Operations.addWithFilter (Operations.mult ())),
255+
(Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)),
255256
float32,
256257
(fun _ -> Utils.nextSingle (System.Random())),
257258
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -263,7 +264,7 @@ type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() =
263264
type Mxm4Float32WithTransposingWithZerosFilterBenchmark() =
264265

265266
inherit MxmBenchmarksWithTransposing<float32>(
266-
Matrix.SpGeMM.masked Operations.addWithFilter (Operations.mult ()),
267+
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
267268
float32,
268269
(fun _ -> Utils.nextSingle (System.Random())),
269270
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,26 +122,26 @@ module WithoutTransfer =
122122
type Float() =
123123

124124
inherit Benchmark<float>(
125-
(fun context -> Vector.map2 context ArithmeticOperations.floatSumOption),
125+
(Vector.map2 ArithmeticOperations.floatSumOption),
126126
VectorGenerator.floatPair Sparse)
127127

128128
type Int32() =
129129

130130
inherit Benchmark<int32>(
131-
(fun context -> Vector.map2 context ArithmeticOperations.intSumOption),
131+
(Vector.map2 ArithmeticOperations.intSumOption),
132132
VectorGenerator.intPair Sparse)
133133

134134
module AtLeastOne =
135135
type Float() =
136136

137137
inherit Benchmark<float>(
138-
(fun context -> Vector.map2AtLeastOne context ArithmeticOperations.floatSumAtLeastOne),
138+
(Vector.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne),
139139
VectorGenerator.floatPair Sparse)
140140

141141
type Int32() =
142142

143143
inherit Benchmark<int32>(
144-
(fun context -> Vector.map2AtLeastOne context ArithmeticOperations.intSumAtLeastOne),
144+
(Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne),
145145
VectorGenerator.intPair Sparse)
146146

147147
module WithTransfer =
@@ -178,24 +178,24 @@ module WithTransfer =
178178
type Float() =
179179

180180
inherit Benchmark<float>(
181-
(fun context -> Vector.map2 context ArithmeticOperations.floatSumOption),
181+
(Vector.map2 ArithmeticOperations.floatSumOption),
182182
VectorGenerator.floatPair Sparse)
183183

184184
type Int32() =
185185

186186
inherit Benchmark<int32>(
187-
(fun context -> Vector.map2 context ArithmeticOperations.intSumOption),
187+
(Vector.map2 ArithmeticOperations.intSumOption),
188188
VectorGenerator.intPair Sparse)
189189

190190
module AtLeastOne =
191191
type Float() =
192192

193193
inherit Benchmark<float>(
194-
(fun context -> Vector.map2AtLeastOne context ArithmeticOperations.floatSumAtLeastOne),
194+
(Vector.map2AtLeastOne ArithmeticOperations.floatSumAtLeastOne),
195195
VectorGenerator.floatPair Sparse)
196196

197197
type Int32() =
198198

199199
inherit Benchmark<int32>(
200-
(fun context -> Vector.map2AtLeastOne context ArithmeticOperations.intSumAtLeastOne),
200+
(Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne),
201201
VectorGenerator.intPair Sparse)

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,28 @@ open GraphBLAS.FSharp.Backend.Objects.ClCell
1414

1515
module BFS =
1616
let singleSource
17-
(clContext: ClContext)
1817
(add: Expr<int option -> int option -> int option>)
1918
(mul: Expr<'a option -> int option -> int option>)
19+
(clContext: ClContext)
2020
workGroupSize
2121
=
2222

2323
let spMVTo =
24-
SpMV.runTo clContext add mul workGroupSize
24+
SpMV.runTo add mul clContext workGroupSize
2525

2626
let zeroCreate =
2727
ClArray.zeroCreate clContext workGroupSize
2828

2929
let ofList = Vector.ofList clContext workGroupSize
3030

3131
let maskComplementedTo =
32-
Vector.map2InPlace clContext Mask.complementedOp workGroupSize
32+
Vector.map2InPlace Mask.complementedOp clContext workGroupSize
3333

3434
let fillSubVectorTo =
35-
Vector.assignByMaskInPlace clContext (Convert.assignToOption Mask.assign) workGroupSize
35+
Vector.assignByMaskInPlace (Convert.assignToOption Mask.assign) clContext workGroupSize
3636

3737
let containsNonZero =
38-
ClArray.exists clContext workGroupSize Predicates.isSome
38+
ClArray.exists Predicates.isSome clContext workGroupSize
3939

4040
fun (queue: MailboxProcessor<Msg>) (matrix: ClMatrix.CSR<'a>) (source: int) ->
4141
let vertexCount = matrix.RowCount

0 commit comments

Comments
 (0)