Commit d0d43618 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Tomáš Oberhuber
Browse files

Added cuda callables to statice expression templates.

parent c9b59e39
Loading
Loading
Loading
Loading
+32 −6
Original line number Diff line number Diff line
@@ -26,12 +26,6 @@ template< typename T1,
          ExpressionVariableType T2Type = ExpressionVariableTypeGetter< T2 >::value >
struct BinaryExpressionTemplate
{
   /*BinaryExpressionTemplate( const T1& a, const T2& b ){};

   static T1 evaluate( const T1& a, const T2& b )
   {
      return Operation< T1, T2 >::evaluate( a, b );
   }*/
};

template< typename T1,
@@ -42,18 +36,22 @@ struct BinaryExpressionTemplate< T1, T2, Operation, VectorVariable, VectorVariab
   using RealType = typename T1::RealType;
   using IsExpressionTemplate = bool;

   __cuda_callable__
   BinaryExpressionTemplate( const T1& a, const T2& b ): op1( a ), op2( b ){}

   __cuda_callable__
   static BinaryExpressionTemplate evaluate( const T1& a, const T2& b )
   {
      return BinaryExpressionTemplate( a, b );
   }

   __cuda_callable__
   RealType operator[]( const int i ) const
   {
       return Operation< typename T1::RealType, typename T2::RealType >::evaluate( op1[ i ], op2[ i ] );
   }

   __cuda_callable__
   int getSize() const
   {
       return op1.getSize();
@@ -73,18 +71,22 @@ struct BinaryExpressionTemplate< T1, T2, Operation, VectorVariable, ArithmeticVa
   using RealType = typename T1::RealType;
   using IsExpressionTemplate = bool;

   __cuda_callable__
   BinaryExpressionTemplate( const T1& a, const T2& b ): op1( a ), op2( b ){}

   __cuda_callable__
   BinaryExpressionTemplate evaluate( const T1& a, const T2& b )
   {
      return BinaryExpressionTemplate( a, b );
   }

   __cuda_callable__
   RealType operator[]( const int i ) const
   {
       return Operation< typename T1::RealType, T2 >::evaluate( op1[ i ], op2 );
   }

   __cuda_callable__
   int getSize() const
   {
       return op1.getSize();
@@ -104,18 +106,22 @@ struct BinaryExpressionTemplate< T1, T2, Operation, ArithmeticVariable, VectorVa
   using RealType = typename T2::RealType;
   using IsExpressionTemplate = bool;

   __cuda_callable__
   BinaryExpressionTemplate( const T1& a, const T2& b ): op1( a ), op2( b ){}

   __cuda_callable__
   BinaryExpressionTemplate evaluate( const T1& a, const T2& b )
   {
      return BinaryExpressionTemplate( a, b );
   }

   __cuda_callable__
   RealType operator[]( const int i ) const
   {
       return Operation< T1, typename T2::RealType >::evaluate( op1, op2[ i ] );
   }

   __cuda_callable__
   int getSize() const
   {
       return op2.getSize();
@@ -134,6 +140,7 @@ template< typename L1,
          typename R1,
          typename R2,
          template< typename, typename > class ROperation >
__cuda_callable__
const Expressions::BinaryExpressionTemplate<
   Expressions::BinaryExpressionTemplate< L1, L2, LOperation >,
   Expressions::BinaryExpressionTemplate< R1, R2, ROperation >,
@@ -150,6 +157,7 @@ operator + ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >&
template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
__cuda_callable__
const Expressions::BinaryExpressionTemplate<
   Expressions::BinaryExpressionTemplate< T1, T2, Operation >,
   typename Expressions::BinaryExpressionTemplate< T1, T2, Operation >::RealType,
@@ -171,6 +179,7 @@ template< typename L1,
          typename R1,
          typename R2,
          template< typename, typename > class ROperation >
__cuda_callable__
const Expressions::BinaryExpressionTemplate<
   Expressions::BinaryExpressionTemplate< L1, L2, LOperation >,
   Expressions::BinaryExpressionTemplate< R1, R2, ROperation >,
@@ -187,6 +196,7 @@ operator - ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >&
template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
__cuda_callable__
const Expressions::BinaryExpressionTemplate<
   Expressions::BinaryExpressionTemplate< T1, T2, Operation >,
   typename Expressions::BinaryExpressionTemplate< T1, T2, Operation >::RealType,
@@ -208,6 +218,7 @@ template< typename L1,
          typename R1,
          typename R2,
          template< typename, typename > class ROperation >
__cuda_callable__
const Expressions::BinaryExpressionTemplate<
   Expressions::BinaryExpressionTemplate< L1, L2, LOperation >,
   Expressions::BinaryExpressionTemplate< R1, R2, ROperation >,
@@ -224,6 +235,7 @@ operator * ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >&
template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
__cuda_callable__
const Expressions::BinaryExpressionTemplate<
   Expressions::BinaryExpressionTemplate< T1, T2, Operation >,
   typename Expressions::BinaryExpressionTemplate< T1, T2, Operation >::RealType,
@@ -245,6 +257,7 @@ template< typename L1,
          typename R1,
          typename R2,
          template< typename, typename > class ROperation >
__cuda_callable__
const Expressions::BinaryExpressionTemplate<
   Expressions::BinaryExpressionTemplate< L1, L2, LOperation >,
   Expressions::BinaryExpressionTemplate< R1, R2, ROperation >,
@@ -261,6 +274,7 @@ operator / ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >&
template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
__cuda_callable__
const Expressions::BinaryExpressionTemplate<
   Expressions::BinaryExpressionTemplate< T1, T2, Operation >,
   typename Expressions::BinaryExpressionTemplate< T1, T2, Operation >::RealType,
@@ -282,6 +296,7 @@ template< typename L1,
          typename R1,
          typename R2,
          template< typename, typename > class ROperation >
__cuda_callable__
bool
operator == ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >& a,
             const Expressions::BinaryExpressionTemplate< R1, R2, ROperation >& b )
@@ -292,6 +307,7 @@ operator == ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >&
template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
__cuda_callable__
bool
operator == ( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& a,
              const typename Expressions::BinaryExpressionTemplate< T1, T2, Operation >::RealType& b )
@@ -307,6 +323,7 @@ template< typename L1,
          typename R1,
          typename R2,
          template< typename, typename > class ROperation >
__cuda_callable__
bool
operator != ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >& a,
             const Expressions::BinaryExpressionTemplate< R1, R2, ROperation >& b )
@@ -317,6 +334,7 @@ operator != ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >&
template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
__cuda_callable__
bool
operator != ( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& a,
              const typename Expressions::BinaryExpressionTemplate< T1, T2, Operation >::RealType& b )
@@ -332,6 +350,7 @@ template< typename L1,
          typename R1,
          typename R2,
          template< typename, typename > class ROperation >
__cuda_callable__
bool
operator < ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >& a,
             const Expressions::BinaryExpressionTemplate< R1, R2, ROperation >& b )
