39#include <boost/test/unit_test.hpp>
51static constexpr double TOL = 1.0e-12;
53#if !defined(NEKTAR_ENABLE_SYCL)
63 const double omega = 2.0 * M_PI * k /
N;
64 for (
int n = 0; n <
N; ++n)
65 phys[n] = std::sin(omega * n);
70 const double omega = 2.0 * M_PI * k /
N;
71 for (
int n = 0; n <
N; ++n)
72 phys[n] = std::cos(omega * n);
77 const double omega = 2.0 * M_PI /
N;
78 for (
int i = 0; i < static_cast<int>(arr.size()); ++i)
82 std::sin(3.0 * omega * n) + 0.5 * std::cos(7.0 * omega * n) + 1.0;
87 int skipReal,
int skipImag)
89 for (
int i = 0; i <
N; ++i)
91 if (i == skipReal || i == skipImag)
95 BOOST_CHECK_SMALL(coef[i],
TOL);
103 BOOST_CHECK_NO_THROW(
112 fft->FFTFwdTrans(phys, coef);
113 BOOST_CHECK_SMALL(coef[0] - 3.5,
TOL);
119 for (
const int k : {1, 3})
125 fft->FFTFwdTrans(phys, coef);
126 BOOST_CHECK_SMALL(coef[2 * k],
TOL);
127 BOOST_CHECK_SMALL(coef[2 * k + 1] + 1.0,
TOL);
131 const int N = 16, k = 1;
135 fft->FFTFwdTrans(phys, coef);
136 BOOST_CHECK_SMALL(coef[2 * k] - 1.0,
TOL);
137 BOOST_CHECK_SMALL(coef[2 * k + 1],
TOL);
144 for (
const int N : {16, 64, 256})
149 fft->FFTFwdTrans(phys, coef);
150 fft->FFTBwdTrans(coef, recv);
151 for (
int n = 0; n <
N; ++n)
152 BOOST_CHECK_SMALL(recv[n] - phys[n],
TOL);
162 fft->UploadPhys(phys.data());
163 fft->FFTFwdTransDevice();
164 fft->FFTBwdTransDevice();
165 fft->DownloadPhys(recv.data());
166 for (
int n = 0; n <
N; ++n)
167 BOOST_CHECK_SMALL(recv[n] - phys[n],
TOL);
172 for (
const int M : {2, 8, 32})
179 fft->FFTFwdTrans(phys, coef);
180 fft->FFTBwdTrans(coef, recv);
181 for (
int i = 0; i < M *
N; ++i)
182 BOOST_CHECK_SMALL(recv[i] - phys[i],
TOL);
188 const int N = 64, M = 2;
199#if defined(NEKTAR_ENABLE_SYCL)
204 BOOST_CHECK(!fft->HasGraph());
205 BOOST_CHECK_THROW(fft->BeginGraphCapture(), std::runtime_error);
206 BOOST_CHECK(!fft->HasGraph());
214 BOOST_CHECK_THROW(fft->BeginGraphCapture(), std::runtime_error);
215 BOOST_CHECK(!fft->HasGraph());
220 for (
const int N : {16, 64, 256})
226 fft->UploadPhys(phys.data());
227 fft->FFTFwdTransDevice();
228 fft->FFTBwdTransDevice();
229 fft->DownloadPhys(ref.data());
230 fft->BeginGraphCapture();
231 fft->FFTFwdTransDevice();
232 fft->FFTBwdTransDevice();
233 fft->EndGraphCapture();
234 for (
int rep = 0; rep < 3; ++rep)
236 fft->UploadPhys(phys.data());
238 fft->DownloadPhys(recv.data());
239 for (
int n = 0; n <
N; ++n)
240 BOOST_CHECK_SMALL(recv[n] - ref[n],
TOL);
252 BOOST_CHECK_THROW(fft->LaunchGraph(), std::runtime_error);
259 BOOST_CHECK_NO_THROW(
268 fft->FFTFwdTrans(phys, coef);
269 BOOST_CHECK_SMALL(coef[0] - 3.5f, 1.0e-5f);
270 for (
int i = 1; i <
N; ++i)
271 BOOST_CHECK_SMALL(coef[i], 1.0e-5f);
276 for (
const int N : {16, 64, 256})
280 const float omega = 2.0f *
static_cast<float>(M_PI) /
N;
281 for (
int i = 0; i <
N; ++i)
282 phys[i] = std::sin(3.0f * omega * i) +
283 0.5f * std::cos(7.0f * omega * i) + 1.0f;
284 fft->FFTFwdTrans(phys, coef);
285 fft->FFTBwdTrans(coef, recv);
286 for (
int n = 0; n <
N; ++n)
287 BOOST_CHECK_SMALL(recv[n] - phys[n], 1.0e-5f);
293 const int N = 64, M = 8;
296 const float omega = 2.0f *
static_cast<float>(M_PI) /
N;
297 for (
int i = 0; i < M *
N; ++i)
300 phys[i] = std::sin(3.0f * omega * n) +
301 0.5f * std::cos(7.0f * omega * n) + 1.0f;
303 fft->FFTFwdTrans(phys, coef);
304 fft->FFTBwdTrans(coef, recv);
305 for (
int i = 0; i < M *
N; ++i)
306 BOOST_CHECK_SMALL(recv[i] - phys[i], 1.0e-5f);
311 const int N = 16, k = 3;
314 const float omega = 2.0f *
static_cast<float>(M_PI) * k /
N;
315 for (
int n = 0; n <
N; ++n)
316 phys[n] = std::sin(omega * n);
317 fft->FFTFwdTrans(phys, coef);
318 BOOST_CHECK_SMALL(coef[2 * k], 1.0e-5f);
319 BOOST_CHECK_SMALL(coef[2 * k + 1] + 1.0f, 1.0e-5f);
320 for (
int i = 0; i <
N; ++i)
321 if (i != 2 * k && i != 2 * k + 1)
322 BOOST_CHECK_SMALL(coef[i], 1.0e-5f);
330 const float omega = 2.0f *
static_cast<float>(M_PI) /
N;
331 for (
int i = 0; i <
N; ++i)
332 phys[i] = std::sin(3.0f * omega * i) + 1.0f;
333 fft->UploadPhys(phys.data());
334 fft->FFTFwdTransDevice();
335 fft->FFTBwdTransDevice();
336 fft->DownloadPhys(recv.data());
337 for (
int n = 0; n <
N; ++n)
338 BOOST_CHECK_SMALL(recv[n] - phys[n], 1.0e-5f);
341#if !defined(NEKTAR_ENABLE_SYCL)
349 const float omega = 2.0f *
static_cast<float>(M_PI) /
N;
350 for (
int i = 0; i <
N; ++i)
351 phys[i] = std::sin(3.0f * omega * i) + 1.0f;
352 fft->UploadPhys(phys.data());
353 fft->FFTFwdTransDevice();
354 fft->FFTBwdTransDevice();
355 fft->DownloadPhys(ref.data());
356 fft->BeginGraphCapture();
357 fft->FFTFwdTransDevice();
358 fft->FFTBwdTransDevice();
359 fft->EndGraphCapture();
360 for (
int rep = 0; rep < 3; ++rep)
362 fft->UploadPhys(phys.data());
364 fft->DownloadPhys(recv.data());
365 for (
int n = 0; n <
N; ++n)
366 BOOST_CHECK_SMALL(recv[n] - ref[n], 1.0e-5f);
static bool IsCacheWarmed(int deviceId, int N, int M)
Return true if the plan cache has been warmed up for the given device, transform size,...
static std::shared_ptr< DataType > AllocateSharedPtr(const Args &...args)
Allocate a shared pointer from the memory pool.
static constexpr double TOL
static constexpr unsigned int GRAPH_STREAM_ID
static void FillSignal(Array< OneD, double > &arr, int N)
BOOST_AUTO_TEST_CASE(TestFactoryRegistration)
static void FillCosine(Array< OneD, double > &phys, int N, int k)
static void FillSine(Array< OneD, double > &phys, int N, int k)
static void CheckOtherModesZero(const Array< OneD, double > &coef, int N, int skipReal, int skipImag)
NektarFFTFactory & GetNektarFFTFactory()
NektarFFTFloatFactory & GetNektarFFTFloatFactory()
static unsigned int nekGetDevice()