Openholo  v4.2
Open Source Digital Holographic Library
ophRec_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 __ophRec_GPU_h
48 //#define __ophRec_GPU_h
49 
50 #include "ophRec.h"
51 #include <cuda_runtime_api.h>
52 #include <cufft.h>
53 
54 #define __CUDA_INTERNAL_COMPILATION__ //for CUDA Math Module
55 #include <math_constants.h>
56 //#include <math_functions_dbl_ptx3.h> //Double Precision Floating
57 #include <vector_functions.h> //Vector Processing Function
58 #undef __CUDA_INTERNAL_COMPILATION__
59 
60 static void HandleError(cudaError_t err,
61  const char *file,
62  int line) {
63  if (err != cudaSuccess) {
64  printf("%s in %s at line %d\n", cudaGetErrorString(err),
65  file, line);
66  exit(EXIT_FAILURE);
67  }
68 }
69 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
70 
71 
72 #define HANDLE_NULL( a ) {if (a == NULL) { \
73  printf( "Host memory failed in %s at line %d\n", \
74  __FILE__, __LINE__ ); \
75  exit( EXIT_FAILURE );}}
76 
77 typedef struct KernelConst {
78  int channel;
79  int n_streams;
80 
81  Real distance;
82 
83  int pnX;
84  int pnY;
85 
86  double ppX;
87  double ppY;
88 
89  double k;
90  double lambda;
91 
92  bool bRandomPhase; // use random phase
93  double pi2;
94 
95  double tx;
96  double ty;
97  double dx;
98  double dy;
99  double htx;
100  double hty;
101  double hdx;
102  double hdy;
103 
104  double baseX;
105  double baseY;
106 
108  const int &channel,
109  const int &n_streams,
110  const int &pnX,
111  const int &pnY,
112  const Real &ppX,
113  const Real &ppY,
114  const Real &propagation_distance,
115  const Real &k,
116  const Real &lambda,
117  const bool &random_phase
118  )
119  {
120  this->channel = channel;
121  this->n_streams = n_streams;
122  this->lambda = lambda;
123 
124  // Output Image Size
125  this->pnX = pnX;
126  this->pnY = pnY;
127 
128  // Pixel pitch at eyepiece lens plane (by simple magnification) ==> SLM pitch
129  this->ppX = ppX;
130  this->ppY = ppY;
131 
132  // WRP
133  this->distance = propagation_distance;
134 
135  // Wave Number
136  this->k = k;
137 
138  this->lambda = lambda;
139 
140  // Random Phase
141  this->bRandomPhase = random_phase;
142 
143  this->pi2 = M_PI * 2;
144 
145  tx = 1 / ppX;
146  ty = 1 / ppY;
147  dx = tx / pnX;
148  dy = ty / pnY;
149 
150  htx = tx / 2;
151  hty = ty / 2;
152  hdx = dx / 2;
153  hdy = dy / 2;
154  baseX = -htx + hdx;
155  baseY = -hty + hdy;
156 
157  }
158 } RecGpuConst;
159 
160 
161 extern "C"
162 {
163  void cudaASMPropagation(
164  const int &nBlocks, const int &nThreads, const int &nx, const int &ny,
165  cuDoubleComplex *src, cuDoubleComplex *dst, Real *encode, const RecGpuConst* cuda_config);
166 }
int pnY
Number of pixel of SLM in x direction.
bool bRandomPhase
wave length = lambda;
Definition: ophRec_GPU.h:92
#define M_PI
Definition: define.h:52
Real lambda
Wave Number = (2 * PI) / lambda;.
KernelConst(const int &channel, const int &n_streams, const int &pnX, const int &pnY, const Real &ppX, const Real &ppY, const Real &propagation_distance, const Real &k, const Real &lambda, const bool &random_phase)
Definition: ophRec_GPU.h:107
struct KernelConst RecGpuConst
Real distance
number of streams
float Real
Definition: typedef.h:55
void cudaASMPropagation(const int &nBlocks, const int &nThreads, const int &nx, const int &ny, cuDoubleComplex *src, cuDoubleComplex *dst, Real *encode, const RecGpuConst *cuda_config)
double baseY
Definition: ophRec_GPU.h:105
double htx
Definition: ophRec_GPU.h:99
Real ppY
Pixel pitch of SLM in x direction.
double hty
Definition: ophRec_GPU.h:100
double baseX
Definition: ophRec_GPU.h:104
double hdy
Definition: ophRec_GPU.h:102
double tx
Definition: ophRec_GPU.h:95
Real ppX
Number of pixel of SLM in y direction.
int n_streams
number of colors per point cloud
Definition: ophRec_GPU.h:79
double ty
Definition: ophRec_GPU.h:96
double dx
Definition: ophRec_GPU.h:97
double dy
Definition: ophRec_GPU.h:98
Real k
Pixel pitch of SLM in y direction.
double hdx
Definition: ophRec_GPU.h:101