Commit f91cf587 authored by Jakub Klinkovský's avatar Jakub Klinkovský
Browse files

Fixed ArrayTest::forElements and VectorTest::reduceElements for CUDA

parent 1d0bcfa4
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -436,21 +436,23 @@ TYPED_TEST( ArrayTest, setElement )
   test_setElement< ArrayType >();
}

TYPED_TEST( ArrayTest, forElements )
// test must be in a plain function because nvcc sucks (extended lambdas are
// not allowed to be defined in protected class member functions)
template< typename ArrayType >
void testArrayForEachElement()
{
   using ArrayType = typename TestFixture::ArrayType;
   using IndexType = typename ArrayType::IndexType;
   using ValueType = typename ArrayType::ValueType;

#if not defined HAVE_CUDA
// nvcc does not accept the following code with
// error #3068-D: The enclosing parent function ("TestBody") for an extended __host__ __device__ lambda cannot have private or protected access within its class
   ArrayType a( 10 );
   a.forEachElement( [] __cuda_callable__ ( IndexType i, ValueType& v ) mutable { v = i; } );

   for( int i = 0; i < 10; i++ )
      EXPECT_EQ( a.getElement( i ), i );
#endif
}
TYPED_TEST( ArrayTest, forElements )
{
   testArrayForEachElement< typename TestFixture::ArrayType >();
}

TYPED_TEST( ArrayTest, containsValue )
+8 −6
Original line number Diff line number Diff line
@@ -80,15 +80,14 @@ TYPED_TEST( VectorTest, constructors )

}

TYPED_TEST( VectorTest, reduceElements )
// test must be in a plain function because nvcc sucks (extended lambdas are
// not allowed to be defined in protected class member functions)
template< typename VectorType >
void testVectorReduceElements()
{
   using VectorType = typename TestFixture::VectorType;
   using IndexType = typename VectorType::IndexType;
   using ValueType = typename VectorType::ValueType;

#if not defined HAVE_CUDA
// nvcc does not accept the following code with
// error #3068-D: The enclosing parent function ("TestBody") for an extended __host__ __device__ lambda cannot have private or protected access within its class
   VectorType a( 10 );
   a.forEachElement( [=] __cuda_callable__ ( IndexType i, ValueType& v ) mutable { v = 1; } );
   auto fetch = [] __cuda_callable__ ( IndexType i, ValueType& v ) -> ValueType { return v; };
@@ -100,7 +99,10 @@ TYPED_TEST( VectorTest, reduceElements )
   auto const_fetch = [] __cuda_callable__ ( IndexType i, const ValueType& v ) -> ValueType { return v; };
   EXPECT_EQ( b.reduceEachElement( const_fetch, reduce, ( ValueType ) 0.0 ),
              b.getSize() );
#endif
}
TYPED_TEST( VectorTest, reduceElements )
{
   testVectorReduceElements< typename TestFixture::VectorType >();
}

TEST( VectorSpecialCasesTest, defaultConstructors )