4 #include <cuda_runtime.h> 10 if (err != cudaSuccess) {
11 printf(
"%s in %s at line %d\n", cudaGetErrorString(err),
16 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ )) 19 #define HANDLE_NULL( a ) {if (a == NULL) { \ 20 printf( "Host memory failed in %s at line %d\n", \ 21 __FILE__, __LINE__ ); \ 22 exit( EXIT_FAILURE );}} 49 void cudaFFT(CUstream_st* stream,
int nx,
int ny, cufftDoubleComplex* in_filed, cufftDoubleComplex* output_field,
int direction,
bool bNormailized =
false);
65 void cudaCropFringe(CUstream_st* stream,
int nx,
int ny, cufftDoubleComplex* in_field, cufftDoubleComplex* out_field,
int cropx1,
int cropx2,
int cropy1,
int cropy2);
86 void cudaDepthHoloKernel(CUstream_st* stream,
int pnx,
int pny, cufftDoubleComplex*
u_o_gpu_,
unsigned char* img_src_gpu_,
unsigned char* dimg_src_gpu_,
double* depth_index_gpu_,
87 int dtr,
double rand_phase_val_a,
double rand_phase_val_b,
double carrier_phase_delay_a,
double carrier_phase_delay_b,
int flag_change_depth_quan,
unsigned int default_depth_quan);
107 double ppx,
double ppy,
double ssx,
double ssy,
double lambda,
double params_k,
double propagation_dist);
126 void cudaGetFringe(CUstream_st* stream,
int pnx,
int pny, cufftDoubleComplex* in_field, cufftDoubleComplex* out_field,
int sig_locationx,
int sig_locationy,
127 double ssx,
double ssy,
double ppx,
double ppy,
double PI);
145 void cudaChangeDepthQuanKernel(CUstream_st* stream_,
int pnx,
int pny,
double* depth_index_gpu,
unsigned char* dimg_src_gpu,
146 int dtr,
double d1,
double d2,
double params_num_of_depth,
double params_far_depthmap,
double params_near_depthmap);
161 const int N = nx * ny;
198 const int N = nx * ny;
216 double temp_depth, d1, d2;
224 d1 = temp_depth -
dstep_ / 2.0;
225 d2 = temp_depth +
dstep_ / 2.0;
250 cudaEventCreate(&start);
251 cudaEventCreate(&stop);
256 cudaEventRecord(start,
stream_);
265 for (
int p = 0; p < depth_sz; ++p)
288 LOG(
"Frame#: %d, Depth: %d of %d, z = %f mm\n", frame, dtr,
params_.
num_of_depth, -temp_depth * 1000);
292 cudaEventRecord(stop,
stream_);
293 cudaEventSynchronize(stop);
295 float elapsedTime = 0.0f;
296 cudaEventElapsedTime(&elapsedTime, start, stop);
297 LOG(
"GPU Time= %f ms. \n", elapsedTime);
323 ppx, ppy, ssx, ssy, lambda,
params_.
k, propagation_dist);
354 cudaGetFringe(
stream_, pnx, pny,
u_complex_gpu_,
k_temp_d_, sig_location[0], sig_location[1], ssx, ssy, ppx, ppy,
PI);
356 cufftDoubleComplex* sample_fd = (cufftDoubleComplex*)malloc(
sizeof(cufftDoubleComplex)*pnx*pny);
357 memset(sample_fd, 0.0,
sizeof(cufftDoubleComplex)*pnx*pny);
362 for (
int i = 0; i < pnx*pny; ++i)
void Propagation_AngularSpectrum_GPU(cufftDoubleComplex *input_u, double propagation_dist)
Angular spectrum propagation method for GPU implementation.
double dstep_
the physical increment of each depth map layer.
cufftDoubleComplex * k_temp_d_
void cudaGetFringe(CUstream_st *stream, int pnx, int pny, cufftDoubleComplex *in_field, cufftDoubleComplex *out_field, int sig_locationx, int sig_locationy, double ssx, double ssy, double ppx, double ppy, double PI)
Encode the CGH according to a signal location parameter on the GPU.
static void HandleError(cudaError_t err, const char *file, int line)
uint num_of_depth
the number of depth level.
unsigned char * dimg_src_gpu_
GPU variable - depth map data, values are from 0 to 255.
uint DEFAULT_DEPTH_QUANTIZATION
default value of the depth quantization - 256
void cudaPropagation_AngularSpKernel(CUstream_st *stream_, int pnx, int pny, cufftDoubleComplex *input_d, cufftDoubleComplex *u_complex, double ppx, double ppy, double ssx, double ssy, double lambda, double params_k, double propagation_dist)
Angular spectrum propagation method for GPU implementation.
void cudaFFT(CUstream_st *stream, int nx, int ny, cufftDoubleComplex *in_filed, cufftDoubleComplex *output_field, int direction, bool bNormailized=false)
Convert data from the spatial domain to the frequency domain using 2D FFT on GPU. ...
bool FLAG_CHANGE_DEPTH_QUANTIZATION
if true, change the depth quantization from the default value.
double far_depthmap
FAR_OF_DEPTH_MAP at config file.
void exponent_complex(Complex *val)
Calculate the exponential of the complex number.
void cudaCropFringe(CUstream_st *stream, int nx, int ny, cufftDoubleComplex *in_field, cufftDoubleComplex *out_field, int cropx1, int cropx2, int cropy1, int cropy2)
Crop input data according to x, y coordinates on GPU.
unsigned char * img_src_gpu_
GPU variable - image source data, values are from 0 to 255.
std::vector< double > dlevel_
the physical value of all depth map layer.
int Propagation_Method_
propagation method - currently AngularSpectrum
cufftDoubleComplex * u_o_gpu_
bool prepare_inputdata_GPU(uchar *img, uchar *dimg)
Copy input image & depth map data into a GPU.
double lambda
WAVELENGTH at config file.
structure for 2-dimensional integer vector and its arithmetic.
ivec2 pn
SLM_PIXEL_NUMBER_X & SLM_PIXEL_NUMBER_Y.
void Calc_Holo_GPU(int frame)
Main method for generating a hologram on the GPU.
std::vector< int > render_depth
Used when only few specific depth levels are rendered, usually for test purpose.
void cudaChangeDepthQuanKernel(CUstream_st *stream_, int pnx, int pny, double *depth_index_gpu, unsigned char *dimg_src_gpu, int dtr, double d1, double d2, double params_num_of_depth, double params_far_depthmap, double params_near_depthmap)
Quantize depth map on the GPU, only when the number of depth quantization is not the default value (i...
#define HANDLE_ERROR(err)
cufftDoubleComplex * u_complex_gpu_
void init_GPU()
Initialize variables for the GPU implementation.
class for the complex number and its arithmetic.
void cudaDepthHoloKernel(CUstream_st *stream, int pnx, int pny, cufftDoubleComplex *u_o_gpu_, unsigned char *img_src_gpu_, unsigned char *dimg_src_gpu_, double *depth_index_gpu_, int dtr, double rand_phase_val_a, double rand_phase_val_b, double carrier_phase_delay_a, double carrier_phase_delay_b, int flag_change_depth_quan, unsigned int default_depth_quan)
Find each depth plane of the input image and apply carrier phase delay to it on GPU.
vec2 pp
SLM_PIXEL_PITCH_X & SLM_PIXEL_PITCH_Y.
double * u255_fringe_
the final hologram, used for writing the result image.
std::vector< double > dlevel_transform_
transfomed dlevel_ variable
double near_depthmap
NEAR_OF_DEPTH_MAP at config file.
void encoding_GPU(int cropx1, int cropx2, int cropy1, int cropy2, ivec2 sig_location)
Encode the CGH according to a signal location parameter on GPU.
void change_depth_quan_GPU()
Quantize depth map on the GPU, when the number of depth quantization is not the default value (i...
void get_rand_phase_value(Complex &rand_phase_val)
Assign random phase value if RANDOM_PHASE == 1.
HologramParams params_
structure variable for hologram parameters
double * depth_index_gpu_
GPU variable - quantized depth map data.