Skip to content
Snippets Groups Projects
Commit 8bdceeae authored by Tomáš Oberhuber's avatar Tomáš Oberhuber
Browse files

Implementing unit tests for Segments.

parent 47d413b3
No related branches found
No related tags found
1 merge request!48Segments
...@@ -25,7 +25,7 @@ void test_SetSegmentsSizes_EqualSizes() ...@@ -25,7 +25,7 @@ void test_SetSegmentsSizes_EqualSizes()
const IndexType segmentsCount = 20; const IndexType segmentsCount = 20;
const IndexType segmentSize = 5; const IndexType segmentSize = 5;
TNL::Containers::Vector< IndexType, DeviceType, IndexType > segmentsSizes( segmentsCount ); TNL::Containers::Vector< IndexType, DeviceType, IndexType > segmentsSizes( segmentsCount );
segmentsSizes = 5;//segmentSize; segmentsSizes = segmentSize;
Segments segments( segmentsSizes ); Segments segments( segmentsSizes );
...@@ -92,4 +92,41 @@ void test_SetSegmentsSizes_EqualSizes_EllpackOnly() ...@@ -92,4 +92,41 @@ void test_SetSegmentsSizes_EqualSizes_EllpackOnly()
EXPECT_EQ( segments3.getSegmentSize( i ), segmentSize ); EXPECT_EQ( segments3.getSegmentSize( i ), segmentSize );
} }
template< typename Segments >
void test_GetMaxInSegments()
{
using DeviceType = typename Segments::DeviceType;
using IndexType = typename Segments::IndexType;
const IndexType segmentsCount = 20;
const IndexType segmentSize = 5;
const IndexType size = segmentsCount * segmentSize;
Segments segments( segmentsCount, segmentSize );
TNL::Containers::Vector< IndexType, DeviceType, IndexType > segmentsSizes( segmentsCount );
segmentsSizes = segmentSize;
Segments segments( segmentsSizes );
TNL::Containers::Vector< IndexType, DeviceType, IndexType > v( size );
for( IndexType i = 0; i < size; i++ )
v.setElement( i, i );
TNL::Containers::Vector< IndexType, DeviceType, IndexType >result( segmentsCount );
const auto v_view = v.getConstView();
auto result_view = result.getView();
auto fetch = [=] __cuda_callable__ ( IndexType i ) -> IndexType {
return v_view[ i ];
}
auto reduce = [] __cuda_callable__ ( IndexType& a, const IndexType b ) {
a = TNL::max( a, b );
}
auto keep = [=] __cuda_callable__ ( IndexType& i, const IndexType a ) mutable {
result_view[ i ] = a;
}
segments.allReduction( fetch, reduction, keep, std::numeric_limits< ResultType >::min() );
}
#endif #endif
...@@ -59,6 +59,12 @@ TYPED_TEST( EllpackSegmentsTest, setSegmentsSizes_EqualSizes_EllpackOnly ) ...@@ -59,6 +59,12 @@ TYPED_TEST( EllpackSegmentsTest, setSegmentsSizes_EqualSizes_EllpackOnly )
test_SetSegmentsSizes_EqualSizes_EllpackOnly< EllpackSegmentsType >(); test_SetSegmentsSizes_EqualSizes_EllpackOnly< EllpackSegmentsType >();
} }
TYPED_TEST( EllpackSegmentsTest, getMaxInSegments )
{
using EllpackSegmentsType = typename TestFixture::EllpackSegmentsType;
test_GetMaxInSegments< EllpackSegmentsType >();
}
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment