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

Renamed Array::checkValue to Array::containsValue.

Implemented Array:containsOnlyValue.
Restored implementation of ArrayOperations::memoryCompare on host.
parent 58c7cc30
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
INSTALL( FILES ${PROJECT_TOOLS_PATH}/share/cmake/CMakeFindTNL.cmake
         DESTINATION share/cmake/Modules )
 No newline at end of file
#INSTALL( FILES ${PROJECT_TOOLS_PATH}/share/cmake/CMakeFindTNL.cmake
#         DESTINATION share/cmake )
 No newline at end of file
+30 −9
Original line number Diff line number Diff line
@@ -69,9 +69,16 @@ class ArrayOperations< Devices::Host >

      template< typename Element,
                typename Index >
      static bool checkValue( const Element* data,
      static bool containsValue( const Element* data,
                                 const Index size,
                                 const Element& value );
      
      template< typename Element,
                typename Index >
      static bool containsOnlyValue( const Element* data,
                                     const Index size,
                                     const Element& value );
      
};

template<>
@@ -121,10 +128,17 @@ class ArrayOperations< Devices::Cuda >

      template< typename Element,
                typename Index >
      static bool checkValue( const Element* data,
      static bool containsValue( const Element* data,
                                 const Index size,
                                 const Element& value );
      
      template< typename Element,
                typename Index >
      static bool containsOnlyValue( const Element* data,
                                     const Index size,
                                     const Element& value );
      

};

template<>
@@ -214,10 +228,17 @@ class ArrayOperations< Devices::MIC >

      template< typename Element,
                typename Index >
      static bool checkValue( const Element* data,
      static bool containsValue( const Element* data,
                                 const Index size,
                                 const Element& value );
      
      template< typename Element,
                typename Index >
      static bool containsOnlyValue( const Element* data,
                                     const Index size,
                                     const Element& value );
      
      
};

template<>
+29 −7
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ template< typename Element,
          typename Index >
bool
ArrayOperations< Devices::Cuda >::
checkValue( const Element* data,
containsValue( const Element* data,
               const Index size,
               const Element& value )
{
@@ -224,9 +224,31 @@ checkValue( const Element* data,
#ifdef HAVE_CUDA
   if( size == 0 ) return false;
   bool result = false;
   Algorithms::ParallelReductionCheckPresence< Element > reductionCheckPresence;
   reductionCheckPresence.setValue( value );
   Reduction< Devices::Cuda >::reduce( reductionCheckPresence, size, data, 0, result );
   Algorithms::ParallelReductionContainsValue< Element > reductionContainsValue;
   reductionContainsValue.setValue( value );
   Reduction< Devices::Cuda >::reduce( reductionContainsValue, size, data, 0, result );
   return result;   
#else
   throw Exceptions::CudaSupportMissing();
#endif
}

template< typename Element,
          typename Index >
bool
ArrayOperations< Devices::Cuda >::
containsOnlyValue( const Element* data,
                   const Index size,
                   const Element& value )
{
   TNL_ASSERT_TRUE( data, "Attempted to check data through a nullptr." );
   TNL_ASSERT_GE( size, 0, "" );
#ifdef HAVE_CUDA
   if( size == 0 ) return false;
   bool result = false;
   Algorithms::ParallelReductionContainsOnlyValue< Element > reductionContainsOnlyValue;
   reductionContainsOnlyValue.setValue( value );
   Reduction< Devices::Cuda >::reduce( reductionContainsOnlyValue, size, data, 0, result );
   return result;   
#else
   throw Exceptions::CudaSupportMissing();
@@ -234,10 +256,10 @@ checkValue( const Element* data,
}



/****
 * Operations CUDA -> Host
 */

template< typename DestinationElement,
          typename SourceElement,
          typename Index >
+37 −13
Original line number Diff line number Diff line
@@ -132,19 +132,42 @@ compareMemory( const DestinationElement* destination,
{
   TNL_ASSERT_TRUE( destination, "Attempted to compare data through a nullptr." );
   TNL_ASSERT_TRUE( source, "Attempted to compare data through a nullptr." );
   if( std::is_same< DestinationElement, SourceElement >::value &&
       ( std::is_fundamental< DestinationElement >::value ||
         std::is_pointer< DestinationElement >::value ) )
   {
      if( memcmp( destination, source, size * sizeof( DestinationElement ) ) != 0 )
         return false;
   }
   else
      for( Index i = 0; i < size; i ++ )
         if( ! ( destination[ i ] == source[ i ] ) )
            return false;
   return true;
}

   //TODO: The parallel reduction on the CUDA device with different element types is needed.
   bool result = false;
   Algorithms::ParallelReductionEqualities< DestinationElement, SourceElement > reductionEqualities;
   Reduction< Devices::Host >::reduce( reductionEqualities, size, destination, source, result );
   return result;
template< typename Element,
          typename Index >
bool
ArrayOperations< Devices::Host >::
containsValue( const Element* data,
               const Index size,
               const Element& value )
{
   TNL_ASSERT_TRUE( data, "Attempted to check data through a nullptr." );
   TNL_ASSERT_GE( size, 0, "" );
   
   for( Index i = 0; i < size; i ++ )
      if( data[ i ] == value )
         return true;
   return false;
}

template< typename Element,
          typename Index >
bool
ArrayOperations< Devices::Host >::
checkValue( const Element* data,
containsOnlyValue( const Element* data,
                   const Index size,
                   const Element& value )
{
@@ -152,14 +175,15 @@ checkValue( const Element* data,
   TNL_ASSERT_GE( size, 0, "" );
   
   if( size == 0 ) return false;
   bool result = false;
   Algorithms::ParallelReductionCheckPresence< Element > reductionCheckPresence;
   reductionCheckPresence.setValue( value );
   Reduction< Devices::Host >::reduce( reductionCheckPresence, size, data, 0, result );
   return result;   
   
   for( Index i = 0; i < size; i ++ )
      if( ! ( data[ i ] == value ) )
         return false;
   return true;
}



#ifdef TEMPLATE_EXPLICIT_INSTANTIATION

extern template bool ArrayOperations< Devices::Host >::allocateMemory< char,        int >( char*& data, const int size );
+22 −3
Original line number Diff line number Diff line
@@ -219,7 +219,7 @@ template< typename Element,
          typename Index >
bool
ArrayOperations< Devices::MIC >::
checkValue( const Element* data,
containsValue( const Element* data,
               const Index size,
               const Element& value )
{
@@ -233,6 +233,25 @@ checkValue( const Element* data,
#endif
}

template< typename Element,
          typename Index >
bool
ArrayOperations< Devices::MIC >::
containsOnlyValue( const Element* data,
                   const Index size,
                   const Element& value )
{
   TNL_ASSERT_TRUE( data, "Attempted to check data through a nullptr." );
   TNL_ASSERT_GE( size, 0, "" );
#ifdef HAVE_MIC
   TNL_ASSERT( false, );
   return false;
#else
   throw Exceptions::MICSupportMissing();
#endif
}



/****
 * Operations MIC -> Host
Loading