Openholo  v5.0
Open Source Digital Holographic Library
ophDepthMap_GPU.h
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install, copy or use the software.
7 //
8 //
9 // License Agreement
10 // For Open Source Digital Holographic Library
11 //
12 // Openholo library is free software;
13 // you can redistribute it and/or modify it under the terms of the BSD 2-Clause license.
14 //
15 // Copyright (C) 2017-2024, Korea Electronics Technology Institute. All rights reserved.
16 // E-mail : contact.openholo@gmail.com
17 // Web : http://www.openholo.org
18 //
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
21 //
22 // 1. Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
24 //
25 // 2. Redistribution's in binary form must reproduce the above copyright notice,
26 // this list of conditions and the following disclaimer in the documentation
27 // and/or other materials provided with the distribution.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the copyright holder or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 // This software contains opensource software released under GNU Generic Public License,
41 // NVDIA Software License Agreement, or CUDA supplement to Software License Agreement.
42 // Check whether software you use contains licensed software.
43 //
44 //M*/
45 
53 #ifndef __ophDepthMap_GPU_h
54 #define __ophDepthMap_GPU_h
55 
56 #include "ophDepthMap.h"
57 
58 #define __DEBUG_LOG_GPU_SPEC_
59 
60 /* CUDA Library Include */
61 #include <cuda_runtime_api.h>
62 #include <cufft.h>
63 static void HandleError(cudaError_t err,
64  const char *file,
65  int line) {
66  if (err != cudaSuccess) {
67  printf("%s in %s at line %d\n", cudaGetErrorString(err),
68  file, line);
69  exit(EXIT_FAILURE);
70  }
71 }
72 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
73 
74 
75 #define HANDLE_NULL( a ) {if (a == NULL) { \
76  printf( "Host memory failed in %s at line %d\n", \
77  __FILE__, __LINE__ ); \
78  exit( EXIT_FAILURE );}}
79 
80 typedef struct DMKernelConfig {
81  int pn_X;
82  int pn_Y;
83  double pp_X;
84  double pp_Y;
85 
86  double ss_X;
87  double ss_Y;
88 
89  double k;
90  double lambda;
91 
93  const ivec2& pixel_number,
94  const vec2& pixel_pitch,
95  const vec2& ss,
96  const Real& k,
97  const Real& lambda
98  )
99  {
100  // Output Image Size
101  this->pn_X = pixel_number[_X];
102  this->pn_Y = pixel_number[_Y];
103 
104  // Pixel pitch at eyepiece lens plane (by simple magnification) ==> SLM pitch
105  this->pp_X = pixel_pitch[_X];
106  this->pp_Y = pixel_pitch[_Y];
107 
108  // Length (Width) of complex field at eyepiece plane (by simple magnification)
109  this->ss_X = ss[_X];
110  this->ss_Y = ss[_Y];
111 
112  // Wave Number
113  this->k = k;
114 
115  this->lambda = lambda;
116  }
118 
119 
120 extern "C"
121 {
133  //void cudaFFT(CUstream_st* stream, int nx, int ny, cufftDoubleComplex* in_filed, cufftDoubleComplex* output_field, int direction);
134 
153  void cudaDepthHoloKernel(CUstream_st* stream, int nx, int ny, cufftDoubleComplex* u_o_gpu_, unsigned char* img_src_gpu, unsigned char* dimg_src_gpu, Real* depth_index_gpu,
154  int dtr, cuDoubleComplex rand_phase_val, cuDoubleComplex carrier_phase_delay, int flag_change_depth_quan, unsigned int default_depth_quan, const unsigned int& mode);
155 
176  const int& nBlocks, const int& nThreads, CUstream_st* stream_, cufftDoubleComplex* input_d, cufftDoubleComplex* u_complex,
177  const DMKernelConfig* cuda_config, Real propagation_dist);
178 
179  //void cudaGetFringe(CUstream_st* stream, int pnx, int pny, cufftDoubleComplex* in_field, cufftDoubleComplex* out_field, int sig_locationx, int sig_locationy,
180  // Real ssx, Real ssy, Real ppx, Real ppy, Real PI);
181 
198  void cudaChangeDepthQuanKernel(CUstream_st* stream_, int pnx, int pny, Real* depth_index_gpu, unsigned char* dimg_src_gpu,
199  int dtr, Real d1, Real d2, Real params_num_of_depth, Real params_far_depthmap, Real params_near_depthmap);
200 
203 }
204 
205 
206 
207 #endif
double ss_Y
(pixel_x * nx) / 2
double lambda
Wave Number = (2 * PI) / lambda;.
void cudaChangeDepthQuanKernel(CUstream_st *stream_, int pnx, int pny, Real *depth_index_gpu, unsigned char *dimg_src_gpu, int dtr, Real d1, Real d2, Real params_num_of_depth, Real params_far_depthmap, Real params_near_depthmap)
Quantize depth map on the GPU, only when the number of depth quantization is not the default value (i...
double k
(pixel_y * ny) / 2
float Real
Definition: typedef.h:55
void cudaPropagation_AngularSpKernel(const int &nBlocks, const int &nThreads, CUstream_st *stream_, cufftDoubleComplex *input_d, cufftDoubleComplex *u_complex, const DMKernelConfig *cuda_config, Real propagation_dist)
Angular spectrum propagation method for GPU implementation.
int pn_Y
Number of pixel of SLM in x direction.
double pp_X
Number of pixel of SLM in y direction.
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
#define _Y
Definition: define.h:96
DMKernelConfig(const ivec2 &pixel_number, const vec2 &pixel_pitch, const vec2 &ss, const Real &k, const Real &lambda)
#define _X
Definition: define.h:92
struct DMKernelConfig DMKernelConfig
double pp_Y
Pixel pitch of SLM in x direction.
structure for 2-dimensional Real type vector and its arithmetic.
Definition: vec.h:66
void cudaDepthHoloKernel(CUstream_st *stream, int nx, int ny, cufftDoubleComplex *u_o_gpu_, unsigned char *img_src_gpu, unsigned char *dimg_src_gpu, Real *depth_index_gpu, int dtr, cuDoubleComplex rand_phase_val, cuDoubleComplex carrier_phase_delay, int flag_change_depth_quan, unsigned int default_depth_quan, const unsigned int &mode)
Convert data from the spatial domain to the frequency domain using 2D FFT on GPU. ...
double ss_X
Pixel pitch of SLM in y direction.