Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef __cmtkDeviceMemory_h_included_
00032 #define __cmtkDeviceMemory_h_included_
00033
00034 #include <cmtkconfig.h>
00035
00036 #ifdef CMTK_USE_CUDA
00037 # include "cmtkDeviceMemoryCUDA.h"
00038 #else
00039 # include "cmtkDeviceMemoryCL.h"
00040 #endif
00041
00042 namespace
00043 cmtk
00044 {
00045
00048
00050 #ifdef CMTK_USE_CUDA
00051 template<typename T,class DeviceMemoryGPU = DeviceMemoryCUDA>
00052 #else
00053 template<typename T,class DeviceMemoryGPU = DeviceMemoryCL>
00054 #endif
00055 class DeviceMemory :
00057 private DeviceMemoryGPU
00058 {
00059 public:
00061 typedef DeviceMemory<T,DeviceMemoryGPU> Self;
00062
00064 typedef SmartConstPointer<Self> SmartConstPtr;
00065
00067 typedef SmartPointer<Self> SmartPtr;
00068
00070 typedef DeviceMemoryGPU Superclass;
00071
00073 DeviceMemory( const size_t n, const size_t padToMultiple = 1 )
00074 : DeviceMemoryGPU( n * sizeof( T ), padToMultiple * sizeof( T ) ),
00075 m_NumberOfItems( n )
00076 {}
00077
00079 static typename Self::SmartPtr Create( const size_t nItems,
00080 const size_t padToMultiple = 1 )
00081 {
00082 return typename Self::SmartPtr( new Self( nItems, padToMultiple ) );
00083 }
00084
00086 static typename Self::SmartPtr Create( const size_t nItems,
00087 const T* initFrom,
00088 const size_t padToMultiple = 1 )
00089 {
00090 Self* newObject = new Self( nItems, padToMultiple );
00091 newObject->CopyToDevice( initFrom, nItems );
00092 return typename Self::SmartPtr( newObject );
00093 }
00094
00096 const T* Ptr() const
00097 {
00098 return static_cast<const T*>( this->m_PointerDevice );
00099 }
00100
00102 T* Ptr()
00103 {
00104 return static_cast<T*>( this->m_PointerDevice );
00105 }
00106
00108 void CopyToDevice( const T *const srcPtrHost, const size_t count )
00109 {
00110 this->Superclass::CopyToDevice( srcPtrHost, count * sizeof( T ) );
00111 }
00112
00114 void CopyToHost( void *const dstPtrHost, const size_t count ) const
00115 {
00116 this->Superclass::CopyToHost( dstPtrHost, count * sizeof( T ) );
00117 }
00118
00120 void CopyOnDevice( const Self& srcPtrDevice, const size_t count )
00121 {
00122 this->Superclass::CopyOnDevice( srcPtrDevice, count * sizeof( T ) );
00123 }
00124
00126 void SetToZero()
00127 {
00128 this->Superclass::Memset( 0, this->m_NumberOfItems * sizeof( T ) );
00129 }
00130
00132 size_t GetNumberOfItems() const
00133 {
00134 return this->m_NumberOfItems;
00135 }
00136
00137 private:
00139 size_t m_NumberOfItems;
00140 };
00141
00143
00144 }
00145
00146 #endif // #ifndef __cmtkDeviceMemory_h_included_