![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsCUDA_VertexListPLHM_Def.cu 00003 00004 CUDA Vertex List with PLHM Definition (i.e., cpp file). 00005 00006 SUKITTI PUNAK (09/18/2009) 00007 UPDATE (09/18/2009) 00008 ******************************************************************************/ 00009 00010 #include "TAPsCUDA_VertexListPLHM.cu" 00011 00012 BEGIN_NAMESPACE_TAPs__CUDA 00013 //============================================================================= 00014 //----------------------------------------------------------------------------- 00015 00016 //============================================================================= 00017 00018 // Constructor 00019 DATA_Vertex_ListPLHM::DATA_Vertex_ListPLHM ( 00020 unsigned int numOfVertices, 00021 bool bIncludeHomeVertices, 00022 unsigned int maxVextexConnection, 00023 bool bIncludeSimFlagsConstraint, 00024 bool bIncludeOrientations, 00025 bool bIncludePrevOrientations, 00026 bool bIncludeForces_1, 00027 bool bIncludeForces_2 00028 ) : 00029 // Pointers to CUDA allocated memory on CPU 00030 m_Ptr_Mem_VertexList( NULL ), 00031 m_Ptr_Mem_PrevVertexList( NULL ), 00032 //m_Ptr_Mem_NextVertexList( NULL ), 00033 m_Ptr_Mem_HomeVertexList( NULL ), 00034 m_Ptr_Mem_VertexConnectionList( NULL ), 00035 m_Ptr_Mem_OrientationList( NULL ), 00036 m_Ptr_Mem_PrevOrientationList( NULL ), 00037 //m_Ptr_Mem_NextOrientationList( NULL ), 00038 m_Ptr_Mem_ForceList_1( NULL ), 00039 m_Ptr_Mem_ForceList_2( NULL ), 00040 00041 // Pointers to CUDA allocated memory on GPU 00042 m_Ptr_DevMem_VertexList( NULL ), 00043 m_Ptr_DevMem_PrevVertexList( NULL ), 00044 //m_Ptr_DevMem_NextVertexList( NULL ), 00045 m_Ptr_DevMem_HomeVertexList( NULL ), 00046 m_Ptr_DevMem_VertexConnectionList( NULL ), 00047 m_Ptr_DevMem_OrientationList( NULL ), 00048 m_Ptr_DevMem_PrevOrientationList( NULL ), 00049 //m_Ptr_DevMem_NextOrientationList( NULL ), 00050 m_Ptr_DevMem_ForceList_1( NULL ), 00051 m_Ptr_DevMem_ForceList_2( NULL ), 00052 00053 // Extra resources for model (CPU) 00054 m_Ptr_Mem_SimFlagsList( NULL ), 00055 m_Ptr_Mem_PosConstraintList( NULL ), 00056 00057 // Extra resources for model (GPU) 00058 m_Ptr_DevMem_SimFlagsList( NULL ), 00059 m_Ptr_DevMem_PosConstraintList( NULL ), 00060 00061 m_uiNumOfVertices( numOfVertices ), 00062 m_bIncludeHomeVertices( bIncludeHomeVertices ), 00063 m_uiMaxConnectionSize( maxVextexConnection ), 00064 m_bIncludeSimFlagsConstraint( bIncludeSimFlagsConstraint ), 00065 m_bIncludeOrientations( bIncludeOrientations ), 00066 m_bIncludePrevOrientations( bIncludePrevOrientations ), 00067 m_bIncludeForces_1( bIncludeForces_1 ), 00068 m_bIncludeForces_2( bIncludeForces_2 ) 00069 { 00070 AllocateTextures(); 00071 } 00072 00073 00074 // Destructor 00075 DATA_Vertex_ListPLHM::~DATA_Vertex_ListPLHM () 00076 { 00077 DeallocateTextures(); 00078 00079 } 00080 00081 00082 // Allocate Textures 00083 #ifdef TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_LIN_MEM 00084 bool DATA_Vertex_ListPLHM::AllocateTextures () 00085 { 00086 //USE: cudaError_t cudaHostAlloc( void** devPtr, size_t count, cudaHostAllocMapped ) 00087 00088 if ( m_uiNumOfVertices > 0 ) { 00089 00090 // Current vertices 00091 CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_VertexList, m_uiNumOfVertices*4*sizeof(float), cudaHostAllocMapped ) ); 00092 CUT_CHECK_ERROR( "cudaHostAlloc for Vertex List Failed!" ); 00093 CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_VertexList, (void*)m_Ptr_Mem_VertexList, 0 ) ); 00094 CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Vertex List Failed!" ); 00095 00096 // Previous vertices 00097 CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_PrevVertexList, m_uiNumOfVertices*4*sizeof(float), cudaHostAllocMapped ) ); 00098 CUT_CHECK_ERROR( "cudaHostAlloc for Previous Vertex List Failed!" ); 00099 CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_PrevVertexList, (void*)m_Ptr_Mem_PrevVertexList, 0 ) ); 00100 CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Previous Vertex List Failed!" ); 00101 00102 // // Next vertices 00103 // CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_NextVertexList, m_uiNumOfVertices*4*sizeof(float), cudaHostAllocMapped ) ); 00104 // CUT_CHECK_ERROR( "cudaHostAlloc for Next Vertex List Failed!" ); 00105 // CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_NextVertexList, (void*)m_Ptr_Mem_NextVertexList, 0 ) ); 00106 // CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Next Vertex List Failed!" ); 00107 00108 // DEBUG 00109 printf( "m_Ptr_Mem_VertexList: %x; m_Ptr_DevMem_VertexList: %x\n", m_Ptr_Mem_VertexList, m_Ptr_DevMem_VertexList ); 00110 00111 // Home Vertices 00112 if ( m_bIncludeHomeVertices ) { 00113 CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_HomeVertexList, m_uiNumOfVertices*4*sizeof(float), cudaHostAllocMapped ) ); 00114 CUT_CHECK_ERROR( "cudaHostAlloc for Home Vertex List Failed!" ); 00115 CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_HomeVertexList, (void*)m_Ptr_Mem_HomeVertexList, 0 ) ); 00116 CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Home Vertex List Failed!" ); 00117 } 00118 if ( m_uiMaxConnectionSize > 0 ) { 00119 CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_VertexConnectionList, m_uiNumOfVertices*m_uiMaxConnectionSize*sizeof(int), cudaHostAllocMapped ) ); 00120 CUT_CHECK_ERROR( "cudaHostAlloc for Vertex Connection List Failed!" ); 00121 CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_VertexConnectionList, (void*)m_Ptr_Mem_VertexConnectionList, 0 ) ); 00122 CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Vertex Connection List Failed!" ); 00123 } 00124 if ( m_bIncludeSimFlagsConstraint ) { 00125 CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_SimFlagsList, m_uiNumOfVertices*sizeof(unsigned int), cudaHostAllocMapped ) ); 00126 CUT_CHECK_ERROR( "cudaHostAlloc for Simulation Flags List Failed!" ); 00127 CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_SimFlagsList, (void*)m_Ptr_Mem_SimFlagsList, 0 ) ); 00128 CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Simulation Flags List Failed!" ); 00129 CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_PosConstraintList, m_uiNumOfVertices*4*sizeof(float), cudaHostAllocMapped ) ); 00130 CUT_CHECK_ERROR( "cudaHostAlloc for Position Constraint List Failed!" ); 00131 CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_PosConstraintList, (void*)m_Ptr_Mem_PosConstraintList, 0 ) ); 00132 CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Position Constraint List Failed!" ); 00133 } 00134 00135 // Orientations 00136 if ( m_bIncludeOrientations ) { 00137 // Current orientations 00138 CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_OrientationList, m_uiNumOfVertices*4*sizeof(float), cudaHostAllocMapped ) ); 00139 CUT_CHECK_ERROR( "cudaHostAlloc for Orientation List Failed!" ); 00140 CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_OrientationList, (void*)m_Ptr_Mem_OrientationList, 0 ) ); 00141 CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Orientation List Failed!" ); 00142 } 00143 if ( m_bIncludePrevOrientations ) { 00144 // Previous orientations 00145 CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_PrevOrientationList, m_uiNumOfVertices*4*sizeof(float), cudaHostAllocMapped ) ); 00146 CUT_CHECK_ERROR( "cudaHostAlloc for Previous Orientation List Failed!" ); 00147 CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_PrevOrientationList, (void*)m_Ptr_Mem_PrevOrientationList, 0 ) ); 00148 CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Previous Orientation List Failed!" ); 00149 // // Next orientations 00150 // CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_NextOrientationList, m_uiNumOfVertices*4*sizeof(float), cudaHostAllocMapped ) ); 00151 // CUT_CHECK_ERROR( "cudaHostAlloc for Next Orientation List Failed!" ); 00152 // CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_NextOrientationList, (void*)m_Ptr_Mem_NextOrientationList, 0 ) ); 00153 // CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Next Orientation List Failed!" ); 00154 } 00155 if ( m_bIncludeForces_1 ) { 00156 CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_ForceList_1, m_uiNumOfVertices*4*sizeof(float), cudaHostAllocMapped ) ); 00157 CUT_CHECK_ERROR( "cudaHostAlloc for Force List Set 1 Failed!" ); 00158 CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_ForceList_1, (void*)m_Ptr_Mem_ForceList_1, 0 ) ); 00159 CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Force List Set 1 Failed!" ); 00160 } 00161 if ( m_bIncludeForces_2 ) { 00162 CUDA_SAFE_CALL( cudaHostAlloc( (void**)&m_Ptr_Mem_ForceList_2, m_uiNumOfVertices*4*sizeof(float), cudaHostAllocMapped ) ); 00163 CUT_CHECK_ERROR( "cudaHostAlloc for Force List Set 2 Failed!" ); 00164 CUDA_SAFE_CALL( cudaHostGetDevicePointer( (void**)&m_Ptr_DevMem_ForceList_2, (void*)m_Ptr_Mem_ForceList_2, 0 ) ); 00165 CUT_CHECK_ERROR( "cudaHostGetDevicePointer for Force List Set 2 Failed!" ); 00166 } 00167 } 00168 return true; 00169 } 00170 #endif//TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_LIN_MEM 00171 00172 00173 // Deallocate Textures 00174 #ifdef TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_LIN_MEM 00175 bool DATA_Vertex_ListPLHM::DeallocateTextures () 00176 { 00177 //USE: cudaError_t cudaFreeHost(void* devPtr) 00178 00179 if ( m_uiNumOfVertices > 0 ) { 00180 // Current vertices 00181 CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_VertexList ) ); 00182 m_Ptr_Mem_VertexList = NULL; 00183 m_Ptr_DevMem_VertexList = NULL; 00184 // Previous vertices 00185 CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_PrevVertexList ) ); 00186 m_Ptr_Mem_PrevVertexList = NULL; 00187 m_Ptr_DevMem_PrevVertexList = NULL; 00188 // // Next vertices 00189 // CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_NextVertexList ) ); 00190 // m_Ptr_Mem_NextVertexList = NULL; 00191 // m_Ptr_DevMem_NextVertexList = NULL; 00192 if ( m_bIncludeHomeVertices ) { 00193 CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_HomeVertexList ) ); 00194 m_Ptr_Mem_HomeVertexList = NULL; 00195 m_Ptr_DevMem_HomeVertexList = NULL; 00196 } 00197 if ( m_uiMaxConnectionSize > 0 ) { 00198 CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_VertexConnectionList ) ); 00199 m_Ptr_Mem_VertexConnectionList = NULL; 00200 m_Ptr_DevMem_VertexConnectionList = NULL; 00201 } 00202 if ( m_bIncludeSimFlagsConstraint ) { 00203 CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_SimFlagsList ) ); 00204 m_Ptr_Mem_SimFlagsList = NULL; 00205 m_Ptr_DevMem_SimFlagsList = NULL; 00206 CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_PosConstraintList ) ); 00207 m_Ptr_Mem_PosConstraintList = NULL; 00208 m_Ptr_DevMem_PosConstraintList = NULL; 00209 } 00210 if ( m_bIncludeOrientations ) { 00211 // Current orientations 00212 CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_OrientationList ) ); 00213 m_Ptr_Mem_OrientationList = NULL; 00214 m_Ptr_DevMem_OrientationList = NULL; 00215 } 00216 if ( m_bIncludePrevOrientations ) { 00217 // Previous orientations 00218 CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_PrevOrientationList ) ); 00219 m_Ptr_Mem_PrevOrientationList = NULL; 00220 m_Ptr_DevMem_PrevOrientationList = NULL; 00221 // // Next orientations 00222 // CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_NextOrientationList ) ); 00223 // m_Ptr_Mem_NextOrientationList = NULL; 00224 // m_Ptr_DevMem_NextOrientationList = NULL; 00225 } 00226 if ( m_bIncludeForces_1 ) { 00227 CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_ForceList_1 ) ); 00228 m_Ptr_Mem_ForceList_1 = NULL; 00229 m_Ptr_DevMem_ForceList_1 = NULL; 00230 } 00231 if ( m_bIncludeForces_2 ) { 00232 CUDA_SAFE_CALL( cudaFreeHost( m_Ptr_Mem_ForceList_2 ) ); 00233 m_Ptr_Mem_ForceList_2 = NULL; 00234 m_Ptr_DevMem_ForceList_2 = NULL; 00235 } 00236 } 00237 return true; 00238 } 00239 #endif//TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_LIN_MEM 00240 00241 // END: class DATA_Vertex_List 00242 //============================================================================= 00243 00244 //----------------------------------------------------------------------------- 00245 //============================================================================= 00246 END_NAMESPACE_TAPs__CUDA 00247 //----------------------------------------------------------------------------- 00248 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00249 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----