Skip to content

Commit 7ec498d

Browse files
committed
wip: refactor
1 parent 0c5db3f commit 7ec498d

13 files changed

Lines changed: 1437 additions & 258 deletions

File tree

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type Benchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : st
2020
buildFunToBenchmark,
2121
converter: string -> 'elem,
2222
converterBool,
23-
buildMatrix: Matrix.COO<_> -> Matrix<_>) =
23+
buildMatrix: Primitives.COO<_> -> Matrix<_>) =
2424

2525
let mutable funToBenchmark = None
2626
let mutable firstMatrix = Unchecked.defaultof<ClMatrix<'elem>>
@@ -138,10 +138,10 @@ module WithoutTransfer =
138138
type Float32() =
139139

140140
inherit Benchmark<ClMatrix.COO<float32>,float32>(
141-
(Matrix.map2 ArithmeticOperations.float32SumOption),
141+
(Primitives.map2 ArithmeticOperations.float32SumOption),
142142
float32,
143143
(fun _ -> Utils.nextSingle (System.Random())),
144-
Matrix.COO
144+
Primitives.COO
145145
)
146146

147147
static member InputMatricesProvider =
@@ -150,10 +150,10 @@ module WithoutTransfer =
150150
type Bool() =
151151

152152
inherit Benchmark<ClMatrix.COO<bool>,bool>(
153-
(Matrix.map2 ArithmeticOperations.boolSumOption),
153+
(Primitives.map2 ArithmeticOperations.boolSumOption),
154154
(fun _ -> true),
155155
(fun _ -> true),
156-
Matrix.COO
156+
Primitives.COO
157157
)
158158

159159
static member InputMatricesProvider =
@@ -163,10 +163,10 @@ module WithoutTransfer =
163163
type Float32() =
164164

165165
inherit Benchmark<ClMatrix.CSR<float32>,float32>(
166-
(Matrix.map2 ArithmeticOperations.float32SumOption),
166+
(Primitives.map2 ArithmeticOperations.float32SumOption),
167167
float32,
168168
(fun _ -> Utils.nextSingle (System.Random())),
169-
(fun matrix -> Matrix.CSR matrix.ToCSR)
169+
(fun matrix -> Primitives.CSR matrix.ToCSR)
170170
)
171171

172172
static member InputMatricesProvider =
@@ -175,10 +175,10 @@ module WithoutTransfer =
175175
type Bool() =
176176

177177
inherit Benchmark<ClMatrix.CSR<bool>,bool>(
178-
(Matrix.map2 ArithmeticOperations.boolSumOption),
178+
(Primitives.map2 ArithmeticOperations.boolSumOption),
179179
(fun _ -> true),
180180
(fun _ -> true),
181-
(fun matrix -> Matrix.CSR matrix.ToCSR)
181+
(fun matrix -> Primitives.CSR matrix.ToCSR)
182182
)
183183

184184
static member InputMatricesProvider =
@@ -189,10 +189,10 @@ module WithoutTransfer =
189189
type Bool() =
190190

