1#ifndef PRDC_CUDA_FFT_TPP
2#define PRDC_CUDA_FFT_TPP
12#include <pscf/cuda/VecOp.h>
83 cufftDestroy(rcfPlan_);
86 cufftDestroy(criPlan_);
89 cufftDestroy(ccPlan_);
105 for (
int i = 0; i < D; ++i) {
117 if (kFieldCopy_.isAllocated()) {
118 if (kFieldCopy_.capacity() != kSize_) {
119 kFieldCopy_.deallocate();
145 #ifdef SINGLE_PRECISION
146 result = cufftExecR2C(rcfPlan_,
const_cast<cudaReal*
>(rField.
cArray()),
149 result = cufftExecD2Z(rcfPlan_,
const_cast<cudaReal*
>(rField.
cArray()),
152 if (result != CUFFT_SUCCESS) {
153 UTIL_THROW(
"Failure in cufft real-to-complex forward transform");
176 #ifdef SINGLE_PRECISION
177 result = cufftExecC2R(criPlan_, kField.
cArray(), rField.
cArray());
179 result = cufftExecZ2D(criPlan_, kField.
cArray(), rField.
cArray());
181 if (result != CUFFT_SUCCESS) {
182 UTIL_THROW(
"Failure in cufft complex-to-real inverse transform");
195 if (kFieldCopy_.isAllocated()) {
197 UTIL_CHECK(kFieldCopy_.meshDimensions() == meshDimensions_);
201 kFieldCopy_ = kField;
226 #ifdef SINGLE_PRECISION
228 kField.
cArray(), CUFFT_FORWARD);
231 kField.
cArray(), CUFFT_FORWARD);
233 if (result != CUFFT_SUCCESS) {
234 UTIL_THROW(
"Failure in cufft complex-to-complex forward transform");
259 #ifdef SINGLE_PRECISION
261 rField.
cArray(), CUFFT_INVERSE);
264 rField.
cArray(), CUFFT_INVERSE);
266 if (result != CUFFT_SUCCESS) {
267 UTIL_THROW(
"Failure in cufft complex-to-complex inverse transform");
283 for (
int i = 0; i < D; ++i) {
285 kMeshDimensions[i] = rMeshDimensions[i];
287 kMeshDimensions[i] = rMeshDimensions[i]/2 + 1;
289 kSize *= kMeshDimensions[i];
int capacity() const
Return array capacity.
Data * cArray()
Return pointer to underlying C array.
An IntVec<D, T> is a D-component vector of elements of integer type T.
Field of complex values on a regular mesh, allocated on a GPU device.
IntVec< D > const & meshDimensions() const
Return mesh dimensions by constant reference.
FFT()
Default constructor.
static void computeKMesh(IntVec< D > const &rMeshDimensions, IntVec< D > &kMeshDimensions, int &kSize)
Compute dimensions and size of k-space mesh for DFT of real data.
void inverseTransform(CField< D > const &kField, CField< D > &rField) const
Compute inverse (complex-to-complex) discrete Fourier transform.
void forwardTransform(RField< D > const &rField, RFieldDft< D > &kField) const
Compute forward (real-to-complex) discrete Fourier transform.
void setup(IntVec< D > const &meshDimensions)
Setup grid dimensions, plans and work space.
void inverseTransformUnsafe(RFieldDft< D > &kField, RField< D > &rField) const
Compute inverse (complex-to-real) DFT, overwriting the input.
const IntVec< D > & meshDimensions() const
Return the dimensions of the grid for which this was allocated.
void inverseTransformSafe(RFieldDft< D > const &kField, RField< D > &rField) const
Compute inverse (complex-to-real) DFT without overwriting input.
virtual ~FFT()
Destructor.
Discrete Fourier Transform (DFT) of a real field, allocated on a GPU.
IntVec< D > const & meshDimensions() const
Return vector of real-space mesh dimensions by constant reference.
Field of real values on a regular mesh, allocated on a GPU device.
IntVec< D > const & meshDimensions() const
Return mesh dimensions by constant reference.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
void mulEqS(Array< double > &a, double b)
Vector-scalar in-place multiplication, a[i] *= b (real).
Fields, FFTs, and utilities for periodic boundary conditions (CUDA).
Periodic fields and crystallography.
PSCF package top-level namespace.
cufftDoubleComplex cudaComplex
Complex number type used in CPU code that uses FFTW.
cufftDoubleReal cudaReal
Real number type used in CPU code that uses FFTW.