Skip to content

Commit 11e7e32

Browse files
committed
Multiply operations
1 parent e773c79 commit 11e7e32

5 files changed

Lines changed: 34 additions & 14 deletions

File tree

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksEWiseAdd.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
364364
type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
365365

366366
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.COOMatrix<float32>,float32>(
367-
(fun context wgSize -> Backend.COOMatrix.eWiseAdd2 context Backend.Common.StandardOperations.float32Sum2 wgSize),
367+
(fun context wgSize -> Backend.COOMatrix.eWiseAddAtLeastOne context Backend.Common.StandardOperations.float32SumAtLeastOne wgSize),
368368
float32,
369369
(fun _ -> Utils.nextSingle (System.Random())),
370370
M.buildCooMatrix
@@ -376,7 +376,7 @@ type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
376376
type EWiseAddAtLeastOneBenchmarks4Float32CSRWithoutDataTransfer() =
377377

378378
inherit EWiseAddBenchmarksWithoutDataTransfer<Backend.CSRMatrix<float32>,float32>(
379-
(fun context wgSize -> Backend.CSRMatrix.eWiseAdd2 context Backend.Common.StandardOperations.float32Sum2 wgSize),
379+
(fun context wgSize -> Backend.CSRMatrix.eWiseAddAtLeastOne context Backend.Common.StandardOperations.float32SumAtLeastOne wgSize),
380380
float32,
381381
(fun _ -> Utils.nextSingle (System.Random())),
382382
M.buildCsrMatrix

src/GraphBLAS-sharp.Backend/Common/StandardOperations.fs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ module StandardOperations =
5959

6060
if res = 0f then None else (Some res) @>
6161

62-
let boolSum2 =
62+
let boolSumAtLeastOne =
6363
<@ fun (_: AtLeastOne<bool, bool>) -> Some true @>
6464

65-
let intSum2 =
65+
let intSumAtLeastOne =
6666
<@ fun (values: AtLeastOne<int, int>) ->
6767
let mutable res = 0
6868

@@ -73,7 +73,7 @@ module StandardOperations =
7373

7474
if res = 0 then None else (Some res) @>
7575

76-
let byteSum2 =
76+
let byteSumAtLeastOne =
7777
<@ fun (values: AtLeastOne<byte, byte>) ->
7878
let mutable res = 0uy
7979

@@ -84,7 +84,7 @@ module StandardOperations =
8484

8585
if res = 0uy then None else (Some res) @>
8686

87-
let floatSum2 =
87+
let floatSumAtLeastOne =
8888
<@ fun (values: AtLeastOne<float, float>) ->
8989
let mutable res = 0.0
9090

@@ -95,7 +95,7 @@ module StandardOperations =
9595

9696
if res = 0.0 then None else (Some res) @>
9797

98-
let float32Sum2 =
98+
let float32SumAtLeastOne =
9999
<@ fun (values: AtLeastOne<float32, float32>) ->
100100
let mutable res = 0f
101101

@@ -105,3 +105,23 @@ module StandardOperations =
105105
| Right s -> res <- s
106106

107107
if res = 0f then None else (Some res) @>
108+
109+
let float32Mul =
110+
<@ fun (values: AtLeastOne<float32, float32>) ->
111+
let mutable res = 0f
112+
113+
match values with
114+
| Both (f, s) -> res <- f * s
115+
| _ -> res <- 0f
116+
117+
if res = 0f then None else (Some res) @>
118+
119+
let boolMul =
120+
<@ fun (values: AtLeastOne<bool, bool>) ->
121+
let mutable res = false
122+
123+
match values with
124+
| Both _ -> res <- true
125+
| _ -> res <- false
126+
127+
if res then None else (Some true) @>

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ module COOMatrix =
662662
Columns = matrix.Columns
663663
Values = matrix.Values }
664664

665-
let private preparePositions2<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
665+
let private preparePositionsAtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
666666
(clContext: ClContext)
667667
(opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>)
668668
workGroupSize
@@ -747,7 +747,7 @@ module COOMatrix =
747747
///<param name="clContext">.</param>
748748
///<param name="opAdd">.</param>
749749
///<param name="workGroupSize">Should be a power of 2 and greater than 1.</param>
750-
let eWiseAdd2<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
750+
let eWiseAddAtLeastOne<'a, 'b, 'c when 'a: struct and 'b: struct and 'c: struct and 'c: equality>
751751
(clContext: ClContext)
752752
(opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>)
753753
workGroupSize
@@ -756,7 +756,7 @@ module COOMatrix =
756756
let merge = merge clContext workGroupSize
757757

758758
let preparePositions =
759-
preparePositions2 clContext opAdd workGroupSize
759+
preparePositionsAtLeastOne clContext opAdd workGroupSize
760760

761761
let setPositions = setPositions<'c> clContext workGroupSize
762762

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ module CSRMatrix =
119119

120120
m3
121121

122-
let eWiseAdd2 (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
122+
let eWiseAddAtLeastOne (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
123123

124124
let toCOOInplaceLeft = toCOOInplace clContext workGroupSize
125125
let toCOOInplaceRight = toCOOInplace clContext workGroupSize
126126

127127
let eWiseCOO =
128-
COOMatrix.eWiseAdd2 clContext opAdd workGroupSize
128+
COOMatrix.eWiseAddAtLeastOne clContext opAdd workGroupSize
129129

130130
let toCSRInplace =
131131
COOMatrix.toCSRInplace clContext workGroupSize

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ module Matrix =
6767
| MatrixCSR m1, MatrixCSR m2 -> CSReWiseAdd processor m1 m2 |> MatrixCSR
6868
| _ -> failwith "Matrix formats are not matching"
6969

70-
let eWiseAdd2 (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
70+
let eWiseAddAtLeastOne (clContext: ClContext) (opAdd: Expr<AtLeastOne<'a, 'b> -> 'c option>) workGroupSize =
7171
let COOeWiseAdd =
72-
COOMatrix.eWiseAdd2 clContext opAdd workGroupSize
72+
COOMatrix.eWiseAddAtLeastOne clContext opAdd workGroupSize
7373

7474
let CSReWiseAdd =
7575
CSRMatrix.eWiseAdd2 clContext opAdd workGroupSize

0 commit comments

Comments
 (0)