|
1 | 1 | module Backend.Copy |
2 | | -// |
3 | | -//open Expecto |
4 | | -//open Expecto.Logging |
5 | | -//open Expecto.Logging.Message |
6 | | -//open Brahma.FSharp.OpenCL |
7 | | -//open GraphBLAS.FSharp.Backend |
8 | | -// |
9 | | -//let logger = Log.create "Copy.Tests" |
10 | | -// |
11 | | -//let context = |
12 | | -// let deviceType = ClDeviceType.Default |
13 | | -// let platformName = ClPlatform.Any |
14 | | -// ClContext(platformName, deviceType) |
15 | | -// |
16 | | -//let testCases = |
17 | | -// let q = context.CommandQueue |
18 | | -// q.Error.Add(fun e -> failwithf "%A" e) |
19 | | -// |
20 | | -// let getCopyFun copy = |
21 | | -// fun (array: array<_>) -> |
22 | | -// let wgSize = |
23 | | -// [| for i in 0 .. 5 -> pown 2 i |] |
24 | | -// |> Array.filter (fun i -> array.Length % i = 0) |
25 | | -// |> Array.max |
26 | | -// |
27 | | -// copy q wgSize |
28 | | -// |
29 | | -// let makeTest getCopyFun (array: array<'a>) filterFun = |
30 | | -// if array.Length > 0 then |
31 | | -// use clArray = context.CreateClArray array |
32 | | -// |
33 | | -// let copy = getCopyFun array |
34 | | -// |
35 | | -// let actual = |
36 | | -// use clActual: ClArray<'a> = copy clArray |
37 | | -// |
38 | | -// let actual = Array.zeroCreate clActual.Length |
39 | | -// q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch)) |
40 | | -// |
41 | | -// logger.debug ( |
42 | | -// eventX "Actual is {actual}" |
43 | | -// >> setField "actual" (sprintf "%A" actual) |
44 | | -// ) |
45 | | -// |
46 | | -// let expected = filterFun array |
47 | | -// let actual = filterFun actual |
48 | | -// |
49 | | -// "Array should be equals to original" |
50 | | -// |> Expect.sequenceEqual actual expected |
51 | | -// |
52 | | -// [ testProperty "Correctness test on random int arrays" |
53 | | -// <| (let copy = ClArray.copy context |
54 | | -// let getCopyFun = getCopyFun copy |
55 | | -// fun (array: array<int>) -> makeTest getCopyFun array id) |
56 | | -// |
57 | | -// testProperty "Correctness test on random bool arrays" |
58 | | -// <| (let copy = ClArray.copy context |
59 | | -// let getCopyFun = getCopyFun copy |
60 | | -// |
61 | | -// fun (array: array<bool>) -> makeTest getCopyFun array id) |
62 | | -// |
63 | | -// testProperty "Correctness test on random float arrays" |
64 | | -// <| (let copy = ClArray.copy context |
65 | | -// let getCopyFun = getCopyFun copy |
66 | | -// |
67 | | -// fun (array: array<float>) -> makeTest getCopyFun array (Array.filter (System.Double.IsNaN >> not))) |
68 | | -// |
69 | | -// testProperty "Correctness test on random byte arrays" |
70 | | -// <| (let copy = ClArray.copy context |
71 | | -// let getCopyFun = getCopyFun copy |
72 | | -// |
73 | | -// fun (array: array<byte>) -> makeTest getCopyFun array id) |
74 | | -// |
75 | | -// ] |
76 | | -// |
77 | | -//let tests = testCases |> testList "Array.copy tests" |
| 2 | + |
| 3 | +open Expecto |
| 4 | +open Expecto.Logging |
| 5 | +open Expecto.Logging.Message |
| 6 | +open Brahma.FSharp |
| 7 | +open GraphBLAS.FSharp.Backend |
| 8 | +open GraphBLAS.FSharp.Tests |
| 9 | + |
| 10 | +let logger = Log.create "Copy.Tests" |
| 11 | + |
| 12 | +let context = Utils.defaultContext.ClContext |
| 13 | + |
| 14 | +let testCases = |
| 15 | + let q = Utils.defaultContext.Queue |
| 16 | + q.Error.Add(fun e -> failwithf "%A" e) |
| 17 | + |
| 18 | + let getCopyFun copy = |
| 19 | + fun (array: array<_>) -> |
| 20 | + let wgSize = |
| 21 | + [| for i in 0 .. 5 -> pown 2 i |] |
| 22 | + |> Array.filter (fun i -> array.Length % i = 0) |
| 23 | + |> Array.max |
| 24 | + |
| 25 | + copy q wgSize |
| 26 | + |
| 27 | + let makeTest getCopyFun (array: array<'a>) filterFun = |
| 28 | + if array.Length > 0 then |
| 29 | + use clArray = context.CreateClArray array |
| 30 | + |
| 31 | + let copy = getCopyFun array |
| 32 | + |
| 33 | + let actual = |
| 34 | + use clActual: ClArray<'a> = copy clArray |
| 35 | + |
| 36 | + let actual = Array.zeroCreate clActual.Length |
| 37 | + q.PostAndReply(fun ch -> Msg.CreateToHostMsg(clActual, actual, ch)) |
| 38 | + |
| 39 | + logger.debug ( |
| 40 | + eventX "Actual is {actual}" |
| 41 | + >> setField "actual" (sprintf "%A" actual) |
| 42 | + ) |
| 43 | + |
| 44 | + let expected = filterFun array |
| 45 | + let actual = filterFun actual |
| 46 | + |
| 47 | + "Array should be equals to original" |
| 48 | + |> Expect.sequenceEqual actual expected |
| 49 | + |
| 50 | + [ testProperty "Correctness test on random int arrays" |
| 51 | + <| (let copy = ClArray.copy context |
| 52 | + let getCopyFun = getCopyFun copy |
| 53 | + fun (array: array<int>) -> makeTest getCopyFun array id) |
| 54 | + |
| 55 | + testProperty "Correctness test on random bool arrays" |
| 56 | + <| (let copy = ClArray.copy context |
| 57 | + let getCopyFun = getCopyFun copy |
| 58 | + |
| 59 | + fun (array: array<bool>) -> makeTest getCopyFun array id) |
| 60 | + |
| 61 | + testProperty "Correctness test on random float arrays" |
| 62 | + <| (let copy = ClArray.copy context |
| 63 | + let getCopyFun = getCopyFun copy |
| 64 | + |
| 65 | + fun (array: array<float>) -> makeTest getCopyFun array (Array.filter (System.Double.IsNaN >> not))) |
| 66 | + |
| 67 | + testProperty "Correctness test on random byte arrays" |
| 68 | + <| (let copy = ClArray.copy context |
| 69 | + let getCopyFun = getCopyFun copy |
| 70 | + |
| 71 | + fun (array: array<byte>) -> makeTest getCopyFun array id) |
| 72 | + |
| 73 | + ] |
| 74 | + |
| 75 | +let tests = testCases |> testList "Array.copy tests" |
0 commit comments