Xmipp  v3.23.11-Nereus
Public Member Functions | Static Public Member Functions | List of all members
Alignment::CudaRotPolarEstimator< T > Class Template Reference

#include <cuda_rot_polar_estimator.h>

Inheritance diagram for Alignment::CudaRotPolarEstimator< T >:
Inheritance graph
[legend]
Collaboration diagram for Alignment::CudaRotPolarEstimator< T >:
Collaboration graph
[legend]

Public Member Functions

 CudaRotPolarEstimator ()
 
virtual ~CudaRotPolarEstimator ()
 
 CudaRotPolarEstimator (CudaRotPolarEstimator &o)=delete
 
CudaRotPolarEstimatoroperator= (const CudaRotPolarEstimator &other)=delete
 
 CudaRotPolarEstimator (CudaRotPolarEstimator &&o)
 
CudaRotPolarEstimator const & operator= (CudaRotPolarEstimator &&o)=delete
 
template<bool FULL_CIRCLE>
void sComputePolarTransform (const GPU &gpu, const Dimensions &dimIn, T *__restrict__ d_in, const Dimensions &dimOut, T *__restrict__ d_out, int posOfFirstRing)
 
template<bool FULL_CIRCLE>
void sNormalize (const GPU &gpu, const Dimensions &dim, T *__restrict__ d_in, T *__restrict__ d_sums, T *__restrict__ d_sumsSqr, int posOfFirstRing)
 
- Public Member Functions inherited from Alignment::ARotationEstimator< T >
 ARotationEstimator ()
 
void init (const RotationEstimationSetting settings, bool reuse)
 
void loadReference (const T *ref)
 
void compute (T *others)
 
const std::vector< float > & getRotations2D () const
 
virtual ~ARotationEstimator ()
 
HWgetHW () const
 
const RotationEstimationSettinggetSettings () const
 

Static Public Member Functions

static void sComputeCorrelationsOneToN (const GPU &gpu, const std::complex< T > *d_in, std::complex< T > *d_out, const std::complex< T > *d_ref, const Dimensions &dims, int firstRingRadius)
 
template<bool FULL_CIRCLE>
static void sComputePolarTransform (const GPU &gpu, const Dimensions &dimIn, T *d_in, const Dimensions &dimOut, T *d_out, int posOfFirstRing)
 
template<bool FULL_CIRCLE>
static void sNormalize (const GPU &gpu, const Dimensions &dimIn, T *d_in, T *d_1, T *d_2, int posOfFirstRing)
 

Additional Inherited Members

- Protected Member Functions inherited from Alignment::ARotationEstimator< T >
std::vector< float > & getRotations2D ()
 
constexpr bool isInitialized () const
 
constexpr bool isRefLoaded () const
 

Detailed Description

template<typename T>
class Alignment::CudaRotPolarEstimator< T >

Definition at line 44 of file cuda_rot_polar_estimator.h.

Constructor & Destructor Documentation

◆ CudaRotPolarEstimator() [1/3]

template<typename T>
Alignment::CudaRotPolarEstimator< T >::CudaRotPolarEstimator ( )
inline

Definition at line 46 of file cuda_rot_polar_estimator.h.

46  {
47  setDefault();
48  }

◆ ~CudaRotPolarEstimator()

template<typename T>
virtual Alignment::CudaRotPolarEstimator< T >::~CudaRotPolarEstimator ( )
inlinevirtual

Definition at line 50 of file cuda_rot_polar_estimator.h.

50  {
51  release();
52  }

◆ CudaRotPolarEstimator() [2/3]

template<typename T>
Alignment::CudaRotPolarEstimator< T >::CudaRotPolarEstimator ( CudaRotPolarEstimator< T > &  o)
delete

◆ CudaRotPolarEstimator() [3/3]

template<typename T>
Alignment::CudaRotPolarEstimator< T >::CudaRotPolarEstimator ( CudaRotPolarEstimator< T > &&  o)
inline

Definition at line 56 of file cuda_rot_polar_estimator.h.

