Skip to content
Snippets Groups Projects
Commit afcbc391 authored by Tomáš Oberhuber's avatar Tomáš Oberhuber Committed by Jakub Klinkovský
Browse files

Trying to debug segments printing for GPUs.

parent 045485d4
No related branches found
No related tags found
1 merge request!105TO/matrices-adaptive-csr
......@@ -35,7 +35,9 @@ void SegmentsExample()
/***
* Print the data managed by the segments.
*/
std::cerr << data << std::endl;
auto fetch = [=] __cuda_callable__ ( IndexType globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout );
std::cout << segments.print( fetch ) << std::endl;
/***
......
......@@ -53,7 +53,7 @@ template< typename Segments,
typename Fetch >
struct SegmentsPrinter
{
SegmentsPrinter( const Segments& segments, Fetch& fetch )
SegmentsPrinter( const Segments& segments, Fetch&& fetch )
: segments( segments ), fetch( fetch ) {}
std::ostream& print( std::ostream& str ) const
......@@ -71,6 +71,8 @@ struct SegmentsPrinter
for( IndexType localIdx = 0; localIdx < segmentSize; localIdx++ )
{
aux.forAllElements( [=] __cuda_callable__ ( IndexType elementIdx, double& v ) mutable {
//printf( "####### localIdx = %d, globalIdx = %d \n", localIdx, view.getGlobalIndex( segmentIdx, localIdx ) );
//v = view.getGlobalIndex( segmentIdx, localIdx );
v = fetch( view.getGlobalIndex( segmentIdx, localIdx ) );
} );
auto value = aux.getElement( 0 );
......@@ -87,7 +89,7 @@ struct SegmentsPrinter
const Segments& segments;
Fetch& fetch;
Fetch fetch;
};
template< typename Segments,
......@@ -97,6 +99,38 @@ std::ostream& operator<<( std::ostream& str, const SegmentsPrinter< Segments, Fe
return printer.print( str );
}
template< typename Segments,
typename Fetch >
std::ostream& printSegments( const Segments& segments, Fetch&& fetch, std::ostream& str )
{
using IndexType = typename Segments::IndexType;
using DeviceType = typename Segments::DeviceType;
using ValueType = decltype( fetch( IndexType() ) );
TNL::Containers::Array< ValueType, DeviceType, IndexType > aux( 1 );
auto view = segments.getConstView();
for( IndexType segmentIdx = 0; segmentIdx < segments.getSegmentsCount(); segmentIdx++ )
{
str << "Seg. " << segmentIdx << ": [ ";
auto segmentSize = segments.getSegmentSize( segmentIdx );
//std::cerr << "Segment size = " << segmentSize << std::endl;
for( IndexType localIdx = 0; localIdx < segmentSize; localIdx++ )
{
aux.forAllElements( [=] __cuda_callable__ ( IndexType elementIdx, double& v ) mutable {
//printf( "####### localIdx = %d, globalIdx = %d \n", localIdx, view.getGlobalIndex( segmentIdx, localIdx ) );
v = fetch( view.getGlobalIndex( segmentIdx, localIdx ) );
//v = view.getGlobalIndex( segmentIdx, localIdx );
} );
auto value = aux.getElement( 0 );
str << value;
if( localIdx < segmentSize - 1 )
str << ", ";
}
str << " ] " << std::endl;
}
return str;
}
} // namespace Segments
} // namespace Algorithms
} // namespace TNL
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