|
1 | 1 | module Backend.BitonicSort |
2 | 2 |
|
3 | 3 | open Expecto |
4 | | -open GraphBLAS.FSharp.Tests |
5 | | -open TypeShape.Core |
6 | 4 | open Expecto.Logging |
7 | 5 | open Expecto.Logging.Message |
8 | 6 | open GraphBLAS.FSharp.Backend.Common |
9 | 7 | open Brahma.FSharp |
10 | 8 | open GraphBLAS.FSharp.Tests.Utils |
| 9 | +open OpenCL.Net |
11 | 10 |
|
12 | 11 | let logger = Log.create "BitonicSort.Tests" |
13 | 12 |
|
14 | 13 | let testContext = |
15 | | - let contexts = "" |> avaliableContexts |> Seq.toList |
16 | | - contexts.[0] |
17 | | - |
18 | | -let context = testContext.ClContext |
19 | | -printfn "%A" testContext |
20 | | - |
21 | | -let makeTest (q: MailboxProcessor<_>) sort (filter: 'a -> bool) (array: ('n * 'n * 'a) []) = |
| 14 | + "" |
| 15 | + |> avaliableContexts |
| 16 | + |> Seq.filter |
| 17 | + (fun context -> |
| 18 | + let mutable e = ErrorCode.Unknown |
| 19 | + let device = context.ClContext.ClDevice.Device |
| 20 | + |
| 21 | + let deviceType = |
| 22 | + Cl |
| 23 | + .GetDeviceInfo(device, DeviceInfo.Type, &e) |
| 24 | + .CastTo<DeviceType>() |
| 25 | + |
| 26 | + deviceType = DeviceType.Gpu) |
| 27 | + |> Seq.tryHead |
| 28 | + |
| 29 | +let makeTest (context: ClContext) (q: MailboxProcessor<_>) sort (filter: 'a -> bool) (array: ('n * 'n * 'a) []) = |
22 | 30 | if array.Length > 0 then |
23 | 31 | let projection (row: 'n) (col: 'n) (v: 'a) = row, col |
24 | 32 |
|
@@ -77,22 +85,26 @@ let makeTest (q: MailboxProcessor<_>) sort (filter: 'a -> bool) (array: ('n * 'n |
77 | 85 | vals) |
78 | 86 | |> Expect.sequenceEqual actualVals expectedVals |
79 | 87 |
|
80 | | -let testFixtures<'a when 'a: equality> config wgSize q filter = |
| 88 | +let testFixtures<'a when 'a: equality> config wgSize context q filter = |
81 | 89 | let sort: MailboxProcessor<_> -> ClArray<int> -> ClArray<int> -> ClArray<'a> -> unit = |
82 | 90 | BitonicSort.sortKeyValuesInplace context wgSize |
83 | 91 |
|
84 | | - makeTest q sort filter |
| 92 | + makeTest context q sort filter |
85 | 93 | |> testPropertyWithConfig config (sprintf "Correctness on %A" typeof<'a>) |
86 | 94 |
|
87 | 95 | let tests = |
88 | | - let config = defaultConfig |
89 | | - |
90 | | - let wgSize = 128 |
91 | | - let q = testContext.Queue |
92 | | - q.Error.Add(fun e -> failwithf "%A" e) |
93 | | - |
94 | | - [ testFixtures<int> config wgSize q (fun _ -> true) |
95 | | - testFixtures<float> config wgSize q (System.Double.IsNaN >> not) |
96 | | - testFixtures<byte> config wgSize q (fun _ -> true) |
97 | | - testFixtures<bool> config wgSize q (fun _ -> true) ] |
| 96 | + match testContext with |
| 97 | + | Some c -> |
| 98 | + let context = c.ClContext |
| 99 | + let config = defaultConfig |
| 100 | + |
| 101 | + let wgSize = 128 |
| 102 | + let q = c.Queue |
| 103 | + q.Error.Add(fun e -> failwithf "%A" e) |
| 104 | + |
| 105 | + [ testFixtures<int> config wgSize context q (fun _ -> true) |
| 106 | + testFixtures<float> config wgSize context q (System.Double.IsNaN >> not) |
| 107 | + testFixtures<byte> config wgSize context q (fun _ -> true) |
| 108 | + testFixtures<bool> config wgSize context q (fun _ -> true) ] |
| 109 | + | _ -> [] |
98 | 110 | |> testList "Backend.Common.BitonicSort tests" |
0 commit comments