CudaImage< T > Struct Template Reference

CudaImage template class. More...

#include <CUDA/CudaImage.H>

List of all members.

Public Member Functions

void clear (const char &val=0)
 clear contents (or set to given value)
Constructors, destructors, assignment

 CudaImage (const T *inarray, int width, int height, const MemoryPolicy mp, const int dev, const MemoryPolicy srcmp, const int srcdev)
 Construct from C array using memory policy.
 CudaImage (const T *inarray, const Dims &dims, const MemoryPolicy mp, const int dev, const MemoryPolicy srcmp, const int srcdev)
 Construct from C array using memory policy.
 CudaImage (int width, int height, InitPolicy init, const MemoryPolicy mp, const int dev)
 Allocates memory for given size, optionally zero-clear that memory, and set the memory policy.
 CudaImage (const Dims &dims, const MemoryPolicy mp, const int dev)
 Constructor that only allocates memory for given size.
 CudaImage (const Dims &dims, InitPolicy init, const MemoryPolicy mp, const int dev)
 Constructor that only allocates memory for given size and init type.
 CudaImage ()
 Construct an empty (0-by-0) image (useful for arrays of CudaImages).
 CudaImage (const CudaImage< T > &A)
 Copy constructor.
 CudaImage (const CudaImage< T > &A, const MemoryPolicy mp, const int dev)
 Copy constructor to particular memory.
 CudaImage (const Image< T > &A, const MemoryPolicy mp, const int dev)
 Import copy constructor.
CudaImage< T > & operator= (const CudaImage< T > &A)
 Assigment operator.
 ~CudaImage ()
 Destructor.
void freeMem ()
 Free memory and switch to uninitialized state.
Math operators

CudaImage< float > & operator+= (const float val)
 Math operators.
CudaImage< float > & operator-= (const float val)
 Subtraction inplace by a host provided scalar.
CudaImage< float > & operator*= (const float val)
 Multiplication inplace by a host provided scalar.
CudaImage< float > & operator/= (const float val)
 Division inplace by a host provided scalar.
CudaImage< float > & operator+= (const CudaImage< float > &im)
 Addition inplace by a device image or scalar (a 1x1 CudaImage is treated as a scalar).
CudaImage< float > & operator-= (const CudaImage< float > &im)
 Subtraction inplace by a device image or scalar (a 1x1 CudaImage is treated as a scalar).
CudaImage< float > & operator*= (const CudaImage< float > &im)
 Multiplication inplace by a device image or scalar (a 1x1 CudaImage is treated as a scalar).
CudaImage< float > & operator/= (const CudaImage< float > &im)
 Division inplace by a device image or scalar (a 1x1 CudaImage is treated as a scalar).
CudaImage< float > operator+ (const float val) const
 Addition by a host provided scalar.
CudaImage< float > operator- (const float val) const
 Subtraction by a host provided scalar.
CudaImage< float > operator* (const float val) const
 Multiplcation by a host provided scalar.
CudaImage< float > operator/ (const float val) const
 Division by a host provided scalar.
CudaImage< float > operator+ (const CudaImage< float > &im) const
 Addition by a device image or scalar (a 1x1 CudaImage is treated as a scalar).
CudaImage< float > operator- (const CudaImage< float > &im) const
 Subtraction by a device image or scalar (a 1x1 CudaImage is treated as a scalar).
CudaImage< float > operator* (const CudaImage< float > &im) const
 Multiplication by a device image or scalar (a 1x1 CudaImage is treated as a scalar).
CudaImage< float > operator/ (const CudaImage< float > &im) const
 Division by a device image or scalar (a 1x1 CudaImage is treated as a scalar).
Memory management functions

void swap (CudaImage< T > &other)
 Swap the contents of two images.
CudaImage< T > deepcopy () const
 Return a new image object with a deep copy of the underlying data.
CudaImage< T > deepcopy (const MemoryPolicy mp, const int dev) const
 Return a new image w/ deep copy of underlying data using memory policy.
Image< T > exportToImage () const
void resize (const Dims &dims, const bool clear=false)
 Free mem and realloc new array (array contents are lost).
void resize (const int width, const int height, const bool clear=false)
 Free mem and realloc new array (array contents are lost).
Access functions

bool initialized () const
 Check whether image is non-empty (i.e., non-zero height and width).
int getSize () const
 Get image size (width * height).
uint size () const
 Get image size (width * height).
int getWidth () const
 Get image width.
int getHeight () const
 Get image height.
const DimsgetDims () const
 Get image width+height in Dims struct.
Rectangle getBounds () const
 Get image bounds as a rectangle with upper-left point at (0,0) and dims matching the image dims.
