forked from gsvgit/Brahma.FSharp
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from dpanfilyonok/profiling
Add benchmarks and fix performance
- Loading branch information
Showing
37 changed files
with
1,050 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
benchmarks/Brahma.FSharp.Benchmarks/BenchmarksAtomic/AtomicBenchamrks.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
namespace Brahma.FSharp.Benchmarks | ||
|
||
open BenchmarkDotNet.Attributes | ||
|
||
[<AbstractClass>] | ||
type AtomicBenchamrks() = | ||
member this.WgSize = 256 | ||
|
||
[<ParamsSource("GlobalWorkSizeProvider")>] | ||
member val GlobalWorkSize = 0 with get, set | ||
|
||
static member GlobalWorkSizeProvider = | ||
seq { | ||
1000 | ||
100_000 | ||
} |
73 changes: 73 additions & 0 deletions
73
benchmarks/Brahma.FSharp.Benchmarks/BenchmarksAtomic/BrahmaAtomicBenchamrks.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
namespace Brahma.FSharp.Benchmarks | ||
|
||
open BenchmarkDotNet.Attributes | ||
open Brahma.FSharp | ||
open Brahma.FSharp.OpenCL.Shared | ||
open FSharp.Quotations | ||
|
||
[<AbstractClass>] | ||
type BrahmaAtomicBenchamrks() = | ||
inherit AtomicBenchamrks() | ||
|
||
member val Program = Unchecked.defaultof<ClProgram<Range1D, int clcell -> unit>> with get, set | ||
|
||
member val Cell = Unchecked.defaultof<int clcell> with get, set | ||
|
||
[<ParamsSource("AvaliableContextsProvider")>] | ||
member val Context = Unchecked.defaultof<RuntimeContext> with get, set | ||
|
||
abstract Command: Expr<Range1D -> int clcell -> unit> | ||
|
||
[<GlobalSetup>] | ||
member this.CompileProgram() = | ||
this.Program <- this.Context.ClContext.Compile(this.Command) | ||
|
||
[<IterationSetup>] | ||
member this.AllocCellOnDevice() = | ||
this.Cell <- | ||
opencl { | ||
return! ClCell.alloc<int> () | ||
} | ||
|> ClTask.runSync this.Context | ||
|
||
abstract RunProgram : unit -> unit | ||
default this.RunProgram() = | ||
opencl { | ||
do! runProgram this.Program <| fun kernel -> | ||
kernel | ||
<| Range1D.CreateValid(this.GlobalWorkSize, this.WgSize) | ||
<| this.Cell | ||
} | ||
|> ClTask.runSync this.Context | ||
|
||
[<IterationCleanup>] | ||
member this.CleanCell() = | ||
this.Cell.Dispose() | ||
|
||
static member AvaliableContextsProvider = | ||
ClDevice.GetAvailableDevices(Platform.Nvidia) | ||
|> Seq.map RuntimeContext | ||
|
||
type BrahmaNativeAtomicBenchmarks() = | ||
inherit BrahmaAtomicBenchamrks() | ||
|
||
override this.Command = | ||
<@ | ||
fun (range: Range1D) (acc: int clcell) -> | ||
atomic (+) acc.Value 1 |> ignore | ||
@> | ||
|
||
[<Benchmark(Baseline = true)>] | ||
override this.RunProgram() = base.RunProgram() | ||
|
||
type BrahmaSpinlockAtomicBenchmarks() = | ||
inherit BrahmaAtomicBenchamrks() | ||
|
||
override this.Command = | ||
<@ | ||
fun (range: Range1D) (acc: int clcell) -> | ||
atomic (fun x -> x + 1) acc.Value |> ignore | ||
@> | ||
|
||
[<Benchmark>] | ||
override this.RunProgram() = base.RunProgram() |
79 changes: 79 additions & 0 deletions
79
benchmarks/Brahma.FSharp.Benchmarks/BenchmarksAtomic/IlgpuAtomicBenchamrks.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
namespace Brahma.FSharp.Benchmarks.Ilgpu | ||
|
||
open System | ||
open Brahma.FSharp.Benchmarks | ||
open BenchmarkDotNet.Attributes | ||
open ILGPU | ||
open ILGPU.AtomicOperations | ||
open ILGPU.Runtime | ||
open ILGPU.Runtime.Cuda | ||
|
||
[<AbstractClass>] | ||
type IlgpuAtomicBenchamrks() = | ||
inherit AtomicBenchamrks() | ||
|
||
member val Program = Unchecked.defaultof<Action<Index1D, VariableView<int>>> with get, set | ||
|
||
member val Cell = Unchecked.defaultof<MemoryBuffer1D<int, Stride1D.Dense>> with get, set | ||
|
||
member val Accelerator = | ||
let context = Context.CreateDefault() | ||
context.CreateCudaAccelerator(0) | ||
|
||
abstract Command: Action<Index1D, VariableView<int>> | ||
|
||
[<GlobalSetup>] | ||
member this.CompileProgram() = | ||
this.Program <- this.Accelerator.LoadAutoGroupedStreamKernel<Index1D, VariableView<int>>(this.Command) | ||
|
||
[<IterationSetup>] | ||
member this.AllocCellOnDevice() = | ||
this.Cell <- this.Accelerator.Allocate1D<int>(1L) | ||
this.Cell.MemSetToZero() | ||
|
||
abstract RunProgram : unit -> unit | ||
default this.RunProgram() = | ||
this.Program.Invoke(Index1D this.GlobalWorkSize, this.Cell.View.VariableView(Index1D 0)) | ||
this.Accelerator.Synchronize() | ||
|
||
[<IterationCleanup>] | ||
member this.CleanCell() = | ||
this.Cell.Dispose() | ||
|
||
type IlgpuNativeAtomicBenchmarks() = | ||
inherit IlgpuAtomicBenchamrks() | ||
|
||
override this.Command = | ||
Action<Index1D, VariableView<int>>(fun index dataView -> | ||
Atomic.Add(&dataView.Value, 1) |> ignore | ||
) | ||
|
||
[<Benchmark(Baseline = true)>] | ||
override this.RunProgram() = base.RunProgram() | ||
|
||
[<Struct>] | ||
type AddOp = | ||
interface IAtomicOperation<int> with | ||
member this.Operation(current, value) = current + value | ||
|
||
[<Struct>] | ||
type CmpXchOp = | ||
interface ICompareExchangeOperation<int> with | ||
member this.CompareExchange(target, compare, value) = Atomic.CompareExchange(&target, compare, value); | ||
member this.IsSame(left, right) = left = right | ||
|
||
type IlgpuSpinlockAtomicBenchmarks() = | ||
inherit IlgpuAtomicBenchamrks() | ||
|
||
override this.Command = | ||
Action<Index1D, VariableView<int>>(fun index dataView -> | ||
Atomic.MakeAtomic( | ||
&dataView.Value, | ||
1, | ||
AddOp(), | ||
CmpXchOp() | ||
) |> ignore | ||
) | ||
|
||
[<Benchmark>] | ||
override this.RunProgram() = base.RunProgram() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
namespace Brahma.FSharp.Benchmarks | ||
|
||
open BenchmarkDotNet.Attributes | ||
open Brahma.FSharp | ||
open Brahma.FSharp.OpenCL.Shared | ||
open FSharp.Quotations | ||
|
||
[<AbstractClass>] | ||
type SimpleBenchamrks() = | ||
member val Program = Unchecked.defaultof<ClProgram<Range1D, int clcell -> unit>> with get, set | ||
|
||
member val Kernel = Unchecked.defaultof<ClKernel<Range1D, int clcell -> unit>> with get, set | ||
|
||
member val Cell = Unchecked.defaultof<int clcell> with get, set | ||
|
||
[<ParamsSource("AvaliableContextsProvider")>] | ||
member val Context = Unchecked.defaultof<RuntimeContext> with get, set | ||
|
||
member this.GlobalWorkSize = 100 | ||
member this.WgSize = 256 | ||
|
||
abstract Command: Expr<Range1D -> int clcell -> unit> | ||
|
||
[<GlobalSetup>] | ||
member this.CompileProgram() = | ||
this.Program <- this.Context.ClContext.Compile(this.Command) | ||
|
||
[<IterationSetup>] | ||
member this.AllocCellOnDevice() = | ||
this.Cell <- | ||
opencl { | ||
return! ClCell.alloc<int> () | ||
} | ||
|> ClTask.runSync this.Context | ||
|
||
this.Kernel <- this.Program.GetKernel() | ||
|
||
[<Benchmark>] | ||
member this.SetAndRunKernel() = | ||
this.Context.CommandQueue.Post(Msg.MsgSetArguments (fun () -> this.Kernel.KernelFunc (Range1D.CreateValid(this.GlobalWorkSize, this.WgSize)) this.Cell)) | ||
this.Context.CommandQueue.Post(Msg.CreateRunMsg this.Kernel) | ||
this.Context.CommandQueue.PostAndReply(MsgNotifyMe) | ||
|
||
[<Benchmark>] | ||
member this.SetWithoutRunningKernel() = | ||
this.Context.CommandQueue.Post(Msg.MsgSetArguments (fun () -> this.Kernel.KernelFunc (Range1D.CreateValid(this.GlobalWorkSize, this.WgSize)) this.Cell)) | ||
this.Context.CommandQueue.PostAndReply(MsgNotifyMe) | ||
|
||
[<IterationCleanup>] | ||
member this.CleanCell() = | ||
this.Cell.Dispose() | ||
|
||
static member AvaliableContextsProvider = | ||
ClDevice.GetAvailableDevices(Platform.Nvidia) | ||
|> Seq.map RuntimeContext | ||
|
||
type SimpleBenchamrks1() = | ||
inherit SimpleBenchamrks() | ||
|
||
override this.Command = | ||
<@ | ||
fun (range: Range1D) (acc: int clcell) -> | ||
acc.Value <- 1 | ||
@> | ||
|
||
type SimpleBenchamrks2() = | ||
inherit SimpleBenchamrks() | ||
|
||
override this.Command = | ||
<@ | ||
fun (range: Range1D) (acc: int clcell) -> | ||
atomic (fun x -> x + 1) acc.Value |> ignore | ||
@> |
Oops, something went wrong.