56  {
57  m_mainStream = o.m_mainStream;
58  m_backgroundStream = o.m_backgroundStream;
59  m_samples = o.m_samples;
60 
61  // device memory
62  m_d_ref = o.m_d_ref;
63  m_d_batch = o.m_d_batch;
64  m_d_batchPolarOrCorr = o.m_d_batchPolarOrCorr;
65  m_d_batchPolarFD = o.m_d_batchPolarFD;
66  m_d_sumsOrMaxPos = o.m_d_sumsOrMaxPos;
67  m_d_sumsSqr = o.m_d_sumsSqr;
68  m_d_batchCorrSumFD = o.m_d_batchCorrSumFD;
69 
70  // FT plans
71  m_singleToFD = o.m_singleToFD;
72  m_batchToFD = o.m_batchToFD;
73  m_batchToSD = o.m_batchToSD;
74 
75  // synch primitives
76  m_mutex = o.m_mutex;
77  m_cv = o.m_cv;
78  m_isDataReady = o.m_isDataReady;
79 
80  // host memory
81  m_h_batchMaxPositions = o.m_h_batchMaxPositions;
82 
83  // remove data from other
84  o.setDefault();
85  }

Member Function Documentation

◆ operator=() [1/2]

template<typename T>
CudaRotPolarEstimator& Alignment::CudaRotPolarEstimator< T >::operator= ( const CudaRotPolarEstimator< T > &  other)
delete

◆ operator=() [2/2]

template<typename T>
CudaRotPolarEstimator const& Alignment::CudaRotPolarEstimator< T >::operator= ( CudaRotPolarEstimator< T > &&  o)
delete

◆ sComputeCorrelationsOneToN()

template<typename T >
void Alignment::CudaRotPolarEstimator< T >::sComputeCorrelationsOneToN ( const GPU gpu,
const std::complex< T > *  d_in,
std::complex< T > *  d_out,
const std::complex< T > *  d_ref,
const Dimensions dims,
int  firstRingRadius 
)
static

Definition at line 216 of file cuda_rot_polar_estimator.cpp.

222  {
223  auto stream = *(cudaStream_t*)gpu.stream();
224  dim3 dimBlock(32);
225  dim3 dimGrid(
226  ceil((dims.x() * dims.n()) / (float)dimBlock.x));
227  if (std::is_same<T, float>::value) {
228  computePolarCorrelationsSumOneToNKernel<float2>
229  <<<dimGrid, dimBlock, 0, stream>>> (
230  (float2*)d_in, (float2*)d_out,
231  (float2*)d_ref,
232  firstRingRadius,
233  dims.x(), dims.y(), dims.n());
234  } else if (std::is_same<T, double>::value) {
235  computePolarCorrelationsSumOneToNKernel<double2>
236  <<<dimGrid, dimBlock, 0, stream>>> (
237  (double2*)d_in, (double2*)d_out,
238  (double2*)d_ref,
239  firstRingRadius,
240  dims.x(), dims.y(), dims.n());
241  } else {
242  REPORT_ERROR(ERR_TYPE_INCORRECT, "Not implemented");
243  }
244 }
void * stream() const
Definition: gpu.h:50
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
CUDA_HD constexpr size_t x() const
Definition: dimensions.h:51
CUDA_HD constexpr size_t y() const
Definition: dimensions.h:60
CUDA_HD constexpr size_t n() const
Definition: dimensions.h:78
Incorrect type received.
Definition: xmipp_error.h:190

◆ sComputePolarTransform() [1/2]

template<typename T>
template<bool FULL_CIRCLE>
static void Alignment::CudaRotPolarEstimator< T >::sComputePolarTransform ( const GPU gpu,
const Dimensions dimIn,
T *  d_in,
const Dimensions dimOut,
T *  d_out,
int  posOfFirstRing 
)
static

◆ sComputePolarTransform() [2/2]