template<class C >
bool isSameSize (const C &other) const
 Check if *this is the same size as the other thing.
bool is1D () const
 Check if the image is 1D, i.e., width == 1 or height == 1.
bool isVector () const
 Check if the image is a vector, i.e., width == 1.
bool isTransposedVector () const
 Check if the image is a transposed vector, i.e., height == 1.
bool isSquare () const
 Check if the image is square, i.e., width == height.
const T * getCudaArrayPtr () const
 Returns read-only (const) pointer to internal image array.
T * getCudaArrayPtr ()
 Returns read/write (non-const) pointer to internal image array.
bool coordsOk (const Point2D< int > &P) const
 Test whether point falls inside array boundaries.
bool coordsOk (const int i, const int j) const
 Test whether point falls inside array boundaries.
bool coordsOk (const Point2D< float > &p) const
 Test whether point falls inside array boundaries.
bool coordsOk (const float i, const float j) const
 Test whether point falls inside array boundaries.
bool rectangleOk (const Rectangle &rect) const
 Test whether rectangle fits in image.
MemoryPolicy getMemoryPolicy () const
 Return memory policy of underlying array data.
int getMemoryDevice () const
 Return memory policy of underlying array data.
Functions for testing/debugging only

bool hasSameData (const CudaImage< T > &b) const
 For testing/debugging only.
long refCount () const throw ()
 For testing/debugging only.
bool isShared () const throw ()
 For testing/debugging only.

Public Attributes

int width
int height
int pitch
float * h_data
float * d_data
void * t_data

Detailed Description

template<class T>
struct CudaImage< T >

CudaImage template class.

This is a image template class for CUDA devices that can handle grayscale as well as color or multispectral images. CudaImage methods should be instantiable for any type T that has the basic arithmetic operators. However, our CUDA processing is inherently float based, so conversions may occur. Note that some CudaImage functions will only work with float types, and other will only work for composite types such as PixRGB.

Definition at line 63 of file CudaImage.H.


Constructor & Destructor Documentation

template<class T>
CudaImage< T >::CudaImage ( const T *  inarray,
int  width,
int  height,
const MemoryPolicy  mp,
const int  dev,
const MemoryPolicy  srcmp,
const int  srcdev 
) [inline]

Construct from C array using memory policy.

Build from C array; an internal copy of the C array will be allocated, so the C array can (and should) be freed without affecting the Image.

Definition at line 430 of file CudaImage.H.

template<class T>
CudaImage< T >::CudaImage ( const T *  inarray,
const Dims dims,
const MemoryPolicy  mp,
const int  dev,
const MemoryPolicy  srcmp,
const int  srcdev 
) [inline]

Construct from C array using memory policy.

Build from C array; an internal copy of the C array will be allocated, so the C array can (and should) be freed without affecting the CudaImage.

Definition at line 436 of file CudaImage.H.

template<class T>
CudaImage< T >::CudaImage ( int  width,
int  height,
InitPolicy  init,
const MemoryPolicy  mp,
const int  dev 
) [inline]

Allocates memory for given size, optionally zero-clear that memory, and set the memory policy.

Definition at line 442 of file CudaImage.H.

template<class T>
CudaImage< T >::CudaImage ( const Dims dims,
const MemoryPolicy  mp,
const int  dev 
) [inline, explicit]

Constructor that only allocates memory for given size.

Definition at line 448 of file CudaImage.H.

template<class T>
CudaImage< T >::CudaImage ( const Dims dims,
InitPolicy  init,
const MemoryPolicy  mp,
const int  dev 
) [inline, explicit]

Constructor that only allocates memory for given size and init type.

Definition at line 454 of file CudaImage.H.

template<class T>
CudaImage< T >::CudaImage (  )  [inline]

Construct an empty (0-by-0) image (useful for arrays of CudaImages).

Definition at line 460 of file CudaImage.H.

template<class T>
CudaImage< T >::CudaImage ( const CudaImage< T > &  A  )  [inline]

Copy constructor.

e.g.:

      CudaImage<byte> im(other);
      // or
      CudaImage<byte> im = other; // with other also of type CudaImage<byte>

Definition at line 466 of file CudaImage.H.

template<class T>
CudaImage< T >::CudaImage ( const CudaImage< T > &  A,
const MemoryPolicy  mp,
const int  dev 
) [inline]

Copy constructor to particular memory.

e.g.:

      CudaImage<byte> im(other);
      // or
      CudaImage<byte> im = other; // with other also of type CudaImage<byte>

Definition at line 472 of file CudaImage.H.

References CudaImage< T >::getCudaArrayPtr(), CudaImage< T >::getMemoryDevice(), CudaImage< T >::getMemoryPolicy(), and CudaImage< T >::size().

template<class T>
CudaImage< T >::CudaImage ( const Image< T > &  A,
const MemoryPolicy  mp,
const int  dev 
) [inline]

Import copy constructor.

e.g.:

      CudaImage<byte> im(other);
      // or
      CudaImage<byte> im = other; // with other of type CudaImage<float>

Definition at line 485 of file CudaImage.H.

References CUDA_HOST_DEVICE_NUM, Image< T >::getArrayPtr(), CudaImage< T >::getCudaArrayPtr(), HOST_MEMORY, and CudaImage< T >::size().

template<class T >
CudaImage< T >::~CudaImage (  )  [inline]

Destructor.

Definition at line 761 of file CudaImage.H.


Member Function Documentation

template<class T >
void CudaImage< T >::clear ( const char &  val = 0  )  [inline]
template<class T >
bool CudaImage< T >::coordsOk ( const float  i,
const float  j 
) const [inline]

Test whether point falls inside array boundaries.

This test is intended to be used before you attempt a getValInterp()

Definition at line 938 of file CudaImage.H.

References CudaImage< T >::getHeight(), and CudaImage< T >::getWidth().

template<class T >
bool CudaImage< T >::coordsOk ( const Point2D< float > &  p  )  const [inline]

Test whether point falls inside array boundaries.

This test is intended to be used before you attempt a getValInterp()

Definition at line 931 of file CudaImage.H.

References CudaImage< T >::coordsOk(), and Point2D< T >::i.

template<class T >
bool CudaImage< T >::coordsOk ( const int  i,
const int  j 
) const [inline]

Test whether point falls inside array boundaries.

Definition at line 924 of file CudaImage.H.

References CudaImage< T >::getHeight(), and CudaImage< T >::getWidth().

template<class T >
bool CudaImage< T >::coordsOk ( const Point2D< int > &  P  )  const [inline]

Test whether point falls inside array boundaries.

Definition at line 917 of file CudaImage.H.

References CudaImage< T >::getHeight(), CudaImage< T >::getWidth(), and Point2D< T >::i.

Referenced by CudaImage< T >::coordsOk(), and cudaCrop().

template<class T >
CudaImage< T > CudaImage< T >::deepcopy ( const MemoryPolicy  mp,
const int  dev 
) const [inline]

Return a new image w/ deep copy of underlying data using memory policy.

This function is needed to allow new image generation to any memory area in the system, which is going to have to be a deep copy

Definition at line 785 of file CudaImage.H.

References CudaImage< T >::getCudaArrayPtr(), CudaImage< T >::getDims(), CudaImage< T >::getMemoryDevice(), and CudaImage< T >::getMemoryPolicy().

template<class T>
CudaImage<T> CudaImage< T >::deepcopy (  )  const [inline]

Return a new image object with a deep copy of the underlying data.

This function is necessary for safe use of attach()/detach(). That is, unfortunately attach()/detach() are not safe for use with shared image objects -- consider the following code:

      double d[4] = { 0.0, 1.0, 2.0, 3.0};

      // create an CudaImage that is attach()'ed to the double array
      CudaImage<double> a;
      a.attach(&d[0], 2, 2);

      const CudaImage<double> b = a;
      // now 'b' thinks it has a safe lock on some const values:

      d[0] = -1.0;
      // OOPS! By changing values in the 'd' array directly, we'll now
      // have changed things to that b[0] == -1.0, even though 'b' was
      // declared as 'const'

The solution to this problem is to prohibit the copy done in 'b=a' above (this triggers an LFATAL() in ArrayData::acquire()). That assures us that any ArrayData that has a StoragePolicy of WRITE_THRU will be un-shareable.

So, back to the point -- the correct way to write the code above would be to use deepcopy():

      double d[4] = { 0.0, 1.0, 2.0, 3.0};

      CudaImage<double> a;
      a.attach(&d[0], 2, 2);

      const CudaImage<double> b = a.deepcopy();

      d[0] = -1.0;
      // Now, 'b' is insulated from any changes to 'd' since we've
      // done a deep copy, so even now we'll still have b[0]==0.0
template<class T >
void CudaImage< T >::freeMem (  )  [inline]

Free memory and switch to uninitialized state.

Note that it is NOT necessary to call this function to ensure proper cleanup, that will be done in the destructor by default. Rather, freeMem() is offered just as a performance optimization, to allow you to release a potentially large chunk of memory when you are finished using it.

Definition at line 766 of file CudaImage.H.

References CudaImage< T >::swap().

