Nektar++
Loading...
Searching...
No Matches
Functions | Variables
Nektar::DeviceFFTUnitTests Namespace Reference

Functions

static void FillSine (Array< OneD, double > &phys, int N, int k)
 
static void FillCosine (Array< OneD, double > &phys, int N, int k)
 
static void FillSignal (Array< OneD, double > &arr, int N)
 
static void CheckOtherModesZero (const Array< OneD, double > &coef, int N, int skipReal, int skipImag)
 
 BOOST_AUTO_TEST_CASE (TestFactoryRegistration)
 
 BOOST_AUTO_TEST_CASE (TestDCSignal)
 
 BOOST_AUTO_TEST_CASE (TestSineCosineMode)
 
 BOOST_AUTO_TEST_CASE (TestRoundTrip)
 
 BOOST_AUTO_TEST_CASE (TestRoundTripDeviceResident)
 
 BOOST_AUTO_TEST_CASE (TestBatchedRoundTrip)
 
 BOOST_AUTO_TEST_CASE (TestPlanCacheIsPopulated)
 
 BOOST_AUTO_TEST_CASE (TestGraphCaptureDefaultStream)
 
 BOOST_AUTO_TEST_CASE (TestGraphRoundTrip)
 
 BOOST_AUTO_TEST_CASE (TestLaunchGraphWithoutCapture)
 
 BOOST_AUTO_TEST_CASE (TestFloatFactoryRegistration)
 
 BOOST_AUTO_TEST_CASE (TestFloatDCSignal)
 
 BOOST_AUTO_TEST_CASE (TestFloatRoundTrip)
 
 BOOST_AUTO_TEST_CASE (TestFloatBatchedRoundTrip)
 
 BOOST_AUTO_TEST_CASE (TestFloatSineCosineMode)
 
 BOOST_AUTO_TEST_CASE (TestFloatRoundTripDeviceResident)
 
 BOOST_AUTO_TEST_CASE (TestFloatGraphRoundTrip)
 

Variables

static constexpr double TOL = 1.0e-12
 
static constexpr unsigned int GRAPH_STREAM_ID = 1
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestBatchedRoundTrip  )

Definition at line 170 of file TestDeviceFFT.cpp.

171{
172 for (const int M : {2, 8, 32})
173 {
174 const int N = 64;
176 Array<OneD, double> phys(M * N, 0.0), coef(M * N, 0.0),
177 recv(M * N, 0.0);
178 FillSignal(phys, N);
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);
183 }
184}
#define TOL
#define N
General purpose memory allocation routines with the ability to allocate from thread specific memory p...

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), FillSignal(), N, and TOL.

◆ BOOST_AUTO_TEST_CASE() [2/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestDCSignal  )

Definition at line 107 of file TestDeviceFFT.cpp.

108{
109 const int N = 16;
111 Array<OneD, double> phys(N, 3.5), coef(N, 0.0);
112 fft->FFTFwdTrans(phys, coef);
113 BOOST_CHECK_SMALL(coef[0] - 3.5, TOL);
114 CheckOtherModesZero(coef, N, 0, -1);
115}
static void CheckOtherModesZero(const Array< OneD, double > &coef, int N, int skipReal, int skipImag)

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), CheckOtherModesZero(), N, and TOL.

◆ BOOST_AUTO_TEST_CASE() [3/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestFactoryRegistration  )

Definition at line 101 of file TestDeviceFFT.cpp.

102{
103 BOOST_CHECK_NO_THROW(
104 GetNektarFFTFactory().CreateInstance("NekDeviceFFT", 16));
105}
NektarFFTFactory & GetNektarFFTFactory()
Definition NektarFFT.cpp:40

References Nektar::LibUtilities::GetNektarFFTFactory().

◆ BOOST_AUTO_TEST_CASE() [4/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestFloatBatchedRoundTrip  )

Definition at line 291 of file TestDeviceFFT.cpp.

292{
293 const int N = 64, M = 8;
295 Array<OneD, float> phys(M * N, 0.0f), coef(M * N, 0.0f), recv(M * N, 0.0f);
296 const float omega = 2.0f * static_cast<float>(M_PI) / N;
297 for (int i = 0; i < M * N; ++i)
298 {
299 const int n = i % N;
300 phys[i] = std::sin(3.0f * omega * n) +
301 0.5f * std::cos(7.0f * omega * n) + 1.0f;
302 }
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);
307}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and N.

◆ BOOST_AUTO_TEST_CASE() [5/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestFloatDCSignal  )

