Skip to content

Commit

Permalink
Merge pull request #84 from artemiipatov/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
gsvgit authored Oct 2, 2023
2 parents f02ef72 + 441a2f9 commit 8a79b41
Show file tree
Hide file tree
Showing 111 changed files with 2,228 additions and 1,137 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ GraphBLAS# is a GPGPU-based [GraphBLAS](https://graphblas.org/)-like API impleme
- [x] COO-COO `map2`
- [x] COO-COO `map2AtLeastOne`
- [x] CSR-CSR multiplication
- [x] CSR-CSR Kronecker product
- **Vector-Matrix**
- [x] Dense-CSR multiplication
- [ ] Sparse-CSR multiplication
Expand Down
42 changes: 24 additions & 18 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

open System.IO
open BenchmarkDotNet.Attributes
open Microsoft.FSharp.Core
open Brahma.FSharp
open GraphBLAS.FSharp
open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.IO
open Brahma.FSharp
open Backend.Algorithms.BFS
open Microsoft.FSharp.Core
open GraphBLAS.FSharp.Backend.Objects.ArraysExtensions
open GraphBLAS.FSharp.Benchmarks
open GraphBLAS.FSharp.Backend.Objects
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Objects.ArraysExtensions
open GraphBLAS.FSharp.Backend.Quotes

[<AbstractClass>]
[<IterationCount(100)>]
Expand All @@ -20,11 +19,12 @@ type Benchmarks<'elem when 'elem : struct>(
buildFunToBenchmark,
converter: string -> 'elem,
binaryConverter,
vertex: int)
vertex: int,
buildMatrix)
=

let mutable funToBenchmark = None
let mutable matrix = Unchecked.defaultof<ClMatrix.CSR<'elem>>
let mutable matrix = Unchecked.defaultof<ClMatrix<'elem>>
let mutable matrixHost = Unchecked.defaultof<_>

member val ResultLevels = Unchecked.defaultof<ClArray<'elem option>> with get,set
Expand Down Expand Up @@ -69,7 +69,7 @@ type Benchmarks<'elem when 'elem : struct>(
this.ResultLevels <- this.FunToBenchmark this.Processor matrix vertex

member this.ClearInputMatrix() =
(matrix :> IDeviceMemObject).Dispose this.Processor
matrix.Dispose this.Processor

member this.ClearResult() = this.ResultLevels.FreeAndWait this.Processor

Expand All @@ -82,7 +82,7 @@ type Benchmarks<'elem when 'elem : struct>(
matrixHost <- this.InputMatrixReader.ReadMatrix converter

member this.LoadMatrixToGPU() =
matrix <- matrixHost.ToCSR.ToDevice this.OclContext
matrix <- buildMatrix this.OclContext matrixHost

abstract member GlobalSetup : unit -> unit

Expand All @@ -96,13 +96,15 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
buildFunToBenchmark,
converter: string -> 'elem,
boolConverter,
vertex) =
vertex,
buildMatrix) =

inherit Benchmarks<'elem>(
buildFunToBenchmark,
converter,
boolConverter,
vertex)
vertex,
buildMatrix)

[<GlobalSetup>]
override this.GlobalSetup() =
Expand All @@ -125,10 +127,11 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
type BFSWithoutTransferBenchmarkInt32() =

inherit WithoutTransferBenchmark<int>(
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
(Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
int32,
(fun _ -> Utils.nextInt (System.Random())),
0)
0,
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))

static member InputMatrixProvider =
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
Expand All @@ -137,13 +140,15 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
buildFunToBenchmark,
converter: string -> 'elem,
boolConverter,
vertex) =
vertex,
buildMatrix) =

inherit Benchmarks<'elem>(
buildFunToBenchmark,
converter,
boolConverter,
vertex)
vertex,
buildMatrix)

[<GlobalSetup>]
override this.GlobalSetup() =
Expand All @@ -168,10 +173,11 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
type BFSWithTransferBenchmarkInt32() =

inherit WithTransferBenchmark<int>(
(singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
(Algorithms.BFS.singleSource ArithmeticOperations.intSumOption ArithmeticOperations.intMulOption),
int32,
(fun _ -> Utils.nextInt (System.Random())),
0)
0,
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context))

