Commit 7993aeec authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Implemented tnlFieldCUDA[1,2,3]D with tests.

parent 3b4ed37c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ libtnl_mpi_dbg_0_1_la_LIBADD = debug/libtnldebug-mpi-dbg-0.1.la \
                       matrix/libtnlmatrix-mpi-dbg-0.1.la
endif                       

tnl_unit_tests_sources = tnl-unit-tests.cu
tnl_unit_tests_sources = tnl-unit-tests.cpp

check_PROGRAMS = tnl-unit-tests
tnl_unit_tests_SOURCES = $(tnl_unit_tests_sources)
+5 −1
Original line number Diff line number Diff line
@@ -10,12 +10,16 @@ EXTRA_DIST = tnlConfigDescriptionParser.y \
	         tnlConfigDescriptionScanner.l \
	         FlexLexer.h

headers = tnlConfigDescription.h \
headers = tnlAssert.h \
          tnlConfigDescription.h \
    	    tnlCurve.h \
		    tnlDataElement.h \
		    tnlField1D.h \
		    tnlFieldCUDA1D.h \
		    tnlField2D.h \
		    tnlFieldCUDA2D.h \
		    tnlField3D.h \
		    tnlFieldCUDA3D.h \
		    tnlFieldSystem1D.h \
		    tnlList.h \
		    tnlLongVector.h \

src/core/tnlAssert.h

0 → 100644
+36 −0
Original line number Diff line number Diff line
/*
 * tnlAssert.h
 *
 *  Created on: Jan 12, 2010
 *      Author: oberhuber
 */

#ifndef TNLASSERT_H_

#ifdef DEBUG

#include <iostream>
#include <stdlib.h>

using namespace std;

#define tnlAssert( ___tnl__assert_condition, ___tnl__assert_command )  \
	if( ! ___tnl__assert_condition )                    \
	{                                    \
		cerr << "Assertion '___tnl__assert_condition' failed !!!" << endl
             << "File: __FILE__" << endl
             << "Function: __PRETTY_FUNCTION__ " << endl
             << "Line: __LINE__" << endl
             << "Diagnostics: ";
        ___tnl__assert_command;
        cerr << endl;
        exit( EXIT_FAILURE );
	}
#else
#define tnlAssert( ___tnl__assert_condition, ___tnl__assert_command )
#endif

#define TNLASSERT_H_


#endif /* TNLASSERT_H_ */
+17 −4
Original line number Diff line number Diff line
@@ -19,8 +19,12 @@
#define tnlField2DH

#include <string.h>
#include "tnlObject.h"
#include "tnlLongVector.h"
#include <core/tnlObject.h>
#include <core/tnlLongVector.h>

#ifdef HAVE_CUDA
template< class T > class tnlFieldCUDA2D;
#endif

template< class T > class tnlField2D : public tnlLongVector< T >
{
@@ -79,13 +83,17 @@ template< class T > class tnlField2D : public tnlLongVector< T >

   const T& operator() ( int i, int j ) const
   {
      assert( i < x_size && j < y_size && i >= 0 && j >= 0 );
      tnlAssert( i < x_size && j < y_size && i >= 0 && j >= 0,
    		     cerr << "i = " << i << " j = " << j
    		          << "x_size = " << x_size << " y_size = " << y_size );
      return tnlLongVector< T > :: data[ i * y_size + j ];
   };

   T& operator() ( int i, int j )
   {
      assert( i < x_size && j < y_size && i >= 0 && j >= 0 );
	  tnlAssert( i < x_size && j < y_size && i >= 0 && j >= 0,
	       		     cerr << "i = " << i << " j = " << j
	       		          << "x_size = " << x_size << " y_size = " << y_size );
      return tnlLongVector< T > :: data[ i * y_size + j ];
   };

@@ -96,6 +104,11 @@ template< class T > class tnlField2D : public tnlLongVector< T >
      return i * y_size + j;
   };
   
#ifdef HAVE_CUDA
   bool copyFrom( const tnlFieldCUDA2D< T >& cuda_vector );
#endif


   //! Method for saving the object to a file as a binary data
   bool Save( ostream& file ) const
   {
+73 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlFieldCUDA1D.h  -  description
                             -------------------
    begin                : 2007/11/26
    copyright            : (C) 2007 by Tomá¹ Oberhuber
    email                : tomas.oberhuber@fjfi.cvut.cz
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef tnlFieldCUDA1DH
#define tnlFieldCUDA1DH

#include <string.h>
#include "tnlObject.h"
#include "tnlLongVectorCUDA.h"

template< class T > class tnlFieldCUDA1D : public tnlLongVectorCUDA< T >
{
   public:

   tnlFieldCUDA1D()
   : tnlLongVectorCUDA< T >( 0 )
   { };

   tnlFieldCUDA1D( int _x_size )
   : tnlLongVectorCUDA< T >( _x_size ),
     x_size( _x_size )
   { };

   tnlFieldCUDA1D( const tnlFieldCUDA1D& f )
   : tnlLongVectorCUDA< T >( f ),
     x_size( f. x_size )
   { };

   tnlString GetType() const
   {
      T t;
      return tnlString( "tnlFieldCUDA1D< " ) + tnlString( GetParameterType( t ) ) + tnlString( " >" );
   };

   int GetXSize() const
   {
      return x_size;
   };

   bool SetNewDimensions( int new_x_size )
   {
      x_size = new_x_size;
      return tnlLongVectorCUDA< T > :: SetNewSize( x_size );
   };

   bool SetNewDimensions( const tnlFieldCUDA1D< T >& f )
   {
      return SetNewDimensions( f. GetXSize() );
   };
   
   protected:

   int x_size;
};

// Explicit instatiation
template class tnlFieldCUDA1D< double >;

#endif
Loading