template<typename T>
template<bool FULL_CIRCLE>
void Alignment::CudaRotPolarEstimator< T >::sComputePolarTransform ( const GPU gpu,
const Dimensions dimIn,
T *__restrict__  d_in,
const Dimensions dimOut,
T *__restrict__  d_out,
int  posOfFirstRing 
)

Definition at line 281 of file cuda_rot_polar_estimator.cpp.

287  {
288  assert (dimIn.x() == dimIn.y());
289  assert ((dimOut.y() + 1) * 2 <= dimIn.x()); // assert that there's space around the biggest ring
290  dim3 dimBlock(32);
291  dim3 dimGrid(
292  ceil((dimOut.x() * dimOut.n()) / (float)dimBlock.x));
293 
294  auto stream = *(cudaStream_t*)gpu.stream();
295 
296  polarFromCartesian<T, FULL_CIRCLE>
297  <<<dimGrid, dimBlock, 0, stream>>> (
298  d_in, dimIn.x(), dimIn.y(),
299  d_out, dimOut.x(), dimOut.y(), dimOut.n(), posOfFirstRing);
300 }
void * stream() const
Definition: gpu.h:50
CUDA_HD constexpr size_t x() const
Definition: dimensions.h:51
CUDA_HD constexpr size_t y() const
Definition: dimensions.h:60
CUDA_HD constexpr size_t n() const
Definition: dimensions.h:78

◆ sNormalize() [1/2]

template<typename T>
template<bool FULL_CIRCLE>
static void Alignment::CudaRotPolarEstimator< T >::sNormalize ( const GPU gpu,
const Dimensions dimIn,
T *  d_in,
T *  d_1,
T *  d_2,
int  posOfFirstRing 
)
static

◆ sNormalize() [2/2]

template<typename T>
template<bool FULL_CIRCLE>
void Alignment::CudaRotPolarEstimator< T >::sNormalize ( const GPU gpu,
const Dimensions dim,
T *__restrict__  d_in,
T *__restrict__  d_sums,
T *__restrict__  d_sumsSqr,
int  posOfFirstRing 
)

Definition at line 304 of file cuda_rot_polar_estimator.cpp.

310  {
311  dim3 dimBlock(64);
312  dim3 dimGrid(
313  ceil((dim.x() * dim.n()) / (float)dimBlock.x));
314 
315  auto stream = *(cudaStream_t*)gpu.stream();
316  // clear the arrays
317  size_t bytes = dim.n() * sizeof(T);
318  gpuErrchk(cudaMemset(d_sums, 0, bytes));
319  gpuErrchk(cudaMemset(d_sumsSqr, 0, bytes));
320  computeSumSumSqr<T, FULL_CIRCLE>
321  <<<dimGrid, dimBlock, 0, stream>>> (
322  d_in, dim.x(), dim.y(), dim.n(),
323  d_sums, d_sumsSqr, posOfFirstRing);
324 
325  const T piConst = FULL_CIRCLE ? (2 * M_PI) : M_PI;
326  // sum of the first n terms of an arithmetic sequence
327  // a1 = first radius (posOfFirstRing)
328  // an = last radius (dim.y() - 1 + posOfFirstRing)
329  // s = n * (a1 + an) / 2
330  const T radiiSum = (dim.y() * (2 * posOfFirstRing + dim.y() - 1)) / (T)2;
331  T norm = piConst * radiiSum;
332 
333  normalize<T>
334  <<<dimGrid, dimBlock, 0, stream>>> (
335  d_in, dim.x(), dim.y(), dim.n(),
336  norm,
337  d_sums, d_sumsSqr);
338 }
#define gpuErrchk(code)
Definition: cuda_asserts.h:31
void * stream() const
Definition: gpu.h:50
T norm(const std::vector< T > &v)
Definition: vector_ops.h:399
CUDA_HD constexpr size_t x() const
Definition: dimensions.h:51
CUDA_HD constexpr size_t y() const
Definition: dimensions.h:60
CUDA_HD constexpr size_t n() const
Definition: dimensions.h:78

The documentation for this class was generated from the following files: