Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RawCommandQueue #95

Merged
merged 9 commits into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/BFS.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ open GraphBLAS.FSharp.IO
open GraphBLAS.FSharp.Benchmarks
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Objects.ArraysExtensions
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
open GraphBLAS.FSharp.Backend.Quotes

[<AbstractClass>]
Expand Down Expand Up @@ -41,7 +40,7 @@ type Benchmarks<'elem when 'elem : struct>(

member this.Processor =
let p = (fst this.OclContextInfo).Queue
p.Error.Add(fun e -> failwithf "%A" e)
//p.Error.Add(fun e -> failwithf "%A" e)
p

static member AvailableContexts = Utils.availableContexts
Expand Down Expand Up @@ -70,7 +69,7 @@ type Benchmarks<'elem when 'elem : struct>(
this.ResultLevels <- this.FunToBenchmark this.Processor matrix vertex

member this.ClearInputMatrix() =
matrix.Dispose this.Processor
matrix.Dispose()

member this.ClearResult() =
match this.ResultLevels with
Expand Down Expand Up @@ -114,12 +113,12 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
override this.GlobalSetup() =
this.ReadMatrix()
this.LoadMatrixToGPU()
finish this.Processor
this.Processor.Synchronize()

[<IterationCleanup>]
override this.IterationCleanup() =
this.ClearResult()
finish this.Processor
this.Processor.Synchronize()

[<GlobalCleanup>]
override this.GlobalCleanup() =
Expand All @@ -128,7 +127,7 @@ type WithoutTransferBenchmark<'elem when 'elem : struct>(
[<Benchmark>]
override this.Benchmark() =
this.BFS()
this.Processor.PostAndReply Msg.MsgNotifyMe
this.Processor.Synchronize()

type BFSWithoutTransferBenchmarkBool() =

Expand Down Expand Up @@ -183,7 +182,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
[<GlobalSetup>]
override this.GlobalSetup() =
this.ReadMatrix()
finish this.Processor
this.Processor.Synchronize()

[<GlobalCleanup>]
override this.GlobalCleanup() =
Expand All @@ -193,7 +192,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
override this.IterationCleanup() =
this.ClearInputMatrix()
this.ClearResult()
finish this.Processor
this.Processor.Synchronize()

[<Benchmark>]
override this.Benchmark() =
Expand All @@ -202,7 +201,7 @@ type WithTransferBenchmark<'elem when 'elem : struct>(
match this.ResultLevels with
| ClVector.Dense result ->
result.ToHost this.Processor |> ignore
this.Processor.PostAndReply Msg.MsgNotifyMe
this.Processor.Synchronize()
| _ -> failwith "Impossible"

type BFSWithTransferBenchmarkBool() =
Expand Down
17 changes: 8 additions & 9 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Algorithms/PageRank.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ open GraphBLAS.FSharp.IO
open Brahma.FSharp
open Microsoft.FSharp.Core
open GraphBLAS.FSharp.Objects.ArraysExtensions
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
open GraphBLAS.FSharp.Benchmarks
open GraphBLAS.FSharp.Objects

Expand Down Expand Up @@ -40,7 +39,7 @@ type Benchmarks(

member this.Processor =
let p = (fst this.OclContextInfo).Queue
p.Error.Add(fun e -> failwithf "%A" e)
//p.Error.Add(fun e -> failwithf "%A" e)
p

static member AvailableContexts = Utils.availableContexts
Expand Down Expand Up @@ -69,12 +68,12 @@ type Benchmarks(
this.Result <- this.FunToBenchmark this.Processor matrixPrepared Constants.PageRank.accuracy

member this.ClearInputMatrix() =
matrix.Dispose this.Processor
matrix.Dispose()

member this.ClearPreparedMatrix() =
matrixPrepared.Dispose this.Processor
matrixPrepared.Dispose()

member this.ClearResult() = this.Result.Dispose this.Processor
member this.ClearResult() = this.Result.Dispose()

member this.ReadMatrix() =
let converter =
Expand Down Expand Up @@ -113,15 +112,15 @@ type PageRankWithoutTransferBenchmarkFloat32() =
override this.GlobalSetup() =
this.ReadMatrix()
this.LoadMatrixToGPU()
finish this.Processor
this.Processor.Synchronize()
this.PrepareMatrix()
this.ClearInputMatrix()
finish this.Processor
this.Processor.Synchronize()

[<IterationCleanup>]
override this.IterationCleanup() =
this.ClearResult()
finish this.Processor
this.Processor.Synchronize()

[<GlobalCleanup>]
override this.GlobalCleanup() =
Expand All @@ -130,4 +129,4 @@ type PageRankWithoutTransferBenchmarkFloat32() =
[<Benchmark>]
override this.Benchmark() =
this.PageRank()
finish this.Processor
this.Processor.Synchronize()
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
wing.mtx
coAuthorsCiteseer.mtx
hollywood-2009.mtx
roadNet-CA.mtx
!hollywood-2009.mtx
roadNet-CA.mtx
belgium_osm.mtx
road_central.mtx
coPapersDBLP.mtx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
Expand All @@ -25,9 +25,9 @@
<Compile Include="Matrix/Map2/MathNET.fs" />
<Compile Include="Vector/Map2.fs" />
<Compile Include="Algorithms/BFS.fs" />
<Compile Include="Algorithms/PageRank.fs" />
<Compile Include="Algorithms/PageRank.fs" />
<Compile Include="Program.fs" />
<Folder Include="Datasets" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
</Project>
23 changes: 14 additions & 9 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Helpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ open Expecto
module Utils =
type BenchmarkContext =
{ ClContext: Brahma.FSharp.ClContext
Queue: MailboxProcessor<Msg> }
Queue: RawCommandQueue }

let getMatricesFilenames configFilename =
let getFullPathToConfig filename =
Expand Down Expand Up @@ -103,9 +103,11 @@ module Utils =
let context =
Brahma.FSharp.ClContext(device, translator)

let queue = context.QueueProvider.CreateQueue()
let queue =
RawCommandQueue(context.ClDevice.Device, context.Context, context.Translator)

{ ClContext = context; Queue = queue })

seq {
for wgSize in workGroupSizes do
for context in contexts do
Expand All @@ -119,13 +121,14 @@ module Utils =

let normalFloatGenerator =
(Arb.Default.NormalFloat()
|> Arb.toGen
|> Gen.map float)
|> Arb.toGen
|> Gen.map float)

let fIsEqual x y = abs (x - y) < Accuracy.medium.absolute || x.Equals y
let fIsEqual x y =
abs (x - y) < Accuracy.medium.absolute
|| x.Equals y

let nextInt (random: System.Random) =
random.Next()
let nextInt (random: System.Random) = random.Next()

module VectorGenerator =
let private pairOfVectorsOfEqualSize (valuesGenerator: Gen<'a>) createVector =
Expand All @@ -144,8 +147,10 @@ module VectorGenerator =
|> pairOfVectorsOfEqualSize Arb.generate<int32>

let floatPair format =
let fIsEqual x y = abs (x - y) < Accuracy.medium.absolute || x = y
let fIsEqual x y =
abs (x - y) < Accuracy.medium.absolute || x = y

let createVector array = Utils.createVectorFromArray format array (fIsEqual 0.0)
let createVector array =
Utils.createVectorFromArray format array (fIsEqual 0.0)

pairOfVectorsOfEqualSize Utils.normalFloatGenerator createVector
22 changes: 10 additions & 12 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/Map2/Map2.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ open GraphBLAS.FSharp.IO
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Objects.MatrixExtensions
open GraphBLAS.FSharp.Objects.ClContextExtensions
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.Benchmarks

Expand Down Expand Up @@ -41,7 +40,7 @@ type Benchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : st

member this.Processor =
let p = (fst this.OclContextInfo).Queue
p.Error.Add(fun e -> failwithf "%A" e)
//p.Error.Add(fun e -> failwithf "%A" e)
p

static member AvailableContexts = Utils.availableContexts
Expand Down Expand Up @@ -80,11 +79,11 @@ type Benchmarks<'matrixT, 'elem when 'matrixT :> IDeviceMemObject and 'elem : st
this.ResultMatrix <- this.FunToBenchmark this.Processor HostInterop firstMatrix secondMatrix

member this.ClearInputMatrices() =
firstMatrix.Dispose this.Processor
secondMatrix.Dispose this.Processor
firstMatrix.Dispose()
secondMatrix.Dispose()

member this.ClearResult() =
this.ResultMatrix.Dispose this.Processor
this.ResultMatrix.Dispose()

member this.ReadMatrices() =
firstMatrixHost <- this.ReadMatrix <| fst this.InputMatrixReader
Expand Down Expand Up @@ -119,12 +118,12 @@ module WithoutTransfer =
override this.GlobalSetup() =
this.ReadMatrices ()
this.LoadMatricesToGPU ()
finish this.Processor
this.Processor.Synchronize()

[<Benchmark>]
override this.Benchmark () =
this.EWiseAddition()
finish this.Processor
this.Processor.Synchronize()

[<IterationCleanup>]
override this.IterationCleanup () =
Expand Down Expand Up @@ -252,7 +251,7 @@ module WithTransfer =
[<GlobalSetup>]
override this.GlobalSetup() =
this.ReadMatrices()
finish this.Processor
this.Processor.Synchronize()

[<GlobalCleanup>]
override this.GlobalCleanup() = ()
Expand All @@ -261,16 +260,15 @@ module WithTransfer =
override this.IterationCleanup() =
this.ClearInputMatrices()
this.ClearResult()
finish this.Processor
this.Processor.Synchronize()

[<Benchmark>]
override this.Benchmark() =
this.LoadMatricesToGPU()
this.EWiseAddition()
this.Processor.PostAndReply Msg.MsgNotifyMe
this.Processor.Synchronize()
resultToHost this.ResultMatrix this.Processor |> ignore
this.Processor.PostAndReply Msg.MsgNotifyMe

this.Processor.Synchronize()
module COO =
type Float32() =

Expand Down
13 changes: 6 additions & 7 deletions benchmarks/GraphBLAS-sharp.Benchmarks/Matrix/SpGeMM/Expand.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ open GraphBLAS.FSharp.IO
open GraphBLAS.FSharp.Backend.Quotes
open GraphBLAS.FSharp.Objects
open GraphBLAS.FSharp.Objects.ClContextExtensions
open GraphBLAS.FSharp.Objects.MailboxProcessorExtensions
open GraphBLAS.FSharp.Benchmarks

[<AbstractClass>]
Expand Down Expand Up @@ -40,7 +39,7 @@ type Benchmarks<'elem when 'elem : struct>(

member this.Processor =
let p = (fst this.OclContextInfo).Queue
p.Error.Add(fun e -> failwithf "%A" e)
//p.Error.Add(fun e -> failwithf "%A" e)
p

static member AvailableContexts = Utils.availableContexts
Expand Down Expand Up @@ -78,11 +77,11 @@ type Benchmarks<'elem when 'elem : struct>(
this.ResultMatrix <- this.FunToBenchmark this.Processor DeviceOnly matrix matrix

member this.ClearInputMatrices() =
matrix.Dispose this.Processor
matrix.Dispose()

member this.ClearResult() =
match this.ResultMatrix with
| Some matrix -> matrix.Dispose this.Processor
| Some matrix -> matrix.Dispose()
| None -> ()

member this.ReadMatrices() =
Expand Down Expand Up @@ -116,17 +115,17 @@ module WithoutTransfer =
override this.GlobalSetup() =
this.ReadMatrices()
this.LoadMatricesToGPU()
finish this.Processor
this.Processor.Synchronize()

[<Benchmark>]
override this.Benchmark() =
this.Mxm()
finish this.Processor
this.Processor.Synchronize()

[<IterationCleanup>]
override this.IterationCleanup () =
this.ClearResult()
finish this.Processor
this.Processor.Synchronize()

[<GlobalCleanup>]
override this.GlobalCleanup () =
Expand Down
Loading
Loading