static member InputMatrixProvider =
Benchmarks<_>.InputMatrixProviderBuilder "BFSBenchmarks.txt"
Expand Down
2 changes: 0 additions & 2 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ namespace GraphBLAS.FSharp.Benchmarks
open Brahma.FSharp
open Brahma.FSharp.OpenCL.Translator
open Brahma.FSharp.OpenCL.Translator.QuotationTransformers
open GraphBLAS.FSharp.Backend.Objects
open OpenCL.Net
open System.IO
open System.Text.RegularExpressions
open GraphBLAS.FSharp.Tests
open FsCheck
open Expecto
open GraphBLAS.FSharp.Test

module Utils =
type BenchmarkContext =
Expand Down
27 changes: 13 additions & 14 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
namespace GraphBLAS.FSharp.Benchmarks.Matrix.Map2

open System.IO
open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.IO
open BenchmarkDotNet.Attributes
open Brahma.FSharp
open GraphBLAS.FSharp
open GraphBLAS.FSharp.IO
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Backend.Objects
open GraphBLAS.FSharp.Objects.MatrixExtensions
open GraphBLAS.FSharp.Backend.Objects.ClContext
open GraphBLAS.FSharp.Backend.Matrix
open GraphBLAS.FSharp.Objects.ClContextExtensions
open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.Benchmarks

[<AbstractClass>]
Expand Down Expand Up @@ -138,7 +137,7 @@ module WithoutTransfer =
type Float32() =

inherit Benchmark<ClMatrix.COO<float32>,float32>(
(Matrix.map2 ArithmeticOperations.float32SumOption),
(Operations.Matrix.map2 ArithmeticOperations.float32SumOption),
float32,
(fun _ -> Utils.nextSingle (System.Random())),
Matrix.COO
Expand All @@ -150,7 +149,7 @@ module WithoutTransfer =
type Bool() =

inherit Benchmark<ClMatrix.COO<bool>,bool>(
(Matrix.map2 ArithmeticOperations.boolSumOption),
(Operations.Matrix.map2 ArithmeticOperations.boolSumOption),
(fun _ -> true),
(fun _ -> true),
Matrix.COO
Expand All @@ -163,7 +162,7 @@ module WithoutTransfer =
type Float32() =

inherit Benchmark<ClMatrix.CSR<float32>,float32>(
(Matrix.map2 ArithmeticOperations.float32SumOption),
(Operations.Matrix.map2 ArithmeticOperations.float32SumOption),
float32,
(fun _ -> Utils.nextSingle (System.Random())),
(fun matrix -> Matrix.CSR matrix.ToCSR)
Expand All @@ -175,7 +174,7 @@ module WithoutTransfer =
type Bool() =

inherit Benchmark<ClMatrix.CSR<bool>,bool>(
(Matrix.map2 ArithmeticOperations.boolSumOption),
(Operations.Matrix.map2 ArithmeticOperations.boolSumOption),
(fun _ -> true),
(fun _ -> true),
(fun matrix -> Matrix.CSR matrix.ToCSR)
Expand All @@ -189,7 +188,7 @@ module WithoutTransfer =
type Bool() =

inherit Benchmark<ClMatrix.COO<bool>,bool>(
(Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
(Operations.Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
(fun _ -> true),
(fun _ -> true),
Matrix.COO
Expand All @@ -201,7 +200,7 @@ module WithoutTransfer =
type Float32() =

inherit Benchmark<ClMatrix.COO<float32>,float32>(
(Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
(Operations.Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
float32,
(fun _ -> Utils.nextSingle (System.Random())),
Matrix.COO
Expand All @@ -214,7 +213,7 @@ module WithoutTransfer =
type Bool() =

inherit Benchmark<ClMatrix.CSR<bool>,bool>(
(Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
(Operations.Matrix.map2AtLeastOne ArithmeticOperations.boolSumAtLeastOne),
(fun _ -> true),
(fun _ -> true),
(fun matrix -> Matrix.CSR matrix.ToCSR)
Expand All @@ -226,7 +225,7 @@ module WithoutTransfer =
type Float32() =

inherit Benchmark<ClMatrix.CSR<float32>,float32>(
(Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
(Operations.Matrix.map2AtLeastOne ArithmeticOperations.float32SumAtLeastOne),
float32,
(fun _ -> Utils.nextSingle (System.Random())),
(fun matrix -> Matrix.CSR matrix.ToCSR)
Expand Down Expand Up @@ -273,7 +272,7 @@ module WithTransfer =
type Float32() =

inherit Benchmark<ClMatrix.COO<float32>,float32>(
(Matrix.map2 ArithmeticOperations.float32SumOption),
(Operations.Matrix.map2 ArithmeticOperations.float32SumOption),
float32,
(fun _ -> Utils.nextSingle (System.Random())),
Matrix.COO,
Expand Down
12 changes: 5 additions & 7 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
module GraphBLAS.FSharp.Benchmarks.Matrix.SpGeMM.Expand

open System.IO
open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.IO
open BenchmarkDotNet.Attributes
open Brahma.FSharp
open GraphBLAS.FSharp
open GraphBLAS.FSharp.IO
open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Backend.Objects
open GraphBLAS.FSharp.Backend.Matrix
open GraphBLAS.FSharp.Backend.Objects.ClContext
open GraphBLAS.FSharp.Objects.ClContextExtensions
open GraphBLAS.FSharp.Benchmarks
open GraphBLAS.FSharp.Backend

[<AbstractClass>]
[<IterationCount(100)>]
Expand Down Expand Up @@ -139,7 +137,7 @@ module WithoutTransfer =
type Float32() =

inherit Benchmark<float32>(
Matrix.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
Operations.SpGeMM.expand (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
float32,
(fun _ -> Utils.nextSingle (System.Random())),
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
Expand Down
18 changes: 8 additions & 10 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Masked.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.IO
open BenchmarkDotNet.Attributes
open Brahma.FSharp
open GraphBLAS.FSharp
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Backend.Objects
open GraphBLAS.FSharp.Backend.Matrix
open GraphBLAS.FSharp.Backend.Objects.ClContext
open GraphBLAS.FSharp.Objects.ClContextExtensions
open GraphBLAS.FSharp.Benchmarks
open GraphBLAS.FSharp.Backend

[<AbstractClass>]
[<IterationCount(100)>]
Expand Down Expand Up @@ -204,7 +202,7 @@ type MxmBenchmarksWithTransposing<'elem when 'elem : struct>(
type Mxm4Float32MultiplicationOnlyBenchmark() =

inherit MxmBenchmarksMultiplicationOnly<float32>(
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
float32,
(fun _ -> Utils.nextSingle (System.Random())),
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
Expand All @@ -216,7 +214,7 @@ type Mxm4Float32MultiplicationOnlyBenchmark() =
type Mxm4Float32WithTransposingBenchmark() =

inherit MxmBenchmarksWithTransposing<float32>(
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
float32,
(fun _ -> Utils.nextSingle (System.Random())),
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
Expand All @@ -228,7 +226,7 @@ type Mxm4Float32WithTransposingBenchmark() =
type Mxm4BoolMultiplicationOnlyBenchmark() =

inherit MxmBenchmarksMultiplicationOnly<bool>(
(Matrix.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
(Operations.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
(fun _ -> true),
(fun _ -> true),
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
Expand All @@ -240,7 +238,7 @@ type Mxm4BoolMultiplicationOnlyBenchmark() =
type Mxm4BoolWithTransposingBenchmark() =

inherit MxmBenchmarksWithTransposing<bool>(
(Matrix.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
(Operations.SpGeMM.masked (fst ArithmeticOperations.boolAdd) (fst ArithmeticOperations.boolMul)),
(fun _ -> true),
(fun _ -> true),
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
Expand All @@ -252,7 +250,7 @@ type Mxm4BoolWithTransposingBenchmark() =
type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() =

inherit MxmBenchmarksMultiplicationOnly<float32>(
(Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)),
(Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul)),
float32,
(fun _ -> Utils.nextSingle (System.Random())),
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
Expand All @@ -264,7 +262,7 @@ type Mxm4Float32MultiplicationOnlyWithZerosFilterBenchmark() =
type Mxm4Float32WithTransposingWithZerosFilterBenchmark() =

inherit MxmBenchmarksWithTransposing<float32>(
Matrix.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
Operations.SpGeMM.masked (fst ArithmeticOperations.float32Add) (fst ArithmeticOperations.float32Mul),
float32,
(fun _ -> Utils.nextSingle (System.Random())),
(fun context matrix -> ClMatrix.CSR <| matrix.ToCSR.ToDevice context)
Expand Down
Loading

0 comments on commit 8a79b41

Please sign in to comment.