| 1 |
/* |
| 2 |
* (C) Copyright 2025- ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#include "FFT.h" |
| 12 |
|
| 13 |
#include <cstdlib> |
| 14 |
|
| 15 |
#include "atlas/library/defines.h" |
| 16 |
|
| 17 |
|
| 18 |
#if ATLAS_HAVE_POCKETFFT |
| 19 |
|
| 20 |
#include "atlas/parallel/omp/omp.h" |
| 21 |
#include "atlas/runtime/Trace.h" |
| 22 |
|
| 23 |
ATLAS_SUPPRESS_WARNINGS_PUSH |
| 24 |
ATLAS_SUPPRESS_WARNINGS_BOTH_INLINE_NOINLINE |
| 25 |
#define POCKETFFT_CACHE_SIZE 4000 |
| 26 |
// POCKETFFT_CACHE_SIZE should keep O8000 grid fft's in cache |
| 27 |
#include "pocketfft_hdronly.h" |
| 28 |
ATLAS_SUPPRESS_WARNINGS_PUSH |
| 29 |
|
| 30 |
namespace atlas::linalg { |
| 31 |
|
| 32 |
void pocketfft::do_plan_inverse_c2r(size_t /*size_out*/, std::complex<double>* /*in*/, double* /*out*/) const {} |
| 33 |
void pocketfft::do_plan_inverse_c2r_many(size_t /*howmany*/, size_t /*size_in*/, size_t /*size_out*/, size_t /*dist_in*/, size_t /*dist_out*/, std::complex<double>* /*in*/, double* /*out*/) const {} |
| 34 |
void pocketfft::do_inverse_c2r(const size_t size_out, std::complex<double>* in, double* out) const { |
| 35 |
ATLAS_TRACE("pocketfft::inverse_c2r"); |
| 36 |
static const ::pocketfft::stride_t stride_in{sizeof(std::complex<double>)}; // in bytes |
| 37 |
static const ::pocketfft::stride_t stride_out{sizeof(double)}; // in bytes |
| 38 |
constexpr size_t axis = 0; |
| 39 |
constexpr double fct = 1.0; |
| 40 |
constexpr size_t nthreads = 1; |
| 41 |
constexpr bool direction = ::pocketfft::BACKWARD; |
| 42 |
::pocketfft::shape_t shape_out{size_out}; |
| 43 |
::pocketfft::c2r(shape_out, stride_in, stride_out, axis, direction, in, out, fct, nthreads); |
| 44 |
} |
| 45 |
void pocketfft::do_inverse_c2r_many(size_t howmany, size_t size_in, size_t size_out, size_t dist_in, size_t dist_out, std::complex<double>* in, double* out) const { |
| 46 |
ATLAS_TRACE("pocketfft::inverse_c2r"); |
| 47 |
static const ::pocketfft::stride_t stride_in{sizeof(std::complex<double>)}; // in bytes |
| 48 |
static const ::pocketfft::stride_t stride_out{sizeof(double)}; // in bytes |
| 49 |
const size_t idist = dist_in; |
| 50 |
const size_t odist = dist_out; |
| 51 |
constexpr size_t axis = 0; |
| 52 |
constexpr double fct = 1.0; |
| 53 |
constexpr size_t nthreads = 1; |
| 54 |
constexpr bool direction = ::pocketfft::BACKWARD; |
| 55 |
const ::pocketfft::shape_t shape_out{size_out}; |
| 56 |
|
| 57 |
atlas_omp_parallel_for(size_t j=0; j<howmany; ++j) { |
| 58 |
::pocketfft::c2r(shape_out, stride_in, stride_out, axis, direction, in+j*idist, out+j*odist, fct, nthreads); |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
} // namespace atlas::linalg |
| 63 |
|
| 64 |
#else |
| 65 |
|
| 66 |
#include "atlas/runtime/Exception.h" |
| 67 |
#define THROW_ATLAS_POCKETFFT_NOT_SUPPORTED() throw_Exception("Atlas was not compiled with pocketfft support", Here()) |
| 68 |
|
| 69 |
namespace atlas::linalg { |
| 70 |
|
| 71 |
void pocketfft::do_plan_inverse_c2r(size_t /*size_out*/, std::complex<double>* /*in*/, double* /*out*/) const {} |
| 72 |
void pocketfft::do_plan_inverse_c2r_many(size_t /*howmany*/, size_t /*size_in*/, size_t /*size_out*/, size_t /*dist_in*/, size_t /*dist_out*/, std::complex<double>* /*in*/, double* /*out*/) const {} |
| 73 |
void pocketfft::do_inverse_c2r(const size_t /*size_out*/, std::complex<double>* /*in*/, double* /*out*/) const { |
| 74 |
THROW_ATLAS_POCKETFFT_NOT_SUPPORTED(); |
| 75 |
} |
| 76 |
void pocketfft::do_inverse_c2r_many(size_t howmany, size_t size_in, size_t size_out, size_t dist_in, size_t dist_out, std::complex<double>* in, double* out) const { |
| 77 |
THROW_ATLAS_POCKETFFT_NOT_SUPPORTED(); |
| 78 |
} |
| 79 |
|
| 80 |
} // namespace atlas::linalg |
| 81 |
|
| 82 |
#endif |