QTrk
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
Image4DMemory< T > Class Template Reference

#include <cudaImageList.h>

Classes

struct  KernelParams
 

Public Member Functions

 Image4DMemory (int w, int h, int d, int L)
 
 ~Image4DMemory ()
 
void free ()
 
void copyToDevice (T *src, bool async=false, cudaStream_t s=0)
 
void copyToHost (T *dst, bool async=false, cudaStream_t s=0)
 
void clear ()
 
float * getImgAddr (int2 imgpos)
 
void copyImageToHost (int z, int l, T *dst, bool async=false, cudaStream_t s=0)
 
void copyImageToDevice (int z, int l, T *src, bool async=false, cudaStream_t s=0)
 
KernelParams bind ()
 
void unbind ()
 

Static Public Member Functions

static __device__ T read (const KernelParams &kp, int x, int y, int2 imgpos)
 
static __device__ void write (T value, const KernelParams &kp, int x, int y, int2 imgpos)
 

Public Attributes

KernelParams kp
 
int layers
 
int totalImg
 
int rows
 

Detailed Description

template<typename T>
class Image4DMemory< T >

Definition at line 404 of file cudaImageList.h.

Constructor & Destructor Documentation

§ Image4DMemory()

template<typename T >
Image4DMemory< T >::Image4DMemory ( int  w,
int  h,
int  d,
int  L 
)
inline

Definition at line 424 of file cudaImageList.h.

424  {
425  kp.imgh = h;
426  kp.imgw = w;
427  kp.depth = d;
428  layers = L;
429  totalImg = d*L;
430 
431  rows = 2048 / kp.imgh;
432  kp.cols = (totalImg + rows - 1) / rows;
433 
434  CheckCUDAError( cudaMallocPitch (&kp.d_data, &kp.pitch, sizeof(T) * kp.cols * kp.imgw, rows * kp.imgh) );
435  }
void CheckCUDAError(cufftResult_t err)
Definition: gpu_utils.h:36
KernelParams kp

§ ~Image4DMemory()

template<typename T >
Image4DMemory< T >::~Image4DMemory ( )
inline

Definition at line 437 of file cudaImageList.h.

437  {
438  free();
439  }

Member Function Documentation

§ bind()

template<typename T >
KernelParams Image4DMemory< T >::bind ( )
inline

Definition at line 494 of file cudaImageList.h.

494 { return kp; }
KernelParams kp

§ clear()

template<typename T >
void Image4DMemory< T >::clear ( )
inline

§ copyImageToDevice()

template<typename T >
void Image4DMemory< T >::copyImageToDevice ( int  z,
int  l,
T *  src,
bool  async = false,
cudaStream_t  s = 0 
)
inline

Definition at line 484 of file cudaImageList.h.

485  {
486  int2 imgpos = kp.GetImagePos(z, l);
487  if (async)
488  cudaMemcpy2DAsync(getImgAddr(imgpos), kp.pitch, src, sizeof(T)*kp.imgw, sizeof(T)*kp.imgw, kp.imgh, cudaMemcpyHostToDevice, s);
489  else
490  cudaMemcpy2D(getImgAddr(imgpos), kp.pitch, src, sizeof(T)*kp.imgw, sizeof(T)*kp.imgw, kp.imgh, cudaMemcpyHostToDevice);
491  }
float * getImgAddr(int2 imgpos)
KernelParams kp
CUBOTH int2 GetImagePos(int z, int l)

§ copyImageToHost()

template<typename T >
void Image4DMemory< T >::copyImageToHost ( int  z,
int  l,
T *  dst,
bool  async = false,
cudaStream_t  s = 0 
)
inline

Definition at line 475 of file cudaImageList.h.

476  {
477  int2 imgpos = kp.GetImagePos(z, l);
478  if (async)
479  cudaMemcpy2DAsync(dst, sizeof(T)*kp.imgw, getImgAddr(imgpos), kp.pitch, kp.imgw * sizeof(T), kp.imgh, cudaMemcpyDeviceToHost, s);
480  else
481  cudaMemcpy2D(dst, sizeof(T)*kp.imgw, getImgAddr(imgpos), kp.pitch, kp.imgw * sizeof(T), kp.imgh, cudaMemcpyDeviceToHost);
482  }
float * getImgAddr(int2 imgpos)
KernelParams kp
CUBOTH int2 GetImagePos(int z, int l)

§ copyToDevice()

template<typename T >
void Image4DMemory< T >::copyToDevice ( T *  src,
bool  async = false,
cudaStream_t  s = 0 
)
inline

Definition at line 445 of file cudaImageList.h.

446  {
447  for (int L=0;L<layers;L++) {
448  for (int i=0;i<kp.depth;i++)
449  copyImageToDevice(i, L, &src[ kp.imgw * kp.imgh * ( kp.depth * L + i ) ], async, s);
450  }
451  }
void copyImageToDevice(int z, int l, T *src, bool async=false, cudaStream_t s=0)
KernelParams kp

§ copyToHost()

template<typename T >
void Image4DMemory< T >::copyToHost ( T *  dst,
bool  async = false,
cudaStream_t  s = 0 
)
inline

Definition at line 453 of file cudaImageList.h.

454  {
455  for (int L=0;L<layers;L++) {
456  for (int i=0;i<kp.depth;i++)
457  copyImageToHost(i, L, &dst[ kp.imgw * kp.imgh * ( kp.depth * L + i ) ], async, s);
458  }
459  }
KernelParams kp
void copyImageToHost(int z, int l, T *dst, bool async=false, cudaStream_t s=0)

§ free()

template<typename T >
void Image4DMemory< T >::free ( )
inline

Definition at line 440 of file cudaImageList.h.

440  {
441  if(kp.d_data) cudaFree(kp.d_data);
442  kp.d_data=0;
443  }
KernelParams kp

§ getImgAddr()

template<typename T >
float* Image4DMemory< T >::getImgAddr ( int2  imgpos)
inline

Definition at line 467 of file cudaImageList.h.

468  {
469  char* d = (char*)kp.d_data;
470  d += imgpos.y * kp.pitch;
471  return &((float*)d)[imgpos.x];
472  }
KernelParams kp

§ read()

template<typename T >
static __device__ T Image4DMemory< T >::read ( const KernelParams kp,
int  x,
int  y,
int2  imgpos 
)
inlinestatic

Definition at line 497 of file cudaImageList.h.

497  {
498  return ((T*)( (char*)kp.d_data + (y + imgpos.y) * kp.pitch))[ x + imgpos.x ];
499  }
KernelParams kp

§ unbind()

template<typename T >
void Image4DMemory< T >::unbind ( )
inline

Definition at line 495 of file cudaImageList.h.

495 {}

§ write()

template<typename T >
static __device__ void Image4DMemory< T >::write ( value,
const KernelParams kp,
int  x,
int  y,
int2  imgpos 
)
inlinestatic

Definition at line 500 of file cudaImageList.h.

500  {
501  ((T*)( (char*)kp.d_data + (y + imgpos.y) * kp.pitch)) [ x + imgpos.x ] = value;
502  }
KernelParams kp

Member Data Documentation

§ kp

template<typename T >
KernelParams Image4DMemory< T >::kp

Definition at line 420 of file cudaImageList.h.

§ layers

template<typename T >
int Image4DMemory< T >::layers

Definition at line 421 of file cudaImageList.h.

§ rows

template<typename T >
int Image4DMemory< T >::rows

Definition at line 422 of file cudaImageList.h.

§ totalImg

template<typename T >
int Image4DMemory< T >::totalImg

Definition at line 421 of file cudaImageList.h.


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