NAMD
Public Member Functions | List of all members
CudaFFTCompute Class Reference

#include <CudaPmeSolverUtil.h>

Inheritance diagram for CudaFFTCompute:
FFTCompute

Public Member Functions

 CudaFFTCompute (int deviceID, cudaStream_t stream)
 
 ~CudaFFTCompute ()
 
void forward ()
 
void backward ()
 
- Public Member Functions inherited from FFTCompute
 FFTCompute ()
 
void init (float *dataSrc_in, int dataSrcSize_in, float *dataDst_in, int dataDstSize_in, int permutation, PmeGrid pmeGrid, int pmePencilType, int jblock, int kblock, int flags)
 
virtual ~FFTCompute ()
 
float * getDataSrc ()
 
float * getDataDst ()
 

Additional Inherited Members

- Protected Attributes inherited from FFTCompute
int jblock
 
int kblock
 
int isize
 
int jsize
 
int ksize
 
float * dataSrc
 
float * dataDst
 
int dataSrcSize
 
int dataDstSize
 
bool dataSrcAllocated
 
bool dataDstAllocated
 

Detailed Description

Definition at line 41 of file CudaPmeSolverUtil.h.

Constructor & Destructor Documentation

◆ CudaFFTCompute()

CudaFFTCompute::CudaFFTCompute ( int  deviceID,
cudaStream_t  stream 
)

Definition at line 61 of file CudaPmeSolverUtil.C.

62  : deviceID(deviceID), stream(stream) {
63  }

◆ ~CudaFFTCompute()

CudaFFTCompute::~CudaFFTCompute ( )

Definition at line 116 of file CudaPmeSolverUtil.C.

References cudaCheck, cufftCheck, FFTCompute::dataDst, FFTCompute::dataDstAllocated, FFTCompute::dataSrc, and FFTCompute::dataSrcAllocated.

116  {
117  cudaCheck(cudaSetDevice(deviceID));
118  cufftCheck(cufftDestroy(forwardPlan));
119  cufftCheck(cufftDestroy(backwardPlan));
120  if (dataSrcAllocated) deallocate_device<float>(&dataSrc);
121  if (dataDstAllocated) deallocate_device<float>(&dataDst);
122 }
#define cufftCheck(stmt)
bool dataDstAllocated
bool dataSrcAllocated
float * dataDst
#define cudaCheck(stmt)
Definition: CudaUtils.h:242
float * dataSrc

Member Function Documentation

◆ backward()

void CudaFFTCompute::backward ( )
virtual

Implements FFTCompute.

Definition at line 182 of file CudaPmeSolverUtil.C.

References cudaCheck, cudaNAMD_bug(), cufftCheck, FFTCompute::dataDst, FFTCompute::dataSrc, and FFTCompute::dataSrcSize.

182  {
183  cudaCheck(cudaSetDevice(deviceID));
184  if (backwardType == CUFFT_C2R) {
185  // if (ncall == 1) {
186  // if (plantype == 1)
187  // writeComplexToDisk((float2 *)data, 33*64*64, "data_fx_by_bz.txt");
188  // else
189  // writeComplexToDisk((float2 *)data, 33*64*64, "data_fx_fy_fz_2.txt");
190  // }
191  cufftCheck(cufftExecC2R(backwardPlan, (cufftComplex *)dataDst, (cufftReal *)dataSrc));
192 #ifdef TESTPID
193  if (1) {
194  cudaCheck(cudaStreamSynchronize(stream));
195  fprintf(stderr, "AP BACKWARD FFT\n");
196  fprintf(stderr, "COPY DEVICE ARRAYS BACK TO HOST\n");
197  float *grid;
198  int gridsize = dataSrcSize;
199  allocate_host<float>(&grid, gridsize);
200  copy_DtoH<float>((float*)dataSrc, grid, gridsize, stream);
201  cudaCheck(cudaStreamSynchronize(stream));
202  TestArray_write<float>("potential_grid_good.bin",
203  "potential grid good", grid, gridsize);
204  deallocate_host<float>(&grid);
205  }
206 #endif
207 
208  // if (ncall == 1)
209  // if (plantype == 1)
210  // writeRealToDisk(data, 64*64*64, "data_bx_by_bz_1D.txt");
211  // else
212  // writeRealToDisk(data, 64*64*64, "data_bx_by_bz_3D.txt");
213  } else if (backwardType == CUFFT_C2C) {
214  // nc2cb++;
215  // if (ncall == 1 && nc2cb == 1)
216  // writeComplexToDisk((float2 *)data, 33*64*64, "data_fz_fx_fy_2.txt");
217  // else if (ncall == 1 && nc2cb == 2)
218  // writeComplexToDisk((float2 *)data, 33*64*64, "data_fy_bz_fx.txt");
219  cufftCheck(cufftExecC2C(backwardPlan, (cufftComplex *)dataDst, (cufftComplex *)dataSrc, CUFFT_INVERSE));
220  // if (ncall == 1 && nc2cb == 1)
221  // writeComplexToDisk((float2 *)data, 33*64*64, "data_bz_fx_fy.txt");
222  // else if (ncall == 1 && nc2cb == 2)
223  // writeComplexToDisk((float2 *)data, 33*64*64, "data_by_bz_fx.txt");
224  } else {
225  cudaNAMD_bug("CudaFFTCompute::backward(), unsupported FFT type");
226  }
227 }
#define cufftCheck(stmt)
void cudaNAMD_bug(const char *msg)
Definition: CudaUtils.C:53
float * dataDst
#define cudaCheck(stmt)
Definition: CudaUtils.h:242
float * dataSrc