@@ -342,6 +361,7 @@ operator < ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >&
template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
__cuda_callable__
bool
operator < ( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& a,
             const typename Expressions::BinaryExpressionTemplate< T1, T2, Operation >::RealType& b )
@@ -357,6 +377,7 @@ template< typename L1,
          typename R1,
          typename R2,
          template< typename, typename > class ROperation >
__cuda_callable__
bool
operator <= ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >& a,
             const Expressions::BinaryExpressionTemplate< R1, R2, ROperation >& b )
@@ -367,6 +388,7 @@ operator <= ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >&
template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
__cuda_callable__
bool
operator <= ( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& a,
             const typename Expressions::BinaryExpressionTemplate< T1, T2, Operation >::RealType& b )
@@ -382,6 +404,7 @@ template< typename L1,
          typename R1,
          typename R2,
          template< typename, typename > class ROperation >
__cuda_callable__
bool
operator > ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >& a,
             const Expressions::BinaryExpressionTemplate< R1, R2, ROperation >& b )
@@ -392,6 +415,7 @@ operator > ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >&
template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
__cuda_callable__
bool
operator > ( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& a,
             const typename Expressions::BinaryExpressionTemplate< T1, T2, Operation >::RealType& b )
@@ -407,6 +431,7 @@ template< typename L1,
          typename R1,
          typename R2,
          template< typename, typename > class ROperation >
__cuda_callable__
bool
operator >= ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >& a,
              const Expressions::BinaryExpressionTemplate< R1, R2, ROperation >& b )
