|
| 1 | +module GraphBLAS.FSharp.Tests.Backend.Common.Choose |
| 2 | + |
| 3 | +open GraphBLAS.FSharp.Backend.Common |
| 4 | +open Expecto |
| 5 | +open GraphBLAS.FSharp.Tests |
| 6 | +open GraphBLAS.FSharp.Tests.Context |
| 7 | +open GraphBLAS.FSharp.Backend.Objects.ClContext |
| 8 | +open Brahma.FSharp |
| 9 | +open GraphBLAS.FSharp.Backend.Quotes |
| 10 | + |
| 11 | +let workGroupSize = Utils.defaultWorkGroupSize |
| 12 | + |
| 13 | +let config = Utils.defaultConfig |
| 14 | + |
| 15 | +let makeTest<'a, 'b> testContext choose mapFun isEqual (array: 'a []) = |
| 16 | + if array.Length > 0 then |
| 17 | + let context = testContext.ClContext |
| 18 | + let q = testContext.Queue |
| 19 | + |
| 20 | + let clArray = context.CreateClArrayWithSpecificAllocationMode(DeviceOnly, array) |
| 21 | + |
| 22 | + let (clResult: ClArray<'b>) = choose q HostInterop clArray |
| 23 | + |
| 24 | + let hostResult = Array.zeroCreate clResult.Length |
| 25 | + q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clResult, hostResult, ch)) |> ignore |
| 26 | + |
| 27 | + let expectedResult = Array.choose mapFun array |
| 28 | + |
| 29 | + "Result should be the same" |
| 30 | + |> Utils.compareArrays isEqual hostResult expectedResult |
| 31 | + |
| 32 | +let createTest<'a, 'b> testContext mapFun mapFunQ isEqual = |
| 33 | + let context = testContext.ClContext |
| 34 | + |
| 35 | + let choose = ClArray.choose context workGroupSize mapFunQ |
| 36 | + |
| 37 | + makeTest<'a, 'b> testContext choose mapFun isEqual |
| 38 | + |> testPropertyWithConfig config $"Correctness on %A{typeof<'a>} -> %A{typeof<'b>}" |
| 39 | + |
| 40 | +let testFixtures testContext = |
| 41 | + let device = testContext.ClContext.ClDevice |
| 42 | + |
| 43 | + [ createTest<int option, int> testContext id Map.id (=) |
| 44 | + createTest<byte option, byte> testContext id Map.id (=) |
| 45 | + createTest<bool option, bool> testContext id Map.id (=) |
| 46 | + |
| 47 | + if Utils.isFloat64Available device then |
| 48 | + createTest<float option, float> testContext id Map.id Utils.floatIsEqual |
| 49 | + |
| 50 | + createTest<float32 option, float32> testContext id Map.id Utils.float32IsEqual ] |
| 51 | + |
| 52 | +let tests = TestCases.gpuTests "ClArray.choose id tests" testFixtures |
0 commit comments