Autonomous Space Robotics Lab

Speeded Up SURF

UTIAS ASRL

asrl::CudaSynchronizedMemory< T > Class Template Reference

a class that handles synchronization of memory between the host and device More...

#include <CudaSynchronizedMemory.hpp>

List of all members.

Public Types

typedef T value_type
 The underlying type of the allocated memory.

Public Member Functions

 CudaSynchronizedMemory ()
 CudaSynchronizedMemory (unsigned N, bool pageLocked=false)
 ~CudaSynchronizedMemory ()
void init (unsigned N, bool pageLocked=false)
void reset ()
T * begin ()
T * end ()
T * h_get ()
T const * h_get () const
T * d_get ()
T const * d_get () const
size_t size () const
T & operator[] (size_t i)
T const & operator[] (size_t i) const
void pushToDevice (size_t nElements=std::numeric_limits< size_t >::max())
void pullFromDevice (size_t nElements=std::numeric_limits< size_t >::max())
void pullFromDeviceAsync (cudaStream_t stream, size_t nElements=std::numeric_limits< size_t >::max())
void memsetHost (int val)
void memsetDevice (int val)
void memset (int val)
bool isPageLocked ()

Private Member Functions

 CudaSynchronizedMemory (CudaSynchronizedMemory const &rhs)
CudaSynchronizedMemoryoperator= (CudaSynchronizedMemory const &rhs)
void freeHostMemory ()
void freeDeviceMemory ()

Private Attributes

T * m_host
 A reference-counted pointer to the host memory.
T * m_device
 A reference-counted pointer to the device memory.
size_t m_size
 The number of elements of type T allocated.
bool m_pageLocked
 Is the host memory page-locked.

Detailed Description

template<typename T>
class asrl::CudaSynchronizedMemory< T >

a class that handles synchronization of memory between the host and device

A class that simplifies allocation/deallocation and synchronization of a buffer allocated on the host and on the device.

Definition at line 60 of file CudaSynchronizedMemory.hpp.


Member Typedef Documentation

template<typename T>
typedef T asrl::CudaSynchronizedMemory< T >::value_type

The underlying type of the allocated memory.

Definition at line 75 of file CudaSynchronizedMemory.hpp.


Constructor & Destructor Documentation

template<typename T>
asrl::CudaSynchronizedMemory< T >::CudaSynchronizedMemory ( CudaSynchronizedMemory< T > const &  rhs  )  [private]

The object is non-copyable as we need to be careful about memory leaks.

template<typename T >
asrl::CudaSynchronizedMemory< T >::CudaSynchronizedMemory (  )  [inline]

A constructor that initializes both the host and device pointers with null values

Definition at line 247 of file CudaSynchronizedMemory.hpp.

template<typename T >
asrl::CudaSynchronizedMemory< T >::CudaSynchronizedMemory ( unsigned  N,
bool  pageLocked = false 
) [inline]

A constructor that allocates memory for N elements of type T on both the host and the device.

Parameters:
N The number of elements to allocate
pageLocked Should the host memory be page-locked

Definition at line 250 of file CudaSynchronizedMemory.hpp.

template<typename T >
asrl::CudaSynchronizedMemory< T >::~CudaSynchronizedMemory (  )  [inline]

A destructor to clean up the allocated memory

Definition at line 256 of file CudaSynchronizedMemory.hpp.


Member Function Documentation

template<typename T >
T * asrl::CudaSynchronizedMemory< T >::begin (  )  [inline]
Returns:
a pointer to the beginning of the host memory

Definition at line 379 of file CudaSynchronizedMemory.hpp.

template<typename T >
T const * asrl::CudaSynchronizedMemory< T >::d_get (  )  const [inline]
Returns:
the device memory pointer

Definition at line 402 of file CudaSynchronizedMemory.hpp.

template<typename T >
T * asrl::CudaSynchronizedMemory< T >::d_get (  )  [inline]
Returns:
the device memory pointer

Definition at line 399 of file CudaSynchronizedMemory.hpp.

template<typename T >
T * asrl::CudaSynchronizedMemory< T >::end (  )  [inline]
Returns:
a pointer to the end of the host memory

Definition at line 386 of file CudaSynchronizedMemory.hpp.

template<typename T >
void asrl::CudaSynchronizedMemory< T >::freeDeviceMemory (  )  [inline, private]

Definition at line 299 of file CudaSynchronizedMemory.hpp.

template<typename T >
void asrl::CudaSynchronizedMemory< T >::freeHostMemory (  )  [inline, private]

Definition at line 279 of file CudaSynchronizedMemory.hpp.

template<typename T >
T const * asrl::CudaSynchronizedMemory< T >::h_get (  )  const [inline]
Returns:
the host memory pointer

Definition at line 396 of file CudaSynchronizedMemory.hpp.

template<typename T >
T * asrl::CudaSynchronizedMemory< T >::h_get (  )  [inline]
Returns:
the host memory pointer

