Openholo  v1.0
Open Source Digital Holographic Library
ophPointCloud_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 __ophPointCloud_GPU_h
54 #define __ophPointCloud_GPU_h
55 
56 #include "ophPointCloud.h"
57 
58 #define __DEBUG_LOG_GPU_SPEC_
59 
60 /* CUDA Library Include */
61 #include <cuda_runtime.h>
62 
63 #define __CUDA_INTERNAL_COMPILATION__ //for CUDA Math Module
64 #include <math_constants.h>
65 #include <math_functions.h> //Single Precision Floating
66 #include <math_functions_dbl_ptx3.h> //Double Precision Floating
67 #include <vector_functions.h> //Vector Processing Function
68 #undef __CUDA_INTERNAL_COMPILATION__
69 
70 #define OPH_CUDA_N_STREAM 100
71 static void HandleError(cudaError_t err,
72  const char *file,
73  int line) {
74  if (err != cudaSuccess) {
75  printf("%s in %s at line %d\n", cudaGetErrorString(err),
76  file, line);
77  exit(EXIT_FAILURE);
78  }
79 }
80 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
81 
82 
83 #define HANDLE_NULL( a ) {if (a == NULL) { \
84  printf( "Host memory failed in %s at line %d\n", \
85  __FILE__, __LINE__ ); \
86  exit( EXIT_FAILURE );}}
87 // for PointCloud only GPU
88 typedef struct KernelConst {
89  int n_points;
90  int n_colors;
91  int n_streams;
92 
93  double scale_X;
94  double scale_Y;
95  double scale_Z;
96 
97  double offset_depth;
98 
99  int pn_X;
100  int pn_Y;
101 
102  double pp_X;
103  double pp_Y;
104 
105  double half_ss_X;
106  double half_ss_Y;
107 
108  double k;
109  double lambda;
110 
112  const int &n_points,
113  const int &n_colors,
114  const int &n_streams,
115  const vec3 &scale_factor,
116  const Real &offset_depth,
117  const ivec2 &pixel_number,
118  const vec2 &pixel_pitch,
119  const vec2 &ss,
120  const Real &k,
121  const Real &lambda,
122  const Real &ratio
123  )
124  {
125  this->n_points = n_points;
126  this->n_colors = n_colors;
127  this->n_streams = n_streams;
128  this->scale_X = scale_factor[_X] * ratio;
129  this->scale_Y = scale_factor[_Y] * ratio;
130  this->scale_Z = scale_factor[_Z];
131  this->offset_depth = offset_depth;
132 
133  // Output Image Size
134  this->pn_X = pixel_number[_X];
135  this->pn_Y = pixel_number[_Y];
136 
137  // Pixel pitch at eyepiece lens plane (by simple magnification) ==> SLM pitch
138  this->pp_X = pixel_pitch[_X];
139  this->pp_Y = pixel_pitch[_Y];
140 
141  // Length (Width) of complex field at eyepiece plane (by simple magnification)
142  this->half_ss_X = ss[_X] / 2;
143  this->half_ss_Y = ss[_Y] / 2;
144 
145  // Wave Number
146  this->k = k;
147 
148  this->lambda = lambda;
149  }
150 } GpuConst;
151 
152 cudaStream_t *streams;
153 
154 typedef struct KernelConst_NotEncodedRS : public KernelConst {
155  double det_tx;
156  double det_ty;
157 
159  const int &n_points,
160  const int &n_colors,
161  const int &n_streams,
162  const vec3 &scale_factor,
163  const Real &offset_depth,
164  const ivec2 &pixel_number,
165  const vec2 &pixel_pitch,
166  const vec2 &ss,
167  const Real &k,
168  const Real &lambda,
169  const Real &ratio
170  )
171  : KernelConst(n_points, n_colors, n_streams, scale_factor, offset_depth, pixel_number, pixel_pitch, ss, k, lambda, ratio)
172  {
173  double tx = lambda / (2 * pixel_pitch[_X]);
174  double ty = lambda / (2 * pixel_pitch[_Y]);
175 
176  this->det_tx = tx / sqrt(1 - tx * tx);
177  this->det_ty = ty / sqrt(1 - ty * ty);
178  }
179 
181  : KernelConst(cuda_config)
182  {
183  double tx = lambda / (2 * cuda_config.pp_X);
184  double ty = lambda / (2 * cuda_config.pp_Y);
185 
186  this->det_tx = tx / sqrt(1 - tx * tx);
187  this->det_ty = ty / sqrt(1 - ty * ty);
188  }
189 } GpuConstNERS;
190 
191 
192 typedef struct KernelConst_NotEncodedFrsn : public KernelConst {
193 
194  double tx;
195  double ty;
196 
198  const int &n_points,
199  const int &n_colors,
200  const int &n_streams,
201  const vec3 &scale_factor,
202  const Real &offset_depth,
203  const ivec2 &pixel_number,
204  const vec2 &pixel_pitch,
205  const vec2 &ss,
206  const Real &k,
207  const Real &lambda,
208  const Real &ratio
209  )
210  : KernelConst(n_points, n_colors, n_streams, scale_factor, offset_depth, pixel_number, pixel_pitch, ss, k, lambda, ratio)
211  {
212  this->tx = lambda / (2 * pixel_pitch[_X]);
213  this->ty = lambda / (2 * pixel_pitch[_Y]);
214  }
215 
217  : KernelConst(cuda_config)
218  {
219  this->tx = lambda / (2 * cuda_config.pp_X);
220  this->ty = lambda / (2 * cuda_config.pp_Y);
221  }
222 } GpuConstNEFR;
223 
224 
225 extern "C"
226 {
228  const int &nBlocks, const int &nThreads, const int &n_pts_per_stream,
229  Real* cuda_pc_data, Real* cuda_amp_data,
230  Real* cuda_dst_real, Real* cuda_dst_imag,
231  const GpuConstNERS* cuda_config, const uint &iChannel);
232 
234  const int &nBlocks, const int &nThreads, const int &n_pts_per_stream,
235  Real* cuda_pc_data, Real* cuda_amp_data,
236  Real* cuda_dst_real, Real* cuda_dst_imag,
237  const GpuConstNEFR* cuda_config, const uint &iChannel);
238 }
239 
240 #endif
KernelConst_NotEncodedFrsn(GpuConst &cuda_config)
double lambda
Wave Number = (2 * PI) / lambda;.
void cudaGenCghPointCloud_NotEncodedRS(const int &nBlocks, const int &nThreads, const int &n_pts_per_stream, Real *cuda_pc_data, Real *cuda_amp_data, Real *cuda_dst_real, Real *cuda_dst_imag, const GpuConstNERS *cuda_config, const uint &iChannel)
double half_ss_Y
(pixel_x * nx) / 2
struct KernelConst GpuConst
double pp_Y
Pixel pitch of SLM in x direction.
float Real
Definition: typedef.h:55
KernelConst_NotEncodedRS(GpuConst &cuda_config)
double offset_depth
Scaling factor of z coordinate of point cloud.
KernelConst(const int &n_points, const int &n_colors, const int &n_streams, const vec3 &scale_factor, const Real &offset_depth, const ivec2 &pixel_number, const vec2 &pixel_pitch, const vec2 &ss, const Real &k, const Real &lambda, const Real &ratio)
double det_ty
tx / sqrt(1 - tx^2), tx = lambda / (2 * pp_X)
double pp_X
Number of pixel of SLM in y direction.
KernelConst_NotEncodedRS(const int &n_points, const int &n_colors, const int &n_streams, const vec3 &scale_factor, const Real &offset_depth, const ivec2 &pixel_number, const vec2 &pixel_pitch, const vec2 &ss, const Real &k, const Real &lambda, const Real &ratio)
ty / sqrt(1 - ty^2), ty = lambda / (2 * pp_Y)
#define _Y
Definition: define.h:84
double scale_Y
Scaling factor of x coordinate of point cloud.
KernelConst_NotEncodedFrsn GpuConstNEFR
double scale_Z
Scaling factor of y coordinate of point cloud.
#define _X
Definition: define.h:80
KernelConst_NotEncodedRS GpuConstNERS
double half_ss_X
Pixel pitch of SLM in y direction.
int n_streams
number of colors per point cloud
int pn_X
Offset value of point cloud in z direction.
void cudaGenCghPointCloud_NotEncodedFrsn(const int &nBlocks, const int &nThreads, const int &n_pts_per_stream, Real *cuda_pc_data, Real *cuda_amp_data, Real *cuda_dst_real, Real *cuda_dst_imag, const GpuConstNEFR *cuda_config, const uint &iChannel)
int n_colors
number of point cloud
double scale_X
number of streams
int pn_Y
Number of pixel of SLM in x direction.
cudaStream_t * streams
#define _Z
Definition: define.h:88
double k
(pixel_y * ny) / 2
unsigned int uint
Definition: typedef.h:62
double ty
tx = lambda / (2 * pp_X)
KernelConst_NotEncodedFrsn(const int &n_points, const int &n_colors, const int &n_streams, const vec3 &scale_factor, const Real &offset_depth, const ivec2 &pixel_number, const vec2 &pixel_pitch, const vec2 &ss, const Real &k, const Real &lambda, const Real &ratio)
ty = lambda / (2 * pp_Y)