forked from kokkos/kokkos-fft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKokkosFFT_Transform.hpp
604 lines (543 loc) · 26.6 KB
/
KokkosFFT_Transform.hpp
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
// SPDX-FileCopyrightText: (C) The Kokkos-FFT development team, see COPYRIGHT.md file
//
// SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
#ifndef KOKKOSFFT_TRANSFORM_HPP
#define KOKKOSFFT_TRANSFORM_HPP
#include <Kokkos_Core.hpp>
#include "KokkosFFT_default_types.hpp"
#include "KokkosFFT_traits.hpp"
#include "KokkosFFT_utils.hpp"
#include "KokkosFFT_normalization.hpp"
#include "KokkosFFT_transpose.hpp"
#include "KokkosFFT_padding.hpp"
#include "KokkosFFT_Plans.hpp"
#if defined(KOKKOS_ENABLE_CUDA)
#include "KokkosFFT_Cuda_transform.hpp"
#ifdef ENABLE_HOST_AND_DEVICE
#include "KokkosFFT_Host_transform.hpp"
#endif
#elif defined(KOKKOS_ENABLE_HIP)
#if defined(KOKKOSFFT_ENABLE_TPL_ROCFFT)
#include "KokkosFFT_ROCM_transform.hpp"
#else
#include "KokkosFFT_HIP_transform.hpp"
#endif
#ifdef ENABLE_HOST_AND_DEVICE
#include "KokkosFFT_Host_transform.hpp"
#endif
#elif defined(KOKKOS_ENABLE_SYCL)
#include "KokkosFFT_SYCL_transform.hpp"
#ifdef ENABLE_HOST_AND_DEVICE
#include "KokkosFFT_Host_transform.hpp"
#endif
#elif defined(KOKKOS_ENABLE_OPENMP)
#include "KokkosFFT_Host_transform.hpp"
#elif defined(KOKKOS_ENABLE_THREADS)
#include "KokkosFFT_Host_transform.hpp"
#else
#include "KokkosFFT_Host_transform.hpp"
#endif
#include <type_traits>
// General Transform Interface
namespace KokkosFFT {
namespace Impl {
template <typename PlanType, typename InViewType, typename OutViewType>
void exec_impl(
const PlanType& plan, const InViewType& in, OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward) {
using in_value_type = typename InViewType::non_const_value_type;
using out_value_type = typename OutViewType::non_const_value_type;
using ExecutionSpace = typename PlanType::execSpace;
auto* idata = reinterpret_cast<typename KokkosFFT::Impl::fft_data_type<
ExecutionSpace, in_value_type>::type*>(in.data());
auto* odata = reinterpret_cast<typename KokkosFFT::Impl::fft_data_type<
ExecutionSpace, out_value_type>::type*>(out.data());
auto const exec_space = plan.exec_space();
auto const direction = direction_type<ExecutionSpace>(plan.direction());
KokkosFFT::Impl::exec_plan(plan.plan(), idata, odata, direction, plan.info());
KokkosFFT::Impl::normalize(exec_space, out, plan.direction(), norm,
plan.fft_size());
}
template <typename PlanType, typename InViewType, typename OutViewType>
void fft_exec_impl(
const PlanType& plan, const InViewType& in, OutViewType& out,
// KokkosFFT::Direction direction,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward) {
using ExecutionSpace = typename PlanType::execSpace;
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"fft_exec_impl: InViewType and OutViewType must have the same base "
"floating point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
plan.template good<InViewType, OutViewType>(in, out);
const auto exec_space = plan.exec_space();
using ManagableInViewType =
typename KokkosFFT::Impl::managable_view_type<InViewType>::type;
using ManagableOutViewType =
typename KokkosFFT::Impl::managable_view_type<OutViewType>::type;
ManagableInViewType _in_s;
InViewType _in;
if (plan.is_crop_or_pad_needed()) {
auto new_shape = plan.shape();
KokkosFFT::Impl::crop_or_pad(exec_space, in, _in_s, new_shape);
_in = _in_s;
} else {
_in = in;
}
if (plan.is_transpose_needed()) {
ManagableInViewType in_T;
ManagableOutViewType out_T;
KokkosFFT::Impl::transpose(exec_space, _in, in_T, plan.map());
KokkosFFT::Impl::transpose(exec_space, out, out_T, plan.map());
KokkosFFT::Impl::exec_impl(plan, in_T, out_T, norm);
KokkosFFT::Impl::transpose(exec_space, out_T, out, plan.map_inv());
} else {
KokkosFFT::Impl::exec_impl(plan, _in, out, norm);
}
}
} // namespace Impl
} // namespace KokkosFFT
namespace KokkosFFT {
/// \brief One dimensional FFT in forward direction
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (complex)
/// \param out [out] Ouput data (complex)
/// \param norm [in] How the normalization is applied (optional)
/// \param axis [in] Axis over which FFT is performed (optional)
/// \param n [in] Length of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void fft(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
int axis = -1, std::optional<std::size_t> n = std::nullopt) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"fft: InViewType and OutViewType must have the same base floating point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(InViewType::rank() >= 1,
"fft: View rank must be larger than or equal to 1");
KokkosFFT::Impl::Plan plan(exec_space, in, out, KokkosFFT::Direction::forward,
axis, n);
KokkosFFT::Impl::fft_exec_impl(plan, in, out, norm);
}
/// \brief One dimensional FFT in backward direction
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (complex)
/// \param out [out] Ouput data (complex)
/// \param norm [in] How the normalization is applied (optional)
/// \param axis [in] Axis over which FFT is performed (optional)
/// \param n [in] Length of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void ifft(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
int axis = -1, std::optional<std::size_t> n = std::nullopt) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"ifft: InViewType and OutViewType must have the same base floating point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(InViewType::rank() >= 1,
"ifft: View rank must be larger than or equal to 1");
KokkosFFT::Impl::Plan plan(exec_space, in, out,
KokkosFFT::Direction::backward, axis, n);
KokkosFFT::Impl::fft_exec_impl(plan, in, out, norm);
}
/// \brief One dimensional FFT for real input
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (real)
/// \param out [out] Ouput data (complex)
/// \param norm [in] How the normalization is applied (optional)
/// \param axis [in] Axis over which FFT is performed (optional)
/// \param n [in] Length of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void rfft(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
int axis = -1, std::optional<std::size_t> n = std::nullopt) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"rfft: InViewType and OutViewType must have the same base floating point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(InViewType::rank() >= 1,
"rfft: View rank must be larger than or equal to 1");
using in_value_type = typename InViewType::non_const_value_type;
using out_value_type = typename OutViewType::non_const_value_type;
static_assert(KokkosFFT::Impl::is_real_v<in_value_type>,
"rfft: InViewType must be real");
static_assert(KokkosFFT::Impl::is_complex_v<out_value_type>,
"rfft: OutViewType must be complex");
fft(exec_space, in, out, norm, axis, n);
}
/// \brief Inverse of rfft
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (complex)
/// \param out [out] Ouput data (real)
/// \param norm [in] How the normalization is applied (optional)
/// \param axis [in] Axis over which FFT is performed (optional)
/// \param n [in] Length of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void irfft(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
int axis = -1, std::optional<std::size_t> n = std::nullopt) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"irfft: InViewType and OutViewType must have the same base floating "
"point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(InViewType::rank() >= 1,
"irfft: View rank must be larger than or equal to 1");
using in_value_type = typename InViewType::non_const_value_type;
using out_value_type = typename OutViewType::non_const_value_type;
static_assert(KokkosFFT::Impl::is_complex_v<in_value_type>,
"irfft: InViewType must be complex");
static_assert(KokkosFFT::Impl::is_real_v<out_value_type>,
"irfft: OutViewType must be real");
ifft(exec_space, in, out, norm, axis, n);
}
/// \brief One dimensional FFT of a signal that has Hermitian symmetry
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (complex)
/// \param out [out] Ouput data (real)
/// \param norm [in] How the normalization is applied (optional)
/// \param axis [in] Axis over which FFT is performed (optional)
/// \param n [in] Length of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void hfft(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
int axis = -1, std::optional<std::size_t> n = std::nullopt) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"hfft: InViewType and OutViewType must have the same base floating point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(InViewType::rank() >= 1,
"hfft: View rank must be larger than or equal to 1");
// [TO DO]
// allow real type as input, need to obtain complex view type from in view
// type
using in_value_type = typename InViewType::non_const_value_type;
using out_value_type = typename OutViewType::non_const_value_type;
static_assert(KokkosFFT::Impl::is_complex_v<in_value_type>,
"hfft: InViewType must be complex");
static_assert(KokkosFFT::Impl::is_real_v<out_value_type>,
"hfft: OutViewType must be real");
auto new_norm = KokkosFFT::Impl::swap_direction(norm);
// using ComplexViewType = typename
// KokkosFFT::Impl::complex_view_type<ExecutionSpace, InViewType>::type;
// ComplexViewType in_conj;
InViewType in_conj;
KokkosFFT::Impl::conjugate(exec_space, in, in_conj);
irfft(exec_space, in_conj, out, new_norm, axis, n);
}
/// \brief Inverse of hfft
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (real)
/// \param out [out] Ouput data (complex)
/// \param norm [in] How the normalization is applied (optional)
/// \param axis [in] Axis over which FFT is performed (optional)
/// \param n [in] Length of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void ihfft(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
int axis = -1, std::optional<std::size_t> n = std::nullopt) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"ihfft: InViewType and OutViewType must have the same base floating "
"point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(InViewType::rank() >= 1,
"ihfft: View rank must be larger than or equal to 1");
using in_value_type = typename InViewType::non_const_value_type;
using out_value_type = typename OutViewType::non_const_value_type;
static_assert(KokkosFFT::Impl::is_real_v<in_value_type>,
"ihfft: InViewType must be real");
static_assert(KokkosFFT::Impl::is_complex_v<out_value_type>,
"ihfft: OutViewType must be complex");
auto new_norm = KokkosFFT::Impl::swap_direction(norm);
OutViewType out_conj;
rfft(exec_space, in, out, new_norm, axis, n);
KokkosFFT::Impl::conjugate(exec_space, out, out_conj);
out = out_conj;
}
// 2D FFT
/// \brief Two dimensional FFT in forward direction
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (complex)
/// \param out [out] Ouput data (complex)
/// \param norm [in] How the normalization is applied (optional)
/// \param axes [in] Axes over which FFT is performed (optional)
/// \param s [in] Shape of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void fft2(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
axis_type<2> axes = {-2, -1}, shape_type<2> s = {0}) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"fft2: InViewType and OutViewType must have the same base floating point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(InViewType::rank() >= 2,
"fft2: View rank must be larger than or equal to 2");
KokkosFFT::Impl::Plan plan(exec_space, in, out, KokkosFFT::Direction::forward,
axes, s);
KokkosFFT::Impl::fft_exec_impl(plan, in, out, norm);
}
/// \brief Two dimensional FFT in backward direction
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (complex)
/// \param out [out] Ouput data (complex)
/// \param norm [in] How the normalization is applied (optional)
/// \param axes [in] Axes over which FFT is performed (optional)
/// \param s [in] Shape of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void ifft2(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
axis_type<2> axes = {-2, -1}, shape_type<2> s = {0}) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"ifft2: InViewType and OutViewType must have the same base floating "
"point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(InViewType::rank() >= 2,
"ifft2: View rank must be larger than or equal to 2");
KokkosFFT::Impl::Plan plan(exec_space, in, out,
KokkosFFT::Direction::backward, axes, s);
KokkosFFT::Impl::fft_exec_impl(plan, in, out, norm);
}
/// \brief Two dimensional FFT for real input
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (real)
/// \param out [out] Ouput data (complex)
/// \param norm [in] How the normalization is applied (optional)
/// \param axes [in] Axes over which FFT is performed (optional)
/// \param s [in] Shape of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void rfft2(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
axis_type<2> axes = {-2, -1}, shape_type<2> s = {0}) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"rfft2: InViewType and OutViewType must have the same base floating "
"point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(InViewType::rank() >= 2,
"rfft2: View rank must be larger than or equal to 2");
using in_value_type = typename InViewType::non_const_value_type;
using out_value_type = typename OutViewType::non_const_value_type;
static_assert(KokkosFFT::Impl::is_real_v<in_value_type>,
"rfft2: InViewType must be real");
static_assert(KokkosFFT::Impl::is_complex_v<out_value_type>,
"rfft2: OutViewType must be complex");
fft2(exec_space, in, out, norm, axes, s);
}
/// \brief Inverse of rfft2 with a given plan
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (complex)
/// \param out [out] Ouput data (real)
/// \param norm [in] How the normalization is applied (optional)
/// \param axes [in] Axes over which FFT is performed (optional)
/// \param s [in] Shape of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType>
void irfft2(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
axis_type<2> axes = {-2, -1}, shape_type<2> s = {0}) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"irfft2: InViewType and OutViewType must have the same base floating "
"point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(InViewType::rank() >= 2,
"irfft2: View rank must be larger than or equal to 2");
using in_value_type = typename InViewType::non_const_value_type;
using out_value_type = typename OutViewType::non_const_value_type;
static_assert(KokkosFFT::Impl::is_complex_v<in_value_type>,
"irfft2: InViewType must be complex");
static_assert(KokkosFFT::Impl::is_real_v<out_value_type>,
"irfft2: OutViewType must be real");
ifft2(exec_space, in, out, norm, axes, s);
}
// ND FFT
/// \brief N-dimensional FFT in forward direction with a given plan
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (complex)
/// \param out [out] Ouput data (complex)
/// \param axes [in] Axes over which FFT is performed
/// \param norm [in] How the normalization is applied (optional)
/// \param s [in] Shape of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType,
std::size_t DIM = 1>
void fftn(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, axis_type<DIM> axes,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
shape_type<DIM> s = {0}) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"fftn: InViewType and OutViewType must have the same base floating point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(DIM >= 1 && DIM <= KokkosFFT::MAX_FFT_DIM,
"fftn: the Rank of FFT axes must be between 1 and MAX_FFT_DIM");
static_assert(
InViewType::rank() >= DIM,
"fftn: View rank must be larger than or equal to the Rank of FFT axes");
KokkosFFT::Impl::Plan plan(exec_space, in, out, KokkosFFT::Direction::forward,
axes, s);
KokkosFFT::Impl::fft_exec_impl(plan, in, out, norm);
}
/// \brief N-dimensional FFT in backward direction with a given plan
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (complex)
/// \param out [out] Ouput data (complex)
/// \param axes [in] Axes over which FFT is performed
/// \param norm [in] How the normalization is applied (optional)
/// \param s [in] Shape of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType,
std::size_t DIM = 1>
void ifftn(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, axis_type<DIM> axes,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
shape_type<DIM> s = {0}) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"ifftn: InViewType and OutViewType must have the same base floating "
"point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(
DIM >= 1 && DIM <= KokkosFFT::MAX_FFT_DIM,
"ifftn: the Rank of FFT axes must be between 1 and MAX_FFT_DIM");
static_assert(
InViewType::rank() >= DIM,
"ifftn: View rank must be larger than or equal to the Rank of FFT axes");
KokkosFFT::Impl::Plan plan(exec_space, in, out,
KokkosFFT::Direction::backward, axes, s);
KokkosFFT::Impl::fft_exec_impl(plan, in, out, norm);
}
/// \brief N-dimensional FFT for real input
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (real)
/// \param out [out] Ouput data (complex)
/// \param axes [in] Axes over which FFT is performed
/// \param norm [in] How the normalization is applied (optional)
/// \param s [in] Shape of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType,
std::size_t DIM = 1>
void rfftn(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, axis_type<DIM> axes,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
shape_type<DIM> s = {0}) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"rfftn: InViewType and OutViewType must have the same base floating "
"point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(
DIM >= 1 && DIM <= KokkosFFT::MAX_FFT_DIM,
"rfftn: the Rank of FFT axes must be between 1 and MAX_FFT_DIM");
static_assert(
InViewType::rank() >= DIM,
"rfftn: View rank must be larger than or equal to the Rank of FFT axes");
using in_value_type = typename InViewType::non_const_value_type;
using out_value_type = typename OutViewType::non_const_value_type;
static_assert(KokkosFFT::Impl::is_real_v<in_value_type>,
"rfftn: InViewType must be real");
static_assert(KokkosFFT::Impl::is_complex_v<out_value_type>,
"rfftn: OutViewType must be complex");
fftn(exec_space, in, out, axes, norm, s);
}
/// \brief Inverse of rfftn
///
/// \param exec_space [in] Kokkos execution space
/// \param in [in] Input data (complex)
/// \param out [out] Ouput data (real)
/// \param axes [in] Axes over which FFT is performed
/// \param norm [in] How the normalization is applied (optional)
/// \param s [in] Shape of the transformed axis of the output (optional)
template <typename ExecutionSpace, typename InViewType, typename OutViewType,
std::size_t DIM = 1>
void irfftn(const ExecutionSpace& exec_space, const InViewType& in,
OutViewType& out, axis_type<DIM> axes,
KokkosFFT::Normalization norm = KokkosFFT::Normalization::backward,
shape_type<DIM> s = {0}) {
static_assert(
KokkosFFT::Impl::are_operatable_views_v<ExecutionSpace, InViewType,
OutViewType>,
"irfftn: InViewType and OutViewType must have the same base floating "
"point "
"type (float/double), the same layout (LayoutLeft/LayoutRight), and the "
"same rank. ExecutionSpace must be accessible to the data in InViewType "
"and OutViewType.");
static_assert(
DIM >= 1 && DIM <= KokkosFFT::MAX_FFT_DIM,
"irfftn: the Rank of FFT axes must be between 1 and MAX_FFT_DIM");
static_assert(
InViewType::rank() >= DIM,
"irfftn: View rank must be larger than or equal to the Rank of FFT axes");
using in_value_type = typename InViewType::non_const_value_type;
using out_value_type = typename OutViewType::non_const_value_type;
static_assert(KokkosFFT::Impl::is_complex_v<in_value_type>,
"irfftn: InViewType must be complex");
static_assert(KokkosFFT::Impl::is_real_v<out_value_type>,
"irfftn: OutViewType must be real");
ifftn(exec_space, in, out, axes, norm, s);
}
} // namespace KokkosFFT
#endif