|
| 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() |
0 commit comments