From ecd167e8c45da5f158a86c8cd9a9de8353410450 Mon Sep 17 00:00:00 2001
From: Tomas Oberhuber <tomas.oberhuber@fjfi.cvut.cz>
Date: Thu, 4 Mar 2010 15:47:35 +0000
Subject: [PATCH] Fixing tnlLongVectorCUDA :: setNewSize.

---
 src/Makefile.am                    |  6 ++-
 src/core/tnl-cuda-kernels.h        | 12 +++---
 src/core/tnlCUDAKernelsTester.h    |  2 +-
 src/core/tnlFieldCUDA2D.h          |  7 +++-
 src/core/tnlLongVectorCUDA.h       | 63 +++++++++++-------------------
 src/core/tnlLongVectorCUDATester.h |  6 ++-
 src/core/tnlObject.cpp             | 10 +----
 src/core/tnlObject.h               |  7 ----
 src/tnl-benchmarks.h               | 14 +++----
 9 files changed, 52 insertions(+), 75 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 004eeba807..31a09732ce 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -72,5 +72,7 @@ endif
 
 
 
-TESTS = tnl-unit-tests \
-        tnl-benchmarks
\ No newline at end of file
+TESTS = tnl-unit-tests 
+
+##tnl-unit-tests \
+##        tnl-benchmarks
\ No newline at end of file
diff --git a/src/core/tnl-cuda-kernels.h b/src/core/tnl-cuda-kernels.h
index 9b5bbc2ed0..75b97d7507 100644
--- a/src/core/tnl-cuda-kernels.h
+++ b/src/core/tnl-cuda-kernels.h
@@ -403,7 +403,7 @@ bool tnlCUDAReduction( const int size,
    if( ! deviceAux )
    {
       int sizeAlloc = :: Max( 1, size / desBlockSize );
-      if( ! deviceAuxVct. SetNewSize( sizeAlloc ) )
+      if( ! deviceAuxVct. setNewSize( sizeAlloc ) )
          return false;
       deviceAux = deviceAuxVct. Data();
    }
@@ -648,7 +648,7 @@ bool tnlCUDASimpleReduction5( const int size,
    if( ! deviceAux )
    {
       int sizeAlloc = :: Max( 1, size / desBlockSize );
-      if( ! deviceAuxVct. SetNewSize( sizeAlloc ) )
+      if( ! deviceAuxVct. setNewSize( sizeAlloc ) )
          return false;
       deviceAux = deviceAuxVct. Data();
    }
@@ -874,7 +874,7 @@ bool tnlCUDASimpleReduction4( const int size,
    if( ! deviceAux )
    {
       int sizeAlloc = :: Max( 1, size / desBlockSize );
-      if( ! deviceAuxVct. SetNewSize( sizeAlloc ) )
+      if( ! deviceAuxVct. setNewSize( sizeAlloc ) )
          return false;
       deviceAux = deviceAuxVct. Data();
    }
@@ -1085,7 +1085,7 @@ bool tnlCUDASimpleReduction3( const int size,
    if( ! deviceAux )
    {
       int sizeAlloc = :: Max( 1, size / desBlockSize );
-      if( ! deviceAuxVct. SetNewSize( sizeAlloc ) )
+      if( ! deviceAuxVct. setNewSize( sizeAlloc ) )
          return false;
       deviceAux = deviceAuxVct. Data();
    }
@@ -1261,7 +1261,7 @@ bool tnlCUDASimpleReduction2( const int size,
    if( ! deviceAux )
    {
       int sizeAlloc = :: Max( 1, size / desBlockSize );
-      if( ! deviceAuxVct. SetNewSize( sizeAlloc ) )
+      if( ! deviceAuxVct. setNewSize( sizeAlloc ) )
          return false;
       deviceAux = deviceAuxVct. Data();
    }
@@ -1420,7 +1420,7 @@ bool tnlCUDASimpleReduction1( const int size,
    if( ! deviceAux )
    {
       int sizeAlloc = :: Max( 1, size / desBlockSize );
-      if( ! deviceAuxVct. SetNewSize( sizeAlloc ) )
+      if( ! deviceAuxVct. setNewSize( sizeAlloc ) )
          return false;
       deviceAux = deviceAuxVct. Data();
    }
diff --git a/src/core/tnlCUDAKernelsTester.h b/src/core/tnlCUDAKernelsTester.h
index 10e871a698..b70f8598c0 100644
--- a/src/core/tnlCUDAKernelsTester.h
+++ b/src/core/tnlCUDAKernelsTester.h
@@ -106,7 +106,7 @@ template< class T > class tnlCUDAKernelsTester : public CppUnit :: TestCase
    {
       const int size = host_input. GetSize();
       tnlLongVectorCUDA< T > device_input;
-      if( ! device_input. SetNewSize( size ) )
+      if( ! device_input. setNewSize( size ) )
          return false;
       device_input. copyFrom( host_input );
 
diff --git a/src/core/tnlFieldCUDA2D.h b/src/core/tnlFieldCUDA2D.h
index c008a04987..16ce0b6780 100644
--- a/src/core/tnlFieldCUDA2D.h
+++ b/src/core/tnlFieldCUDA2D.h
@@ -70,7 +70,7 @@ template< class T > class tnlFieldCUDA2D : public tnlLongVectorCUDA< T >
    {
       x_size = new_x_size;
       y_size = new_y_size;
-      return tnlLongVectorCUDA< T > :: SetNewSize( x_size * y_size );
+      return tnlLongVectorCUDA< T > :: setNewSize( x_size * y_size );
    };
 
    bool SetNewDimensions( const tnlFieldCUDA2D< T >& f )
@@ -78,6 +78,11 @@ template< class T > class tnlFieldCUDA2D : public tnlLongVectorCUDA< T >
       return SetNewDimensions( f. GetXSize(), f. GetYSize() );
    };
 
+   bool SetNewDimensions( const tnlField2D< T >& f )
+   {
+	   return SetNewDimensions( f. GetXSize(), f. GetYSize() );
+   };
+
    void SetSharedData( T* _data, const int _x_size, const int _y_size )
    {
       tnlLongVectorCUDA< T > :: SetSharedData( _data, _x_size * _y_size );
diff --git a/src/core/tnlLongVectorCUDA.h b/src/core/tnlLongVectorCUDA.h
index bd1adcbeac..989c3264c1 100644
--- a/src/core/tnlLongVectorCUDA.h
+++ b/src/core/tnlLongVectorCUDA.h
@@ -44,6 +44,7 @@ using namespace std;
 #include <core/tnlObject.h>
 #include <core/param-types.h>
 #include <core/tnlLongVector.h>
+#include <debug/tnlDebug.h>
 
 template< class T > class tnlLongVectorCUDA : public tnlObject
 {
@@ -51,17 +52,9 @@ template< class T > class tnlLongVectorCUDA : public tnlObject
    //! Constructor with given size
    tnlLongVectorCUDA( const char* name = 0, int _size = 0 )
 #ifdef HAVE_CUDA
-    : tnlObject( name ), size( _size ), data( NULL ), shared_data( false )
+    : tnlObject( name ), size( 0 ), data( NULL ), shared_data( false )
    {
-      if( size && cudaMalloc( ( void** ) &data, ( size ) * sizeof( T ) ) != cudaSuccess  )
-      {
-         cerr << "Unable to allocate new long vector '" << GetName() << "' with size "
-              << size << " on CUDA device for "
-              << GetName() << "." << endl;
-         data = NULL;
-         abort();
-      }
-      //data ++;
+      if( _size ) setNewSize( _size );
    };
 #else
    {
@@ -72,16 +65,10 @@ template< class T > class tnlLongVectorCUDA : public tnlObject
    //! Constructor with another long vector as template
    tnlLongVectorCUDA( const tnlLongVectorCUDA& v )
 #ifdef HAVE_CUDA
-    : tnlObject( v ), size( v. size ), data( NULL ), shared_data( false )
+    : tnlObject( v ), size( 0 ), data( NULL ), shared_data( false )
    {
-	  if( size )
-		  if( cudaMalloc( ( void** ) &data, size * sizeof( T ) ) != cudaSuccess )
-		  {
-			  cerr << "Unable to allocate new long vector '" << GetName() << "' with size " << size << " on CUDA device." << endl;
-			  data = NULL;
-			  abort();
-		  }
-      //data ++;
+	  if( v. GetSize() )
+		  setNewSize( v. size );
    };
 #else
    {
@@ -92,15 +79,9 @@ template< class T > class tnlLongVectorCUDA : public tnlObject
    //! Constructor with another long vector as template
    tnlLongVectorCUDA( const tnlLongVector< T >& v )
 #ifdef HAVE_CUDA
-    : tnlObject( v ), size( v. GetSize() ), data( NULL ), shared_data( false )
+    : tnlObject( v ), size( 0 ), data( NULL ), shared_data( false )
    {
-      if( size && cudaMalloc( ( void** ) &data, size * sizeof( T ) ) != cudaSuccess )
-      {
-         cerr << "Unable to allocate new long vector with size " << size << " on CUDA device." << endl;
-         data = NULL;
-         abort();
-      }
-      //data ++;
+	   if( v. GetSize() ) setNewSize( v. GetSize() );
    };
 #else
    {
@@ -116,19 +97,21 @@ template< class T > class tnlLongVectorCUDA : public tnlObject
    }
 
 
-   bool SetNewSize( int _size )
+   bool setNewSize( int _size )
 #ifdef HAVE_CUDA
    {
-      if( debug )
-	   cout << "Setting new size to " << _size << " for " << GetName() << endl;
+	  dbgFunctionName( "tnlLongVectorCUDA", "setNewSize" );
+      dbgCout( "Setting new size to " << _size << " for " << GetName() );
       if( size == _size ) return true;
       if( data && ! shared_data )
       {
+    	 dbgCout( "Freeing allocated memory on CUDA device of " << GetName() );
          cudaFree( data );
          data = NULL;
       }
       size = _size;
       shared_data = false;
+      cerr << "###########" << endl;
       if( cudaMalloc( ( void** ) &data, size * sizeof( T ) ) != cudaSuccess )
       {
          cerr << "Unable to allocate new long vector with size "
@@ -147,9 +130,14 @@ template< class T > class tnlLongVectorCUDA : public tnlObject
    };
 #endif
 
-   bool SetNewSize( const tnlLongVectorCUDA< T >& v )
+   bool setNewSize( const tnlLongVectorCUDA< T >& v )
    {
-      return SetNewSize( v. GetSize() );
+      return setNewSize( v. GetSize() );
+   };
+
+   bool setNewSize( const tnlLongVector< T >& v )
+   {
+	   return setNewSize( v. GetSize() );
    };
 
    void SetSharedData( T* _data, const int _size )
@@ -239,11 +227,11 @@ template< class T > class tnlLongVectorCUDA : public tnlObject
    virtual
    ~tnlLongVectorCUDA()
    {
+	   dbgFunctionName( "tnlLongVectorCUDA", "~tnlLOngVectorCUDA" );
 #ifdef HAVE_CUDA
       if( data && ! shared_data )
       {
-         if( debug )
-            cout << "Freeing allocated memory of " << GetName() << " on CUDA device." << endl;
+         dbgCout( "Freeing allocated memory of " << GetName() << " on CUDA device." );
          if( cudaFree( data ) != cudaSuccess )
          {
             cerr << "Unable to free alocated memory on CUDA device of " << GetName() << "." << endl;
@@ -254,11 +242,6 @@ template< class T > class tnlLongVectorCUDA : public tnlObject
 #endif
    };
 
-   static void setDebug( bool _debug )
-   {
-      debug = _debug;
-   };
-
    private:
 
    int size;
@@ -290,6 +273,4 @@ template< class T > bool tnlLongVector< T > :: copyFrom( const tnlLongVectorCUDA
 
 }
 
-template< class T > bool tnlLongVectorCUDA< T > :: debug;
-
 #endif /* TNLLONGVECTORCUDA_H_ */
diff --git a/src/core/tnlLongVectorCUDATester.h b/src/core/tnlLongVectorCUDATester.h
index 0f3e100d0b..885a53331e 100644
--- a/src/core/tnlLongVectorCUDATester.h
+++ b/src/core/tnlLongVectorCUDATester.h
@@ -25,6 +25,7 @@
 #include <cppunit/TestResult.h>
 #include <cppunit/TestCaller.h>
 #include <cppunit/TestCase.h>
+#include <cppunit/Message.h>
 #include <core/tnlLongVectorCUDA.h>
 #include <core/tnlLongVector.h>
 
@@ -164,13 +165,14 @@ template< class T > class tnlLongVectorCUDATester : public CppUnit :: TestCase
       tnlLongVectorCUDA< T > cuda_vector_1;
       CPPUNIT_ASSERT( !cuda_vector_1 );
  
-      cuda_vector_1. SetNewSize( 100 );
+      cuda_vector_1. setNewSize( 100 );
+
       CPPUNIT_ASSERT( cuda_vector_1 );
       CPPUNIT_ASSERT( cuda_vector_1. GetSize() == 100 );
 
       tnlLongVectorCUDA< T > cuda_vector_2;
       CPPUNIT_ASSERT( !cuda_vector_2 );
-      cuda_vector_2. SetNewSize( cuda_vector_1 );
+      cuda_vector_2. setNewSize( cuda_vector_1 );
       CPPUNIT_ASSERT( cuda_vector_2. GetSize() == 100 );
 
       tnlLongVectorCUDA< T > cuda_vector_3( "cuda-vector", 100 );
diff --git a/src/core/tnlObject.cpp b/src/core/tnlObject.cpp
index ca49633088..af114326ea 100644
--- a/src/core/tnlObject.cpp
+++ b/src/core/tnlObject.cpp
@@ -25,7 +25,6 @@
 
 const char magic_number[] = "SIM33";
 
-bool tnlObject :: debug = false;
 //--------------------------------------------------------------------------
 tnlObject :: tnlObject( )
 {
@@ -33,9 +32,9 @@ tnlObject :: tnlObject( )
 //--------------------------------------------------------------------------
 tnlObject :: tnlObject( const char* name )
 {
+   dbgFunctionName( "tnlObject", "tnlObject" );
+   dbgCout( "Initiating object " << GetName() );
    SetName( name );
-   if( debug )
-      cout << "Initiating object " << GetName() << endl;
 }
 //--------------------------------------------------------------------------
 tnlObject :: tnlObject( const tnlObject& object )
@@ -85,11 +84,6 @@ bool tnlObject :: Load( istream& file )
    return true;
 }
 //--------------------------------------------------------------------------
-void tnlObject :: setDebug( bool _debug )
-{
-   debug = _debug;
-}
-//--------------------------------------------------------------------------
 bool GetObjectType( istream& file, tnlString& type )
 {
    dbgFunctionName( "", "GetObjectType" );
diff --git a/src/core/tnlObject.h b/src/core/tnlObject.h
index 6c91c5e6be..3378f613d3 100644
--- a/src/core/tnlObject.h
+++ b/src/core/tnlObject.h
@@ -59,9 +59,6 @@ class tnlObject
    //! Method for restoring the object from a file
    virtual bool Load( istream& file );   
 
-   //! Debug moder setter
-   static void setDebug( bool );
-
    //! Destructor
    virtual ~tnlObject(){};
 
@@ -69,10 +66,6 @@ class tnlObject
 
    //! Object name
    tnlString name;
-
-   //! Turns on debuging messages
-   static bool debug;
-
 };
 
 bool GetObjectType( istream& file, tnlString& type );
diff --git a/src/tnl-benchmarks.h b/src/tnl-benchmarks.h
index 07213972ce..b9b4a467a7 100644
--- a/src/tnl-benchmarks.h
+++ b/src/tnl-benchmarks.h
@@ -28,10 +28,10 @@ bool transferBenchmark( const int size,
                         double& device_to_device_band_width )
 {
 
-  tnlLongVector< T > host_vector( size );
-  tnlLongVector< T > host_vector2( size );
-  tnlLongVectorCUDA< T > device_vector( size );
-  tnlLongVectorCUDA< T > device_vector2( size );
+  tnlLongVector< T > host_vector( "transferBenchmark:host-vector", size );
+  tnlLongVector< T > host_vector2( "transferBenchmark:host-vector-2", size );
+  tnlLongVectorCUDA< T > device_vector( "transferBenchmark:device-vector", size );
+  tnlLongVectorCUDA< T > device_vector2( "transferBenchmark:device-vector-2", size );
 
    for( int i = 0; i < size; i ++ )
       host_vector[ i ] = i + 1;
@@ -122,9 +122,9 @@ template< class T >
 void reductionBenchmark( const int size,
                          const int algorithm )
 {
-   tnlLongVector< T > host_vector( size );
-   tnlLongVectorCUDA< T > device_vector( size );
-   tnlLongVectorCUDA< T > device_aux( size / 2 );
+   tnlLongVector< T > host_vector( "reductionBenchmark:host-vector", size );
+   tnlLongVectorCUDA< T > device_vector( "reductionBenchmark:device-vector", size );
+   tnlLongVectorCUDA< T > device_aux( "reductionBenchmark:device-aux", size / 2 );
 
    for( int i = 0; i < size; i ++ )
       host_vector[ i ] = i + 1;
-- 
GitLab