From 3688fbc0f64b1f8b6b9fce692b196e833f0ce1cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Klinkovsk=C3=BD?= <klinkjak@fjfi.cvut.cz> Date: Fri, 4 Aug 2017 09:10:14 +0200 Subject: [PATCH] Fixed StaticVector for MIC - The inherited operator= is weird, but this seems to work. - Use TNL::pow instead of std::pow etc. --- src/TNL/Containers/StaticVector.h | 79 +++++++----------------- src/TNL/Containers/StaticVector1D_impl.h | 25 +------- src/TNL/Containers/StaticVector2D_impl.h | 35 +++-------- src/TNL/Containers/StaticVector3D_impl.h | 39 ++++-------- src/TNL/Containers/StaticVector_impl.h | 31 +++------- 5 files changed, 53 insertions(+), 156 deletions(-) diff --git a/src/TNL/Containers/StaticVector.h b/src/TNL/Containers/StaticVector.h index 7aba1bbc29..095c9c1ffe 100644 --- a/src/TNL/Containers/StaticVector.h +++ b/src/TNL/Containers/StaticVector.h @@ -17,15 +17,15 @@ namespace TNL { namespace Containers { template< int Size, typename Real = double > -class StaticVector : public Containers::StaticArray< Size, Real > +class StaticVector : public StaticArray< Size, Real > { public: typedef Real RealType; typedef StaticVector< Size, Real > ThisType; enum { size = Size }; - using Containers::StaticArray< Size, Real >::operator=; - + using StaticArray< Size, Real >::operator=; + __cuda_callable__ StaticVector(); @@ -91,33 +91,24 @@ class StaticVector : public Containers::StaticArray< Size, Real > template< typename OtherReal > __cuda_callable__ operator StaticVector< Size, OtherReal >() const; - - + __cuda_callable__ ThisType abs() const; - -#ifdef HAVE_MIC - __cuda_callable__ - inline StaticVector< Size, Real >& operator = ( const StaticVector< Size, Real >& vct ); - - template< typename Vct > - __cuda_callable__ - inline StaticVector< Size, Real >& operator = ( const Vct& Real ); - -#endif __cuda_callable__ Real lpNorm( const Real& p ) const; }; template< typename Real > -class StaticVector< 1, Real > : public Containers::StaticArray< 1, Real > +class StaticVector< 1, Real > : public StaticArray< 1, Real > { public: typedef Real RealType; typedef StaticVector< 1, Real > ThisType; enum { size = 1 }; - + + using StaticArray< 1, Real >::operator=; + __cuda_callable__ StaticVector(); @@ -186,28 +177,21 @@ class StaticVector< 1, Real > : public Containers::StaticArray< 1, Real > __cuda_callable__ ThisType abs() const; - -#ifdef HAVE_MIC - __cuda_callable__ - inline StaticVector< 1, Real >& operator = ( const StaticVector< 1, Real >& vct ); - template< typename Vct > - __cuda_callable__ - inline StaticVector< 1, Real >& operator = ( const Vct& Real ); -#endif - __cuda_callable__ Real lpNorm( const Real& p ) const; }; template< typename Real > -class StaticVector< 2, Real > : public Containers::StaticArray< 2, Real > +class StaticVector< 2, Real > : public StaticArray< 2, Real > { public: typedef Real RealType; typedef StaticVector< 2, Real > ThisType; enum { size = 2 }; - + + using StaticArray< 2, Real >::operator=; + __cuda_callable__ StaticVector(); @@ -279,29 +263,21 @@ class StaticVector< 2, Real > : public Containers::StaticArray< 2, Real > __cuda_callable__ ThisType abs() const; - -#ifdef HAVE_MIC - __cuda_callable__ - inline StaticVector< 2, Real >& operator = ( const StaticVector< 2, Real >& vct ); - template< typename Vct > - __cuda_callable__ - inline StaticVector< 2, Real >& operator = ( const Vct& Real ); -#endif - - __cuda_callable__ Real lpNorm( const Real& p ) const; }; template< typename Real > -class StaticVector< 3, Real > : public Containers::StaticArray< 3, Real > +class StaticVector< 3, Real > : public StaticArray< 3, Real > { public: typedef Real RealType; typedef StaticVector< 3, Real > ThisType; enum { size = 3 }; - + + using StaticArray< 3, Real >::operator=; + __cuda_callable__ StaticVector(); @@ -373,16 +349,7 @@ class StaticVector< 3, Real > : public Containers::StaticArray< 3, Real > __cuda_callable__ ThisType abs() const; - - #ifdef HAVE_MIC - __cuda_callable__ - inline StaticVector< 3, Real >& operator = ( const StaticVector< 3, Real >& vct ); - template< typename Vct > - __cuda_callable__ - inline StaticVector< 3, Real >& operator = ( const Vct& Real ); -#endif - __cuda_callable__ Real lpNorm( const Real& p ) const; }; @@ -417,21 +384,21 @@ StaticVector< 3, Real > VectorProduct( const StaticVector< 3, Real >& u, p[ 1 ] = u[ 2 ] * v[ 0 ] - u[ 0 ] * v[ 2 ]; p[ 2 ] = u[ 0 ] * v[ 1 ] - u[ 1 ] * v[ 0 ]; return p; -}; +} template< typename Real > Real tnlScalarProduct( const StaticVector< 2, Real >& u, const StaticVector< 2, Real >& v ) { return u[ 0 ] * v[ 0 ] + u[ 1 ] * v[ 1 ]; -}; +} template< typename Real > Real tnlScalarProduct( const StaticVector< 3, Real >& u, const StaticVector< 3, Real >& v ) { return u[ 0 ] * v[ 0 ] + u[ 1 ] * v[ 1 ] + u[ 2 ] * v[ 2 ]; -}; +} template< typename Real > Real tnlTriangleArea( const StaticVector< 2, Real >& a, @@ -447,8 +414,8 @@ Real tnlTriangleArea( const StaticVector< 2, Real >& a, u2. z() = 0; const StaticVector< 3, Real > v = VectorProduct( u1, u2 ); - return 0.5 * ::sqrt( tnlScalarProduct( v, v ) ); -}; + return 0.5 * TNL::sqrt( tnlScalarProduct( v, v ) ); +} template< typename Real > Real tnlTriangleArea( const StaticVector< 3, Real >& a, @@ -464,8 +431,8 @@ Real tnlTriangleArea( const StaticVector< 3, Real >& a, u2. z() = c. z() - a. z(); const StaticVector< 3, Real > v = VectorProduct( u1, u2 ); - return 0.5 * ::sqrt( tnlScalarProduct( v, v ) ); -}; + return 0.5 * TNL::sqrt( tnlScalarProduct( v, v ) ); +} } // namespace Containers } // namespace TNL diff --git a/src/TNL/Containers/StaticVector1D_impl.h b/src/TNL/Containers/StaticVector1D_impl.h index 5bd9b05021..3127a62191 100644 --- a/src/TNL/Containers/StaticVector1D_impl.h +++ b/src/TNL/Containers/StaticVector1D_impl.h @@ -25,21 +25,21 @@ template< typename Real > template< typename _unused > __cuda_callable__ StaticVector< 1, Real >::StaticVector( const Real v[ 1 ] ) -: Containers::StaticArray< 1, Real >( v ) +: StaticArray< 1, Real >( v ) { } template< typename Real > __cuda_callable__ StaticVector< 1, Real >::StaticVector( const Real& v ) -: Containers::StaticArray< 1, Real >( v ) +: StaticArray< 1, Real >( v ) { } template< typename Real > __cuda_callable__ StaticVector< 1, Real >::StaticVector( const StaticVector< 1, Real >& v ) -: Containers::StaticArray< 1, Real >( v ) +: StaticArray< 1, Real >( v ) { } @@ -148,25 +148,6 @@ bool StaticVector< 1, Real >::operator >= ( const StaticVector& v ) const return ( this->data[ 0 ] >= v[ 0 ] ); } -#ifdef HAVE_MIC -template<typename Real > -__cuda_callable__ -inline StaticVector< 1, Real >& StaticVector< 1, Real >::operator = ( const StaticVector< 1, Real >& vct ) -{ - StaticArray<1,Real>::operator =(vct); - return *this; -} - -template<typename Real > -template< typename Vct > -__cuda_callable__ -inline StaticVector< 1, Real >& StaticVector< 1, Real >::operator = ( const Vct& vct ) -{ - StaticArray<1,Real>::operator =(vct); - return *this; -} -#endif - template< typename Real > template< typename OtherReal > __cuda_callable__ diff --git a/src/TNL/Containers/StaticVector2D_impl.h b/src/TNL/Containers/StaticVector2D_impl.h index fc8ba70f82..d66979bf7a 100644 --- a/src/TNL/Containers/StaticVector2D_impl.h +++ b/src/TNL/Containers/StaticVector2D_impl.h @@ -25,28 +25,28 @@ template< typename Real > template< typename _unused > __cuda_callable__ StaticVector< 2, Real >::StaticVector( const Real v[ 2 ] ) -: Containers::StaticArray< 2, Real >( v ) +: StaticArray< 2, Real >( v ) { } template< typename Real > __cuda_callable__ StaticVector< 2, Real >::StaticVector( const Real& v ) -: Containers::StaticArray< 2, Real >( v ) +: StaticArray< 2, Real >( v ) { } template< typename Real > __cuda_callable__ StaticVector< 2, Real >::StaticVector( const Real& v1, const Real& v2 ) -: Containers::StaticArray< 2, Real >( v1, v2 ) +: StaticArray< 2, Real >( v1, v2 ) { } template< typename Real > __cuda_callable__ StaticVector< 2, Real >::StaticVector( const StaticVector< 2, Real >& v ) -: Containers::StaticArray< 2, Real >( v ) +: StaticArray< 2, Real >( v ) { } @@ -167,23 +167,6 @@ bool StaticVector< 2, Real >::operator >= ( const StaticVector& v ) const this->data[ 1 ] >= v[ 1 ] ); } -#ifdef HAVE_MIC -template<typename Real > -__cuda_callable__ -inline StaticVector< 2, Real >& StaticVector< 2, Real >::operator = ( const StaticVector< 2, Real >& vct ) -{ - StaticArray<1,Real>::operator =(vct); -} - -template<typename Real > -template< typename Vct > -__cuda_callable__ -inline StaticVector< 2, Real >& StaticVector< 2, Real >::operator = ( const Vct& vct ) -{ - StaticArray<2,Real>::operator =(vct); -} -#endif - template< typename Real > template< typename OtherReal > __cuda_callable__ @@ -201,8 +184,8 @@ __cuda_callable__ StaticVector< 2, Real > StaticVector< 2, Real >::abs() const { - return StaticVector< 2, Real >( ::abs( this->data[ 0 ] ), - ::abs( this->data[ 1 ] ) ); + return StaticVector< 2, Real >( TNL::abs( this->data[ 0 ] ), + TNL::abs( this->data[ 1 ] ) ); } template< typename Real > @@ -213,10 +196,10 @@ StaticVector< 2, Real >::lpNorm( const Real& p ) const if( p == 1.0 ) return TNL::abs( this->data[ 0 ] ) + TNL::abs( this->data[ 1 ] ); if( p == 2.0 ) - return std::sqrt( this->data[ 0 ] * this->data[ 0 ] + + return TNL::sqrt( this->data[ 0 ] * this->data[ 0 ] + this->data[ 1 ] * this->data[ 1 ] ); - return std::pow( std::pow( TNL::abs( this->data[ 0 ] ), p ) + - std::pow( TNL::abs( this->data[ 1 ] ), p ), 1.0 / p ); + return TNL::pow( TNL::pow( TNL::abs( this->data[ 0 ] ), p ) + + TNL::pow( TNL::abs( this->data[ 1 ] ), p ), 1.0 / p ); } #ifdef UNDEF //TEMPLATE_EXPLICIT_INSTANTIATION diff --git a/src/TNL/Containers/StaticVector3D_impl.h b/src/TNL/Containers/StaticVector3D_impl.h index dded2d7121..d01e82077a 100644 --- a/src/TNL/Containers/StaticVector3D_impl.h +++ b/src/TNL/Containers/StaticVector3D_impl.h @@ -25,28 +25,28 @@ template< typename Real > template< typename _unused > __cuda_callable__ StaticVector< 3, Real >::StaticVector( const Real v[ 3 ] ) -: Containers::StaticArray< 3, Real >( v ) +: StaticArray< 3, Real >( v ) { } template< typename Real > __cuda_callable__ StaticVector< 3, Real >::StaticVector( const Real& v ) -: Containers::StaticArray< 3, Real >( v ) +: StaticArray< 3, Real >( v ) { } template< typename Real > __cuda_callable__ StaticVector< 3, Real >::StaticVector( const Real& v1, const Real& v2, const Real& v3 ) -: Containers::StaticArray< 3, Real >( v1, v2, v3 ) +: StaticArray< 3, Real >( v1, v2, v3 ) { } template< typename Real > __cuda_callable__ StaticVector< 3, Real >::StaticVector( const StaticVector< 3, Real >& v ) -: Containers::StaticArray< 3, Real >( v ) +: StaticArray< 3, Real >( v ) { } @@ -179,23 +179,6 @@ bool StaticVector< 3, Real >::operator >= ( const StaticVector& v ) const this->data[ 2 ] >= v[ 2 ] ); } -#ifdef HAVE_MIC -template<typename Real > -__cuda_callable__ -inline StaticVector< 3, Real >& StaticVector< 3, Real >::operator = ( const StaticVector< 3, Real >& vct ) -{ - StaticArray<1,Real>::operator =(vct); -} - -template<typename Real > -template< typename Vct > -__cuda_callable__ -inline StaticVector< 3, Real >& StaticVector< 3, Real >::operator = ( const Vct& vct ) -{ - StaticArray<3,Real>::operator =(vct); -} -#endif - template< typename Real > template< typename OtherReal > __cuda_callable__ @@ -214,9 +197,9 @@ __cuda_callable__ StaticVector< 3, Real > StaticVector< 3, Real >::abs() const { - return StaticVector< 3, Real >( ::abs( this->data[ 0 ] ), - ::abs( this->data[ 1 ] ), - ::abs( this->data[ 2 ] ) ); + return StaticVector< 3, Real >( TNL::abs( this->data[ 0 ] ), + TNL::abs( this->data[ 1 ] ), + TNL::abs( this->data[ 2 ] ) ); } template< typename Real > @@ -229,12 +212,12 @@ StaticVector< 3, Real >::lpNorm( const Real& p ) const TNL::abs( this->data[ 1 ] ) + TNL::abs( this->data[ 2 ] ); if( p == 2.0 ) - return std::sqrt( this->data[ 0 ] * this->data[ 0 ] + + return TNL::sqrt( this->data[ 0 ] * this->data[ 0 ] + this->data[ 1 ] * this->data[ 1 ] + this->data[ 2 ] * this->data[ 2 ] ); - return std::pow( std::pow( TNL::abs( this->data[ 0 ] ), p ) + - std::pow( TNL::abs( this->data[ 1 ] ), p ) + - std::pow( TNL::abs( this->data[ 2 ] ), p ), 1.0 / p ); + return TNL::pow( TNL::pow( TNL::abs( this->data[ 0 ] ), p ) + + TNL::pow( TNL::abs( this->data[ 1 ] ), p ) + + TNL::pow( TNL::abs( this->data[ 2 ] ), p ), 1.0 / p ); } diff --git a/src/TNL/Containers/StaticVector_impl.h b/src/TNL/Containers/StaticVector_impl.h index b0795ad58f..45e680a098 100644 --- a/src/TNL/Containers/StaticVector_impl.h +++ b/src/TNL/Containers/StaticVector_impl.h @@ -25,21 +25,21 @@ template< int Size, typename Real > template< typename _unused > __cuda_callable__ StaticVector< Size, Real >::StaticVector( const Real v[ Size ] ) -: Containers::StaticArray< Size, Real >( v ) +: StaticArray< Size, Real >( v ) { } template< int Size, typename Real > __cuda_callable__ StaticVector< Size, Real >::StaticVector( const Real& v ) -: Containers::StaticArray< Size, Real >( v ) +: StaticArray< Size, Real >( v ) { } template< int Size, typename Real > __cuda_callable__ StaticVector< Size, Real >::StaticVector( const StaticVector< Size, Real >& v ) -: Containers::StaticArray< Size, Real >( v ) +: StaticArray< Size, Real >( v ) { } @@ -211,12 +211,12 @@ StaticVector< Size, Real >::lpNorm( const Real& p ) const Real aux = this->data[ 0 ] * this->data[ 0 ]; for( int i = 1; i < Size; i++ ) aux += this->data[ i ] * this->data[ i ]; - return std::sqrt( aux ); + return TNL::sqrt( aux ); } - Real aux = std::pow( TNL::abs( this->data[ 0 ] ), p ); + Real aux = TNL::pow( TNL::abs( this->data[ 0 ] ), p ); for( int i = 1; i < Size; i++ ) - aux += std::pow( TNL::abs( this->data[ i ] ), p ); - return std::pow( aux, 1.0 / p ); + aux += TNL::pow( TNL::abs( this->data[ i ] ), p ); + return TNL::pow( aux, 1.0 / p ); } template< int Size, typename Real, typename Scalar > @@ -226,23 +226,6 @@ StaticVector< Size, Real > operator * ( const Scalar& c, const StaticVector< Siz return u * c; } -#ifdef HAVE_MIC -template< int Size, typename Real > -__cuda_callable__ -inline StaticVector< Size, Real >& StaticVector< Size, Real >::operator = ( const StaticVector< Size, Real >& vct ) -{ - StaticArray<Size,Real>::operator =(vct); -} - -template< int Size, typename Real > -template< typename Vct > -__cuda_callable__ -inline StaticVector< Size, Real >& StaticVector< Size, Real >::operator = ( const Vct& vct ) -{ - StaticArray<Size,Real>::operator =(vct); -} -#endif - #ifdef UNDEF //TEMPLATE_EXPLICIT_INSTANTIATION #ifndef HAVE_CUDA -- GitLab