Openholo  v2.1
Open Source Digital Holographic Library
ophWRP_GPU.h
Go to the documentation of this file.
1 #pragma once
2 /*M///////////////////////////////////////////////////////////////////////////////////////
3 //
4 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 //
6 // By downloading, copying, installing or using the software you agree to this license.
7 // If you do not agree to this license, do not download, install, copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Digital Holographic Library
12 //
13 // Openholo library is free software;
14 // you can redistribute it and/or modify it under the terms of the BSD 2-Clause license.
15 //
16 // Copyright (C) 2017-2024, Korea Electronics Technology Institute. All rights reserved.
17 // E-mail : contact.openholo@gmail.com
18 // Web : http://www.openholo.org
19 //
20 // Redistribution and use in source and binary forms, with or without modification,
21 // are permitted provided that the following conditions are met:
22 //
23 // 1. Redistribution's of source code must retain the above copyright notice,
24 // this list of conditions and the following disclaimer.
25 //
26 // 2. Redistribution's in binary form must reproduce the above copyright notice,
27 // this list of conditions and the following disclaimer in the documentation
28 // and/or other materials provided with the distribution.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the copyright holder or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 // This software contains opensource software released under GNU Generic Public License,
42 // NVDIA Software License Agreement, or CUDA supplement to Software License Agreement.
43 // Check whether software you use contains licensed software.
44 //
45 //M*/
46 
47 //#ifndef __ophWRP_GPU_h
48 //#define __ophWRP_GPU_h
49 
50 #include "ophWRP.h"
51 
52 #define __DEBUG_LOG_GPU_SPEC_
53 
54 #include <cuda_runtime.h>
55 #include <cufft.h>
56 
57 #define __CUDA_INTERNAL_COMPILATION__ //for CUDA Math Module
58 #include <math_constants.h>
59 #include <math_functions.h> //Single Precision Floating
60 #include <math_functions_dbl_ptx3.h> //Double Precision Floating
61 #include <vector_functions.h> //Vector Processing Function
62 #undef __CUDA_INTERNAL_COMPILATION__
63 
64 static void HandleError(cudaError_t err,
65  const char *file,
66  int line) {
67  if (err != cudaSuccess) {
68  printf("%s in %s at line %d\n", cudaGetErrorString(err),
69  file, line);
70  exit(EXIT_FAILURE);
71  }
72 }
73 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
74 
75 
76 #define HANDLE_NULL( a ) {if (a == NULL) { \
77  printf( "Host memory failed in %s at line %d\n", \
78  __FILE__, __LINE__ ); \
79  exit( EXIT_FAILURE );}}
80 
81 // for PointCloud only GPU
82 typedef struct KernelConst {
83  int n_points;
84  int n_colors;
85  int n_streams;
86 
87  Real wrp_d;
88  Real propa_d;
89 
90  int pn_X;
91  int pn_Y;
92 
93  double pp_X;
94  double pp_Y;
95 
96  double k;
97  double lambda;
98 
99  Real zmax;
100  bool bRandomPhase; // use random phase
101  int iAmplitude;
102 
103  double pi2;
104  double tx;
105  double ty;
106  double det_tx;
107  double det_ty;
108 
110  const int &n_points,
111  const int &n_colors,
112  const int &n_streams,
113  const ivec2 &pixel_number,
114  const vec2 &pixel_pitch,
115  const Real wrp_dis,
116  const Real propagation_distance,
117  const Real depth_max,
118  const Real &k,
119  const Real &lambda,
120  const bool &random_phase,
121  const int &index_amplitude
122  )
123  {
124  this->lambda = lambda;
125 
126  this->n_points = n_points;
127  this->n_colors = n_colors;
128  this->n_streams = n_streams;
129 
130  // Output Image Size
131  this->pn_X = pixel_number[_X];
132  this->pn_Y = pixel_number[_Y];
133 
134  // Pixel pitch at eyepiece lens plane (by simple magnification) ==> SLM pitch
135  this->pp_X = pixel_pitch[_X];
136  this->pp_Y = pixel_pitch[_Y];
137 
138  // WRP
139  this->wrp_d = wrp_dis;
140  this->propa_d = propagation_distance;
141  this->zmax = depth_max;
142 
143  // Wave Number
144  this->k = k;
145 
146  this->lambda = lambda;
147 
148  // Random Phase
149  this->bRandomPhase = random_phase;
150 
151  // Amplitude index
152  this->iAmplitude = index_amplitude;
153 
154  this->pi2 = M_PI * 2;
155 
156  this->tx = lambda / (2 * pp_X);
157  this->ty = lambda / (2 * pp_Y);
158  this->det_tx = tx / sqrt(1 - tx * tx);
159  this->det_ty = ty / sqrt(1 - ty * ty);
160 
161  }
162 } WRPGpuConst;
163 
164 //cufftDoubleComplex *p_wrp_gpu_;
165 
166 
167 extern "C"
168 {
170  const int &nBlocks, const int &nBlocks2, const int &nThreads, const int &nx, const int &ny,
171  cuDoubleComplex *src, cuDoubleComplex *dst, cufftDoubleComplex *fftsrc, cufftDoubleComplex *fftdst,
172  const WRPGpuConst* cuda_config);
173 
174  void cudaGenWRP(
175  const int &nBlocks, const int &nThreads, const int &n_pts_per_stream,
176  Real* cuda_pc_data, Real* cuda_amp_data,
177  cuDoubleComplex* cuda_dst, const WRPGpuConst* cuda_config);
178 }
bool bRandomPhase
wave length = lambda;
Definition: ophWRP_GPU.h:100
Real lambda
Wave Number = (2 * PI) / lambda;.
double det_ty
Definition: ophWRP_GPU.h:107
double det_tx
Definition: ophWRP_GPU.h:106
void cudaGenWRP(const int &nBlocks, const int &nThreads, const int &n_pts_per_stream, Real *cuda_pc_data, Real *cuda_amp_data, cuDoubleComplex *cuda_dst, const WRPGpuConst *cuda_config)
double pp_Y
Pixel pitch of SLM in x direction.
Real wrp_d
number of streams
Definition: ophWRP_GPU.h:87
#define _Y
Definition: define.h:84
double pp_X
Number of pixel of SLM in y direction.
Real zmax
wave length = lambda;
Definition: ophWRP_GPU.h:99
double tx
Definition: ophWRP_GPU.h:104
int n_streams
number of colors per point cloud
int pn_X
Offset value of point cloud in z direction.
KernelConst(const int &n_points, const int &n_colors, const int &n_streams, const ivec2 &pixel_number, const vec2 &pixel_pitch, const Real wrp_dis, const Real propagation_distance, const Real depth_max, const Real &k, const Real &lambda, const bool &random_phase, const int &index_amplitude)
Definition: ophWRP_GPU.h:109
int n_colors
number of point cloud
#define M_PI
Definition: define.h:52
double ty
Definition: ophWRP_GPU.h:105
int pn_Y
Number of pixel of SLM in x direction.
void cudaFresnelPropagationWRP(const int &nBlocks, const int &nBlocks2, const int &nThreads, const int &nx, const int &ny, cuDoubleComplex *src, cuDoubleComplex *dst, cufftDoubleComplex *fftsrc, cufftDoubleComplex *fftdst, const WRPGpuConst *cuda_config)
float Real
Definition: typedef.h:55
#define _X
Definition: define.h:80
int iAmplitude
Definition: ophWRP_GPU.h:101
struct KernelConst WRPGpuConst
Real k
Pixel pitch of SLM in y direction.
Real propa_d
wrp location
Definition: ophWRP_GPU.h:88