|
| 1 | +#include "InterpolatorHandle.h" |
| 2 | + |
| 3 | +#include <isce3/cuda/except/Error.h> |
| 4 | +#include <isce3/except/Error.h> |
| 5 | + |
| 6 | +#include <pyre/journal.h> |
| 7 | + |
| 8 | +#include <cuda_runtime.h> |
| 9 | +#include <thrust/complex.h> |
| 10 | +#include <thrust/device_vector.h> |
| 11 | + |
| 12 | +template<class T> |
| 13 | +using DeviceInterp = isce3::cuda::core::gpuInterpolator<T>; |
| 14 | + |
| 15 | +namespace isce3::cuda::core { |
| 16 | + |
| 17 | +template<class T> |
| 18 | +__global__ void init_interp( |
| 19 | + DeviceInterp<T>** interp, isce3::core::dataInterpMethod interp_method, |
| 20 | + bool * unsupported_interp) |
| 21 | +{ |
| 22 | + if (threadIdx.x == 0 && blockIdx.x == 0) { |
| 23 | + // Choose interpolator |
| 24 | + switch(interp_method) { |
| 25 | + case isce3::core::BILINEAR_METHOD: |
| 26 | + (*interp) = new isce3::cuda::core::gpuBilinearInterpolator<T>(); |
| 27 | + break; |
| 28 | + case isce3::core::BICUBIC_METHOD: |
| 29 | + (*interp) = new isce3::cuda::core::gpuBicubicInterpolator<T>(); |
| 30 | + break; |
| 31 | + case isce3::core::BIQUINTIC_METHOD: |
| 32 | + { |
| 33 | + size_t order = 6; |
| 34 | + (*interp) = new isce3::cuda::core::gpuSpline2dInterpolator<T>(order); |
| 35 | + break; |
| 36 | + } |
| 37 | + default: |
| 38 | + *unsupported_interp = true; |
| 39 | + break; |
| 40 | + } |
| 41 | + } |
| 42 | +} |
| 43 | + |
| 44 | +template<class T> |
| 45 | +__global__ void finalize_interp(DeviceInterp<T>** interp) |
| 46 | +{ |
| 47 | + if (threadIdx.x == 0 && blockIdx.x == 0) { |
| 48 | + delete *interp; |
| 49 | + } |
| 50 | +} |
| 51 | + |
| 52 | +template<class T> |
| 53 | +InterpolatorHandle<T>::InterpolatorHandle( |
| 54 | + isce3::core::dataInterpMethod interp_method) |
| 55 | +{ |
| 56 | + checkCudaErrors(cudaMalloc(&_interp, sizeof(DeviceInterp<T>**))); |
| 57 | + |
| 58 | + thrust::device_vector<bool> d_unsupported_interp(1, false); |
| 59 | + init_interp<<<1, 1>>>(_interp, interp_method, d_unsupported_interp.data().get()); |
| 60 | + checkCudaErrors(cudaPeekAtLastError()); |
| 61 | + checkCudaErrors(cudaDeviceSynchronize()); |
| 62 | + |
| 63 | + bool unsupported_interp = d_unsupported_interp[0]; |
| 64 | + if (unsupported_interp) |
| 65 | + { |
| 66 | + pyre::journal::error_t error( |
| 67 | + "isce.cuda.core.InterpolatorHandle.InterpolatorHandle"); |
| 68 | + error << "Unsupported interpolator method provided." |
| 69 | + << pyre::journal::endl; |
| 70 | + throw isce3::except::InvalidArgument(ISCE_SRCINFO(), |
| 71 | + "Unsupported interpolator method provided."); |
| 72 | + } |
| 73 | +} |
| 74 | + |
| 75 | +template<class T> |
| 76 | +InterpolatorHandle<T>::~InterpolatorHandle() |
| 77 | +{ |
| 78 | + finalize_interp<<<1, 1>>>(_interp); |
| 79 | + checkCudaErrors(cudaPeekAtLastError()); |
| 80 | + checkCudaErrors(cudaDeviceSynchronize()); |
| 81 | + checkCudaErrors(cudaFree(_interp)); |
| 82 | +} |
| 83 | + |
| 84 | +template class InterpolatorHandle<float>; |
| 85 | +template class InterpolatorHandle<thrust::complex<float>>; |
| 86 | +template class InterpolatorHandle<double>; |
| 87 | +template class InterpolatorHandle<thrust::complex<double>>; |
| 88 | +} // namespace isce3::cuda::core |
0 commit comments