template<class T >
Rectangle CudaImage< T >::getBounds (  )  const [inline]

Get image bounds as a rectangle with upper-left point at (0,0) and dims matching the image dims.

Definition at line 873 of file CudaImage.H.

template<class T >
T * CudaImage< T >::getCudaArrayPtr (  )  [inline]

Returns read/write (non-const) pointer to internal image array.

Definition at line 910 of file CudaImage.H.

template<class T >
const T * CudaImage< T >::getCudaArrayPtr (  )  const [inline]
template<class T >
const Dims & CudaImage< T >::getDims (  )  const [inline]
template<class T >
int CudaImage< T >::getHeight (  )  const [inline]
template<class T >
int CudaImage< T >::getMemoryDevice (  )  const [inline]
template<class T >
MemoryPolicy CudaImage< T >::getMemoryPolicy (  )  const [inline]
template<class T >
int CudaImage< T >::getSize (  )  const [inline]
template<class T >
int CudaImage< T >::getWidth (  )  const [inline]
template<class T>
bool CudaImage< T >::hasSameData ( const CudaImage< T > &  b  )  const [inline]

For testing/debugging only.

Definition at line 989 of file CudaImage.H.

template<class T >
bool CudaImage< T >::initialized (  )  const [inline]
template<class T >
bool CudaImage< T >::is1D (  )  const [inline]

Check if the image is 1D, i.e., width == 1 or height == 1.

Definition at line 883 of file CudaImage.H.

References CudaImage< T >::getHeight(), and CudaImage< T >::getWidth().

template<class T >
template<class C >
bool CudaImage< T >::isSameSize ( const C &  other  )  const [inline]
template<class T >
bool CudaImage< T >::isShared (  )  const throw () [inline]

For testing/debugging only.

Check if the ArrayHandle is shared.

Definition at line 998 of file CudaImage.H.

template<class T >
bool CudaImage< T >::isSquare (  )  const [inline]

Check if the image is square, i.e., width == height.

Definition at line 898 of file CudaImage.H.

References CudaImage< T >::getHeight(), and CudaImage< T >::getWidth().

template<class T >
bool CudaImage< T >::isTransposedVector (  )  const [inline]

Check if the image is a transposed vector, i.e., height == 1.

Definition at line 893 of file CudaImage.H.

References CudaImage< T >::getHeight().

template<class T >
bool CudaImage< T >::isVector (  )  const [inline]

Check if the image is a vector, i.e., width == 1.

Definition at line 888 of file CudaImage.H.

References CudaImage< T >::getWidth().

template<class T >
CudaImage< float > CudaImage< T >::operator* ( const CudaImage< float > &  im  )  const [inline]
template<class T >
CudaImage< float > CudaImage< T >::operator* ( const float  val  )  const [inline]
template<class T >
CudaImage< float > & CudaImage< T >::operator*= ( const CudaImage< float > &  im  )  [inline]

Multiplication inplace by a device image or scalar (a 1x1 CudaImage is treated as a scalar).

Definition at line 587 of file CudaImage.H.

References ASSERT, CudaImage< T >::getCudaArrayPtr(), CudaImage< T >::getMemoryDevice(), CudaImage< T >::getSize(), CudaImage< T >::initialized(), CudaImage< T >::isSameSize(), CudaImage< T >::size(), and Dims::sz().

template<class T >
CudaImage< float > & CudaImage< T >::operator*= ( const float  val  )  [inline]

Multiplication inplace by a host provided scalar.

Definition at line 524 of file CudaImage.H.

References CudaImage< T >::getCudaArrayPtr(), CudaImage< T >::getMemoryDevice(), CudaImage< T >::size(), and Dims::sz().

template<class T >
CudaImage< float > CudaImage< T >::operator+ ( const CudaImage< float > &  im  )  const [inline]
template<class T >
CudaImage< float > CudaImage< T >::operator+ ( const float  val  )  const [inline]
template<class T >
CudaImage< float > & CudaImage< T >::operator+= ( const CudaImage< float > &  im  )  [inline]

Addition inplace by a device image or scalar (a 1x1 CudaImage is treated as a scalar).

Definition at line 547 of file CudaImage.H.

References ASSERT, CudaImage< T >::getCudaArrayPtr(), CudaImage< T >::getMemoryDevice(), CudaImage< T >::getSize(), CudaImage< T >::initialized(), CudaImage< T >::isSameSize(), CudaImage< T >::size(), and Dims::sz().

template<class T >
CudaImage< float > & CudaImage< T >::operator+= ( const float  val  )  [inline]

Math operators.

Addition inplace by a host provided scalar

Definition at line 504 of file CudaImage.H.

