@@ -50,10 +50,11 @@ naive_cross_correlation(sycl::queue& Q,
50
50
}
51
51
52
52
int main (int argc, char ** argv) {
53
- unsigned int N = (argc == 1 ) ? 32 : std::stoi (argv[1 ]);
53
+ const unsigned int N = (argc > 1 ) ? std::stoi (argv[1 ]) : 32 ;
54
54
// N >= 8 required for the arbitrary signals as defined herein
55
- if (N < 8 )
56
- throw std::invalid_argument (" The input value N must be 8 or greater." );
55
+ if (N < 8 || N > INT_MAX)
56
+ throw std::invalid_argument (" The period of the signal, chosen as input of "
57
+ " the program, must be 8 or greater." );
57
58
58
59
// Let s be an integer s.t. 0 <= s < N and let
59
60
// corr[s] = \sum_{j = 0}^{N-1} sig1[j] sig2[(j - s + N) mod N]
@@ -72,12 +73,15 @@ int main(int argc, char** argv) {
72
73
// Initialize signal and correlation arrays. The arrays must be large enough
73
74
// to store the forward and backward domains' data, consisting of N real
74
75
// values and (N/2 + 1) complex values, respectively (for the DFT-based
75
- // calculations).
76
+ // calculations). Note: 2 * (N / 2 + 1) > N for all N > 0, since
77
+ // 2 * (N / 2 + 1) = N + 1 if N is odd
78
+ // 2 * (N / 2 + 1) = N + 2 if N is even
79
+ // so max(N, 2 * (N / 2 + 1)) == 2 * (N / 2 + 1)
76
80
auto sig1 = sycl::malloc_shared<float >(2 * (N / 2 + 1 ), Q);
77
81
auto sig2 = sycl::malloc_shared<float >(2 * (N / 2 + 1 ), Q);
78
82
auto corr = sycl::malloc_shared<float >(2 * (N / 2 + 1 ), Q);
79
83
// Array used for calculating corr without Discrete Fourier Transforms
80
- // ( for comparison purposes):
84
+ // for comparison purposes (calculations entirely done in forward domain ):
81
85
auto naive_corr = sycl::malloc_shared<float >(N, Q);
82
86
83
87
// Initialize input signals with artificial "noise" data (random values of
@@ -113,6 +117,8 @@ int main(int argc, char** argv) {
113
117
// Initialize DFT descriptor
114
118
oneapi::mkl::dft::descriptor<oneapi::mkl::dft::precision::SINGLE,
115
119
oneapi::mkl::dft::domain::REAL> desc (N);
120
+ // oneMKL DFT descriptors use unit scaling factors by default. Explicitly set
121
+ // the non-default scaling factor for the backward ("inverse") DFT:
116
122
desc.set_value (oneapi::mkl::dft::config_param::BACKWARD_SCALE, 1 .0f / N);
117
123
desc.commit (Q);
118
124
// Compute in-place forward transforms of both signals:
0 commit comments