Skip to content

Commit 1b0a670

Browse files
committed
SetArgs benchmark
SetArgs benchmark
1 parent 13e0b52 commit 1b0a670

File tree

3 files changed

+120
-4
lines changed

3 files changed

+120
-4
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
module GraphBLAS.FSharp.Benchmarks.Common.SetArgs
2+
3+
open FsCheck
4+
open BenchmarkDotNet.Attributes
5+
open Brahma.FSharp
6+
open GraphBLAS.FSharp.Backend.Quotes
7+
open GraphBLAS.FSharp
8+
open GraphBLAS.FSharp.Benchmarks
9+
open GraphBLAS.FSharp.Tests
10+
open GraphBLAS.FSharp.Objects
11+
open GraphBLAS.FSharp.Objects.ArraysExtensions
12+
open GraphBLAS.FSharp.Objects.ClContextExtensions
13+
open GraphBLAS.FSharp.Objects.ClCellExtensions
14+
15+
[<IterationCount(20)>]
16+
[<WarmupCount(10)>]
17+
[<Config(typeof<Configs.MinMaxMean>)>]
18+
type BenchmarkSetArgs() =
19+
20+
//let kernel = <@ fun (ndRange: Range1D) (inputArray1: ClArray<int>) (inputArray2: ClArray<int>) (inputArray3: ClArray<int>) (inputArray4: ClArray<int>) (inputArray5: ClArray<int>) (inputArray6: ClArray<int>) (inputArray7: ClArray<int>) (inputArray8: ClArray<int>) (inputArray9: ClArray<int>) (inputArray10: ClArray<int>) -> () @>
21+
let kernel = <@ fun (ndRange: Range1D) (inputArray1: ClArray<int>) -> () @>
22+
23+
member val kernelCompiled = None with get, set
24+
25+
member val DeviceArray1 = Unchecked.defaultof<ClArray<int>> with get, set
26+
member val DeviceArray2 = Unchecked.defaultof<ClArray<int>> with get, set
27+
member val DeviceArray3 = Unchecked.defaultof<ClArray<int>> with get, set
28+
member val DeviceArray4 = Unchecked.defaultof<ClArray<int>> with get, set
29+
member val DeviceArray5 = Unchecked.defaultof<ClArray<int>> with get, set
30+
member val DeviceArray6 = Unchecked.defaultof<ClArray<int>> with get, set
31+
member val DeviceArray7 = Unchecked.defaultof<ClArray<int>> with get, set
32+
member val DeviceArray8 = Unchecked.defaultof<ClArray<int>> with get, set
33+
member val DeviceArray9 = Unchecked.defaultof<ClArray<int>> with get, set
34+
member val DeviceArray10 = Unchecked.defaultof<ClArray<int>> with get, set
35+
36+
member val HostArray = Unchecked.defaultof<int []> with get, set
37+
38+
member val ArraySize = 1000000
39+
40+
member val Iterations = 1000
41+
42+
[<ParamsSource("AvailableContexts")>]
43+
member val OclContextInfo = Unchecked.defaultof<Utils.BenchmarkContext * int> with get, set
44+
45+
member this.OclContext: ClContext = (fst this.OclContextInfo).ClContext
46+
member this.WorkGroupSize = snd this.OclContextInfo
47+
48+
member this.Processor =
49+
let p = (fst this.OclContextInfo).Queue
50+
p.Error.Add(fun e -> failwithf $"%A{e}")
51+
p
52+
53+
static member AvailableContexts = Utils.availableContexts
54+
55+
member this.ClearInputArrays() =
56+
this.DeviceArray1.FreeAndWait this.Processor
57+
this.DeviceArray2.FreeAndWait this.Processor
58+
this.DeviceArray3.FreeAndWait this.Processor
59+
this.DeviceArray4.FreeAndWait this.Processor
60+
this.DeviceArray5.FreeAndWait this.Processor
61+
this.DeviceArray6.FreeAndWait this.Processor
62+
this.DeviceArray7.FreeAndWait this.Processor
63+
this.DeviceArray8.FreeAndWait this.Processor
64+
this.DeviceArray9.FreeAndWait this.Processor
65+
this.DeviceArray10.FreeAndWait this.Processor
66+
67+
member this.CreateArray() =
68+
this.HostArray <- Array.create this.ArraySize 1
69+
70+
member this.LoadArraysToGPU() =
71+
this.DeviceArray1 <- this.OclContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, this.HostArray)
72+
this.DeviceArray2 <- this.OclContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, this.HostArray)
73+
this.DeviceArray3 <- this.OclContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, this.HostArray)
74+
this.DeviceArray4 <- this.OclContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, this.HostArray)
75+
this.DeviceArray5 <- this.OclContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, this.HostArray)
76+
this.DeviceArray6 <- this.OclContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, this.HostArray)
77+
this.DeviceArray7 <- this.OclContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, this.HostArray)
78+
this.DeviceArray8 <- this.OclContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, this.HostArray)
79+
this.DeviceArray9 <- this.OclContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, this.HostArray)
80+
this.DeviceArray10 <- this.OclContext.CreateClArrayWithSpecificAllocationMode(DeviceOnly, this.HostArray)
81+
82+
[<GlobalSetup>]
83+
member this.GlobalSetup() =
84+
this.kernelCompiled <- Some (this.OclContext.Compile kernel)
85+
this.CreateArray()
86+
this.LoadArraysToGPU()
87+
88+
[<IterationSetup>]
89+
member this.IterationSetup() =
90+
this.Processor.PostAndReply Msg.MsgNotifyMe
91+
92+
[<Benchmark>]
93+
member this.Benchmark() =
94+
let mutable i = 0
95+
while i < this.Iterations do
96+
let ndRange =
97+
Range1D.CreateValid(1, this.WorkGroupSize)
98+
99+
let kernel = this.kernelCompiled.Value.GetKernel()
100+
101+
//this.Processor.Post(Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange this.DeviceArray1 this.DeviceArray2 this.DeviceArray3 this.DeviceArray4 this.DeviceArray5 this.DeviceArray6 this.DeviceArray7 this.DeviceArray8 this.DeviceArray9 this.DeviceArray10))
102+
this.Processor.Post(Msg.MsgSetArguments(fun () -> kernel.KernelFunc ndRange this.DeviceArray1))
103+
104+
this.Processor.Post(Msg.CreateRunMsg<_, _>(kernel))
105+
106+
this.Processor.PostAndReply Msg.MsgNotifyMe
107+
i <- i + 1
108+
109+
[<IterationCleanup>]
110+
member this.IterationCleanup() = ()
111+
112+
113+
[<GlobalCleanup>]
114+
member this.GlobalCleanup() =
115+
this.ClearInputArrays()

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -19,15 +19,16 @@
1919
<Compile Include="Helpers.fs" />
2020
<Compile Include="Columns.fs" />
2121
<Compile Include="Configs.fs" />
22+
<Compile Include="Common/SetArgs.fs" />
2223
<Compile Include="Matrix/SpGeMM/Masked.fs" />
2324
<Compile Include="Matrix/SpGeMM/Expand.fs" />
2425
<Compile Include="Matrix/Map2/Map2.fs" />
2526
<Compile Include="Matrix/Map2/MathNET.fs" />
2627
<Compile Include="Vector/Map2.fs" />
2728
<Compile Include="Algorithms/BFS.fs" />
28-
<Compile Include="Algorithms/PageRank.fs" />
29+
<Compile Include="Algorithms/PageRank.fs" />
2930
<Compile Include="Program.fs" />
3031
<Folder Include="Datasets" />
3132
</ItemGroup>
3233
<Import Project="..\..\.paket\Paket.Restore.targets" />
33-
</Project>
34+
</Project>

benchmarks/GraphBLAS-sharp.Benchmarks/Program.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ open BenchmarkDotNet.Running
44
[<EntryPoint>]
55
let main argv =
66
let benchmarks =
7-
BenchmarkSwitcher [| typeof<Algorithms.BFS.BFSPushPullWithoutTransferBenchmarkBool> |]
7+
BenchmarkSwitcher [| typeof<Common.SetArgs.BenchmarkSetArgs> |]
88

99
benchmarks.Run argv |> ignore
1010
0

0 commit comments

Comments
 (0)