-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunit_tests.jl
165 lines (124 loc) · 6.53 KB
/
unit_tests.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
using Test
dim1 = true
dim2 = true
dim3 = true
dim1 && include("fft_example_1D.jl")
dim2 && include("fft_example_2D.jl")
dim3 && include("fft_example_3D.jl")
# 1D
if dim1
for N in (100, 200, 500)
z = rand(N)
z2_wei = M_perpt_M_perp_vec_wei(1, (N,), z, Int[])
@test z2_wei ≈ z
res1_wei = M_perp_tz_wei(1, (N,), z)
@test norm(res1_wei) ≈ norm(z)
res2_wei = M_perp_beta_wei(1, (N,), z, Int[])
@test norm(res2_wei) ≈ norm(z)
for rdft in (false, true)
@testset "1D -- CPU -- rdft=$rdft -- $N" begin
nlp, solver, results = fft_example_1D(N; gpu=false, rdft, check=true)
z2 = M_perpt_M_perp_vec(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 1, (N,), z, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test z2 ≈ z
res1 = M_perp_tz(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 1, (N,), z, nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res1) ≈ norm(z)
@test res1_wei ≈ res1
res2 = M_perp_beta(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 1, (N,), z, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res2) ≈ norm(z)
@test res2_wei ≈ res2
end
if CUDA.functional()
@testset "1D -- GPU -- rdft=$rdft -- $N" begin
nlp, solver, results = fft_example_1D(N; gpu=true, rdft, check=true)
z_gpu = CuArray(z)
z2_gpu = M_perpt_M_perp_vec(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 1, (N,), z_gpu, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test z2_gpu ≈ z_gpu
res1_gpu = M_perp_tz(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 1, (N,), z_gpu, nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res1_gpu) ≈ norm(z_gpu)
@test res1_wei ≈ collect(res1_gpu)
res2_gpu = M_perp_beta(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 1, (N,), z_gpu, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res2_gpu) ≈ norm(z_gpu)
@test res2_wei ≈ collect(res2_gpu)
end
end
end
end
end
# 2D
if dim2
for (N1, N2) in ((16, 16), (12, 18), (16, 24), (32, 32))
z = rand(N1 * N2)
z2_wei = M_perpt_M_perp_vec_wei(2, (N1, N2), z, Int[])
@test z2_wei ≈ z
res1_wei = M_perp_tz_wei(2, (N1, N2), reshape(z, (N1, N2)))
@test norm(res1_wei) ≈ norm(z)
res2_wei = M_perp_beta_wei(2, (N1, N2), z, Int[])
@test norm(res2_wei) ≈ norm(z)
for rdft in (false, true)
@testset "2D -- CPU -- rdft=$rdft -- $N1 × $N2" begin
nlp, solver, results = fft_example_2D(N1, N2; gpu=false, rdft, check=true)
z2 = M_perpt_M_perp_vec(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 2, (N1, N2), z, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test z2 ≈ z
res1 = M_perp_tz(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 2, (N1, N2), reshape(z, (N1, N2)), nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res1) ≈ norm(z)
@test res1_wei ≈ res1
res2 = M_perp_beta(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 2, (N1, N2), z, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res2) ≈ norm(z)
@test res2_wei ≈ res2
end
if CUDA.functional()
@testset "2D -- GPU -- rdft=$rdft -- $N1 × $N2" begin
nlp, solver, results = fft_example_2D(N1, N2; gpu=true, rdft, check=true)
z_gpu = CuArray(z)
z2_gpu = M_perpt_M_perp_vec(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 2, (N1, N2), z_gpu, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test z2_gpu ≈ z_gpu
res1_gpu = M_perp_tz(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 2, (N1, N2), reshape(z_gpu, (N1, N2)), nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res1_gpu) ≈ norm(z_gpu)
@test res1_wei ≈ collect(res1_gpu)
res2_gpu = M_perp_beta(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 2, (N1, N2), z_gpu, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res2_gpu) ≈ norm(z_gpu)
@test res2_wei ≈ collect(res2_gpu)
end
end
end
end
end
# 3D
if dim3
for (N1, N2, N3) in ((8, 8, 8), (2, 4, 6), (6, 10, 12), (14, 8, 4), (8, 6, 4), (16, 16, 16))
z = rand(N1 * N2 * N3)
z2_wei = M_perpt_M_perp_vec_wei(3, (N1, N2, N3), z, Int[])
@test z2_wei ≈ z
res1_wei = M_perp_tz_wei(3, (N1, N2, N3), reshape(z, (N1, N2, N3)))
@test norm(res1_wei) ≈ norm(z)
res2_wei = M_perp_beta_wei(3, (N1, N2, N3), z, Int[])
@test norm(res2_wei) ≈ norm(z)
for rdft in (false, true)
@testset "3D -- CPU -- rdft=$rdft -- $N1 × $N2 × $N3" begin
nlp, solver, results = fft_example_3D(N1, N2, N3; gpu=false, rdft, check=true)
z2 = M_perpt_M_perp_vec(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 3, (N1, N2, N3), z, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test z2 ≈ z
res1 = M_perp_tz(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 3, (N1, N2, N3), reshape(z, (N1, N2, N3)), nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res1) ≈ norm(z)
@test res1_wei ≈ res1
res2 = M_perp_beta(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 3, (N1, N2, N3), z, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res2) ≈ norm(z)
@test res2_wei ≈ res2
end
if CUDA.functional()
@testset "3D -- GPU -- rdft=$rdft -- $N1 × $N2 × $N3" begin
nlp, solver, results = fft_example_3D(N1, N2, N3; gpu=true, rdft, check=true)
z_gpu = CuArray(z)
z2_gpu = M_perpt_M_perp_vec(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 3, (N1, N2, N3), z_gpu, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test z2_gpu ≈ z_gpu
res1_gpu = M_perp_tz(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 3, (N1, N2, N3), reshape(z_gpu, (N1, N2, N3)), nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res1_gpu) ≈ norm(z_gpu)
@test res1_wei ≈ collect(res1_gpu)
res2_gpu = M_perp_beta(nlp.buffer_real, nlp.buffer_complex1, nlp.buffer_complex2, nlp.op, 3, (N1, N2, N3), z_gpu, Int[], nlp.fft_timer, nlp.mapping_timer; rdft)
@test norm(res2_gpu) ≈ norm(z_gpu)
@test res2_wei ≈ collect(res2_gpu)
end
end
end
end
end