Definition at line 263 of file TestDeviceFFT.cpp.

264{
265 const int N = 16;
267 Array<OneD, float> phys(N, 3.5f), coef(N, 0.0f);
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);
272}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and N.

◆ BOOST_AUTO_TEST_CASE() [6/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestFloatFactoryRegistration  )

Definition at line 257 of file TestDeviceFFT.cpp.

258{
259 BOOST_CHECK_NO_THROW(
260 GetNektarFFTFloatFactory().CreateInstance("NekDeviceFFT", 16));
261}
NektarFFTFloatFactory & GetNektarFFTFloatFactory()
Definition NektarFFT.cpp:46

References Nektar::LibUtilities::GetNektarFFTFloatFactory().

◆ BOOST_AUTO_TEST_CASE() [7/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestFloatGraphRoundTrip  )

Definition at line 343 of file TestDeviceFFT.cpp.

344{
345 const int N = 64;
347 N, 1, GRAPH_STREAM_ID);
348 Array<OneD, float> phys(N, 0.0f), ref(N, 0.0f), recv(N, 0.0f);
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)
361 {
362 fft->UploadPhys(phys.data());
363 fft->LaunchGraph();
364 fft->DownloadPhys(recv.data());
365 for (int n = 0; n < N; ++n)
366 BOOST_CHECK_SMALL(recv[n] - ref[n], 1.0e-5f);
367 }
368}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), GRAPH_STREAM_ID, and N.

◆ BOOST_AUTO_TEST_CASE() [8/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestFloatRoundTrip  )

Definition at line 274 of file TestDeviceFFT.cpp.

275{
276 for (const int N : {16, 64, 256})
277 {
279 Array<OneD, float> phys(N, 0.0f), coef(N, 0.0f), recv(N, 0.0f);
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);
288 }
289}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and N.

◆ BOOST_AUTO_TEST_CASE() [9/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestFloatRoundTripDeviceResident  )

Definition at line 325 of file TestDeviceFFT.cpp.

326{
327 const int N = 64;
329 Array<OneD, float> phys(N, 0.0f), recv(N, 0.0f);
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);
339}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and N.

◆ BOOST_AUTO_TEST_CASE() [10/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestFloatSineCosineMode  )

Definition at line 309 of file TestDeviceFFT.cpp.

310{
311 const int N = 16, k = 3;
313 Array<OneD, float> phys(N, 0.0f), coef(N, 0.0f);
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);
323}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), and N.

◆ BOOST_AUTO_TEST_CASE() [11/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestGraphCaptureDefaultStream  )

Definition at line 211 of file TestDeviceFFT.cpp.

212{
214 BOOST_CHECK_THROW(fft->BeginGraphCapture(), std::runtime_error);
215 BOOST_CHECK(!fft->HasGraph());
216}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ BOOST_AUTO_TEST_CASE() [12/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestGraphRoundTrip  )

Definition at line 218 of file TestDeviceFFT.cpp.

219{
220 for (const int N : {16, 64, 256})
221 {
223 N, 1, GRAPH_STREAM_ID);
224 Array<OneD, double> phys(N, 0.0), ref(N, 0.0), recv(N, 0.0);
225 FillSignal(phys, N);
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)
235 {
236 fft->UploadPhys(phys.data());
237 fft->LaunchGraph();
238 fft->DownloadPhys(recv.data());
239 for (int n = 0; n < N; ++n)
240 BOOST_CHECK_SMALL(recv[n] - ref[n], TOL);
241 }
242 }
243}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), FillSignal(), GRAPH_STREAM_ID, N, and TOL.

◆ BOOST_AUTO_TEST_CASE() [13/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestLaunchGraphWithoutCapture  )

Definition at line 249 of file TestDeviceFFT.cpp.

250{
252 BOOST_CHECK_THROW(fft->LaunchGraph(), std::runtime_error);
253}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr().

◆ BOOST_AUTO_TEST_CASE() [14/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestPlanCacheIsPopulated  )

Definition at line 186 of file TestDeviceFFT.cpp.

187{
188 const int N = 64, M = 2;
189 {
191 }
192 int deviceId = Nektar::nekGetDevice();
193 BOOST_CHECK(NekDeviceFFT::IsCacheWarmed(deviceId, N, M));
194}
static unsigned int nekGetDevice()
Definition Backends.hpp:380

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), Nektar::LibUtilities::NekDeviceFFTImpl< TData >::IsCacheWarmed(), N, and Nektar::nekGetDevice().

