Skip to content

Commit 999799c

Browse files
authored
Merge pull request #59 from IgorErin/ewisegen
Ewisegen
2 parents d14ef08 + 4e55216 commit 999799c

44 files changed

Lines changed: 1821 additions & 1443 deletions

Some content is hidden

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

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksEWiseAdd.fs

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,6 @@ open GraphBLAS.FSharp.Objects.Matrix
1515
open GraphBLAS.FSharp.Benchmarks.MatrixExtensions
1616
open GraphBLAS.FSharp.Backend.Objects.ClContext
1717

18-
type Config() =
19-
inherit ManualConfig()
20-
21-
do
22-
base.AddColumn(
23-
MatrixShapeColumn("RowCount", (fun (matrix,_) -> matrix.ReadMatrixShape().RowCount)) :> IColumn,
24-
MatrixShapeColumn("ColumnCount", (fun (matrix,_) -> matrix.ReadMatrixShape().ColumnCount)) :> IColumn,
25-
MatrixShapeColumn(
26-
"NNZ",
27-
fun (matrix,_) ->
28-
match matrix.Format with
29-
| Coordinate -> matrix.ReadMatrixShape().Nnz
30-
| Array -> 0
31-
)
32-
:> IColumn,
33-
MatrixShapeColumn(
34-
"SqrNNZ",
35-
fun (_,matrix) ->
36-
match matrix.Format with
37-
| Coordinate -> matrix.ReadMatrixShape().Nnz
38-
| Array -> 0
39-
)
40-
:> IColumn,
41-
TEPSColumn() :> IColumn,
42-
StatisticColumn.Min,
43-
StatisticColumn.Max
44-
)
45-
|> ignore
46-
4718
[<AbstractClass>]
4819
[<IterationCount(100)>]
4920
[<WarmupCount(10)>]
@@ -109,7 +80,7 @@ type EWiseAddBenchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'e
10980
reader.ReadMatrix converter
11081

11182
member this.EWiseAddition() =
112-
this.ResultMatrix <- this.FunToBenchmark this.Processor firstMatrix secondMatrix
83+
this.ResultMatrix <- this.FunToBenchmark this.Processor HostInterop firstMatrix secondMatrix
11384

11485
member this.ClearInputMatrices() =
11586
(firstMatrix :> IDeviceMemObject).Dispose this.Processor
@@ -225,7 +196,7 @@ module M =
225196
type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
226197

227198
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<float32>,float32>(
228-
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.float32Sum wgSize HostInterop),
199+
(fun context wgSize -> COOMatrix.map2 context ArithmeticOperations.float32Sum wgSize),
229200
float32,
230201
(fun _ -> Utils.nextSingle (System.Random())),
231202
Matrix.ToBackendCOO
@@ -237,7 +208,7 @@ type EWiseAddBenchmarks4Float32COOWithoutDataTransfer() =
237208
type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
238209

239210
inherit EWiseAddBenchmarksWithDataTransfer<ClMatrix.COO<float32>,float32>(
240-
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.float32Sum wgSize HostInterop),
211+
(fun context wgSize -> COOMatrix.map2 context ArithmeticOperations.float32Sum wgSize),
241212
float32,
242213
(fun _ -> Utils.nextSingle (System.Random())),
243214
Matrix.ToBackendCOO<float32>,
@@ -251,7 +222,7 @@ type EWiseAddBenchmarks4Float32COOWithDataTransfer() =
251222
type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
252223

