Skip to content

Commit 78c338c

Browse files
committed
refactor: Matrix.elementwise* -> .map2*
1 parent 0c9739b commit 78c338c

11 files changed

Lines changed: 66 additions & 71 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksEWiseAdd.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ module M =
196196
type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
197197

198198
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<float32>,float32>(
199-
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
199+
(fun context wgSize -> COOMatrix.map2 context ArithmeticOperations.float32Sum wgSize),
200200
float32,
201201
(fun _ -> Utils.nextSingle (System.Random())),
202202
Matrix.ToBackendCOO
@@ -208,7 +208,7 @@ type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
208208
type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
209209

210210
inherit EWiseAddBenchmarksWithDataTransfer<ClMatrix.COO<float32>,float32>(
211-
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
211+
(fun context wgSize -> COOMatrix.map2 context ArithmeticOperations.float32Sum wgSize),
212212
float32,
213213
(fun _ -> Utils.nextSingle (System.Random())),
214214
Matrix.ToBackendCOO<float32>,
@@ -222,7 +222,7 @@ type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
222222
type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
223223

224224
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<bool>,bool>(
225-
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.boolSum wgSize),
225+
(fun context wgSize -> COOMatrix.map2 context ArithmeticOperations.boolSum wgSize),
226226
(fun _ -> true),
227227
(fun _ -> true),
228228
Matrix.ToBackendCOO<bool>
@@ -235,7 +235,7 @@ type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
235235
type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
236236

237237
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<float32>,float32>(
238-
(fun context wgSize -> CSRMatrix.elementwise context ArithmeticOperations.float32Sum wgSize),
238+
(fun context wgSize -> CSRMatrix.map2 context ArithmeticOperations.float32Sum wgSize),
239239
float32,
240240
(fun _ -> Utils.nextSingle (System.Random())),
241241
Matrix.ToBackendCSR
@@ -248,7 +248,7 @@ type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
248248
type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
249249

250250
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<bool>,bool>(
251-
(fun context wgSize -> CSRMatrix.elementwise context ArithmeticOperations.boolSum wgSize),
251+
(fun context wgSize -> CSRMatrix.map2 context ArithmeticOperations.boolSum wgSize),
252252
(fun _ -> true),
253253
(fun _ -> true),
254254
Matrix.ToBackendCSR
@@ -262,7 +262,7 @@ type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
262262
type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
263263

264264
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<bool>,bool>(
265-
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
265+
(fun context wgSize -> COOMatrix.map2AtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
266266
(fun _ -> true),
267267
(fun _ -> true),
268268
Matrix.ToBackendCOO<bool>
@@ -274,7 +274,7 @@ type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
274274
type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
275275

276276
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<bool>,bool>(
277-
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
277+
(fun context wgSize -> CSRMatrix.map2AtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
278278
(fun _ -> true),
279279
(fun _ -> true),
280280
Matrix.ToBackendCSR
@@ -286,7 +286,7 @@ type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
286286
type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
287287

288288
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<float32>,float32>(
289-
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
289+
(fun context wgSize -> COOMatrix.map2AtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
290290
float32,
291291
(fun _ -> Utils.nextSingle (System.Random())),
292292
Matrix.ToBackendCOO<float32>
@@ -298,7 +298,7 @@ type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
298298
type EWiseAddAtLeastOneBenchmarks4Float32CSRWithoutDataTransfer() =
299299

300300
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<float32>,float32>(
301-
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
301+
(fun context wgSize -> CSRMatrix.map2AtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
302302
float32,
303303
(fun _ -> Utils.nextSingle (System.Random())),
304304
Matrix.ToBackendCSR<float32>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
<!--Compile Include="Matrices.fs" /-->
3636
<Compile Include="Matrix/Common.fs" />
3737
<Compile Include="Matrix/COOMatrix/COOMatrix.fs" />
38-
<Compile Include="Matrix/CSRMatrix/Elementwise.fs" />
38+
<Compile Include="Matrix\CSRMatrix\Map2.fs" />
3939
<Compile Include="Matrix/CSRMatrix/SpGEMM.fs" />
4040
<Compile Include="Matrix/CSRMatrix/CSRMatrix.fs" />
4141
<Compile Include="Matrix/Matrix.fs" />
42-
<Compile Include="Vector/SparseVector/Elementwise.fs" />
42+
<Compile Include="Vector\SparseVector\Map2.fs" />
4343
<Compile Include="Vector/SparseVector/SparseVector.fs" />
4444
<Compile Include="Vector/DenseVector/DenseVector.fs" />
4545
<Compile Include="Vector/Vector.fs" />

src/GraphBLAS-sharp.Backend/Matrix/COOMatrix/COOMatrix.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ module COOMatrix =
262262
///<param name="clContext">.</param>
263263
///<param name="opAdd">.</param>
264264
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
265-
let elementwise<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
265+
let map2<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
266266
(clContext: ClContext)
267267
(opAdd: Expr<'a option -> 'b option -> 'c option>)
268268
workGroupSize
@@ -414,13 +414,13 @@ module COOMatrix =
414414
///<param name="clContext">.</param>
415415
///<param name="opAdd">.</param>
416416
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
417-
let elementwiseAtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
417+
let map2AtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
418418
(clContext: ClContext)
419419
(opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>)
420420
workGroupSize
421421
=
422422

423-
elementwise clContext (Convert.atLeastOneToOption opAdd) workGroupSize
423+
map2 clContext (Convert.atLeastOneToOption opAdd) workGroupSize
424424

425425
let transposeInplace (clContext: ClContext) workGroupSize =
426426

src/GraphBLAS-sharp.Backend/Matrix/CSRMatrix/CSRMatrix.fs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ namespace GraphBLAS.FSharp.Backend.Matrix.CSR
33
open Brahma.FSharp
44
open GraphBLAS.FSharp.Backend.Common
55
open GraphBLAS.FSharp.Backend
6-
open GraphBLAS.FSharp.Backend.Matrix.CSR.Elementwise
6+
open GraphBLAS.FSharp.Backend.Matrix.CSR.Map2
77
open GraphBLAS.FSharp.Backend.Quotes
88
open Microsoft.FSharp.Quotations
99
open GraphBLAS.FSharp.Backend.Matrix.COO
@@ -92,13 +92,13 @@ module CSRMatrix =
9292
Values = matrix.Values }
9393

9494
///<remarks>Old version</remarks>
95-
let elementwiseWithCOO (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize =
95+
let map2WithCOO (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize =
9696

9797
let prepareRows =
9898
expandRowPointers clContext workGroupSize
9999

100100
let eWiseCOO =
101-
COOMatrix.elementwise clContext opAdd workGroupSize
101+
COOMatrix.map2 clContext opAdd workGroupSize
102102

103103
let toCSRInplace =
104104
COOMatrix.toCSRInplace clContext workGroupSize
@@ -129,13 +129,9 @@ module CSRMatrix =
129129
toCSRInplace processor allocationMode m3COO
130130

131131
///<remarks>Old version</remarks>
132-
let elementwiseAtLeastOneWithCOO
133-
(clContext: ClContext)
134-
(opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>)
135-
workGroupSize
136-
=
132+
let map2AtLeastOneWithCOO (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
137133

138-
elementwiseWithCOO clContext (Convert.atLeastOneToOption opAdd) workGroupSize
134+
map2WithCOO clContext (Convert.atLeastOneToOption opAdd) workGroupSize
139135

140136
let transposeInplace (clContext: ClContext) workGroupSize =
141137

@@ -167,7 +163,7 @@ module CSRMatrix =
167163
|> transposeInplace queue
168164
|> toCSRInplace queue allocationMode
169165

170-
let elementwiseToCOO<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
166+
let map2ToCOO<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
171167
(clContext: ClContext)
172168
(opAdd: Expr<'a option -> 'b option -> 'c option>)
173169
workGroupSize
@@ -216,14 +212,13 @@ module CSRMatrix =
216212
Columns = resultColumns
217213
Values = resultValues }
218214

219-
let elementwise<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
215+
let map2<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
220216
(clContext: ClContext)
221217
(opAdd: Expr<'a option -> 'b option -> 'c option>)
222218
workGroupSize
223219
=
224220

225-
let elementwiseToCOO =
226-
elementwiseToCOO clContext opAdd workGroupSize
221+
let elementwiseToCOO = map2ToCOO clContext opAdd workGroupSize
227222

228223
let toCSRInplace =
229224
COOMatrix.toCSRInplace clContext workGroupSize
@@ -232,21 +227,21 @@ module CSRMatrix =
232227
elementwiseToCOO queue allocationMode matrixLeft matrixRight
233228
|> toCSRInplace queue allocationMode
234229

235-
let elementwiseAtLeastOneToCOO<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
230+
let map2AtLeastOneToCOO<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
236231
(clContext: ClContext)
237232
(opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>)
238233
workGroupSize
239234
=
240235

241-
elementwiseToCOO clContext (Convert.atLeastOneToOption opAdd) workGroupSize
236+
map2ToCOO clContext (Convert.atLeastOneToOption opAdd) workGroupSize
242237

243-
let elementwiseAtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
238+
let map2AtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
244239
(clContext: ClContext)
245240
(opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>)
246241
workGroupSize
247242
=
248243

249-
elementwise clContext (Convert.atLeastOneToOption opAdd) workGroupSize
244+
map2 clContext (Convert.atLeastOneToOption opAdd) workGroupSize
250245

251246
let spgemmCSC
252247
(clContext: ClContext)

src/GraphBLAS-sharp.Backend/Matrix/CSRMatrix/Elementwise.fs renamed to src/GraphBLAS-sharp.Backend/Matrix/CSRMatrix/Map2.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open GraphBLAS.FSharp.Backend.Quotes
66
open Microsoft.FSharp.Quotations
77
open GraphBLAS.FSharp.Backend.Objects.ClContext
88

9-
module internal Elementwise =
9+
module internal Map2 =
1010
let preparePositions<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
1111
(clContext: ClContext)
1212
(opAdd: Expr<'a option -> 'b option -> 'c option>)

src/GraphBLAS-sharp.Backend/Matrix/Matrix.fs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ module Matrix =
247247
Values = csrT.Values }
248248
|> ClMatrix.CSC
249249

250-
let elementwise (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize =
250+
let map2 (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize =
251251
let COOElementwise =
252-
COOMatrix.elementwise clContext opAdd workGroupSize
252+
COOMatrix.map2 clContext opAdd workGroupSize
253253

254254
let CSRElementwise =
255-
CSRMatrix.elementwise clContext opAdd workGroupSize
255+
CSRMatrix.map2 clContext opAdd workGroupSize
256256

257257
fun (processor: MailboxProcessor<_>) allocationMode matrix1 matrix2 ->
258258
match matrix1, matrix2 with
@@ -291,12 +291,12 @@ module Matrix =
291291
|> ClMatrix.CSC
292292
| _ -> failwith "Matrix formats are not matching"
293293

294-
let elementwiseToCOO (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize =
294+
let map2ToCOO (clContext: ClContext) (opAdd: Expr<'a option -> 'b option -> 'c option>) workGroupSize =
295295
let COOElementwise =
296-
COOMatrix.elementwise clContext opAdd workGroupSize
296+
COOMatrix.map2 clContext opAdd workGroupSize
297297

298298
let CSRElementwise =
299-
CSRMatrix.elementwiseToCOO clContext opAdd workGroupSize
299+
CSRMatrix.map2ToCOO clContext opAdd workGroupSize
300300

301301
let transposeCOOInplace =
302302
COOMatrix.transposeInplace clContext workGroupSize
@@ -331,12 +331,12 @@ module Matrix =
331331
|> ClMatrix.COO
332332
| _ -> failwith "Matrix formats are not matching"
333333

334-
let elementwiseAtLeastOne (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
334+
let map2AtLeastOne (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
335335
let COOElementwise =
336-
COOMatrix.elementwiseAtLeastOne clContext opAdd workGroupSize
336+
COOMatrix.map2AtLeastOne clContext opAdd workGroupSize
337337

338338
let CSRElementwise =
339-
CSRMatrix.elementwiseAtLeastOne clContext opAdd workGroupSize
339+
CSRMatrix.map2AtLeastOne clContext opAdd workGroupSize
340340

341341
fun (processor: MailboxProcessor<_>) allocationMode matrix1 matrix2 ->
342342
match matrix1, matrix2 with
@@ -375,12 +375,12 @@ module Matrix =
375375
|> ClMatrix.CSC
376376
| _ -> failwith "Matrix formats are not matching"
377377

378-
let elementwiseAtLeastOneToCOO (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
378+
let map2AtLeastOneToCOO (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
379379
let COOElementwise =
380-
COOMatrix.elementwiseAtLeastOne clContext opAdd workGroupSize
380+
COOMatrix.map2AtLeastOne clContext opAdd workGroupSize
381381

382382
let CSRElementwise =
383-
CSRMatrix.elementwiseAtLeastOneToCOO clContext opAdd workGroupSize
383+
CSRMatrix.map2AtLeastOneToCOO clContext opAdd workGroupSize
384384

385385
let transposeCOOInplace =
386386
COOMatrix.transposeInplace clContext workGroupSize

src/GraphBLAS-sharp.Backend/Vector/SparseVector/Elementwise.fs renamed to src/GraphBLAS-sharp.Backend/Vector/SparseVector/Map2.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open Brahma.FSharp
44
open GraphBLAS.FSharp.Backend.Quotes
55
open FSharp.Quotations
66

7-
module Elementwise =
7+
module Map2 =
88
let binSearch<'a> =
99
<@ fun lenght sourceIndex (indices: ClArray<int>) (values: ClArray<'a>) ->
1010

src/GraphBLAS-sharp.Backend/Vector/SparseVector/SparseVector.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module SparseVector =
5656

5757
let kernel =
5858
clContext.Compile
59-
<| Elementwise.preparePositionsGeneral opAdd
59+
<| Map2.preparePositionsGeneral opAdd
6060

6161
fun (processor: MailboxProcessor<_>) (vectorLenght: int) (leftValues: ClArray<'a>) (leftIndices: ClArray<int>) (rightValues: ClArray<'b>) (rightIndices: ClArray<int>) ->
6262

@@ -128,7 +128,7 @@ module SparseVector =
128128
let private merge<'a, 'b when 'a: struct and 'b: struct> (clContext: ClContext) workGroupSize =
129129

130130
let kernel =
131-
clContext.Compile(Elementwise.merge workGroupSize)
131+
clContext.Compile(Map2.merge workGroupSize)
132132

133133
fun (processor: MailboxProcessor<_>) (firstIndices: ClArray<int>) (firstValues: ClArray<'a>) (secondIndices: ClArray<int>) (secondValues: ClArray<'b>) ->
134134

@@ -185,7 +185,7 @@ module SparseVector =
185185
=
186186

187187
let kernel =
188-
clContext.Compile(Elementwise.preparePositions op)
188+
clContext.Compile(Map2.preparePositions op)
189189

190190
fun (processor: MailboxProcessor<_>) (allIndices: ClArray<int>) (leftValues: ClArray<'a>) (rightValues: ClArray<'b>) (isLeft: ClArray<int>) ->
191191

@@ -258,7 +258,7 @@ module SparseVector =
258258
=
259259

260260
let kernel =
261-
clContext.Compile(Elementwise.prepareFillVector op)
261+
clContext.Compile(Map2.prepareFillVector op)
262262

263263
fun (processor: MailboxProcessor<_>) (allIndices: ClArray<int>) (leftValues: ClArray<'a>) (rightValues: ClArray<'b>) (value: ClCell<'a>) (isLeft: ClArray<int>) ->
264264

tests/GraphBLAS-sharp.Tests/GraphBLAS-sharp.Tests.fsproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
<Compile Include="Vector/SpMV.fs" />
3939
<Compile Include="Algorithms/BFS.fs" />
4040
<Compile Include="Matrix/Convert.fs" />
41-
<Compile Include="Matrix/Elementwise.fs" />
41+
<Compile Include="Matrix\Map2.fs" />
4242
<Compile Include="Matrix/Mxm.fs" />
4343
<Compile Include="Matrix/Transpose.fs" />
4444
<Compile Include="Program.fs" />

0 commit comments

Comments
 (0)