1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
10 // For Open Source Digital Holographic Library
12 // Openholo library is free software;
13 // you can redistribute it and/or modify it under the terms of the BSD 2-Clause license.
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
19 // Redistribution and use in source and binary forms, with or without modification,
20 // are permitted provided that the following conditions are met:
22 // 1. Redistribution's of source code must retain the above copyright notice,
23 // this list of conditions and the following disclaimer.
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.
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.
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.
47 * @file ophRecKernel.cu
48 * @brief Openholo Reconstruction with CUDA GPGPU
54 #ifndef ophRecKernel_cu__
55 #define ophRecKernel_cu__
56 #include "ophKernel.cuh"
57 #include <cuda_runtime_api.h>
59 #include <curand_kernel.h>
60 #include <curand_uniform.h>
61 #include <device_launch_parameters.h>
62 #include "ophRec_GPU.h"
64 __global__ void cudaKernel_Encode(cuDoubleComplex *src, double *dst, const RecGpuConst* config)
66 ulonglong tid = blockIdx.x * blockDim.x + threadIdx.x;
82 double re = src[tid].x;
83 double im = src[tid].y;
84 dst[tid] = sqrt(re * re + im * im);
88 __global__ void cudaKernel_GetKernel(cuDoubleComplex *dst, const RecGpuConst* config)
90 ulonglong tid = blockIdx.x * blockDim.x + threadIdx.x;
95 __shared__ double lambda;
99 __shared__ double baseX;
100 __shared__ double baseY;
105 if (threadIdx.x == 0)
110 lambda = config->lambda;
113 baseX = config->baseX;
114 baseY = config->baseY;
116 z = config->distance;
125 double curX = baseX + (x * dx);
126 double curY = baseY + (y * dy);
127 double xx = curX * lambda;
128 double yy = curY * lambda;
130 cuDoubleComplex kernel;
132 kernel.y = sqrt(1 - xx * xx - yy * yy) * k * z;
133 exponent_complex(&kernel);
135 double re = dst[tid].x;
136 double im = dst[tid].y;
138 dst[tid].x = re * kernel.x - im * kernel.y;
139 dst[tid].y = re * kernel.y + im * kernel.x;
146 void cudaASMPropagation(
147 const int &nBlocks, const int &nThreads, const int &nx, const int &ny,
148 cuDoubleComplex *src, cuDoubleComplex *dst, Real *encode, const RecGpuConst* cuda_config)
150 cudaFFT(nullptr, nx, ny, src, dst, CUFFT_FORWARD, false);
152 cudaKernel_GetKernel << <nBlocks, nThreads >> > (dst, cuda_config);
154 if (cudaDeviceSynchronize() != cudaSuccess) {
155 LOG("Cuda error: Failed to synchronize\n");
159 cudaFFT(nullptr, nx, ny, dst, src, CUFFT_INVERSE, true);
161 cudaKernel_Encode << <nBlocks, nThreads >> > (src, encode, cuda_config);
167 #endif // !OphRecKernel_cu__