-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.i
315 lines (268 loc) · 8.29 KB
/
check.i
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
plug_dir, ["."];
require, "yfftw.i";
require, "offt.i";
func _fftw_check (void)
{
if (is_void(n)) n= 1024;
write,""
write,"Exec. this twice to see the effect of cached wisdom";
write,""
write,"Caching or retrieving optimization info for pow(2) 1&2-D fft's....patience";
elapsed= elapsed0= split1= split2= split3= split4= split5= [0., 0., 0.];
//check init function
timer, elapsed;elapsed0= elapsed;
ck_init;
timer, elapsed, split1;
write,"Done caching wisdom";
//various usages examples
d= [1,128];
fd= [2,2,128]; //watch it (no fun)
ld= 1;
//double /*---------------------------------------*/
c= cplxgr(d);
//out-of-place
fw= fftw(c, ld); /* plan and exec */
plan= fftw(dimsof(c), ld); /* plan */
fw= fftw(c, ld, [], plan); /* exec */
fftw_clean, plan;
//in-place
fw= c;
fftw, fw, ld; /* plan and exec */
fftw, dimsof(c), ld, [], plan; /* plan */
fw= c;
fftw, fw, ld, [], plan; /* exec */
fftw_clean, plan;
write,"Done double use cases";
//float /*---------------------------------------*/
c= cplx2f(c);
//out-of-place
fw= fftw(c, ld, fcplx=1); /* plan and exec */
plan= fftw(dimsof(c), ld, fcplx=1); /* plan */
fw= fftw(c, ld, [], plan, fcplx=1); /* exec */
fftw_clean, plan, fcplx=1;
//in-place
fw= c;
fftw, fw, ld, fcplx=1; /* plan and exec */
fftw, dimsof(c), ld, [], plan, fcplx=1; /* plan */
fw= c;
fftw, fw, ld, [], plan, fcplx=1; /* exec */
fftw_clean, plan, fcplx=1;
write,"Done float use cases";
timer, elapsed, split2;
//many dimensions
ck1,[3,32,17,13],[0,1,-1];
ck1,[5,12,5,9,22,11],[1,1,0,0,-1];
//Swarztrauber vs. fftw timing
d= [2,512,512]
c= cplxgr(d);
ld= 1;
write,"";
write,"Timing comparison: fft(x,ld) with dimsof(x)="+pr1(d)+" and ld="+pr1(ld);
//fftw
plan= fftw(d, ld); /* plan */
for (i=0 ; i<32 ; i++) fw= fftw(c, ld, [], plan, keep=1); /* exec */
fftw_clean, plan;
timer, elapsed, split3;
write,"Fftw done:";
//fft
ws= fft_setup(d);
for (i=0 ; i<32 ; i++) fs= fft(c, ld, setup=ws); /* exec */
timer, elapsed, split4;
write,"Swarztrauber done:";
//testm.i fft tests
write,""
write, "testing fftw routines as in testm.i...";
force2d = 0;
fftw_test, 95;
fftw_test, 32;
fftw_test, 14;
fftw_test, 1024;
fftw_test, 4096;
for (i=0 ; i<32 ; i++) fftw_test, 4096, nosave=1;
force2d = 1; fftw_test, 128; force2d = 0;
timer, elapsed, split5;
write, "\n\n------------ yfftw tests complete ------------";
write, "\n\n------------------ timing info ----------------";
timer_print, "FFTW pow2 initialization ", split1,\
"1-d use tests ", split2,\
"FFTW plan and 32Xexec ", split3,\
"Swarztrauber setup+32Xexec ", split4,\
"testm.i, but with FFTW ", split5,\
"-total ", elapsed-elapsed0;
return;
}
func ck1(d,ld)
{
write,""
write,"fft(x,ld) with dimsof(x)="+pr1(d)+" and ld="+pr1(ld);
c= cplxgr(d);
fs= fft(c, ld);
fw= fftw(c, ld);
write,(fs.re-fw.re)(*)(ptp),(fs.im-fw.im)(*)(ptp),\
format=" PTP-Diffs {Double_Swarztrauber - Double_fftw} [Re, IM]: %15.8lg %15.8lg \n";
fc= cplx2f(c);
fw= fftw(fc, ld, fcplx=1);
fw= fw(1,..)+1i*fw(2,..);
write,(fs.re-fw.re)(*)(ptp),(fs.im-fw.im)(*)(ptp),\
format=" PTP-Diffs {Double_Swarztrauber - Float_fftw} [Re, IM]: %15.8lg %15.8lg \n";
return;
}
func ck_init (void)
{
fftw_init_wisdom, [11,10];
fftwf_init_wisdom, [11,10];
return;
}
func fcabs(x) {return abs(x(1,..),x(2,..));}
func fftw_test(n, nosave=)
{
index= (2*pi*indgen(0:n-1))/n;
z= sin(index*3);
fz= array(float,[2,2,n]);
fz(1,..)= z;
//
zf= fftw(z, 1,nosave=nosave);
fzf= fftw(fz, 1,nosave=nosave,fcplx=1);
z3= z2= array(0i, n);
z3(4)= -0.5i*n;
z3(-2)= 0.5i*n;
zb= fftw(z, -1,nosave=nosave);
fzb= fftw(fz, -1,nosave=nosave,fcplx=1);
if (max(abs(zf-z3))>1.e-12*n || max(abs(zb-conj(z3)))>1.e-12*n)
write, "***WARNING*** failed double 1D fftw test";
if (max(fcabs(fzf-cplx2f(z3)))>1.e-6*n || max(fcabs(fzb-cplx2f(conj(z3))))>1.e-6*n)
write, "***WARNING*** failed float 1D fftw test";
if (n<=96 || force2d) {
z*= cos(index*2)(-,);
fz*= float(cos(index*2))(-,-,);
zf= fftw(z, [0, 1],nosave=nosave);
fzf= fftw(fz, [0, 1],nosave=nosave,fcplx=1);
z2(3)= z2(-1)= 0.5*n;
zb= fftw(z, [], [-1, 0],nosave=nosave);
fzb= fftw(fz, [], [-1, 0],nosave=nosave,fcplx=1);
if (max(abs(zf-sin(index*3)*z2(-,)))>1.e-12*n ||
max(abs(zb-conj(z3)*cos(index*2)(-,)))>1.e-12*n)
error, "***WARNING*** failed first double 2D fftw test";
if (max(fcabs(fzf-cplx2f(sin(index*3)*z2(-,))))>1.e-6*n ||
max(fcabs(fzb-cplx2f(conj(z3)*cos(index*2)(-,))))>1.e-6*n)
error, "***WARNING*** failed first float 2D fftw test";
zf= fftw(z, 1,nosave=nosave);
zb= fftw(z, -1,nosave=nosave);
fzf= fftw(fz, 1,nosave=nosave,fcplx=1);
fzb= fftw(fz, -1,nosave=nosave,fcplx=1);
if (max(abs(zf-z3*z2(-,)))>1.e-12*n ||
max(abs(zb-conj(z3)*z2(-,)))>1.e-12*n)
error, "***WARNING*** failed second double 2D fftw test";
if (max(fcabs(fzf-cplx2f(z3*z2(-,))))>1.e-5*n ||
max(fcabs(fzb-cplx2f(conj(z3)*z2(-,))))>1.e-5*n)
error, "***WARNING*** failed second float 2D fftw test";
}
}
func cplxgr (d) {
return random_n(d)+1i*random_n(d);
}
func cplx2f (z) {
d= dimsof(z);
f= array(0.f,_(d(1)+1,2,d(2:)));
f(1,..)= z.re; f(2,..)= z.im;
return f;
}
func _offt_check (d,usefftw=)
{
if (is_void(d)) d= [2,128,256];
for (n=1,i=1;i<=d(1);i++)
n*= d(i+1);
oo= offt(usefftw=usefftw);
ooi= offt(usefftw=usefftw);
c= cplxgr(d);
cf= oo(c,1);
cf= ooi(cf,-1)/n;
oo, reset=1;
ooi, reset=1;
sf= (usefftw==1?" FFTW":string(0));
write,"\n double out-of-place"+sf;
write,"fft Mean, STD: ",(dd=abs(c-cf)(*))(avg),dd(rms);
oo= offt(usefftw=usefftw);
ooi= offt(usefftw=usefftw);
c= cplxgr(d);
cf= c;
oo, cf, 1;
ooi, cf, -1;
cf*= 1.0/n;
oo, reset=1;
ooi, reset=1;
write,"\n double in-place"+sf;
write,"fft Mean, STD: ",(dd=abs(c-cf)(*))(avg),dd(rms);
if (usefftw==1) {
d2= _(d(1)+1,2,d(2:));
oow= offt(usefftw=1);
ooiw= offt(usefftw=1);
c= cplx2f(cplxgr(d));
cfw= oow(c,1,fcplx=1);
cfw= ooiw(cfw,-1,fcplx=1)/n;
oow, reset=1;
ooiw, reset=1;
write,"\n float out-of-place"+sf;
write,"fftw Mean, STD: ",(dd=abs(c-cfw)(*))(avg),dd(rms);
oow= offt(usefftw=1,fcplx=1);
ooiw= offt(usefftw=1,fcplx=1);
c= cplx2f(cplxgr(d));
cfw= c;
oow, cfw, 1;
ooiw, cfw, -1;
cfw*= 1.0/n;
oow, reset=1;
ooiw, reset=1;
write,"\n float in-place"+sf;
write,"fftw Mean, STD: ",(dd=abs(c-cfw)(*))(avg),dd(rms);
}
}
func _fftwrap_check (d,usefftw=)
{
if (is_void(d)) d= [2,128,256];
for (n=1,i=1;i<=d(1);i++)
n*= d(i+1);
oo= fftwrap(d,1,usefftw=usefftw);
oo, add, d, -1, usefftw=usefftw;
c= cplxgr(d);
cf= oo(eval,c,1,usefftw=usefftw,reset=usefftw);
cf= oo(eval,cf,-1,usefftw=usefftw,reset=1)/n;
sf= (usefftw==1?" FFTW":string(0));
write,"\n double out-of-place"+sf;
write,"fft Mean, STD: ",(dd=abs(c-cf)(*))(avg),dd(rms);
oo= fftwrap(d,1,usefftw=usefftw,inplace=1);
oo, add, d, -1, usefftw=usefftw,inplace=1;
c= cplxgr(d);
cf= c;
oo,eval, cf, 1, usefftw=usefftw,reset=usefftw;
oo,eval, cf,-1, usefftw=usefftw,reset=1;
cf*= 1.0/n;
write,"\n double in-place"+sf;
write,"fft Mean, STD: ",(dd=abs(c-cf)(*))(avg),dd(rms);
if (usefftw==1) {
d2= _(d(1)+1,2,d(2:));
oow= fftwrap(d2,1,usefftw=1,fcplx=1);
oow,add,d2,-1,usefftw=1,fcplx=1;
c= cplx2f(cplxgr(d));
cfw= oow(eval,c,1,fcplx=1,usefftw=usefftw,reset=1);
cfw= oow(eval,cfw,-1,fcplx=1,usefftw=usefftw,reset=1)/n;
write,"\n float out-of-place"+sf;
write,"fftw Mean, STD: ",(dd=abs(c-cfw)(*))(avg),dd(rms);
oow= fftwrap(d2,1,usefftw=1,fcplx=1,inplace=1);
oow, add,d2,-1,usefftw=1,fcplx=1,inplace=1;
c= cplx2f(cplxgr(d));
cfw= c;
oow,eval, cfw, 1,fcplx=1,usefftw=usefftw,reset=1;
oow,eval, cfw,-1,fcplx=1,usefftw=usefftw,reset=1;
cfw*= 1.0/n;
write,"\n float in-place"+sf;
write,"fftw Mean, STD: ",(dd=abs(c-cfw)(*))(avg),dd(rms);
}
}
if (batch()) {
_fftw_check;
_offt_check;
_offt_check,usefftw=1;
_fftwrap_check;
_fftwrap_check,usefftw=1;
}