Openholo  v4.0
Open Source Digital Holographic Library
ophLightField_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 
46 #ifndef __ophLightField_GPU_h
47 #define __ophLightField_GPU_h
48 
49 #include "ophLightField.h"
50 #include <cuda_runtime_api.h>
51 #include <cufft.h>
52 #include <math_constants.h>
53 
54 
55 static void HandleError(cudaError_t err,
56  const char *file,
57  int line) {
58  if (err != cudaSuccess) {
59  printf("%s in %s at line %d\n", cudaGetErrorString(err),
60  file, line);
61  return;
62  }
63 }
64 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
65 
66 
67 #define HANDLE_NULL( a ) {if (a == NULL) { \
68  printf( "Host memory failed in %s at line %d\n", \
69  __FILE__, __LINE__ ); \
70  exit( EXIT_FAILURE );}}
71 
72 typedef struct KernelConst {
73  int pnX;
74  int pnY;
82  int nX;
83  int nY;
84  int rX;
85  int rY;
86  int nChannel;
87  int iAmp;
88 
90  const int &channel,
91  const int &iAmp,
92  const int &pnX,
93  const int &pnY,
94  const Real &ppX,
95  const Real &ppY,
96  const int &nX,
97  const int &nY,
98  const int &rX,
99  const int &rY,
100  const Real &distance,
101  const Real &k,
102  const Real &lambda,
103  const bool &random_phase
104  )
105  {
106  this->nChannel = channel;
107  this->iAmp = iAmp;
108  this->pnX = pnX;
109  this->pnY = pnY;
110  this->ppX = ppX;
111  this->ppY = ppY;
112  this->nX = nX;
113  this->nY = nY;
114  this->rX = rX;
115  this->rY = rY;
116  this->lambda = lambda;
117  this->pi2 = M_PI * 2;
118  this->k = pi2 / lambda;
119  this->distance = distance;
120  this->randomPhase = random_phase;
121  }
122 } LFGpuConst;
123 
124 extern "C"
125 {
126  void cudaConvertLF2ComplexField_Kernel(CUstream_st* stream, const int &nBlocks, const int &nThreads, const LFGpuConst *config, uchar1** LF, cufftDoubleComplex* output);
127  void cudaFFT_LF(cufftHandle *plan, CUstream_st* stream, const int &nBlocks, const int &nThreads, const int &nx, const int &ny, cufftDoubleComplex* in_field, cufftDoubleComplex* output_field, const int &direction);
128 
129  void procMultiplyPhase(CUstream_st* stream, const int &nBlocks, const int &nThreads, const LFGpuConst *config, cufftDoubleComplex* in, cufftDoubleComplex* output);
130 
132  const int &nBlocks, const int &nBlocks2, const int &nThreads, const int &nx, const int &ny,
133  cufftDoubleComplex *src, cufftDoubleComplex *tmp, cufftDoubleComplex *tmp2, cufftDoubleComplex *dst,
134  const LFGpuConst* cuda_config);
135 }
136 
137 
138 #endif
int pnY
Number of pixel of SLM in x direction.
Real lambda
Wave Number = (2 * PI) / lambda;.
Real distance
number of streams
float Real
Definition: typedef.h:55
void cudaConvertLF2ComplexField_Kernel(CUstream_st *stream, const int &nBlocks, const int &nThreads, const LFGpuConst *config, uchar1 **LF, cufftDoubleComplex *output)
void cudaFFT_LF(cufftHandle *plan, CUstream_st *stream, const int &nBlocks, const int &nThreads, const int &nx, const int &ny, cufftDoubleComplex *in_field, cufftDoubleComplex *output_field, const int &direction)
struct KernelConst LFGpuConst
void cudaFresnelPropagationLF(const int &nBlocks, const int &nBlocks2, const int &nThreads, const int &nx, const int &ny, cufftDoubleComplex *src, cufftDoubleComplex *tmp, cufftDoubleComplex *tmp2, cufftDoubleComplex *dst, const LFGpuConst *cuda_config)
KernelConst(const int &channel, const int &iAmp, const int &pnX, const int &pnY, const Real &ppX, const Real &ppY, const int &nX, const int &nY, const int &rX, const int &rY, const Real &distance, const Real &k, const Real &lambda, const bool &random_phase)
void procMultiplyPhase(CUstream_st *stream, const int &nBlocks, const int &nThreads, const LFGpuConst *config, cufftDoubleComplex *in, cufftDoubleComplex *output)
Real k
Pixel pitch of SLM in y direction.
#define M_PI
Definition: define.h:52