◆ forward()

void CudaFFTCompute::forward ( )
virtual

Implements FFTCompute.

Definition at line 133 of file CudaPmeSolverUtil.C.

References cudaCheck, cudaNAMD_bug(), cufftCheck, FFTCompute::dataDst, FFTCompute::dataDstSize, and FFTCompute::dataSrc.

133  {
134  cudaCheck(cudaSetDevice(deviceID));
135  // ncall++;
136  if (forwardType == CUFFT_R2C) {
137  cufftCheck(cufftExecR2C(forwardPlan, (cufftReal *)dataSrc, (cufftComplex *)dataDst));
138 #ifdef TESTPID
139  if (1) {
140  cudaCheck(cudaStreamSynchronize(stream));
141  fprintf(stderr, "AP FORWARD FFT\n");
142  fprintf(stderr, "COPY DEVICE ARRAYS BACK TO HOST\n");
143  int m = dataDstSize;
144  float *tran = 0;
145  allocate_host<float>(&tran, m);
146  copy_DtoH<float>(dataDst, tran, m, stream);
147  cudaCheck(cudaStreamSynchronize(stream));
148  TestArray_write<float>("tran_charge_grid_good.bin",
149  "transformed charge grid good", tran, m);
150  deallocate_host<float>(&tran);
151  }
152 #endif
153 
154  // if (ncall == 1) {
155  // writeComplexToDisk((float2 *)dataSrc, (isize/2+1)*jsize*ksize, "dataSrc.txt", stream);
156  // }
157 
158  // if (ncall == 1 && plantype == 2) {
159  // writeComplexToDisk((float2 *)data, (isize/2+1)*jsize*ksize, "data_fx_fy_z.txt", stream);
160  // }
161 
162  } else if (forwardType == CUFFT_C2C) {
163  // nc2cf++;
164  // if (ncall == 1 && nc2cf == 1)
165  // writeComplexToDisk((float2 *)data, 33*64*64, "data_y_z_fx.txt");
166  // else if (ncall == 1 && nc2cf == 2)
167  // writeComplexToDisk((float2 *)data, 33*64*64, "data_z_fx_fy.txt");
168  cufftCheck(cufftExecC2C(forwardPlan, (cufftComplex *)dataSrc, (cufftComplex *)dataDst, CUFFT_FORWARD));
169  // fprintf(stderr, "ncall %d plantype %d\n", ncall, plantype);
170  // if (ncall == 1 && plantype == 1 && isize == 62) {
171  // writeComplexToDisk((float2 *)data, isize*jsize*(ksize/2+1), "data_fy_z_fx.txt", stream);
172  // }
173  // if (ncall == 1 && nc2cf == 1)
174  // writeComplexToDisk((float2 *)data, 33*64*64, "data_fy_z_fx.txt");
175  // else if (ncall == 1 && nc2cf == 2)
176  // writeComplexToDisk((float2 *)data, 33*64*64, "data_fz_fx_fy.txt");
177  } else {
178  cudaNAMD_bug("CudaFFTCompute::forward(), unsupported FFT type");
179  }
180 }
#define cufftCheck(stmt)
void cudaNAMD_bug(const char *msg)
Definition: CudaUtils.C:53
float * dataDst
#define cudaCheck(stmt)
Definition: CudaUtils.h:242
float * dataSrc

The documentation for this class was generated from the following files: