Openholo  v4.2
Open Source Digital Holographic Library
ophTriMesh_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 __ophTriMesh_GPU_h
47 #define __ophTriMesh_GPU_h
48 
49 #include "ophTriMesh.h"
50 
51 #include "sys.h"
52 #include <stdio.h>
53 #include <cuda_runtime_api.h>
54 #include <cufft.h>
55 #include <curand.h>
56 #include <math_constants.h>
57 
58 
59 static void HandleError(cudaError_t err,
60  const char *file,
61  int line) {
62  if (err != cudaSuccess) {
63  printf("%s in %s at line %d\n", cudaGetErrorString(err),
64  file, line);
65  exit(EXIT_FAILURE);
66  }
67 }
68 #define HANDLE_ERROR( err ) (HandleError( err, __FILE__, __LINE__ ))
69 
70 
71 #define HANDLE_NULL( a ) {if (a == NULL) { \
72  printf( "Host memory failed in %s at line %d\n", __FILE__, __LINE__ ); \
73  exit( EXIT_FAILURE );}}
74 
75 #define CUDA_CALL(x) { if((x)!=cudaSuccess) { \
76  printf("Error at %s:%d\n",__FILE__,__LINE__);\
77  exit( EXIT_FAILURE ); }}
78 #define CURAND_CALL(x) { if((x)!=CURAND_STATUS_SUCCESS) { \
79  printf("Error at %s:%d\n",__FILE__,__LINE__);\
80  exit( EXIT_FAILURE ); }}
81 
82 
83 typedef struct MeshKernelConfig {
84  int pn_X;
85  int pn_Y;
86  double pp_X;
87  double pp_Y;
88  unsigned int shading_flag; // flat or continuous
89  double dfx;
90  double dfy;
91  double lambda;
92  double min_double;
93  double tolerence;
94  double pi;
95  double pi2;
96  double square_pi2;
97  double cube_pi2;
98 
100  const ivec2& pixel_number,
101  const vec2& pixel_pitch,
102  const Real& lambda,
103  const uint& shading_flag
104  )
105  {
106  // Output Image Size
107  this->pn_X = pixel_number[_X];
108  this->pn_Y = pixel_number[_Y];
109 
110  // Pixel pitch at eyepiece lens plane (by simple magnification) ==> SLM pitch
111  this->pp_X = pixel_pitch[_X];
112  this->pp_Y = pixel_pitch[_Y];
113 
114  this->lambda = lambda;
115 
116  this->dfx = (1.0 / this->pp_X) / this->pn_X;
117  this->dfy = (1.0 / this->pp_Y) / this->pn_Y;
118 
119  this->shading_flag = shading_flag;
120 
121  min_double = (double)2.2250738585072014e-308;
122  tolerence = 1e-12;
123  pi = M_PI;
124  pi2 = pi * 2;
125  square_pi2 = pi2 * pi2;
126  cube_pi2 = square_pi2 * pi2;
127  }
129 
130 
131 extern "C"
132 {
133  void cudaMesh_Flat(
134  const int& nBlocks, const int& nThreads, cufftDoubleComplex* output,
135  const MeshKernelConfig* config, double shading_factor, const geometric* geom,
136  double carrierWaveX, double carrierWaveY, double carrierWaveZ, CUstream_st* stream
137  );
138 
139  void cudaMesh_Continuous(
140  const int& nBlocks, const int& nThreads, cufftDoubleComplex* output,
141  const MeshKernelConfig* config, const geometric* geom, double av0, double av1, double av2,
142  double carrierWaveX, double carrierWaveY, double carrierWaveZ, CUstream_st* stream
143  );
144 
145  void call_fftGPU(int nx, int ny, cufftDoubleComplex* input, cufftDoubleComplex* output, CUstream_st* streamTriMesh);
146  void call_fftGPUf(int nx, int ny, cuFloatComplex* input, cuFloatComplex* output, CUstream_st* streamTriMesh);
147 
148 }
149 
150 #endif
void call_fftGPUf(int nx, int ny, cuFloatComplex *input, cuFloatComplex *output, CUstream_st *streamTriMesh)
unsigned int shading_flag
Pixel pitch of SLM in y direction.
#define M_PI
Definition: define.h:52
void call_fftGPU(int nx, int ny, cufftDoubleComplex *input, cufftDoubleComplex *output, CUstream_st *streamTriMesh)
void cudaMesh_Continuous(const int &nBlocks, const int &nThreads, cufftDoubleComplex *output, const MeshKernelConfig *config, const geometric *geom, double av0, double av1, double av2, double carrierWaveX, double carrierWaveY, double carrierWaveZ, CUstream_st *stream)
float Real
Definition: typedef.h:55
structure for 2-dimensional integer vector and its arithmetic.
Definition: ivec.h:66
struct MeshKernelConfig MeshKernelConfig
MeshKernelConfig(const ivec2 &pixel_number, const vec2 &pixel_pitch, const Real &lambda, const uint &shading_flag)
double pp_X
Number of pixel of SLM in y direction.
#define _X
Definition: define.h:92
geometrical relations
Definition: ophTriMesh.h:62
void cudaMesh_Flat(const int &nBlocks, const int &nThreads, cufftDoubleComplex *output, const MeshKernelConfig *config, double shading_factor, const geometric *geom, double carrierWaveX, double carrierWaveY, double carrierWaveZ, CUstream_st *stream)
int pn_Y
Number of pixel of SLM in x direction.
structure for 2-dimensional Real type vector and its arithmetic.
Definition: vec.h:66
#define _Y
Definition: define.h:96
double pp_Y
Pixel pitch of SLM in x direction.
unsigned int uint
Definition: typedef.h:62