51 static void HandleError(cudaError_t err,
54 if (err != cudaSuccess) {
55 printf(
"%s in %s at line %d\n", cudaGetErrorString(err),
60 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ )) 69 Complex<Real> *host_data;
75 cuDoubleComplex* dev_src_data;
78 temp_angle[0] = angleX;
79 temp_angle[1] = angleY;
87 size_t nxy =
sizeof(cuDoubleComplex) * nx * ny;
89 cudaMalloc((
void**)&dev_src_data, nxy);
90 cudaMalloc((
void**)&dev_dst_data,
sizeof(
Real)*nx*ny);
91 cudaMalloc((
void**)&F, nxy);
92 cudaMalloc((
void**)&device_config,
sizeof(
ophSigConfig));
93 cudaMalloc((
void**)&device_angle,
sizeof(
Real) * 2);
96 cudaMemcpy(dev_src_data, host_data, nxy, cudaMemcpyHostToDevice);
97 cudaMemcpy(dev_dst_data, 0,
sizeof(
Real)*nx*ny, cudaMemcpyHostToDevice);
98 cudaMemcpy(F, 0, nxy, cudaMemcpyHostToDevice);
100 cudaMemcpy(device_angle, temp_angle,
sizeof(
Real)*2, cudaMemcpyHostToDevice);
104 cudaCvtOFF(dev_src_data, dev_dst_data, device_config, nx, ny,wl, F, device_angle);
106 cudaMemcpy(host_data, dev_src_data, nxy, cudaMemcpyDeviceToHost);
110 cudaFree(dev_src_data);
111 cudaFree(dev_dst_data);
113 cudaFree(device_config);
114 cudaFree(device_angle);
123 Complex<Real> *host_data;
124 cufftDoubleComplex *fft_temp_data,*out_data, *F;
127 if (cufftPlan2d(&fftplan, nx, ny, CUFFT_Z2Z) != CUFFT_SUCCESS)
129 LOG(
"FAIL in creating cufft plan");
137 size_t nxy =
sizeof(cufftDoubleComplex)* nx* ny;
139 cudaMalloc((
void**)&fft_temp_data, nxy);
140 cudaMalloc((
void**)&out_data, nxy);
141 cudaMalloc((
void**)&F, nxy);
142 cudaMalloc((
void**)&device_config,
sizeof(
ophSigConfig));
144 cudaMemcpy(fft_temp_data, host_data, nxy, cudaMemcpyHostToDevice);
145 cudaMemcpy(out_data, 0, nxy, cudaMemcpyHostToDevice);
146 cudaMemcpy(F, 0, nxy, cudaMemcpyHostToDevice);
149 cudaCuFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_FORWARD);
154 Real_t NA_g = NA * redRate;
155 Real Rephase = -(1 / (4 *
M_PI)*pow((wl / NA_g), 2));
160 cudaCuIFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_INVERSE);
162 cudaMemcpy(host_data, fft_temp_data, nxy, cudaMemcpyDeviceToHost);
167 cudaFree(device_config);
169 cudaFree(fft_temp_data);
170 cufftDestroy(fftplan);
186 Complex<Real>* host_data;
187 cufftDoubleComplex *fft_temp_data, *out_data, *F;
192 if (cufftPlan2d(&fftplan, nx, ny, CUFFT_Z2Z) != CUFFT_SUCCESS)
194 LOG(
"FAIL in creating cufft plan");
198 size_t nxy =
sizeof(cufftDoubleComplex) * nx * ny;
201 cudaMalloc((
void**)&fft_temp_data, nxy);
202 cudaMalloc((
void**)&out_data, nxy);
203 cudaMalloc((
void**)&F, nxy);
204 cudaMalloc((
void**)&device_config,
sizeof(
ophSigConfig));
206 cudaMemcpy(F, 0, nxy, cudaMemcpyHostToDevice);
208 cudaMemcpy(fft_temp_data, 0, nxy, cudaMemcpyHostToDevice);
209 cudaMemcpy(out_data, 0, nxy, cudaMemcpyHostToDevice);
213 cudaMemcpy(out_data, host_data, nxy, cudaMemcpyHostToDevice);
215 cudaCuFFT(&fftplan, out_data, fft_temp_data, nx, ny, CUFFT_FORWARD);
217 double sigmaf = ((
_foc[2] -
_foc[0]) * blue) / (4 *
M_PI);
218 cudaCvtCAC(fft_temp_data, out_data,F,device_config,nx, ny,sigmaf,radius);
220 cudaCuIFFT(&fftplan, out_data, fft_temp_data, nx, ny, CUFFT_INVERSE);
223 cudaMemcpy(host_data, out_data, nxy, cudaMemcpyDeviceToHost);
229 cudaMemcpy(out_data, host_data, nxy, cudaMemcpyHostToDevice);
231 cudaCuFFT(&fftplan, out_data, fft_temp_data, nx, ny, CUFFT_FORWARD);
234 cudaCvtCAC(fft_temp_data, out_data, F, device_config, nx, ny, sigmaf, radius);
236 cudaCuIFFT(&fftplan, out_data, fft_temp_data, nx, ny, CUFFT_INVERSE);
239 cudaMemcpy(host_data, out_data, nxy, cudaMemcpyDeviceToHost);
244 cudaFree(device_config);
247 cudaFree(fft_temp_data);
248 cufftDestroy(fftplan);
259 Complex<Real> *host_data;
260 cufftDoubleComplex *fft_temp_data, *out_data, *F;
265 if (cufftPlan2d(&fftplan, nx, ny, CUFFT_Z2Z) != CUFFT_SUCCESS)
267 LOG(
"FAIL in creating cufft plan");
273 size_t nxy =
sizeof(cufftDoubleComplex) * nx * ny;
274 cudaMalloc((
void**)&fft_temp_data, nxy);
275 cudaMalloc((
void**)&out_data, nxy);
276 cudaMalloc((
void**)&F, nxy);
277 cudaMalloc((
void**)&device_config,
sizeof(
ophSigConfig));
279 cudaMemcpy(fft_temp_data, host_data, nxy, cudaMemcpyHostToDevice);
280 cudaMemcpy(out_data, 0, nxy, cudaMemcpyHostToDevice);
281 cudaMemcpy(F, 0, nxy, cudaMemcpyHostToDevice);
285 cudaCuFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_FORWARD);
290 cudaPropagation(out_data, fft_temp_data, F, device_config, nx, ny, sigmaf);
292 cudaCuIFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_INVERSE);
296 cudaMemcpy(host_data, fft_temp_data, nx*ny *
sizeof(Complex<Real>), cudaMemcpyDeviceToHost);
301 cudaFree(device_config);
303 cudaFree(fft_temp_data);
304 cufftDestroy(fftplan);
315 Complex<Real> *host_data;
316 cufftDoubleComplex *fft_temp_data, *out_data, *F;
321 if (cufftPlan2d(&fftplan, nx, ny, CUFFT_Z2Z) != CUFFT_SUCCESS)
323 LOG(
"FAIL in creating cufft plan");
329 size_t nxy =
sizeof(cufftDoubleComplex) * nx * ny;
330 cudaMalloc((
void**)&fft_temp_data, nxy);
331 cudaMalloc((
void**)&out_data, nxy);
332 cudaMalloc((
void**)&F, nxy);
333 cudaMalloc((
void**)&device_config,
sizeof(
ophSigConfig));
335 cudaMemcpy(fft_temp_data, 0, nxy, cudaMemcpyHostToDevice);
336 cudaMemcpy(out_data, 0, nxy, cudaMemcpyHostToDevice);
337 cudaMemcpy(F, 0, nxy, cudaMemcpyHostToDevice);
347 cudaMemcpy(fft_temp_data, host_data, nxy, cudaMemcpyHostToDevice);
349 cudaCuFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_FORWARD);
350 cudaPropagation(out_data, fft_temp_data, F, device_config, nx, ny, sigmaf);
351 cudaCuIFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_INVERSE);
353 cudaMemcpy(host_data, fft_temp_data, nxy, cudaMemcpyDeviceToHost);
360 cudaMemcpy(fft_temp_data, host_data, nxy, cudaMemcpyHostToDevice);
362 cudaCuFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_FORWARD);
364 cudaPropagation(out_data, fft_temp_data, F, device_config, nx, ny, sigmaf);
365 cudaCuIFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_INVERSE);
367 cudaMemcpy(host_data, fft_temp_data, nxy, cudaMemcpyDeviceToHost);
373 cudaMemcpy(fft_temp_data, host_data,
sizeof(Complex<Real>)*nx*ny, cudaMemcpyHostToDevice);
375 cudaCuFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_FORWARD);
376 cudaPropagation(out_data, fft_temp_data, F, device_config, nx, ny, sigmaf);
377 cudaCuIFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_INVERSE);
379 cudaMemcpy(host_data, fft_temp_data, nx*ny *
sizeof(Complex<Real>), cudaMemcpyDeviceToHost);
383 cudaFree(device_config);
385 cudaFree(fft_temp_data);
386 cufftDestroy(fftplan);
398 Complex<Real> *host_data;
399 cufftDoubleComplex *fft_temp_data, *out_data, *Ftemp_data, *FH;
407 size_t nxy =
sizeof(cufftDoubleComplex) * nx * ny;
409 cudaMalloc((
void**)&f,
sizeof(
Real)*nx*ny);
410 cudaMalloc((
void**)&FH, nxy);
411 cudaMalloc((
void**)&device_config,
sizeof(
ophSigConfig));
412 cudaMalloc((
void**)&fft_temp_data, nxy);
413 cudaMalloc((
void**)&Ftemp_data, nxy);
414 cudaMalloc((
void**)&out_data, nxy);
416 if (cufftPlan2d(&fftplan, nx, ny, CUFFT_Z2Z) != CUFFT_SUCCESS)
418 LOG(
"FAIL in creating cufft plan");
424 cudaMemcpy(fft_temp_data, host_data, nxy, cudaMemcpyHostToDevice);
425 cudaMemcpy(out_data, 0, nxy, cudaMemcpyHostToDevice);
429 cudaCuFFT(&fftplan, fft_temp_data, out_data, nx, ny, CUFFT_FORWARD);
431 cudaMemcpy(FH, 0, nxy, cudaMemcpyHostToDevice);
432 cudaMemcpy(f, 0, nxy, cudaMemcpyHostToDevice);
435 depth =
cudaGetParamSF(&fftplan, out_data, Ftemp_data, fft_temp_data, f, FH, device_config, nx, ny, zMax, zMin, sampN, th, wl);
444 cudaFree(device_config);
445 cudaFree(Ftemp_data);
447 cudaFree(fft_temp_data);
449 cufftDestroy(fftplan);
467 Complex<Real>* host_data;
468 cuDoubleComplex* Flr, * Fli, * G, *tmp1, *tmp2;
469 cufftDoubleComplex *fft_data, *out_data;
481 if (cufftPlan2d(&fftplan, nx, ny, CUFFT_Z2Z) != CUFFT_SUCCESS)
483 LOG(
"FAIL in creating cufft plan");
489 size_t nxy =
sizeof(cufftDoubleComplex) * nx * ny;
490 cudaMalloc((
void**)&Flr, nxy);
491 cudaMalloc((
void**)&Fli, nxy);
492 cudaMalloc((
void**)&tmp1, nxy);
493 cudaMalloc((
void**)&tmp2, nxy);
494 cudaMalloc((
void**)&G, nxy);
495 cudaMalloc((
void**)&device_config,
sizeof(
ophSigConfig));
497 cudaMalloc((
void**)&fft_data, nxy);
498 cudaMalloc((
void**)&out_data, nxy);
501 cudaMemcpy(fft_data, host_data, nxy, cudaMemcpyHostToDevice);
502 cudaMemcpy(Flr, 0, nxy, cudaMemcpyHostToDevice);
503 cudaMemcpy(Fli, 0, nxy, cudaMemcpyHostToDevice);
504 cudaMemcpy(G, 0, nxy, cudaMemcpyHostToDevice);
507 cudaMemcpy(out_data, 0, nxy, cudaMemcpyHostToDevice);
508 cudaMemcpy(tmp1, 0, nxy, cudaMemcpyHostToDevice);
509 cudaMemcpy(tmp2, 0, nxy, cudaMemcpyHostToDevice);
511 cudaGetParamAT1(fft_data, Flr, Fli, G, device_config, nx, ny, NA_g, wl);
514 cudaCuFFT(&fftplan, Flr, tmp1, nx, ny, CUFFT_FORWARD);
518 cudaCuFFT(&fftplan, Fli, tmp2, nx, ny, CUFFT_FORWARD);
524 cudaMemcpy(host_data, out_data, nxy, cudaMemcpyDeviceToHost);
529 cudaFree(device_config);
533 cufftDestroy(fftplan);
539 Fon.resize(1, t.size());
541 for (
int i = 0; i < tn.size(); i++)
543 tn.at(i) = pow(t.at(i), 0.5);
544 Fon(0, i)[
_RE] = Fo_temp(nx / 2 - 1, nx / 2 - 1 + i)[
_RE];
548 yn.resize(1, tn.size());
551 Ab_yn.resize(yn.size[
_X], yn.size[
_Y]);
553 Ab_yn_half.resize(1, nx / 4 + 1);
555 for (
int i = 0; i < nx / 4 + 1; i++)
557 Ab_yn_half(0, i) = Ab_yn(0, nx / 4 + i - 1)[
_RE];
558 if (i == 0) max = Ab_yn_half(0, 0);
561 if (Ab_yn_half(0, i) > max)
563 max = Ab_yn_half(0, i);
569 index = -(((index + 1) - 120) / 10) / 140 + 0.1;
oph::matrix< Complex< Real > > OphComplexField
void cField2Buffer(matrix< Complex< Real >> &src, Complex< Real > **dst, int nx, int ny)
Function for move data from matrix<Complex<Real>> to Complex<Real>
void ColorField2Buffer(matrix< Complex< Real >> &src, Complex< Real > **dst, int nx, int ny)
Function for move Color data from matrix<Complex<Real>> to Complex<Real>
double sigGetParamAT_GPU()
Extraction of distance parameter using axis transfomation by using GPU.
void fft1(matrix< Complex< T >> &src, matrix< Complex< T >> &dst, int sign=OPH_FORWARD, uint flag=OPH_ESTIMATE)
Function for Fast Fourier transform 1D.
bool sigConvertHPO_GPU(Real depth, Real_t redRate)
Function for convert complex hologram to horizontal parallax only hologram by using GPU...
void cudaCvtHPO(CUstream_st *stream, cufftDoubleComplex *src_data, cufftDoubleComplex *dst_data, ophSigConfig *device_config, cuDoubleComplex *F, int nx, int ny, Real Rephase, Real Imphase)
void cudaGetParamAT1(cuDoubleComplex *src_data, cuDoubleComplex *Flr, cuDoubleComplex *Fli, cuDoubleComplex *G, ophSigConfig *device_config, int nx, int ny, Real_t NA_g, Real wl)
bool Color_propagationHolo_GPU(float depth)
void cudaGetParamAT2(cuDoubleComplex *Flr, cuDoubleComplex *Fli, cuDoubleComplex *G, cuDoubleComplex *temp_data, int nx, int ny)
bool sigConvertCAC_GPU(double red, double green, double blue)
Function for Chromatic aberration compensation filter by using GPU.
void cudaCuIFFT(cufftHandle *plan, cufftDoubleComplex *src_data, cufftDoubleComplex *dst_data, int nx, int ny, int direction)
OphComplexField * ComplexH
oph::matrix< Real > OphRealField
void absMat(matrix< Complex< T >> &src, matrix< T > &dst)
Function for extracts Complex absolute value.
bool propagationHolo_GPU(float depth)
Function for propagation hologram by using GPU.
void linInterp(vector< T > &X, matrix< Complex< T >> &src, vector< T > &Xq, matrix< Complex< T >> &dst)
Linear interpolation.
void cudaPropagation(cufftDoubleComplex *src_data, cufftDoubleComplex *dst_data, cuDoubleComplex *FH, ophSigConfig *device_config, int nx, int ny, Real sigmaf)
void Buffer2Field(const T *src, matrix< T > &dst, const ivec2 buffer_size)
double cudaGetParamSF(cufftHandle *fftplan, cufftDoubleComplex *src_data, cufftDoubleComplex *temp_data, cufftDoubleComplex *dst_data, Real *f, cuDoubleComplex *FH, ophSigConfig *device_config, int nx, int ny, float zMax, float zMin, int sampN, float th, Real wl)
double sigGetParamSF_GPU(float zMax, float zMin, int sampN, float th)
Extraction of distance parameter using sharpness functions by using GPU.
void cudaCuFFT(cufftHandle *plan, cufftDoubleComplex *src_data, cufftDoubleComplex *dst_data, int nx, int ny, int direction)
void cudaCvtOFF(cuDoubleComplex *src_data, Real *dst_data, ophSigConfig *device_config, int nx, int ny, Real wl, cuDoubleComplex *F, Real *angle)
void cvtOffaxis_GPU(Real angleX, Real angleY)
void cudaCvtCAC(cufftDoubleComplex *src_data, cufftDoubleComplex *dst_data, cuDoubleComplex *FFZP, ophSigConfig *device_config, int nx, int ny, Real sigmaf, Real radius)
vector< T > linspace(T first, T last, int len)
Generate linearly spaced vector.