◆ BOOST_AUTO_TEST_CASE() [15/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestRoundTrip  )

Definition at line 142 of file TestDeviceFFT.cpp.

143{
144 for (const int N : {16, 64, 256})
145 {
147 Array<OneD, double> phys(N, 0.0), coef(N, 0.0), recv(N, 0.0);
148 FillSignal(phys, N);
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);
153 }
154}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), FillSignal(), N, and TOL.

◆ BOOST_AUTO_TEST_CASE() [16/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestRoundTripDeviceResident  )

Definition at line 156 of file TestDeviceFFT.cpp.

157{
158 const int N = 64;
160 Array<OneD, double> phys(N, 0.0), recv(N, 0.0);
161 FillSignal(phys, N);
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);
168}
static void FillSignal(Array< OneD, double > &arr, int N)

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), FillSignal(), N, and TOL.

◆ BOOST_AUTO_TEST_CASE() [17/17]

Nektar::DeviceFFTUnitTests::BOOST_AUTO_TEST_CASE ( TestSineCosineMode  )

Definition at line 117 of file TestDeviceFFT.cpp.

118{
119 for (const int k : {1, 3})
120 {
121 const int N = 16;
123 Array<OneD, double> phys(N, 0.0), coef(N, 0.0);
124 FillSine(phys, N, k);
125 fft->FFTFwdTrans(phys, coef);
126 BOOST_CHECK_SMALL(coef[2 * k], TOL);
127 BOOST_CHECK_SMALL(coef[2 * k + 1] + 1.0, TOL);
128 CheckOtherModesZero(coef, N, 2 * k, 2 * k + 1);
129 }
130 {
131 const int N = 16, k = 1;
132 auto fft = MemoryManager<NekDeviceFFT>::AllocateSharedPtr(N, 1);
133 Array<OneD, double> phys(N, 0.0), coef(N, 0.0);
134 FillCosine(phys, N, k);
135 fft->FFTFwdTrans(phys, coef);
136 BOOST_CHECK_SMALL(coef[2 * k] - 1.0, TOL);
137 BOOST_CHECK_SMALL(coef[2 * k + 1], TOL);
138 CheckOtherModesZero(coef, N, 2 * k, 2 * k + 1);
139 }
140}

References Nektar::MemoryManager< DataType >::AllocateSharedPtr(), CheckOtherModesZero(), FillCosine(), FillSine(), N, and TOL.

◆ CheckOtherModesZero()

static void Nektar::DeviceFFTUnitTests::CheckOtherModesZero ( const Array< OneD, double > &  coef,
int  N,
int  skipReal,
int  skipImag 
)
static

Definition at line 86 of file TestDeviceFFT.cpp.

88{
89 for (int i = 0; i < N; ++i)
90 {
91 if (i == skipReal || i == skipImag)
92 {
93 continue;
94 }
95 BOOST_CHECK_SMALL(coef[i], TOL);
96 }
97}

References N, and TOL.

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ FillCosine()

static void Nektar::DeviceFFTUnitTests::FillCosine ( Array< OneD, double > &  phys,
int  N,
int  k 
)
static

Definition at line 68 of file TestDeviceFFT.cpp.

69{
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);
73}

References N.

Referenced by BOOST_AUTO_TEST_CASE().

◆ FillSignal()

static void Nektar::DeviceFFTUnitTests::FillSignal ( Array< OneD, double > &  arr,
int  N 
)
static

Definition at line 75 of file TestDeviceFFT.cpp.

76{
77 const double omega = 2.0 * M_PI / N;
78 for (int i = 0; i < static_cast<int>(arr.size()); ++i)
79 {
80 const int n = i % N;
81 arr[i] =
82 std::sin(3.0 * omega * n) + 0.5 * std::cos(7.0 * omega * n) + 1.0;
83 }
84}

References N.

Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ FillSine()

static void Nektar::DeviceFFTUnitTests::FillSine ( Array< OneD, double > &  phys,
int  N,
int  k 
)
static

Definition at line 61 of file TestDeviceFFT.cpp.

62{
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);
66}

References N.

Referenced by BOOST_AUTO_TEST_CASE().

Variable Documentation

◆ GRAPH_STREAM_ID

constexpr unsigned int Nektar::DeviceFFTUnitTests::GRAPH_STREAM_ID = 1
staticconstexpr

Definition at line 56 of file TestDeviceFFT.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().

◆ TOL

constexpr double Nektar::DeviceFFTUnitTests::TOL = 1.0e-12
staticconstexpr