191191
inherit Benchmark<ClMatrix.COO<bool>,bool>(
192-
(Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
192+
(Primitives.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
193193
(fun _ -> true),
194194
(fun _ -> true),
195-
Matrix.COO
195+
Primitives.COO
196196
)
197197

198198
static member InputMatricesProvider =
@@ -201,10 +201,10 @@ module WithoutTransfer =
201201
type Float32() =
202202

203203
inherit Benchmark<ClMatrix.COO<float32>,float32>(
204-
(Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
204+
(Primitives.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
205205
float32,
206206
(fun _ -> Utils.nextSingle (System.Random())),
207-
Matrix.COO
207+
Primitives.COO
208208
)
209209

210210
static member InputMatricesProvider =
@@ -214,10 +214,10 @@ module WithoutTransfer =
214214
type Bool() =
215215

216216
inherit Benchmark<ClMatrix.CSR<bool>,bool>(
217-
(Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
217+
(Primitives.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
218218
(fun _ -> true),
219219
(fun _ -> true),
220-
(fun matrix -> Matrix.CSR matrix.ToCSR)
220+
(fun matrix -> Primitives.CSR matrix.ToCSR)
221221
)
222222

223223
static member InputMatricesProvider =
@@ -226,10 +226,10 @@ module WithoutTransfer =
226226
type Float32() =
227227

228228
inherit Benchmark<ClMatrix.CSR<float32>,float32>(
229-
(Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
229+
(Primitives.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
230230
float32,
231231
(fun _ -> Utils.nextSingle (System.Random())),
232-
(fun matrix -> Matrix.CSR matrix.ToCSR)
232+
(fun matrix -> Primitives.CSR matrix.ToCSR)
233233
)
234234

235235
static member InputMatricesProvider =
@@ -273,10 +273,10 @@ module WithTransfer =
273273
type Float32() =
274274

275275
inherit Benchmark<ClMatrix.COO<float32>,float32>(
276-
(Matrix.map2 ArithmeticOperations.float32SumOption),
276+
(Primitives.map2 ArithmeticOperations.float32SumOption),
277277
float32,
278278
(fun _ -> Utils.nextSingle (System.Random())),
279-
Matrix.COO,
279+
Primitives.COO,
280280
(fun matrix -> matrix.ToHost)
281281
)
282282

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ module WithoutTransfer =
139139
type Float32() =
140140

141141
inherit Benchmark<float32>(
142-
Matrix.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
142+
Primitives.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
143143
float32,
144144
(fun _ -> Utils.nextSingle (System.Random())),
145145
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ type Masked<'elem when 'elem : struct>(
7777
member this.FunCSR2CSC =
7878
match funCSR2CSC with
7979
| None ->
80-
let x = Matrix.toCSCInPlace this.OclContext this.WorkGroupSize
80+
let x = Primitives.toCSCInPlace this.OclContext this.WorkGroupSize
8181
funCSR2CSC <- Some x
8282
x
8383
| Some x -> x
8484

8585
member this.FunCSC2CSR =
8686
match funCSC2CSR with
8787
| None ->
88-
let x = Matrix.toCSRInPlace this.OclContext this.WorkGroupSize
88+
let x = Primitives.toCSRInPlace this.OclContext this.WorkGroupSize
8989
funCSC2CSR <- Some x
9090
x
9191
| Some x -> x
@@ -110,7 +110,7 @@ type Masked<'elem when 'elem : struct>(
110110
this.ResultMatrix.Dispose this.Processor
111111

112112
member this.ReadMask(maskReader) =
113-
maskHost <- Matrix.COO <| this.ReadMatrix maskReader
113+
maskHost <- Primitives.COO <| this.ReadMatrix maskReader
114114

115115
member this.ReadMatrices() =
116116
let matrixReader, maskReader = this.InputMatrixReader
@@ -204,7 +204,7 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>(
204204
type Mxm4Float32MultiplicationOnlyBenchmark() =
205205

206206
inherit MxmBenchmarksMultiplicationOnly<float32>(
207-
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
207+
Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
208208
float32,
209209
(fun _ -> Utils.nextSingle (System.Random())),
210210
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -216,7 +216,7 @@ type Mxm4Float32MultiplicationOnlyBenchmark() =
216216
type Mxm4Float32WithTransposingBenchmark() =
217217

218218
inherit MxmBenchmarksWithTransposing<float32>(
219-
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
219+
Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
220220
float32,
221221
(fun _ -> Utils.nextSingle (System.Random())),
222222
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -228,7 +228,7 @@ type Mxm4Float32WithTransposingBenchmark() =
228228
type Mxm4BoolMultiplicationOnlyBenchmark() =
229229

230230
inherit MxmBenchmarksMultiplicationOnly<bool>(
231-
(Matrix.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
231+
(Primitives.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
232232
(fun _ -> true),
233233
(fun _ -> true),
234234
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -240,7 +240,7 @@ type Mxm4BoolMultiplicationOnlyBenchmark() =
240240
type Mxm4BoolWithTransposingBenchmark() =
241241

242242
inherit MxmBenchmarksWithTransposing<bool>(
243-
(Matrix.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
243+
(Primitives.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
244244
(fun _ -> true),
245245
(fun _ -> true),
246246
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -252,7 +252,7 @@ type Mxm4BoolWithTransposingBenchmark() =
252252
type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() =
253253

254254
inherit MxmBenchmarksMultiplicationOnly<float32>(
255-
(Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)),
255+
(Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)),
256256
float32,
257257
(fun _ -> Utils.nextSingle (System.Random())),
258258
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
@@ -264,7 +264,7 @@ type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() =
264264
type Mxm4Float32WithTransposingWithZerosFilterBenchmark() =
265265

266266
inherit MxmBenchmarksWithTransposing<float32>(
267-
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
267+
Primitives.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
268268
float32,
269269
(fun _ -> Utils.nextSingle (System.Random())),
270270
(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-
(Vector.map2 ArithmeticOperations.floatSumOption),
125+
(Primitives.map2 ArithmeticOperations.floatSumOption),
126126
VectorGenerator.floatPair Sparse)
127127

128128
type Int32() =
129129

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

134134
module AtLeastOne =
135135
type Float() =
136136

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

141141
type Int32() =
142142

143143
inherit Benchmark<int32>(
144-
(Vector.map2AtLeastOne ArithmeticOperations.intSumAtLeastOne),
144+
(Primitives.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-
(Vector.map2 ArithmeticOperations.floatSumOption),
181+
(Primitives.map2 ArithmeticOperations.floatSumOption),
182182
VectorGenerator.floatPair Sparse)
183183

184184
type Int32() =
185185

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

190190
module AtLeastOne =
191191
type Float() =
192192

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

197197
type Int32() =
198198

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ module BFS =
2626
let zeroCreate =
2727
ClArray.zeroCreate clContext workGroupSize
2828

29-
let ofList = Vector.ofList clContext workGroupSize
29+
let ofList = Primitives.ofList clContext workGroupSize
3030

3131
let maskComplementedTo =
3232
Vector.map2InPlace Mask.complementedOp clContext workGroupSize

src/GraphBLAS-sharp.Backend/GraphBLAS-sharp.Backend.fsproj

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@
4646
<Compile Include="Vector/Sparse/Map2.fs" />
4747
<Compile Include="Vector/Sparse/Map.fs" />
4848
<Compile Include="Vector/Sparse/Vector.fs" />
49-
<Compile Include="Vector/SpMV.fs" />
50-
<Compile Include="Vector/Vector.fs" />
49+
<Compile Include="Vector\Primitives.fs" />
5150
<Compile Include="Matrix/Common.fs" />
5251
<Compile Include="Matrix/COO/Map.fs" />
5352
<Compile Include="Matrix/COO/Merge.fs" />
@@ -61,10 +60,20 @@
6160
<Compile Include="Matrix/LIL/Matrix.fs" />
6261
<Compile Include="Matrix/SpGeMM/Expand.fs" />
6362
<Compile Include="Matrix/SpGeMM/Masked.fs" />
64-
<Compile Include="Matrix/Matrix.fs" />
63+
<Compile Include="Matrix\Primitives.fs" />
6564

6665
<Compile Include="Algorithms/BFS.fs" />
6766

67+
<Compile Include="Operations\SpGeMM\Expand.fs" />
68+
69+
<Compile Include="Operations\SpGeMM\Masked.fs" />
70+
71+
<Compile Include="Operations\SpMV.fs" />
72+
73+
<Compile Include="Operations\Kronecker.fs" />
74+
75+
<Compile Include="Operations\Operations.fs" />
76+
6877
</ItemGroup>
6978
<Import Project="..\..\.paket\Paket.Restore.targets" />
7079
</Project>

0 commit comments

Comments
 (0)