Commit 7581b3fc authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Adding verbose command line parameter to mgrid-view.

Adding tests for CUDA to configure.ac.
Adding tnlLongVectorCUDA.
Adding CppUnit lib.
parent d269824d
Loading
Loading
Loading
Loading
+111 −15
Original line number Original line Diff line number Diff line
@@ -8,6 +8,15 @@ AM_INIT_AUTOMAKE(libtnl,0.1)
AM_CONFIG_HEADER(config.h)
AM_CONFIG_HEADER(config.h)
AM_PROG_LIBTOOL
AM_PROG_LIBTOOL


dnl -----------------------------------------
dnl ----------- check for progs -------------
dnl -----------------------------------------

AC_PROG_CXX
AC_PROG_AWK
AC_LANG_SAVE
AC_LANG_CPLUSPLUS

dnl -----------------------------------------
dnl -----------------------------------------
dnl ----------- check for icpc --------------
dnl ----------- check for icpc --------------
dnl -----------------------------------------
dnl -----------------------------------------
@@ -19,17 +28,82 @@ fi
dnl -----------------------------------------
dnl -----------------------------------------
dnl ----------- check for CUDA --------------
dnl ----------- check for CUDA --------------
dnl -----------------------------------------
dnl -----------------------------------------
AC_ARG_VAR(CUDA_LIBS,
           AS_HELP_STRING([],[point to a directory with CUDA libraries e.g. /usr/local/cuda/lib])
           )
AC_ARG_VAR(CUDA_HEADERS,
           AS_HELP_STRING([],[point to a directory with CUDA headers e.g. /usr/local/cuda/include])
           )
if test x$CUDA_LIBS = x;
then
   CUDA_LIBS="/usr/local/cuda/lib"
fi
if test x$CUDA_HEADERS = x;
then
   CUDA_HEADERS="/usr/local/cuda/include"
fi
AC_ARG_WITH(cuda,
            AS_HELP_STRING([--with-cuda=[yes/no]],[turn on nVidia CUDA support [default=yes]]),
            with_cuda=$withval,
            with_cuda=yes)
AC_ARG_WITH(cuda_headers,
            AS_HELP_STRING([--with-cuda-headers=dir],[nVidia CUDA headers [default=/usr/local/cuda/include]]),
            CUDA_HEADERS=$withval)
AC_ARG_WITH(cuda_libdir,
            AS_HELP_STRING([--with-cuda-libdir],
                           [says where the CUDA libraries can be found, default is /usr/local/cuda/lib]),
            CUDA_LIBS=$withval)  
if test x$with_cuda = xyes;
then
                    
   AC_CHECK_PROG(cuda,nvcc,"yes","no")
   AC_CHECK_PROG(cuda,nvcc,"yes","no")
if test x$cuda = xyes; then
   NVCC="nvcc"
	CXX="nvcc"
   AC_SUBST(NVCC)
   STORE_CXXFLAGS=$CXXFLAGS
   STORE_CPPFLAGS=$CPPFLAGS
   STORE_LDFLAGS=$LDFLAGS
   CUDA_LDFLAGS="-L$CUDA_LIBS"
   CUDA_CXXFLAGS="-I$CUDA_HEADERS -DHAVE_CUDA"
   CXXFLAGS="$CXXFLAGS -I$CUDA_HEADERS"
   CPPFLAGS="$CPPFLAGS -I$CUDA_HEADERS"
   LDFLAGS="$LDFLAGS $CUDA_LDFLAGS"
   AC_CHECK_HEADER(cuda.h,HAVE_CUDA="yes",HAVE_CUDA="no")
   if test x$HAVE_CUDA = xyes;
   then
      AC_CHECK_HEADER(cuda.h,HAVE_CUDA="yes",HAVE_CUDA="no")
   fi
   if test x$HAVE_CUDA = xyes;
   then
      AC_CHECK_HEADER(cuda_runtime.h,HAVE_CUDA="yes",HAVE_CUDA="no")
   fi
   if test x$HAVE_CUDA = xyes;
   then
      AC_CHECK_LIB(cudart,cudaMalloc,HAVE_CUDA="yes",HAVE_CUDA="no")
   fi
   if test x$HAVE_CUDA = xyes;
   then
      CUDA_LDFLAGS="$CUDA_LDFLAGS -lcudart"
   else
      CUDA_LDFLAGS=""
      CUDA_CXXFLAGS=""
   fi
   CXXFLAGS=$STORE_CXXFLAGS
   CPPFLAGS=$STORE_CPPFLAGS
   LDFLAGS=$STORE_LDFLAGS