Definition at line 393 of file CudaSynchronizedMemory.hpp.

template<typename T >
void asrl::CudaSynchronizedMemory< T >::init ( unsigned  N,
bool  pageLocked = false 
) [inline]

A function that allocates memory for N elements of type T on both the host and the device.

Parameters:
N The number of elements to allocate
pageLocked Should the host memory be page-locked

Definition at line 339 of file CudaSynchronizedMemory.hpp.

template<typename T >
bool asrl::CudaSynchronizedMemory< T >::isPageLocked (  )  [inline]
Returns:
returns true if the underlying host memory is page-locked

Definition at line 373 of file CudaSynchronizedMemory.hpp.

template<typename T >
void asrl::CudaSynchronizedMemory< T >::memset ( int  val  )  [inline]

Calls memset on both the host and device memory.

Definition at line 315 of file CudaSynchronizedMemory.hpp.

template<typename T >
void asrl::CudaSynchronizedMemory< T >::memsetDevice ( int  val  )  [inline]

calls cudaMemset() on the device memory.

Definition at line 330 of file CudaSynchronizedMemory.hpp.

template<typename T >
void asrl::CudaSynchronizedMemory< T >::memsetHost ( int  val  )  [inline]

calls memset() on the host memory.

Definition at line 323 of file CudaSynchronizedMemory.hpp.

template<typename T>
CudaSynchronizedMemory& asrl::CudaSynchronizedMemory< T >::operator= ( CudaSynchronizedMemory< T > const &  rhs  )  [private]

The object is non-copyable as we need to be careful about memory leaks.

template<typename T >
T const & asrl::CudaSynchronizedMemory< T >::operator[] ( size_t  i  )  const [inline]

An convenience operator that dereferences the host array

Parameters:
i the index to dereference the host array
Returns:
a const reference to the value at host_memory[i]

Definition at line 415 of file CudaSynchronizedMemory.hpp.

template<typename T >
T & asrl::CudaSynchronizedMemory< T >::operator[] ( size_t  i  )  [inline]

An convenience operator that dereferences the host array

Parameters:
i the index to dereference the host array
Returns:
a reference to the value at host_memory[i]

Definition at line 408 of file CudaSynchronizedMemory.hpp.

template<typename T >
void asrl::CudaSynchronizedMemory< T >::pullFromDevice ( size_t  nElements = std::numeric_limits<size_t>::max()  )  [inline]

Pulls bytes from the device to the host.

Parameters:
nElements The number of elements of the array to pull. If this is greater than size() or -1, all allocated elements are pulled from the device.

Definition at line 433 of file CudaSynchronizedMemory.hpp.

template<typename T >
void asrl::CudaSynchronizedMemory< T >::pullFromDeviceAsync ( cudaStream_t  stream,
size_t  nElements = std::numeric_limits<size_t>::max() 
) [inline]

Initiate an asynchronous transfer from the host to the device.

Parameters:
stream The cuda stream associated with the transfer.
nElements The number of elements to pull. If this is greater than size() or -1, all allocated elements are pulled from the device.

Definition at line 443 of file CudaSynchronizedMemory.hpp.

template<typename T >
void asrl::CudaSynchronizedMemory< T >::pushToDevice ( size_t  nElements = std::numeric_limits<size_t>::max()  )  [inline]

Pushes bytes from the host to the device.

Parameters:
nElements The number of elements to push. If this is greater than size() or -1, all allocated elements are pushed to the device.

Definition at line 422 of file CudaSynchronizedMemory.hpp.

template<typename T >
void asrl::CudaSynchronizedMemory< T >::reset (  )  [inline]

Clear both the host and device memory.

Definition at line 269 of file CudaSynchronizedMemory.hpp.

template<typename T >
size_t asrl::CudaSynchronizedMemory< T >::size (  )  const [inline]
Returns:
the number of elements allocated

Definition at line 405 of file CudaSynchronizedMemory.hpp.


Member Data Documentation

template<typename T>
T* asrl::CudaSynchronizedMemory< T >::m_device [private]

A reference-counted pointer to the device memory.

Definition at line 237 of file CudaSynchronizedMemory.hpp.

template<typename T>
T* asrl::CudaSynchronizedMemory< T >::m_host [private]

A reference-counted pointer to the host memory.

Definition at line 235 of file CudaSynchronizedMemory.hpp.

template<typename T>
bool asrl::CudaSynchronizedMemory< T >::m_pageLocked [private]

Is the host memory page-locked.

Definition at line 241 of file CudaSynchronizedMemory.hpp.

template<typename T>
size_t asrl::CudaSynchronizedMemory< T >::m_size [private]

The number of elements of type T allocated.

Definition at line 239 of file CudaSynchronizedMemory.hpp.


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

Generated on Fri Apr 30 20:06:20 2010 for gpusurf by doxygen 1.6.2