-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathcufinufft3d.cu
120 lines (96 loc) · 3.98 KB
/
cufinufft3d.cu
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
#include <cmath>
#include <complex>
#include <iomanip>
#include <iostream>
#include <cufft.h>
#include <helper_cuda.h>
#include <cufinufft/cudeconvolve.h>
#include <cufinufft/memtransfer.h>
#include <cufinufft/spreadinterp.h>
#include <cufinufft/types.h>
using namespace cufinufft::deconvolve;
using namespace cufinufft::spreadinterp;
using std::min;
template <typename T>
int cufinufft3d1_exec(cuda_complex<T> *d_c, cuda_complex<T> *d_fk, cufinufft_plan_t<T> *d_plan)
/*
3D Type-1 NUFFT
This function is called in "exec" stage (See ../cufinufft.cu).
It includes (copied from doc in finufft library)
Step 1: spread data to oversampled regular mesh using kernel
Step 2: compute FFT on uniform mesh
Step 3: deconvolve by division of each Fourier mode independently by the
Fourier series coefficient of the kernel.
Melody Shih 07/25/19
*/
{
int blksize;
int ier;
cuda_complex<T> *d_fkstart;
cuda_complex<T> *d_cstart;
for (int i = 0; i * d_plan->maxbatchsize < d_plan->ntransf; i++) {
blksize = min(d_plan->ntransf - i * d_plan->maxbatchsize, d_plan->maxbatchsize);
d_cstart = d_c + i * d_plan->maxbatchsize * d_plan->M;
d_fkstart = d_fk + i * d_plan->maxbatchsize * d_plan->ms * d_plan->mt * d_plan->mu;
d_plan->c = d_cstart;
d_plan->fk = d_fkstart;
checkCudaErrors(cudaMemset(
d_plan->fw, 0, d_plan->maxbatchsize * d_plan->nf1 * d_plan->nf2 * d_plan->nf3 * sizeof(cuda_complex<T>)));
// Step 1: Spread
ier = cuspread3d<T>(d_plan, blksize);
if (ier != 0) {
printf("error: cuspread3d, method(%d)\n", d_plan->opts.gpu_method);
return ier;
}
// Step 2: FFT
cufft_ex(d_plan->fftplan, d_plan->fw, d_plan->fw, d_plan->iflag);
// Step 3: deconvolve and shuffle
cudeconvolve3d<T>(d_plan, blksize);
}
return 0;
}
template <typename T>
int cufinufft3d2_exec(cuda_complex<T> *d_c, cuda_complex<T> *d_fk, cufinufft_plan_t<T> *d_plan)
/*
3D Type-2 NUFFT
This function is called in "exec" stage (See ../cufinufft.cu).
It includes (copied from doc in finufft library)
Step 1: deconvolve (amplify) each Fourier mode, dividing by kernel
Fourier coeff
Step 2: compute FFT on uniform mesh
Step 3: interpolate data to regular mesh
Melody Shih 07/25/19
*/
{
int blksize;
int ier;
cuda_complex<T> *d_fkstart;
cuda_complex<T> *d_cstart;
for (int i = 0; i * d_plan->maxbatchsize < d_plan->ntransf; i++) {
blksize = min(d_plan->ntransf - i * d_plan->maxbatchsize, d_plan->maxbatchsize);
d_cstart = d_c + i * d_plan->maxbatchsize * d_plan->M;
d_fkstart = d_fk + i * d_plan->maxbatchsize * d_plan->ms * d_plan->mt * d_plan->mu;
d_plan->c = d_cstart;
d_plan->fk = d_fkstart;
// Step 1: amplify Fourier coeffs fk and copy into upsampled array fw
cudeconvolve3d<T>(d_plan, blksize);
// Step 2: FFT
cudaDeviceSynchronize();
cufft_ex(d_plan->fftplan, d_plan->fw, d_plan->fw, d_plan->iflag);
// Step 3: deconvolve and shuffle
ier = cuinterp3d<T>(d_plan, blksize);
if (ier != 0) {
printf("error: cuinterp3d, method(%d)\n", d_plan->opts.gpu_method);
return ier;
}
}
return 0;
}
template int cufinufft3d1_exec<float>(cuda_complex<float> *d_c, cuda_complex<float> *d_fk,
cufinufft_plan_t<float> *d_plan);
template int cufinufft3d1_exec<double>(cuda_complex<double> *d_c, cuda_complex<double> *d_fk,
cufinufft_plan_t<double> *d_plan);
template int cufinufft3d2_exec<float>(cuda_complex<float> *d_c, cuda_complex<float> *d_fk,
cufinufft_plan_t<float> *d_plan);
template int cufinufft3d2_exec<double>(cuda_complex<double> *d_c, cuda_complex<double> *d_fk,
cufinufft_plan_t<double> *d_plan);