253224
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<bool>,bool>(
254-
(fun context wgSize -> COOMatrix.elementwise context ArithmeticOperations.boolSum wgSize HostInterop),
225+
(fun context wgSize -> COOMatrix.map2 context ArithmeticOperations.boolSum wgSize),
255226
(fun _ -> true),
256227
(fun _ -> true),
257228
Matrix.ToBackendCOO<bool>
@@ -264,7 +235,7 @@ type EWiseAddBenchmarks4BoolCOOWithoutDataTransfer() =
264235
type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
265236

266237
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<float32>,float32>(
267-
(fun context wgSize -> CSRMatrix.elementwise context ArithmeticOperations.float32Sum wgSize HostInterop),
238+
(fun context wgSize -> CSRMatrix.map2 context ArithmeticOperations.float32Sum wgSize),
268239
float32,
269240
(fun _ -> Utils.nextSingle (System.Random())),
270241
Matrix.ToBackendCSR
@@ -277,7 +248,7 @@ type EWiseAddBenchmarks4Float32CSRWithoutDataTransfer() =
277248
type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
278249

279250
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<bool>,bool>(
280-
(fun context wgSize -> CSRMatrix.elementwise context ArithmeticOperations.boolSum wgSize HostInterop),
251+
(fun context wgSize -> CSRMatrix.map2 context ArithmeticOperations.boolSum wgSize),
281252
(fun _ -> true),
282253
(fun _ -> true),
283254
Matrix.ToBackendCSR
@@ -291,7 +262,7 @@ type EWiseAddBenchmarks4BoolCSRWithoutDataTransfer() =
291262
type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
292263

293264
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<bool>,bool>(
294-
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize HostInterop),
265+
(fun context wgSize -> COOMatrix.map2AtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
295266
(fun _ -> true),
296267
(fun _ -> true),
297268
Matrix.ToBackendCOO<bool>
@@ -303,7 +274,7 @@ type EWiseAddAtLeastOneBenchmarks4BoolCOOWithoutDataTransfer() =
303274
type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
304275

305276
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<bool>,bool>(
306-
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize HostInterop),
277+
(fun context wgSize -> CSRMatrix.map2AtLeastOne context ArithmeticOperations.boolSumAtLeastOne wgSize),
307278
(fun _ -> true),
308279
(fun _ -> true),
309280
Matrix.ToBackendCSR
@@ -315,7 +286,7 @@ type EWiseAddAtLeastOneBenchmarks4BoolCSRWithoutDataTransfer() =
315286
type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
316287

317288
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.COO<float32>,float32>(
318-
(fun context wgSize -> COOMatrix.elementwiseAtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize HostInterop),
289+
(fun context wgSize -> COOMatrix.map2AtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
319290
float32,
320291
(fun _ -> Utils.nextSingle (System.Random())),
321292
Matrix.ToBackendCOO<float32>
@@ -327,7 +298,7 @@ type EWiseAddAtLeastOneBenchmarks4Float32COOWithoutDataTransfer() =
327298
type EWiseAddAtLeastOneBenchmarks4Float32CSRWithoutDataTransfer() =
328299

329300
inherit EWiseAddBenchmarksWithoutDataTransfer<ClMatrix.CSR<float32>,float32>(
330-
(fun context wgSize -> CSRMatrix.elementwiseAtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize HostInterop),
301+
(fun context wgSize -> CSRMatrix.map2AtLeastOne context ArithmeticOperations.float32SumAtLeastOne wgSize),
331302
float32,
332303
(fun _ -> Utils.nextSingle (System.Random())),
333304
Matrix.ToBackendCSR<float32>

benchmarks/GraphBLAS-sharp.Benchmarks/BenchmarksMxm.fs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ type MxmBenchmarks<'elem when 'elem : struct>(
7575
member this.FunCSR2CSC =
7676
match funCSR2CSC with
7777
| None ->
78-
let x = Matrix.toCSCInplace this.OclContext this.WorkGroupSize HostInterop
78+
let x = Matrix.toCSCInplace this.OclContext this.WorkGroupSize
7979
funCSR2CSC <- Some x
8080
x
8181
| Some x -> x
8282

8383
member this.FunCSC2CSR =
8484
match funCSC2CSR with
8585
| None ->
86-
let x = Matrix.toCSRInplace this.OclContext this.WorkGroupSize HostInterop
86+
let x = Matrix.toCSRInplace this.OclContext this.WorkGroupSize
8787
funCSC2CSR <- Some x
8888
x
8989
| Some x -> x
@@ -130,10 +130,10 @@ type MxmBenchmarks<'elem when 'elem : struct>(
130130
mask <- maskHost.ToBackend(this.OclContext)
131131

132132
member this.ConvertSecondMatrixToCSC() =
133-
secondMatrix <- this.FunCSR2CSC this.Processor secondMatrix
133+
secondMatrix <- this.FunCSR2CSC this.Processor HostInterop secondMatrix
134134

135135
member this.ConvertSecondMatrixToCSR() =
136-
secondMatrix <- this.FunCSC2CSR this.Processor secondMatrix
136+
secondMatrix <- this.FunCSC2CSR this.Processor HostInterop secondMatrix
137137

138138
abstract member GlobalSetup : unit -> unit
139139

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<ProjectReference Include="..\..\src\GraphBLAS-sharp\GraphBLAS-sharp.fsproj">
1313
<Name>GraphBLAS-sharp.fsproj</Name>
1414
</ProjectReference>
15+
<ProjectReference Include="..\..\tests\GraphBLAS-sharp.Tests\GraphBLAS-sharp.Tests.fsproj" />
1516
</ItemGroup>
1617
<ItemGroup>
1718
<Compile Include="AssemblyInfo.fs" />
@@ -23,6 +24,7 @@
2324
<Compile Include="BenchmarksMxm.fs" />
2425
<!--Compile Include="BenchmarksTranspose.fs" /-->
2526
<Compile Include="BenchmarksMathNET.fs" />
27+
<Compile Include="VectorEWiseAddGen.fs" />
2628
<Compile Include="Program.fs" />
2729
</ItemGroup>
2830
<Import Project="..\..\.paket\Paket.Restore.targets" />

benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs

Lines changed: 85 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ open BenchmarkDotNet.Reports
55
open BenchmarkDotNet.Running
66
open Brahma.FSharp
77
open Brahma.FSharp.OpenCL.Translator
8-
open GraphBLAS.FSharp.Backend.Objects
98
open OpenCL.Net
109
open GraphBLAS.FSharp.IO
1110
open System.IO
1211
open System.Text.RegularExpressions
1312
open BenchmarkDotNet.Configs
1413
open BenchmarkDotNet.Jobs
15-
open GraphBLAS.FSharp.Objects
14+
open GraphBLAS.FSharp.Tests
15+
open FsCheck
16+
open Expecto
1617

1718
type CommonConfig() =
1819
inherit ManualConfig()
@@ -38,6 +39,35 @@ type CommonConfig() =
3839
)
3940
|> ignore
4041

42+
type Config() =
43+
inherit ManualConfig()
44+
45+
do
46+
base.AddColumn(
47+
MatrixShapeColumn("RowCount", (fun (matrix,_) -> matrix.ReadMatrixShape().RowCount)) :> IColumn,
48+
MatrixShapeColumn("ColumnCount", (fun (matrix,_) -> matrix.ReadMatrixShape().ColumnCount)) :> IColumn,
49+
MatrixShapeColumn(
50+
"NNZ",
51+
fun (matrix,_) ->
52+
match matrix.Format with
53+
| Coordinate -> matrix.ReadMatrixShape().Nnz
54+
| Array -> 0
55+
)
56+
:> IColumn,
57+
MatrixShapeColumn(
58+
"SqrNNZ",
59+
fun (_,matrix) ->
60+
match matrix.Format with
61+
| Coordinate -> matrix.ReadMatrixShape().Nnz
62+
| Array -> 0
63+
)
64+
:> IColumn,
65+
TEPSColumn() :> IColumn,
66+
StatisticColumn.Min,
67+
StatisticColumn.Max
68+
)
69+
|> ignore
70+
4171
type MatrixShapeColumn(columnName: string, getShape: (MtxReader * MtxReader) -> int) =
4272
interface IColumn with
4373
member this.AlwaysShow: bool = true
@@ -225,3 +255,56 @@ module Utils =
225255
random.NextBytes buffer
226256
System.BitConverter.ToSingle(buffer, 0)
227257

258+
module VectorGenerator =
259+
let private pairOfVectorsOfEqualSize (valuesGenerator: Gen<'a>) createVector =
260+
gen {
261+
let! length = Gen.sized <| fun size -> Gen.constant size
262+
263+
let! leftArray = Gen.arrayOfLength length valuesGenerator
264+
265+
let! rightArray = Gen.arrayOfLength length valuesGenerator
266+
267+
return (createVector leftArray, createVector rightArray)
268+
}
269+
270+
let intPair format =
271+
fun array -> Utils.createVectorFromArray format array ((=) 0)
272+
|> pairOfVectorsOfEqualSize Arb.generate<int32>
273+
274+
let floatPair format =
275+
let normalFloatGenerator =
276+
(Arb.Default.NormalFloat()
277+
|> Arb.toGen
278+
|> Gen.map float)
279+
280+
let fIsEqual x y = abs (x - y) < Accuracy.medium.absolute || x = y
281+
282+
let createVector array = Utils.createVectorFromArray format array (fIsEqual 0.0)
283+
284+
pairOfVectorsOfEqualSize normalFloatGenerator createVector
285+
286+
module MatrixGenerator =
287+
let private pairOfMatricesOfEqualSizeGenerator (valuesGenerator: Gen<'a>) createMatrix =
288+
gen {
289+
let! nrows, ncols = Generators.dimension2DGenerator
290+
let! matrixA = valuesGenerator |> Gen.array2DOfDim (nrows, ncols)
291+
let! matrixB = valuesGenerator |> Gen.array2DOfDim (nrows, ncols)
292+
return (createMatrix matrixA, createMatrix matrixB)
293+
}
294+
295+
let intPairOfEqualSizes format =
296+
fun array -> Utils.createMatrixFromArray2D format array ((=) 0)
297+
|> pairOfMatricesOfEqualSizeGenerator Arb.generate<int32>
298+
299+
let floatPairOfEqualSizes format =
300+
let normalFloatGenerator =
301+
(Arb.Default.NormalFloat()
302+
|> Arb.toGen
303+
|> Gen.map float)
304+
305+
let fIsEqual x y = abs (x - y) < Accuracy.medium.absolute || x = y
306+
307+
fun array -> Utils.createMatrixFromArray2D format array (fIsEqual 0.0)
308+
|> pairOfMatricesOfEqualSizeGenerator normalFloatGenerator
309+
310+

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ let main argv =
1313
typeof<MxmBenchmarks4Float32WithTransposing>
1414
typeof<MxmBenchmarks4BoolMultiplicationOnly>
1515
typeof<MxmBenchmarks4BoolWithTransposing>
16+
typeof<VectorEWiseBenchmarks4Int32SparseWithoutDataTransfer>
17+
typeof<VectorEWiseGeneralBenchmarks4Int32SparseWithoutDataTransfer>
18+
typeof<VectorEWiseBenchmarks4FloatSparseWithoutDataTransfer>
19+
typeof<VectorEWiseGeneralBenchmarks4FloatSparseWithoutDataTransfer>
1620
//typeof<BFSBenchmarks>
1721
//typeof<MxvBenchmarks>
1822
//typeof<TransposeBenchmarks>

0 commit comments

Comments
 (0)