fi
fi


CXXFLAGS="$CXXFLAGS $CUDA_CXXFLAGS"
CPPFLAGS="$CPPFLAGS $CUDA_CPPFLAGS"
LDFLAGS="$LDFLAGS $CUDA_LDFLAGS"

dnl -----------------------------------------
dnl -----------------------------------------
dnl ----------- check for debug--------------
dnl ----------- check for debug--------------
dnl -----------------------------------------
dnl -----------------------------------------
AC_ARG_ENABLE(debug,[  --enable-debug=[no/yes]	turn on debugging [default=no]] )
AC_ARG_ENABLE(debug,[  --enable-debug=[no/yes]	turn on debugging [default=no]] )
if test x"$enable_debug" = xyes; then
if test x"$enable_debug" = xyes; then
   DBGCXXFLAGS="-O0 -DDEBUG -g3 -Wall -W -ansi -Wno-unused"
   DBGCXXFLAGS="-O0 -DDEBUG"
   DBGCXXFLAGS="$DBGCXXFLAGS -g3 -Wall -W -ansi -Wno-unused"
   
   DBGSTATUS="yes"
   DBGSTATUS="yes"
else
else
   DBGSTATUS="no"
   DBGSTATUS="no"
@@ -100,10 +174,6 @@ then
   CXXFLAGS="$CXXFLAGS -pg"
   CXXFLAGS="$CXXFLAGS -pg"
fi
fi



AC_PROG_CXX
AC_PROG_AWK

AC_CHECK_FUNCS(bzero)
AC_CHECK_FUNCS(bzero)
AC_CHECK_FUNCS(pow)
AC_CHECK_FUNCS(pow)
AC_CHECK_FUNCS(sqrt)
AC_CHECK_FUNCS(sqrt)
@@ -150,11 +220,9 @@ then
      fi
      fi
   fi
   fi
   STORE_CXXFLAGS="$CXXFLAGS"
   STORE_CXXFLAGS="$CXXFLAGS"
   AC_LANG_SAVE
   
   AC_LANG_CPLUSPLUS
   CXXFLAGS="$CXXFLAGS $MPICXXFLAGS"
   CXXFLAGS="$CXXFLAGS $MPICXXFLAGS"
   AC_CHECK_HEADERS(mpi.h, MPICXXFLAGS="$MPICXXFLAGS -DHAVE_MPI")
   AC_CHECK_HEADERS(mpi.h, MPICXXFLAGS="$MPICXXFLAGS -DHAVE_MPI")
   AC_LANG_RESTORE
   CXXFLAGS="$STORE_CXXFLAGS"
   CXXFLAGS="$STORE_CXXFLAGS"
   AC_SUBST(MPICXXFLAGS)
   AC_SUBST(MPICXXFLAGS)
   AC_SUBST(MPILDFLAGS)
   AC_SUBST(MPILDFLAGS)
@@ -163,7 +231,6 @@ fi
dnl -----------------------------------------
dnl -----------------------------------------
dnl ---------- check for OpenMP -------------
dnl ---------- check for OpenMP -------------
dnl -----------------------------------------
dnl -----------------------------------------

AC_ARG_WITH(openmp, 
AC_ARG_WITH(openmp, 
            AS_HELP_STRING([--with-openmp=[yes/no],compile with OpenMP support[default=no]]),
            AS_HELP_STRING([--with-openmp=[yes/no],compile with OpenMP support[default=no]]),
            with_openmp=$withval,
            with_openmp=$withval,
@@ -173,6 +240,31 @@ then
   AC_CHECK_HEADER(omp.h, OPENMPFLAGS="-openmp -DHAVE_OPENMP" )
   AC_CHECK_HEADER(omp.h, OPENMPFLAGS="-openmp -DHAVE_OPENMP" )
fi
fi


dnl -----------------------------------------
dnl ---------- check for CppUnit ------------
dnl -----------------------------------------
AC_CHECK_HEADER(cppunit/TestCase.h)
STORE_LDFLAGS=$LDFLAGS
LDFLAGS="$LDFLAGS -lcppunit"
AC_TRY_LINK([#include <cppunit/TestCase.h>],
            [
               class IntegerTest : public CppUnit::TestCase 
               {  
                  public: 
                  void runTest()
                  { 
                     CPPUNIT_ASSERT( 1 == 1 );
                  };
                }
              ],HAVE_CPPUNIT="yes",HAVE_CPPUNIT="no")
if test x$HAVE_CPPUNIT="xyes";
then
   CXXFLAGS="$CXXFLAGS -DHAVE_CPPUNIT"
else
   LDFLAGS=$STORE_LDFLAGS
fi
AC_LANG_RESTORE

CXXFLAGS="$CXXFLAGS -I../../src -I../../src/debug -I../src/debug"
CXXFLAGS="$CXXFLAGS -I../../src -I../../src/debug -I../src/debug"


AM_CONDITIONAL([BUILD_MPI],[test x"$MPISTATUS" = xyes] )
AM_CONDITIONAL([BUILD_MPI],[test x"$MPISTATUS" = xyes] )
@@ -291,9 +383,7 @@ echo "" >> mdiff-err-norms-def.h
echo "#define CONFIG_DESCRIPTION_FILE \"$prefix/share/mdiff-tools/mdiff-err-norms.cfg.desc\"" >> mdiff-err-norms-def.h
echo "#define CONFIG_DESCRIPTION_FILE \"$prefix/share/mdiff-tools/mdiff-err-norms.cfg.desc\"" >> mdiff-err-norms-def.h




CXXFLAGS="$CXXFLAGS $OPENMPFLAGS -I../src/debug -I../src/core -I../src/diff -I../../src -I../../../src"
CXXFLAGS="$CXXFLAGS $OPENMPFLAGS $CUDA_CXXFLAGS -I../src/debug -I../src/core -I../src/diff -I../../src -I../../../src"




AC_OUTPUT(Makefile \
AC_OUTPUT(Makefile \
          src/core/Makefile \
          src/core/Makefile \
@@ -305,6 +395,8 @@ AC_OUTPUT(Makefile \
          tools/share/Makefile \
          tools/share/Makefile \
          tools/src/Makefile)
          tools/src/Makefile)




echo
echo
echo "**************************************************"
echo "**************************************************"
echo "*                                                *"
echo "*                                                *"
@@ -313,12 +405,16 @@ echo "* *"
echo "**************************************************"
echo "**************************************************"
echo "*"
echo "*"
echo "* Compiler:" $CXX
echo "* Compiler:" $CXX
echo "* Preprocessor:" $CPP
echo "* Compiler flags:" $CXXFLAGS
echo "* Compiler flags:" $CXXFLAGS
echo "* Preprocessor glags:" $CPPFLAGS
echo "* Linker flags: " $LDFLAGS
echo "* Linker flags: " $LDFLAGS
echo "* Debug flags: " $DBGCXXFLAGS
echo "* Debug flags: " $DBGCXXFLAGS
echo "* Optimising flags: " $OPTIMISECXXFLAGS
echo "* Optimising flags: " $OPTIMISECXXFLAGS
echo "* MPI compiler flags:" $MPICXXFLAGS
echo "* MPI compiler flags:" $MPICXXFLAGS
echo "* MPI linker flags:" $MPILDFLAGS
echo "* MPI linker flags:" $MPILDFLAGS
echo "* CUDA flags:" $CUDA_CXXFLAGS
 




if eval test "x$enable_debug = xyes"; then
if eval test "x$enable_debug = xyes"; then
+29 −27
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@ headers = tnlConfigDescription.h \
		    tnlFieldSystem1D.h \
		    tnlFieldSystem1D.h \
		    tnlList.h \
		    tnlList.h \
		    tnlLongVector.h \
		    tnlLongVector.h \
		    tnlLongVectorCUDA.h \
		    tnlLogger.h \
		    tnlLogger.h \
		    tnlObject.h \
		    tnlObject.h \
		    tnlStack.h \
		    tnlStack.h \
@@ -86,4 +87,5 @@ check_LTLIBRARIES = libcore-tests.la
libcore_tests_la_SOURCES = tnlStringTester.cpp \
libcore_tests_la_SOURCES = tnlStringTester.cpp \
                           tnlStringTester.h \
                           tnlStringTester.h \
                           tnlObjectTester.cpp \
                           tnlObjectTester.cpp \
                           tnlObjectTester.h 
                           tnlObjectTester.h \
                           tnlLongVectorCUDATester.h
+3 −3
Original line number Original line Diff line number Diff line
@@ -19,8 +19,8 @@
#define tnlLongVectorH
#define tnlLongVectorH


#include <assert.h>
#include <assert.h>
#include "tnlObject.h"
#include <core/tnlObject.h>
#include "param-types.h"
#include <core/param-types.h>


template< class T > class tnlLongVector : public tnlObject
template< class T > class tnlLongVector : public tnlObject
{
{
@@ -136,7 +136,7 @@ template< class T > class tnlLongVector : public tnlObject
      for( i = 0; i < size; i ++ ) data[ i ] = ( T ) 0;
      for( i = 0; i < size; i ++ ) data[ i ] = ( T ) 0;
   };
   };


   ~tnlLongVector()
   virtual ~tnlLongVector()
   {
   {
      if( data && ! shared_data ) delete -- data;
      if( data && ! shared_data ) delete -- data;
   };
   };
+140 −0
Original line number Original line Diff line number Diff line
/***************************************************************************
 tnlLongVectorCUDA.h  -  description
 -------------------
 begin                : Dec 27, 2009
 copyright            : (C) 2009 by Tomas 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 TNLLONGVECTORCUDA_H_
#define TNLLONGVECTORCUDA_H_

#ifdef HAVE_CUDA

/*
 *
 */
#include <cuda_runtime.h>
#include <core/tnlObject.h>
#include <core/param-types.h>

template< class T > class tnlLongVectorCUDA : public tnlObject
{
   public:
   //! Constructor with given size
   tnlLongVectorCUDA( int _size = 0 )
    : size( _size ), shared_data( false )
   {
      cudaMalloc( ( void** ) &data, ( size + 1 ) * sizeof( T ) );
      if( ! data )
      {
         cerr << "Unable to allocate new long vector with size " << size << " on CUDA device." << endl;
         abort();
      }
      //data ++;
    };

   //! Constructor with another long vector as template
   tnlLongVectorCUDA( const tnlLongVectorCUDA& v )
    : tnlObject( v ), size( v. size ), shared_data( false )
   {
      cudaMalloc( ( void** ) &data, ( size + 1 ) * sizeof( T ) );
      if( ! data )
      {
         cerr << "Unable to allocate new long vector with size " << size << " on CUDA device." << endl;
         abort();
      }
      //data ++;
   };

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

   bool SetNewSize( int _size )
   {
      if( size == _size ) return true;
      if( ! shared_data )
      {
         cudaFree( data );
         data = 0;
      }
      size = _size;
      cudaMalloc( ( void** ) &data, size * sizeof( T ) );
      shared_data = false;
      if( ! data )
      {
         cerr << "Unable to allocate new long vector with size " << size << " on CUDA device." << endl;
         size = 0;
         return false;
      }
      return true;
   };

   bool SetNewSize( const tnlLongVectorCUDA< T >& v )
   {
      return SetNewSize( v. GetSize() );
   };

   void SetSharedData( T* _data, const int _size )
   {
      if( data && ! shared_data ) cudaFree( data );
      data = _data;
      shared_data = true;
      size = _size;
   };

   int GetSize() const
   {
      return size;
   };

   //! Returns pointer to data
   /*! This is not clear from the OOP point of view however it is necessary for keeping
       good performance of derived numerical structure like solvers.
    */
   const T* Data() const
   {
      return data;
   };

   //! Returns pointer to data
   T* Data()
   {
      return data;
   }

   operator bool() const
   {
      return ( GetSize() != 0 );
   };

   virtual
   ~tnlLongVectorCUDA()
   {
      if( data && ! shared_data ) cudaFree( data );
   };

   private:

   int size;

   T* data;

   bool shared_data;

   //friend class tnlLongVectorCUDATester< T >;
};
#endif
#endif /* TNLLONGVECTORCUDA_H_ */
+58 −0
Original line number Original line Diff line number Diff line
/***************************************************************************
 tnlLongVectorCUDATester.h  -  description
 -------------------
 begin                : Dec 27, 2009
 copyright            : (C) 2009 by Tomas 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 TNLLONGVECTORCUDATESTER_H_
#define TNLLONGVECTORCUDATESTER_H_

/*
 *
 */
#include <cppunit/TestSuite.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestCaller.h>
#include <cppunit/TestCase.h>
#include <core/tnlLongVectorCUDA.h>

template< class T > class tnlLongVectorCUDATester : public CppUnit :: TestCase
{
   public:
   tnlLongVectorCUDATester(){};

   virtual
   ~tnlLongVectorCUDATester(){};

   static CppUnit :: Test* suite()
   {
      CppUnit :: TestSuite suite;
      CppUnit :: TestResult result;
      suite.addTest( new CppUnit :: TestCaller< tnlLongVectorCUDATester< float > >(
                     "testAllocation",
                     & tnlLongVectorCUDATester< float > :: testAllocation )
                   );
      suite.run( &result );
   }

   void testAllocation()
   {
      tnlLongVectorCUDA< T > cuda_vector;
      CPPUNIT_ASSERT( ! cuda_vector );

   }

};

#endif /* TNLLONGVECTORCUDATESTER_H_ */
Loading