References CudaImage< T >::getCudaArrayPtr(), CudaImage< T >::getMemoryDevice(), CudaImage< T >::size(), and Dims::sz().

template<class T >
CudaImage< float > CudaImage< T >::operator- ( const CudaImage< float > &  im  )  const [inline]
template<class T >
CudaImage< float > CudaImage< T >::operator- ( const float  val  )  const [inline]
template<class T >
CudaImage< float > & CudaImage< T >::operator-= ( const CudaImage< float > &  im  )  [inline]

Subtraction inplace by a device image or scalar (a 1x1 CudaImage is treated as a scalar).

Definition at line 567 of file CudaImage.H.

References ASSERT, CudaImage< T >::getCudaArrayPtr(), CudaImage< T >::getMemoryDevice(), CudaImage< T >::getSize(), CudaImage< T >::initialized(), CudaImage< T >::isSameSize(), CudaImage< T >::size(), and Dims::sz().

template<class T >
CudaImage< float > & CudaImage< T >::operator-= ( const float  val  )  [inline]

Subtraction inplace by a host provided scalar.

Definition at line 514 of file CudaImage.H.

References CudaImage< T >::getCudaArrayPtr(), CudaImage< T >::getMemoryDevice(), CudaImage< T >::size(), and Dims::sz().

template<class T >
CudaImage< float > CudaImage< T >::operator/ ( const CudaImage< float > &  im  )  const [inline]
template<class T >
CudaImage< float > CudaImage< T >::operator/ ( const float  val  )  const [inline]
template<class T >
CudaImage< float > & CudaImage< T >::operator/= ( const CudaImage< float > &  im  )  [inline]

Division inplace by a device image or scalar (a 1x1 CudaImage is treated as a scalar).

Definition at line 607 of file CudaImage.H.

References ASSERT, CudaImage< T >::getCudaArrayPtr(), CudaImage< T >::getMemoryDevice(), CudaImage< T >::getSize(), CudaImage< T >::initialized(), CudaImage< T >::isSameSize(), CudaImage< T >::size(), and Dims::sz().

template<class T >
CudaImage< float > & CudaImage< T >::operator/= ( const float  val  )  [inline]

Division inplace by a host provided scalar.

Definition at line 534 of file CudaImage.H.

References CudaImage< T >::getCudaArrayPtr(), CudaImage< T >::getMemoryDevice(), CudaImage< T >::size(), and Dims::sz().

template<class T>
CudaImage< T > & CudaImage< T >::operator= ( const CudaImage< T > &  A  )  [inline]

Assigment operator.

e.g.:

      CudaImage<byte> im1, im2; im2 = im1;

Definition at line 496 of file CudaImage.H.

References CudaImage< T >::swap().

template<class T >
bool CudaImage< T >::rectangleOk ( const Rectangle rect  )  const [inline]

Test whether rectangle fits in image.

Definition at line 946 of file CudaImage.H.

References Rectangle::bottomI(), CudaImage< T >::getHeight(), CudaImage< T >::getWidth(), Rectangle::left(), Rectangle::rightI(), and Rectangle::top().

template<class T >
long CudaImage< T >::refCount (  )  const throw () [inline]

For testing/debugging only.

Returns the current reference count.

Definition at line 994 of file CudaImage.H.

template<class T >
void CudaImage< T >::resize ( const int  width,
const int  height,
const bool  clear = false 
) [inline]

Free mem and realloc new array (array contents are lost).

Use rescale() instead if you want to preserve image contents.

Definition at line 832 of file CudaImage.H.

References CudaImage< T >::resize().

template<class T >
void CudaImage< T >::resize ( const Dims dims,
const bool  clear = false 
) [inline]

Free mem and realloc new array (array contents are lost).

Use rescale() instead if you want to preserve image contents.

Definition at line 808 of file CudaImage.H.

References CudaImage< T >::clear(), CudaImage< T >::getDims(), CudaImage< T >::getMemoryDevice(), CudaImage< T >::getMemoryPolicy(), NO_INIT, and ZEROS.

Referenced by CudaHmaxFLSal::extractRandC1Patches(), CudaHmaxFL::extractRandC1Patches(), and CudaImage< T >::resize().

template<class T >
uint CudaImage< T >::size (  )  const [inline]
template<class T>
void CudaImage< T >::swap ( CudaImage< T > &  other  )  [inline]

Swap the contents of two images.

Definition at line 778 of file CudaImage.H.

Referenced by CudaImage< T >::freeMem(), and CudaImage< T >::operator=().


The documentation for this struct was generated from the following files:
Generated on Sun May 8 08:43:19 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3