-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathhybridconv2.cc
131 lines (112 loc) · 2.8 KB
/
hybridconv2.cc
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
#include <vector>
#include "convolve.h"
#include "timing.h"
#include "direct.h"
using namespace std;
using namespace utils;
using namespace Array;
using namespace fftwpp;
size_t A=2; // number of inputs
size_t B=1; // number of outputs
int main(int argc, char *argv[])
{
Lx=Ly=8; // input data length
Mx=My=16; // minimum padded length
fftw::maxthreads=get_max_threads();
#ifndef __SSE2__
fftw::effort |= FFTW_NO_SIMD;
#endif
optionsHybrid(argc,argv);
cout << "Lx=" << Lx << endl;
cout << "Ly=" << Ly << endl;
cout << "Mx=" << Mx << endl;
cout << "My=" << My << endl;
if(Output || testError)
K=0;
if(K == 0) minCount=1;
cout << "K=" << K << endl << endl;
K *= 1.0e9;
if(Sx == 0) Sx=Ly;
vector<double> T;
size_t N=max(A,B);
Application appx(A,B,multNone,fftw::maxthreads,0,mx,Dx,Ix);
fftPad fftx(Lx,Mx,appx,Ly,Sx);
bool embed=fftx.embed();
size_t size=embed ? fftx.outputSize() : fftx.inputSize();
Complex **f=ComplexAlign(N,size);
Application appy(A,B,multbinary,appx.Threads(),fftx.l,my,Dy,Iy);
Convolution convolvey(Ly,My,appy);
Convolution2 Convolve2(&fftx,&convolvey,embed ? f : NULL);
// Convolution2 Convolve2(Lx,Mx,Ly,My,A,B);
for(size_t a=0; a < A; ++a) {
Complex *fa=f[a];
for(size_t i=0; i < Lx; ++i) {
for(size_t j=0; j < Ly; ++j) {
fa[Sx*i+j]=Output || testError ? Complex((1.0+a)*i,j+a) : 0.0;
}
}
}
Complex *h=NULL;
if(testError) {
h=ComplexAlign(Lx*Ly);
DirectConvolution2 C(Lx,Ly,Sx);
C.convolve(h,f[0],f[1]);
}
double sum=0.0;
while(sum <= K || T.size() < minCount) {
double t;
if(normalized || testError) {
double t0=nanoseconds();
Convolve2.convolve(f);
t=nanoseconds()-t0;
} else {
double t0=nanoseconds();
Convolve2.convolveRaw(f);
t=nanoseconds()-t0;
}
T.push_back(t);
sum += t;
}
cout << endl;
timings("Hybrid",Lx*Ly,T.data(),T.size(),stats);
cout << endl;
if(Output) {
if(testError)
cout << "Hybrid:" << endl;
for(size_t b=0; b < B; ++b) {
for(size_t i=0; i < Lx; ++i) {
for(size_t j=0; j < Ly; ++j) {
cout << f[b][Sx*i+j] << " ";
}
cout << endl;
}
}
}
if(testError) {
if(Output) {
cout << endl;
cout << "Direct:" << endl;
for(size_t i=0; i < Lx; ++i) {
for(size_t j=0; j < Ly; ++j) {
cout << h[Ly*i+j] << " ";
}
cout << endl;
}
cout << endl;
}
double err=0.0;
double norm=0.0;
// Assumes B=1
for(size_t i=0; i < Lx; ++i) {
for(size_t j=0; j < Ly; ++j) {
Complex hij=h[Ly*i+j];
err += abs2(f[0][Sx*i+j]-hij);
norm += abs2(hij);
}
}
double relError=sqrt(err/norm);
cout << "Error: "<< relError << endl;
deleteAlign(h);
}
return 0;
}