Commit 5f7eb0f3 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Refactoring of the vector operations.

parent 0f6cef3d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@ if( WITH_TEMPLATE_EXPLICIT_INSTANTIATION STREQUAL "yes" )
endif()   

if( WITH_CUDA STREQUAL "yes" )
   AddCompilerFlag( "-DHAVE_NOT_CXX11" )
   AddCompilerFlag( "-DHAVE_NOT_CXX11 -U_GLIBCXX_ATOMIC_BUILTINS -U_GLIBCXX_USE_INT128" )
else()
   AddCompilerFlag( "-std=gnu++0x" )
endif()      
+1 −1
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@

TARGET=TNL
INSTALL_PREFIX=${HOME}/local
WITH_CUDA=yes
WITH_CUDA=no
WITH_CUSPARSE=no
CUDA_ARCHITECTURE=2.0
TEMPLATE_EXPLICIT_INSTANTIATION=yes
+2 −1
Original line number Diff line number Diff line
set( headers tnlVector.h
             tnlMultiVector.h
             tnlSharedVector.h )
             tnlSharedVector.h
             tnlVectorOperations.h )

INSTALL( FILES ${headers} DESTINATION include/tnl-${tnlVersion}/core/vectors )
 No newline at end of file
+207 −0
Original line number Diff line number Diff line
/***************************************************************************
                          tnlVectorOperations.h  -  description
                             -------------------
    begin                : Nov 8, 2012
    copyright            : (C) 2012 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 TNLVECTOROPERATIONS_H_
#define TNLVECTOROPERATIONS_H_

#include <core/cuda/device-check.h>
#include <core/cuda/cuda-reduction.h>
#include <core/cuda/reduction-operations.h>
#include <core/tnlHost.h>
#include <core/tnlCuda.h>

template< typename Device >
class tnlVectorOperations{};

template<>
class tnlVectorOperations< tnlHost >
{
   public:

   template< typename Vector >
   static typename Vector :: RealType getVectorMax( const Vector& v );

   template< typename Vector >
   static typename Vector :: RealType getVectorMin( const Vector& v );

   template< typename Vector >
   static typename Vector :: RealType getVectorAbsMax( const Vector& v );

   template< typename Vector >
   static typename Vector :: RealType getVectorAbsMin( const Vector& v );

   template< typename Vector >
   static typename Vector :: RealType getVectorLpNorm( const Vector& v,
                                                       const typename Vector :: RealType& p );

   template< typename Vector >
   static typename Vector :: RealType getVectorSum( const Vector& v );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceMax( const Vector1& v1,
                                                               const Vector2& v2 );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceMin( const Vector1& v1,
                                                               const Vector2& v2 );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceAbsMax( const Vector1& v1,
                                                                  const Vector2& v2 );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceAbsMin( const Vector1& v1,
                                                                  const Vector2& v2 );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceLpNorm( const Vector1& v1,
                                                           const Vector2& v2,
                                                           const typename Vector1 :: RealType& p );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceSum( const Vector1& v1,
                                                               const Vector2& v2 );
   template< typename Vector >
   static void vectorScalarMultiplication( Vector& v,
                                           const typename Vector :: RealType& alpha );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorSdot( const Vector1& v1,
                                                      const Vector2& v2 );

   template< typename Vector1, typename Vector2 >
   static void vectorSaxpy( Vector1& y,
                     const Vector2& x,
                     const typename Vector1 :: RealType& alpha );
   template< typename Vector1, typename Vector2 >
   static void vectorSaxmy( Vector1& y,
                            const Vector2& x,
                            const typename Vector1 :: RealType& alpha );

   template< typename Vector1, typename Vector2 >
   static void vectorSaxpsby( Vector1& y,
                              const Vector2& x,
                              const typename Vector1 :: RealType& alpha,
                              const typename Vector1 :: RealType& beta );


   template< typename Vector1, typename Vector2 >
   static void vectorSaxpsbz( Vector1& y,
                              const Vector2& x,
                              const typename Vector1 :: RealType& alpha,
                              const Vector2& z,
                              const typename Vector1 :: RealType& beta );

   template< typename Vector1, typename Vector2 >
   static void vectorSaxpsbzpy( Vector1& y,
                                const Vector2& x,
                                const typename Vector1 :: RealType& alpha,
                                const Vector2& z,
                                const typename Vector1 :: RealType& beta );
};

template<>
class tnlVectorOperations< tnlCuda >
{
   public:

   template< typename Vector >
   static typename Vector :: RealType getVectorMax( const Vector& v );

   template< typename Vector >
   static typename Vector :: RealType getVectorMin( const Vector& v );

   template< typename Vector >
   static typename Vector :: RealType getVectorAbsMax( const Vector& v );

   template< typename Vector >
   static typename Vector :: RealType getVectorAbsMin( const Vector& v );

   template< typename Vector >
   static typename Vector :: RealType getVectorLpNorm( const Vector& v,
                                                       const typename Vector :: RealType& p );

   template< typename Vector >
   static typename Vector :: RealType getVectorSum( const Vector& v );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceMax( const Vector1& v1,
                                                               const Vector2& v2 );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceMin( const Vector1& v1,
                                                               const Vector2& v2 );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceAbsMax( const Vector1& v1,
                                                                  const Vector2& v2 );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceAbsMin( const Vector1& v1,
                                                                  const Vector2& v2 );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceLpNorm( const Vector1& v1,
                                                           const Vector2& v2,
                                                           const typename Vector1 :: RealType& p );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorDifferenceSum( const Vector1& v1,
                                                               const Vector2& v2 );
   template< typename Vector >
   static void vectorScalarMultiplication( Vector& v,
                                           const typename Vector :: RealType& alpha );

   template< typename Vector1, typename Vector2 >
   static typename Vector1 :: RealType getVectorSdot( const Vector1& v1,
                                                      const Vector2& v2 );

   template< typename Vector1, typename Vector2 >
   static void vectorSaxpy( Vector1& y,
                     const Vector2& x,
                     const typename Vector1 :: RealType& alpha );
   template< typename Vector1, typename Vector2 >
   static void vectorSaxmy( Vector1& y,
                            const Vector2& x,
                            const typename Vector1 :: RealType& alpha );

   template< typename Vector1, typename Vector2 >
   static void vectorSaxpsby( Vector1& y,
                              const Vector2& x,
                              const typename Vector1 :: RealType& alpha,
                              const typename Vector1 :: RealType& beta );


   template< typename Vector1, typename Vector2 >
   static void vectorSaxpsbz( Vector1& y,
                              const Vector2& x,
                              const typename Vector1 :: RealType& alpha,
                              const Vector2& z,
                              const typename Vector1 :: RealType& beta );

   template< typename Vector1, typename Vector2 >
   static void vectorSaxpsbzpy( Vector1& y,
                                const Vector2& x,
                                const typename Vector1 :: RealType& alpha,
                                const Vector2& z,
                                const typename Vector1 :: RealType& beta );
};

#include <implementation/core/vectors/tnlVectorOperationsHost_impl.h>
#include <implementation/core/vectors/tnlVectorOperationsCuda_impl.h>

#endif /* TNLVECTOROPERATIONS_H_ */
+3 −3
Original line number Diff line number Diff line
@@ -19,7 +19,8 @@ set( common_SOURCES
     ${CURRENT_DIR}/tnlTimerCPU.cpp      
     ${CURRENT_DIR}/mfilename.cpp 
     ${CURRENT_DIR}/mpi-supp.cpp 
     ${CURRENT_DIR}/tnlHost_impl.cpp )       
     ${CURRENT_DIR}/tnlHost_impl.cpp
     ${CURRENT_DIR}/tnlCuda.cpp )       

IF( BUILD_CUDA )
   set( tnl_implementation_core_CUDA__SOURCES
@@ -28,7 +29,6 @@ IF( BUILD_CUDA )
        ${tnl_implementation_core_vectors_CUDA__SOURCES}
        ${common_SOURCES}
        ${CURRENT_DIR}/memory-operations_impl.cu 
        ${CURRENT_DIR}/tnlCuda.cu 
        PARENT_SCOPE )
ENDIF()    

Loading