Openholo  v5.0
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_api.h>
55 #include <cufft.h>
56 
57 #define __CUDA_INTERNAL_COMPILATION__ //for CUDA Math Module
58 #include <math_constants.h>
59 //#include <math_functions_dbl_ptx3.h> //Double Precision Floating
60 #include <vector_functions.h> //Vector Processing Function
61 #undef __CUDA_INTERNAL_COMPILATION__
62 
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 // for PointCloud only GPU
81 typedef struct KernelConst {
82  int n_points;
83  int n_colors;
84  int n_streams;
85 
88 
89  int pn_X;
90  int pn_Y;
91 
92  double pp_X;
93  double pp_Y;
94 
95  double k;
96  double lambda;
97 
99  bool bRandomPhase; // use random phase
101 
102  double pi2;
103  double tx;
104  double ty;
105  double det_tx;
106  double det_ty;
107 
109  const int &n_points,
110  const int &n_colors,
111  const int &n_streams,
112  const ivec2 &pixel_number,
113  const vec2 &pixel_pitch,
114  const Real wrp_dis,
115  const Real propagation_distance,
116  const Real depth_max,
117  const Real &k,
118  const Real &lambda,
119  const bool &random_phase,
120  const int &index_amplitude
121  )
122  {
123  this->lambda = lambda;
124 
125  this->n_points = n_points;
126  this->n_colors = n_colors;
127  this->n_streams = n_streams;
128 
129  // Output Image Size
130  this->pn_X = pixel_number[_X];
131  this->pn_Y = pixel_number[_Y];
132 
133  // Pixel pitch at eyepiece lens plane (by simple magnification) ==> SLM pitch
134  this->pp_X = pixel_pitch[_X];
135  this->pp_Y = pixel_pitch[_Y];
136 
137  // WRP
138  this->wrp_d = wrp_dis;
139  this->propa_d = propagation_distance;
140  this->zmax = depth_max;
141 
142  // Wave Number
143  this->k = k;
144 
145  this->lambda = lambda;
146 
147  // Random Phase
148  this->bRandomPhase = random_phase;
149 
150  // Amplitude index
151  this->iAmplitude = index_amplitude;
152 
153  this->pi2 = M_PI * 2;
154 
155  this->tx = lambda / (2 * pp_X);
156  this->ty = lambda / (2 * pp_Y);
157  this->det_tx = tx / sqrt(1 - tx * tx);
158  this->det_ty = ty / sqrt(1 - ty * ty);
159 
160  }
161 } WRPGpuConst;
162 
163 //cufftDoubleComplex *p_wrp_gpu_;
164 
165 
166 extern "C"
167 {
169  const int &nBlocks, const int &nBlocks2, const int &nThreads, const int &nx, const int &ny,
170  cuDoubleComplex *src, cuDoubleComplex *dst, cufftDoubleComplex *fftsrc, cufftDoubleComplex *fftdst,
171  const WRPGpuConst* cuda_config);
172 
173  void cudaGenWRP(
174  const int &nBlocks, const int &nThreads, const int &n_pts_per_stream,
175  //Real* cuda_pc_data, Real* cuda_amp_data,
176  Vertex* cuda_pc_data,
177  cuDoubleComplex* cuda_dst, const WRPGpuConst* cuda_config);
178 }
bool bRandomPhase
wave length = lambda;
Definition: ophWRP_GPU.h:99
void cudaGenWRP(const int &nBlocks, const int &nThreads, const int &n_pts_per_stream, Vertex *cuda_pc_data, cuDoubleComplex *cuda_dst, const WRPGpuConst *cuda_config)
double lambda
Wave Number = (2 * PI) / lambda;.
Definition: ophWRP_GPU.h:96
double det_ty
Definition: ophWRP_GPU.h:106
double det_tx
Definition: ophWRP_GPU.h:105
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)
double pp_Y
Pixel pitch of SLM in x direction.
Definition: ophWRP_GPU.h:93
float Real
Definition: typedef.h:55
Real wrp_d
number of streams
Definition: ophWRP_GPU.h:86
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
double pp_X
Number of pixel of SLM in y direction.
Definition: ophWRP_GPU.h:92
#define _Y
Definition: define.h:96
#define _X
Definition: define.h:92
double pi2
Definition: ophWRP_GPU.h:102
Real zmax
wave length = lambda;
Definition: ophWRP_GPU.h:98
int n_points
Definition: ophWRP_GPU.h:82
struct KernelConst WRPGpuConst
structure for 2-dimensional Real type vector and its arithmetic.
Definition: vec.h:66
double tx
Definition: ophWRP_GPU.h:103
Definition: struct.h:102
int n_streams
number of colors per point cloud
Definition: ophWRP_GPU.h:84
int pn_X
propagation distance
Definition: ophWRP_GPU.h:89
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:108
int n_colors
number of point cloud
Definition: ophWRP_GPU.h:83
double ty
Definition: ophWRP_GPU.h:104
int pn_Y
Number of pixel of SLM in x direction.
Definition: ophWRP_GPU.h:90
int iAmplitude
Definition: ophWRP_GPU.h:100
double k
Pixel pitch of SLM in y direction.
Definition: ophWRP_GPU.h:95
Real propa_d
wrp location
Definition: ophWRP_GPU.h:87
#define M_PI
Definition: define.h:52