Loading src/Makefile.am +4 −2 Original line number Diff line number Diff line Loading @@ -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 src/core/tnl-cuda-kernels.h +6 −6 Original line number Diff line number Diff line Loading @@ -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(); } Loading Loading @@ -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(); } Loading Loading @@ -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(); } Loading Loading @@ -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(); } Loading Loading @@ -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(); } Loading Loading @@ -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(); } Loading src/core/tnlCUDAKernelsTester.h +1 −1 Original line number Diff line number Diff line Loading @@ -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 ); Loading src/core/tnlFieldCUDA2D.h +6 −1 Original line number Diff line number Diff line Loading @@ -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 ) Loading @@ -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 ); Loading src/core/tnlLongVectorCUDA.h +22 −41 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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 { Loading @@ -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 { Loading @@ -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 ) { if( size && cudaMalloc( ( void** ) &data, size * sizeof( T ) ) != cudaSuccess ) : tnlObject( v ), size( 0 ), data( NULL ), shared_data( false ) { 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 { Loading @@ -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 " Loading @@ -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() ); }; bool setNewSize( const tnlLongVector< T >& v ) { return SetNewSize( v. GetSize() ); return setNewSize( v. GetSize() ); }; void SetSharedData( T* _data, const int _size ) Loading Loading @@ -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; Loading @@ -254,11 +242,6 @@ template< class T > class tnlLongVectorCUDA : public tnlObject #endif }; static void setDebug( bool _debug ) { debug = _debug; }; private: int size; Loading Loading @@ -290,6 +273,4 @@ template< class T > bool tnlLongVector< T > :: copyFrom( const tnlLongVectorCUDA } template< class T > bool tnlLongVectorCUDA< T > :: debug; #endif /* TNLLONGVECTORCUDA_H_ */ Loading
src/Makefile.am +4 −2 Original line number Diff line number Diff line Loading @@ -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
src/core/tnl-cuda-kernels.h +6 −6 Original line number Diff line number Diff line Loading @@ -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(); } Loading Loading @@ -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(); } Loading Loading @@ -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(); } Loading Loading @@ -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(); } Loading Loading @@ -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(); } Loading Loading @@ -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(); } Loading
src/core/tnlCUDAKernelsTester.h +1 −1 Original line number Diff line number Diff line Loading @@ -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 ); Loading
src/core/tnlFieldCUDA2D.h +6 −1 Original line number Diff line number Diff line Loading @@ -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 ) Loading @@ -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 ); Loading
src/core/tnlLongVectorCUDA.h +22 −41 Original line number Diff line number Diff line Loading @@ -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 { Loading @@ -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 { Loading @@ -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 { Loading @@ -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 ) { if( size && cudaMalloc( ( void** ) &data, size * sizeof( T ) ) != cudaSuccess ) : tnlObject( v ), size( 0 ), data( NULL ), shared_data( false ) { 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 { Loading @@ -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 " Loading @@ -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() ); }; bool setNewSize( const tnlLongVector< T >& v ) { return SetNewSize( v. GetSize() ); return setNewSize( v. GetSize() ); }; void SetSharedData( T* _data, const int _size ) Loading Loading @@ -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; Loading @@ -254,11 +242,6 @@ template< class T > class tnlLongVectorCUDA : public tnlObject #endif }; static void setDebug( bool _debug ) { debug = _debug; }; private: int size; Loading Loading @@ -290,6 +273,4 @@ template< class T > bool tnlLongVector< T > :: copyFrom( const tnlLongVectorCUDA } template< class T > bool tnlLongVectorCUDA< T > :: debug; #endif /* TNLLONGVECTORCUDA_H_ */