@@ -417,6 +442,7 @@ operator >= ( const Expressions::BinaryExpressionTemplate< L1, L2, LOperation >&
template< typename T1,
          typename T2,
          template< typename, typename > class Operation >
__cuda_callable__
bool
operator >= ( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& a,
              const typename Expressions::BinaryExpressionTemplate< T1, T2, Operation >::RealType& b )
+4 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ namespace TNL {
template< typename T1, typename T2 >
struct Addition
{
   __cuda_callable__
   static auto evaluate( const T1& a, const T2& b ) -> decltype( a + b )
   {
      return a + b;
@@ -26,6 +27,7 @@ struct Addition
template< typename T1, typename T2 >
struct Subtraction
{
   __cuda_callable__
   static auto evaluate( const T1& a, const T2& b ) -> decltype( a - b )
   {
      return a - b;
@@ -35,6 +37,7 @@ struct Subtraction
template< typename T1, typename T2 >
struct Multiplication
{
   __cuda_callable__
   static auto evaluate( const T1& a, const T2& b ) -> decltype( a * b )
   {
      return a * b;
@@ -44,6 +47,7 @@ struct Multiplication
template< typename T1, typename T2 >
struct Division
{
   __cuda_callable__
   static auto evaluate( const T1& a, const T2& b ) -> decltype( a / b )
   {
      return a / b;
+6 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ namespace TNL {

template< typename T1,
          typename T2 >
__cuda_callable__
bool StaticComparisonEQ( const T1& a, const T2& b )
{
   TNL_ASSERT_EQ( a.getSize(), b.getSize(), "Sizes of expressions to be compared do not fit." );
@@ -29,6 +30,7 @@ bool StaticComparisonEQ( const T1& a, const T2& b )

template< typename T1,
          typename T2 >
__cuda_callable__
bool StaticComparisonNE( const T1& a, const T2& b )
{
   return ! StaticComparisonEQ( a, b );
@@ -36,6 +38,7 @@ bool StaticComparisonNE( const T1& a, const T2& b )

template< typename T1,
          typename T2 >
__cuda_callable__
bool StaticComparisonGT( const T1& a, const T2& b )
{
   TNL_ASSERT_EQ( a.getSize(), b.getSize(), "Sizes of expressions to be compared do not fit." );
@@ -47,6 +50,7 @@ bool StaticComparisonGT( const T1& a, const T2& b )

template< typename T1,
          typename T2 >
__cuda_callable__
bool StaticComparisonLE( const T1& a, const T2& b )
{
   return ! StaticComparisonGT( a, b );
@@ -54,6 +58,7 @@ bool StaticComparisonLE( const T1& a, const T2& b )

template< typename T1,
          typename T2 >
__cuda_callable__
bool StaticComparisonLT( const T1& a, const T2& b )
{
   TNL_ASSERT_EQ( a.getSize(), b.getSize(), "Sizes of expressions to be compared do not fit." );
@@ -65,6 +70,7 @@ bool StaticComparisonLT( const T1& a, const T2& b )

template< typename T1,
          typename T2 >
__cuda_callable__
bool StaticComparisonGE( const T1& a, const T2& b )
{
   return ! StaticComparisonLT( a, b );
+8 −1
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ class StaticVector : public StaticArray< Size, Real >
   template< typename T1,
             typename T2,
             template< typename, typename > class Operation >
   __cuda_callable__
   StaticVector( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& op );

   /**
@@ -290,6 +291,7 @@ class StaticVector< 1, Real > : public StaticArray< 1, Real >
   template< typename T1,
             typename T2,
             template< typename, typename > class Operation >
   __cuda_callable__
   StaticVector( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& op );

   bool setup( const Config::ParameterContainer& parameters,
@@ -426,6 +428,7 @@ class StaticVector< 2, Real > : public StaticArray< 2, Real >
   template< typename T1,
             typename T2,
             template< typename, typename > class Operation >
   __cuda_callable__
   StaticVector( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& op );

   bool setup( const Config::ParameterContainer& parameters,
@@ -563,9 +566,9 @@ class StaticVector< 3, Real > : public StaticArray< 3, Real >
   template< typename T1,
             typename T2,
             template< typename, typename > class Operation >
   __cuda_callable__
   StaticVector( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& op );


   bool setup( const Config::ParameterContainer& parameters,
               const String& prefix = "" );

@@ -680,6 +683,7 @@ namespace Containers {
template< int Size, typename Real1, typename Real2 >
struct StaticScalarProductGetter
{
   __cuda_callable__
   static auto compute( const Real1* u, const Real2* v ) -> decltype( u[ 0 ] * v[ 0 ] )
   {
      return u[ 0 ] * v[ 0 ] + StaticScalarProductGetter< Size - 1, Real1, Real2 >::compute( &u[ 1 ], &v[ 1 ] );
@@ -689,6 +693,7 @@ struct StaticScalarProductGetter
template< typename Real1, typename Real2 >
struct StaticScalarProductGetter< 1, Real1, Real2 >
{
   __cuda_callable__
   static auto compute( const Real1* u, const Real2* v ) -> decltype( u[ 0 ] * v[ 0 ] )
   {
      return u[ 0 ] * v[ 0 ];
@@ -696,6 +701,7 @@ struct StaticScalarProductGetter< 1, Real1, Real2 >
};

template< int Size, typename Real1, typename Real2 >
__cuda_callable__
auto ScalarProduct( const StaticVector< Size, Real1 >& u,
                    const StaticVector< Size, Real2 >& v ) -> decltype( u[ 0 ] * v[ 0 ] )
{
@@ -703,6 +709,7 @@ auto ScalarProduct( const StaticVector< Size, Real1 >& u,
}

template< int Size, typename Real1, typename Real2 >
__cuda_callable__
auto operator,( const StaticVector< Size, Real1 >& u,
                    const StaticVector< Size, Real2 >& v ) -> decltype( u[ 0 ] * v[ 0 ] )
{
+1 −0
Original line number Diff line number Diff line
@@ -55,6 +55,7 @@ template< typename Real >
   template< typename T1,
             typename T2,
             template< typename, typename > class Operation >
__cuda_callable__
StaticVector< 1, Real >::StaticVector( const Expressions::BinaryExpressionTemplate< T1, T2, Operation >& op )
{
   Algorithms::VectorAssignment< StaticVector< 1, Real >, Expressions::BinaryExpressionTemplate< T1, T2, Operation > >::assign( *this, op );
Loading