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 58 of file CudaPmeSolverUtil.C.

59  : deviceID(deviceID), stream(stream) {
60  }

◆ ~CudaFFTCompute()

CudaFFTCompute::~CudaFFTCompute ( )

Definition at line 113 of file CudaPmeSolverUtil.C.

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

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

Member Function Documentation

◆ backward()

void CudaFFTCompute::backward ( )
virtual

Implements FFTCompute.

Definition at line 179 of file CudaPmeSolverUtil.C.

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

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

◆ forward()

void CudaFFTCompute::forward ( )
virtual

Implements FFTCompute.

Definition at line 130 of file CudaPmeSolverUtil.C.

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

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

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