TAPs 0.7.7.3
TAPsCUDA_VertexList.cu
Go to the documentation of this file.
00001 /******************************************************************************
00002 TAPsCUDA_VetexList.cu
00003 ******************************************************************************/
00008 /******************************************************************************
00009 SUKITTI PUNAK   (08/27/2008)
00010 UPDATE          (09/21/2009)
00011 ******************************************************************************/
00012 #ifndef TAPs_CUDA_VERTEX_LIST_HPP
00013 #define TAPs_CUDA_VERTEX_LIST_HPP
00014 
00015 #include "TAPsCUDA_GlobalTextureRef.cu"
00016 
00017 BEGIN_NAMESPACE_TAPs__CUDA
00018 //=============================================================================
00019 //-----------------------------------------------------------------------------
00020 class DATA_Vertex_List
00021 {
00022 public:
00023 
00025     DATA_Vertex_List ( 
00026         unsigned int numOfVertices,             
00027         bool bIncludeHomeVertices,              
00028         unsigned int maxVextexConnection,       
00029         bool bIncludeSimFlagsConstraint,        
00030         bool bIncludeOrientations = false,      
00031         bool bIncludePrevOrientations = false,  
00032         bool bIncludeForces_1 = false,          
00033         bool bIncludeForces_2 = false           
00034     );
00035 
00037     ~DATA_Vertex_List ();
00038 
00039 
00040 
00042     void PrindDebug_VertexList ( unsigned int numOfVertices, float * host_VL )
00043     {
00044         unsigned int size = numOfVertices*sizeof(float)*4;
00045         float * vertexList = (float *)malloc(size);
00046         CUDA_SAFE_CALL( cudaMemcpy( vertexList, m_Ptr_Mem_VertexList, size, cudaMemcpyDeviceToHost ) );
00047         for ( int i = 0; i < 2; ++i ) {
00048             int idx = i*4;
00049             printf( "Vertex List #          %d: %g %g %g %g\n", i, vertexList[idx], vertexList[idx+1], vertexList[idx+2], vertexList[idx+3] );
00050             printf( "Host Vertex List #     %d: %g %g %g %g\n", i, host_VL[idx], host_VL[idx+1], host_VL[idx+2], host_VL[idx+3] );
00051             printf( "\n" );
00052         }
00053         free( vertexList );
00054     }
00055     void PrindDebug_PrevVertexList ( unsigned int numOfVertices, float * host_PVL )
00056     {
00057         unsigned int size = numOfVertices*sizeof(float)*4;
00058         float * prevVertexList = (float *)malloc(size);
00059         CUDA_SAFE_CALL( cudaMemcpy( prevVertexList, m_Ptr_Mem_PrevVertexList, size, cudaMemcpyDeviceToHost ) );
00060         for ( int i = 0; i < 2; ++i ) {
00061             int idx = i*4;
00062             printf( "Prev Vertex List #     %d: %g %g %g %g\n", i, prevVertexList[idx], prevVertexList[idx+1], prevVertexList[idx+2], prevVertexList[idx+3] );
00063             printf( "Host Prev Vertex List #%d: %g %g %g %g\n", i, host_PVL[idx], host_PVL[idx+1], host_PVL[idx+2], host_PVL[idx+3] );
00064             printf( "\n" );
00065         }
00066         free( prevVertexList );
00067     }
00068     void PrindDebug_HomeVertexList ( unsigned int numOfVertices, float * host_HVL )
00069     {
00070         unsigned int size = numOfVertices*sizeof(float)*4;
00071         float * homeVertexList = (float *)malloc(size);
00072         CUDA_SAFE_CALL( cudaMemcpy( homeVertexList, m_Ptr_Mem_HomeVertexList, size, cudaMemcpyDeviceToHost ) );
00073         for ( int i = 0; i < 2; ++i ) {
00074             int idx = i*4;
00075             printf( "Prev Vertex List #     %d: %g %g %g %g\n", i, homeVertexList[idx], homeVertexList[idx+1], homeVertexList[idx+2], homeVertexList[idx+3] );
00076             printf( "Host Home Vertex List #%d: %g %g %g %g\n", i, host_HVL[idx], host_HVL[idx+1], host_HVL[idx+2], host_HVL[idx+3] );
00077             printf( "\n" );
00078         }
00079         free( homeVertexList );
00080     }
00081     void PrindDebug_SimFlagsAndPosConstraintLists ( unsigned int numOfVertices, unsigned int * host_SFL, float * host_PCL )
00082     {
00083         unsigned int size_PosConstraint = numOfVertices*sizeof(float)*4;
00084         unsigned int size_SimFlags      = numOfVertices*sizeof(unsigned int);
00085         unsigned int * simFlagsList = (unsigned int *)malloc( size_SimFlags );
00086         float * posConstraintList = (float *)malloc( size_PosConstraint );
00087         CUDA_SAFE_CALL( cudaMemcpy( simFlagsList, m_Ptr_Mem_SimFlagsList, size_SimFlags, cudaMemcpyDeviceToHost ) );
00088         CUDA_SAFE_CALL( cudaMemcpy( posConstraintList, m_Ptr_Mem_PosConstraintList, size_PosConstraint, cudaMemcpyDeviceToHost ) );
00089         for ( unsigned int i = 0; i < numOfVertices; ++i ) {
00090             if ( simFlagsList[i] > 0 ) {
00091                 int idx = i*4;
00092                 printf( "Sim Flags List #     %d: %d\n", i, simFlagsList[i] );
00093                 printf( "Pos Constraint List #%d: %g %g %g %g\n", i, posConstraintList[idx], posConstraintList[idx+1], posConstraintList[idx+2], posConstraintList[idx+3] );
00094                 printf( "Host Sim Flags List #     %d: %d\n", i, host_SFL[i] );
00095                 printf( "Host Pos Constraint List #%d: %g %g %g %g\n", i, host_PCL[idx], host_PCL[idx+1], host_PCL[idx+2], host_PCL[idx+3] );
00096                 printf( "\n" );
00097             }
00098         }
00099         free( simFlagsList );
00100         free( posConstraintList );
00101     }
00102 
00103     void PrintDebug ( 
00104         unsigned int numOfVertices, 
00105         float *         host_VL = NULL, 
00106         float *         host_PVL = NULL, 
00107         float *         host_HVL = NULL, 
00108         unsigned int *  host_SFL = NULL, 
00109         float *         host_PCL = NULL 
00110     ) {
00111         if ( host_VL )  PrindDebug_VertexList( numOfVertices, host_VL );
00112         if ( host_PVL ) PrindDebug_PrevVertexList( numOfVertices, host_PVL );
00113         if ( host_HVL ) PrindDebug_HomeVertexList( numOfVertices, host_HVL );
00114         if ( host_SFL && host_PCL ) PrindDebug_SimFlagsAndPosConstraintLists( numOfVertices, host_SFL, host_PCL );
00115     }
00116 
00118     void PrintDebug_ConnectionList ( unsigned int numOfVertices, unsigned int max_connection_size, int * host_VCL )
00119     {
00120         unsigned int size = numOfVertices*max_connection_size*sizeof(int);
00121         int * vertexConnectionList = (int *)malloc(size);
00122         CUDA_SAFE_CALL( cudaMemcpy( vertexConnectionList, m_Ptr_Mem_VertexConnectionList, size, cudaMemcpyDeviceToHost ) );
00123         int idx = 0;
00124         for ( int i = 0; i < 5; ++i, idx+=max_connection_size ) {
00125             //printf( "     VC List #%d:", i );
00126             //for ( int j = 0; j < max_connection_size; ++j ) {
00127             //  printf( "\t%d", vertexConnectionList[idx+j] );
00128             //}
00129             //printf( "\n" );
00130             printf( "Host VC List #%d:", i );
00131             for ( unsigned int j = 0; j < max_connection_size; ++j ) {
00132                  printf( "\t%d", host_VCL[idx+j] );
00133             }
00134             printf( "\n" );
00135         }
00136         free( vertexConnectionList );
00137     }
00138  
00140     float * GetVertexList ()    { return m_Ptr_Mem_VertexList; }
00142     float * GetPrevVertexList ()    { return m_Ptr_Mem_PrevVertexList; }
00144     float * GetHomeVertexList ()    { return m_Ptr_Mem_HomeVertexList; }
00146     int *   GetVertexConnectionList ()  { return m_Ptr_Mem_VertexConnectionList; }
00148     unsigned int *  GetSimFlagsList ()  { return m_Ptr_Mem_SimFlagsList; }
00150     float * GetPosConstraintList () { return m_Ptr_Mem_PosConstraintList; }
00152     float * GetOrientationList ()   { return m_Ptr_Mem_OrientationList; }
00154     float * GetPrevOrientationList ()   { return m_Ptr_Mem_PrevOrientationList; }
00156     float * GetForceList_1 ()   { return m_Ptr_Mem_ForceList_1; }
00158     float * GetForceList_2 ()   { return m_Ptr_Mem_ForceList_2; }
00159 
00160     // Swap pointers between Vertex List and Previous Vertex List
00161     void    SwapVertexList ()
00162     {
00163         float * tmpPtr = m_Ptr_Mem_VertexList;
00164         m_Ptr_Mem_VertexList = m_Ptr_Mem_PrevVertexList;
00165         m_Ptr_Mem_PrevVertexList = tmpPtr;
00166     
00167         if ( m_bIncludePrevOrientations ) {
00168             float * tmpPtr = m_Ptr_Mem_OrientationList;
00169             m_Ptr_Mem_OrientationList = m_Ptr_Mem_PrevOrientationList;
00170             m_Ptr_Mem_PrevOrientationList = tmpPtr;
00171         }
00172     }
00173 
00175     void BindVertexList ( int numOfVertices )
00176     {
00177         CUDA_SAFE_CALL( cudaBindTexture( 0, CudaTexVertexList, m_Ptr_Mem_VertexList, numOfVertices*sizeof(float4) ) );
00178         CUT_CHECK_ERROR( "Binding Vertex List Failed!" );
00179     }
00181     void BindPrevVertexList ( int numOfVertices )
00182     {
00183         CUDA_SAFE_CALL( cudaBindTexture( 0, CudaTexPrevVertexList, m_Ptr_Mem_PrevVertexList, numOfVertices*sizeof(float4) ) );
00184         CUT_CHECK_ERROR( "Binding Previous Vertex List Failed!" );
00185     }
00187     void BindHomeVertexList ( int numOfVertices )
00188     {
00189         CUDA_SAFE_CALL( cudaBindTexture( 0, CudaTexHomeVertexList, m_Ptr_Mem_HomeVertexList, numOfVertices*sizeof(float4) ) );
00190         CUT_CHECK_ERROR( "Binding Home Vertex List Failed!" );
00191     }
00193     void BindVertexConnectionList ( int numOfVertices, int maxConnectionSize )
00194     {
00195         CUDA_SAFE_CALL( cudaBindTexture( 0, CudaTexVertexConnectionList, m_Ptr_Mem_VertexConnectionList, numOfVertices*maxConnectionSize*sizeof(int1) ) );
00196         CUT_CHECK_ERROR( "Binding Vertex Connection List Failed!" );
00197     }
00199     void BindSimFlagsList ( int numOfVertices )
00200     {
00201         CUDA_SAFE_CALL( cudaBindTexture( 0, CudaTexSimFlagsList, m_Ptr_Mem_SimFlagsList, numOfVertices*sizeof(uint1) ) );
00202         CUT_CHECK_ERROR( "Binding Simulation Flags List Failed!" );
00203     }
00205     void BindPosConstraintList ( int numOfVertices )
00206     {
00207         CUDA_SAFE_CALL( cudaBindTexture( 0, CudaTexPosConstraintList, m_Ptr_Mem_PosConstraintList, numOfVertices*sizeof(float4) ) );
00208         CUT_CHECK_ERROR( "Binding Position Constraint List Failed!" );
00209     }
00211     void BindOrientationList ( int numOfVertices )
00212     {
00213         CUDA_SAFE_CALL( cudaBindTexture( 0, CudaTexOrientationList, m_Ptr_Mem_OrientationList, numOfVertices*sizeof(float4) ) );
00214         CUT_CHECK_ERROR( "Binding Orientation List Failed!" );
00215     }
00217     void BindPrevOrientationList ( int numOfVertices )
00218     {
00219         CUDA_SAFE_CALL( cudaBindTexture( 0, CudaTexPrevOrientationList, m_Ptr_Mem_PrevOrientationList, numOfVertices*sizeof(float4) ) );
00220         CUT_CHECK_ERROR( "Binding Previous Orientation List Failed!" );
00221     }
00223     void BindForceList_1 ( int numOfVertices )
00224     {
00225         CUDA_SAFE_CALL( cudaBindTexture( 0, CudaTexForceList_1, m_Ptr_Mem_ForceList_1, numOfVertices*sizeof(float4) ) );
00226         CUT_CHECK_ERROR( "Binding Force List Set 1 Failed!" );
00227     }
00229     void BindForceList_2 ( int numOfVertices )
00230     {
00231         CUDA_SAFE_CALL( cudaBindTexture( 0, CudaTexForceList_2, m_Ptr_Mem_ForceList_2, numOfVertices*sizeof(float4) ) );
00232         CUT_CHECK_ERROR( "Binding Force List Set 2 Failed!" );
00233     }
00234 
00236     void UnbindVertexList () {  CUDA_SAFE_CALL( cudaUnbindTexture( CudaTexVertexList ) ); }
00238     void UnbindPrevVertexList () {  CUDA_SAFE_CALL( cudaUnbindTexture( CudaTexPrevVertexList ) ); }
00240     void UnbindHomeVertexList () { CUDA_SAFE_CALL( cudaUnbindTexture( CudaTexHomeVertexList ) ); }
00242     void UnbindVertexConnectionList () { CUDA_SAFE_CALL( cudaUnbindTexture( CudaTexVertexConnectionList ) ); }
00244     void UnbindSimFlagsList () {    CUDA_SAFE_CALL( cudaUnbindTexture( CudaTexSimFlagsList ) ); }
00246     void UnbindPosConstraintList () {   CUDA_SAFE_CALL( cudaUnbindTexture( CudaTexPosConstraintList ) ); }
00248     void UnbindOrientationList () { CUDA_SAFE_CALL( cudaUnbindTexture( CudaTexOrientationList ) ); }
00250     void UnbindPrevOrientationList () { CUDA_SAFE_CALL( cudaUnbindTexture( CudaTexPrevOrientationList ) ); }
00252     void UnbindForceList_1 () { CUDA_SAFE_CALL( cudaUnbindTexture( CudaTexForceList_1 ) ); }
00254     void UnbindForceList_2 () { CUDA_SAFE_CALL( cudaUnbindTexture( CudaTexForceList_2 ) ); }
00255 
00256 protected:
00257 
00258 #ifdef  TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_LIN_MEM
00259     bool AllocateTextures ();
00260     bool DeallocateTextures ();
00261 #endif//TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_LIN_MEM
00262 
00263 #ifdef  TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_ARRAY
00264 #endif//TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_FROM_ARRAY
00265 
00266 #ifdef  TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_MIXED
00267 #endif//TAPs_CUDA_DATA_VERTEX_LIST_TEXTURE_MIXED
00268 
00272     float *     m_Ptr_Mem_VertexList;               
00273     float *     m_Ptr_Mem_PrevVertexList;           
00274     float *     m_Ptr_Mem_HomeVertexList;           
00275     int *       m_Ptr_Mem_VertexConnectionList;     
00276     float *     m_Ptr_Mem_OrientationList;          
00277     float *     m_Ptr_Mem_PrevOrientationList;      
00278     float *     m_Ptr_Mem_ForceList_1;              
00279     float *     m_Ptr_Mem_ForceList_2;              
00280 
00281     // Extra resources for strand model
00282     unsigned int *  m_Ptr_Mem_SimFlagsList;         
00283     float *         m_Ptr_Mem_PosConstraintList;    
00284 
00285     unsigned int    m_uiNumOfVertices;              
00286     bool            m_bIncludeHomeVertices;         
00287     unsigned int    m_uiMaxConnectionSize;          
00288     bool            m_bIncludeSimFlagsConstraint;   
00289     bool            m_bIncludeOrientations;         
00290     bool            m_bIncludePrevOrientations;     
00291     bool            m_bIncludeForces_1;             
00292     bool            m_bIncludeForces_2;             
00293 
00294 private:
00295 }; // END: class DATA_Vertex_List
00296 //=============================================================================
00297 END_NAMESPACE_TAPs__CUDA
00298 //-----------------------------------------------------------------------------
00299 
00300 #include "TAPsCUDA_VertexList_Def.cu"
00301 
00302 #endif
00303 //34567890123456789012345678901234567890123456789012345678901234567890123456789
00304 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines