![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsCUDA_VertexList_Def.cu 00003 00004 CUDA Vertex List Definition (i.e., cpp file). 00005 00006 SUKITTI PUNAK (08/27/2008) 00007 UPDATE (09/17/2009) 00008 ******************************************************************************/ 00009 00010 #include "TAPsCUDA_VertexList.cu" 00011 00012 BEGIN_NAMESPACE_TAPs__CUDA 00013 //============================================================================= 00014 //----------------------------------------------------------------------------- 00015 00016 //============================================================================= 00017 00018 // Constructor 00019 DATA_Vertex_List::DATA_Vertex_List ( 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 m_Ptr_Mem_VertexList( NULL ), 00030 m_Ptr_Mem_PrevVertexList( NULL ), 00031 m_Ptr_Mem_HomeVertexList( NULL ), 00032 m_Ptr_Mem_VertexConnectionList( NULL ), 00033 m_Ptr_Mem_OrientationList( NULL ), 00034 m_Ptr_Mem_PrevOrientationList( NULL ), 00035 m_Ptr_Mem_ForceList_1( NULL ), 00036 m_Ptr_Mem_ForceList_2( NULL ), 00037 00038 m_Ptr_Mem_SimFlagsList( NULL ), 00039 m_Ptr_Mem_PosConstraintList( NULL ), 00040 00041 m_uiNumOfVertices( numOfVertices ), 00042 m_bIncludeHomeVertices( bIncludeHomeVertices ), 00043 m_uiMaxConnectionSize( maxVextexConnection ), 00044 m_bIncludeSimFlagsConstraint( bIncludeSimFlagsConstraint ), 00045 m_bIncludeOrientations( bIncludeOrientations ), 00046 m_bIncludePrevOrientations( bIncludePrevOrientations ), 00047 m_bIncludeForces_1( bIncludeForces_1 ), 00048 m_bIncludeForces_2( bIncludeForces_2 ) 00049 { 00050 AllocateTextures(); 00051 } 00052 00053 00054 // Destructor 00055 DATA_Vertex_List::~DATA_Vertex_List () 00056 { 00057 DeallocateTextures(); 00058 00059 } 00060 00061 00062 // Allocate Textures 00063 #ifdef TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_LIN_MEM 00064 bool DATA_Vertex_List::AllocateTextures () 00065 { 00066 //USE: cudaError_t cudaMalloc( void** devPtr, size_t count ) 00067 00068 if ( m_uiNumOfVertices > 0 ) { 00069 // Vertices 00070 CUDA_SAFE_CALL( cudaMalloc( (void**)&m_Ptr_Mem_VertexList, m_uiNumOfVertices*4*sizeof(float) ) ); 00071 CUT_CHECK_ERROR( "cudaMalloc for Vertex List Failed!" ); 00072 // Previous vertices for the Verlet Integration 00073 CUDA_SAFE_CALL( cudaMalloc( (void**)&m_Ptr_Mem_PrevVertexList, m_uiNumOfVertices*4*sizeof(float) ) ); 00074 CUT_CHECK_ERROR( "cudaMalloc for Previous Vertex List Failed!" ); 00075 // Home Vertices 00076 if ( m_bIncludeHomeVertices ) { 00077 CUDA_SAFE_CALL( cudaMalloc( (void**)&m_Ptr_Mem_HomeVertexList, m_uiNumOfVertices*4*sizeof(float) ) ); 00078 CUT_CHECK_ERROR( "cudaMalloc for Home Vertex List Failed!" ); 00079 } 00080 if ( m_uiMaxConnectionSize > 0 ) { 00081 CUDA_SAFE_CALL( cudaMalloc( (void**)&m_Ptr_Mem_VertexConnectionList, m_uiNumOfVertices*m_uiMaxConnectionSize*sizeof(int) ) ); 00082 CUT_CHECK_ERROR( "cudaMalloc for Vertex Connection List Failed!" ); 00083 } 00084 if ( m_bIncludeSimFlagsConstraint ) { 00085 CUDA_SAFE_CALL( cudaMalloc( (void**)&m_Ptr_Mem_SimFlagsList, m_uiNumOfVertices*sizeof(unsigned int) ) ); 00086 CUT_CHECK_ERROR( "cudaMalloc for Simulation Flags List Failed!" ); 00087 CUDA_SAFE_CALL( cudaMalloc( (void**)&m_Ptr_Mem_PosConstraintList, m_uiNumOfVertices*4*sizeof(float) ) ); 00088 CUT_CHECK_ERROR( "cudaMalloc for Position Constraint List Failed!" ); 00089 } 00090 if ( m_bIncludeOrientations ) { 00091 CUDA_SAFE_CALL( cudaMalloc( (void**)&m_Ptr_Mem_OrientationList, m_uiNumOfVertices*4*sizeof(float) ) ); 00092 CUT_CHECK_ERROR( "cudaMalloc for Orientation List Failed!" ); 00093 } 00094 if ( m_bIncludePrevOrientations ) { 00095 CUDA_SAFE_CALL( cudaMalloc( (void**)&m_Ptr_Mem_PrevOrientationList, m_uiNumOfVertices*4*sizeof(float) ) ); 00096 CUT_CHECK_ERROR( "cudaMalloc for Previous Orientation List Failed!" ); 00097 } 00098 if ( m_bIncludeForces_1 ) { 00099 CUDA_SAFE_CALL( cudaMalloc( (void**)&m_Ptr_Mem_ForceList_1, m_uiNumOfVertices*4*sizeof(float) ) ); 00100 CUT_CHECK_ERROR( "cudaMalloc for Force List Set 1 Failed!" ); 00101 } 00102 if ( m_bIncludeForces_2 ) { 00103 CUDA_SAFE_CALL( cudaMalloc( (void**)&m_Ptr_Mem_ForceList_2, m_uiNumOfVertices*4*sizeof(float) ) ); 00104 CUT_CHECK_ERROR( "cudaMalloc for Force List Set 2 Failed!" ); 00105 } 00106 } 00107 return true; 00108 } 00109 #endif//TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_LIN_MEM 00110 00111 00112 // Deallocate Textures 00113 #ifdef TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_LIN_MEM 00114 bool DATA_Vertex_List::DeallocateTextures () 00115 { 00116 //USE: cudaError_t cudaFree(void* devPtr) 00117 00118 if ( m_uiNumOfVertices > 0 ) { 00119 CUDA_SAFE_CALL( cudaFree( m_Ptr_Mem_VertexList ) ); 00120 m_Ptr_Mem_VertexList = NULL; 00121 CUDA_SAFE_CALL( cudaFree( m_Ptr_Mem_PrevVertexList ) ); 00122 m_Ptr_Mem_PrevVertexList = NULL; 00123 if ( m_bIncludeHomeVertices ) { 00124 CUDA_SAFE_CALL( cudaFree( m_Ptr_Mem_HomeVertexList ) ); 00125 m_Ptr_Mem_HomeVertexList = NULL; 00126 } 00127 if ( m_uiMaxConnectionSize > 0 ) { 00128 CUDA_SAFE_CALL( cudaFree( m_Ptr_Mem_VertexConnectionList ) ); 00129 m_Ptr_Mem_VertexConnectionList = NULL; 00130 } 00131 if ( m_bIncludeSimFlagsConstraint ) { 00132 CUDA_SAFE_CALL( cudaFree( m_Ptr_Mem_SimFlagsList ) ); 00133 m_Ptr_Mem_SimFlagsList = NULL; 00134 CUDA_SAFE_CALL( cudaFree( m_Ptr_Mem_PosConstraintList ) ); 00135 m_Ptr_Mem_PosConstraintList = NULL; 00136 } 00137 if ( m_bIncludeOrientations ) { 00138 CUDA_SAFE_CALL( cudaFree( m_Ptr_Mem_OrientationList ) ); 00139 m_Ptr_Mem_OrientationList = NULL; 00140 } 00141 if ( m_bIncludePrevOrientations ) { 00142 CUDA_SAFE_CALL( cudaFree( m_Ptr_Mem_PrevOrientationList ) ); 00143 m_Ptr_Mem_PrevOrientationList = NULL; 00144 } 00145 if ( m_bIncludeForces_1 ) { 00146 CUDA_SAFE_CALL( cudaFree( m_Ptr_Mem_ForceList_1 ) ); 00147 m_Ptr_Mem_ForceList_1 = NULL; 00148 } 00149 if ( m_bIncludeForces_2 ) { 00150 CUDA_SAFE_CALL( cudaFree( m_Ptr_Mem_ForceList_2 ) ); 00151 m_Ptr_Mem_ForceList_2 = NULL; 00152 } 00153 } 00154 return true; 00155 } 00156 #endif//TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_LIN_MEM 00157 00158 // END: class DATA_Vertex_List 00159 //============================================================================= 00160 00161 //----------------------------------------------------------------------------- 00162 //============================================================================= 00163 END_NAMESPACE_TAPs__CUDA 00164 //----------------------------------------------------------------------------- 00165 //34567890123456789012345678901234567890123456789012345678901234567890123456789 00166 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----