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

Added method print to Segments for better use with output streams.

parent d5984f14
No related branches found
No related tags found
1 merge request!105TO/matrices-adaptive-csr
Showing
with 106 additions and 12 deletions
...@@ -35,7 +35,7 @@ void SegmentsExample() ...@@ -35,7 +35,7 @@ void SegmentsExample()
* Print the data managed by the segments. * Print the data managed by the segments.
*/ */
auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl;
} }
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
......
...@@ -34,7 +34,7 @@ void SegmentsExample() ...@@ -34,7 +34,7 @@ void SegmentsExample()
* Print the data managed by the segments. * Print the data managed by the segments.
*/ */
auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl;
} }
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
......
...@@ -33,7 +33,7 @@ void SegmentsExample() ...@@ -33,7 +33,7 @@ void SegmentsExample()
* Print the data managed by the segments. * Print the data managed by the segments.
*/ */
auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl;
} }
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
......
...@@ -36,7 +36,7 @@ void SegmentsExample() ...@@ -36,7 +36,7 @@ void SegmentsExample()
* Print the data managed by the segments. * Print the data managed by the segments.
*/ */
auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl;
} }
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
......
...@@ -36,7 +36,7 @@ void SegmentsExample() ...@@ -36,7 +36,7 @@ void SegmentsExample()
* Print the data managed by the segments. * Print the data managed by the segments.
*/ */
auto fetch = [=] __cuda_callable__ ( IndexType globalIdx ) -> double { return data_view[ globalIdx ]; }; auto fetch = [=] __cuda_callable__ ( IndexType globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl;
/*** /***
* Compute sums of elements in particular segments. * Compute sums of elements in particular segments.
......
...@@ -34,7 +34,7 @@ void SegmentsExample() ...@@ -34,7 +34,7 @@ void SegmentsExample()
std::cout << "Data setup with no check ... " << std::endl; std::cout << "Data setup with no check ... " << std::endl;
std::cout << "Array: " << data << std::endl; std::cout << "Array: " << data << std::endl;
auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout ) << std::endl; std::cout << segments.print( fetch ) << std::endl;
/*** /***
* Insert data into particular segments. * Insert data into particular segments.
...@@ -50,7 +50,7 @@ void SegmentsExample() ...@@ -50,7 +50,7 @@ void SegmentsExample()
*/ */
std::cout << "Data setup with check for padding elements..." << std::endl; std::cout << "Data setup with check for padding elements..." << std::endl;
std::cout << "Array: " << data << std::endl; std::cout << "Array: " << data << std::endl;
printSegments( segments, fetch, std::cout ) << std::endl; std::cout << segments.print( fetch ) << std::endl;
} }
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
......
...@@ -39,7 +39,7 @@ void SegmentsExample() ...@@ -39,7 +39,7 @@ void SegmentsExample()
* Print the data managed by the segments. * Print the data managed by the segments.
*/ */
auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl;
} }
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
......
...@@ -33,7 +33,7 @@ void SegmentsExample() ...@@ -33,7 +33,7 @@ void SegmentsExample()
*/ */
std::cout << "Values of elements after intial setup: " << std::endl; std::cout << "Values of elements after intial setup: " << std::endl;
auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch );
/*** /***
* Divide elements in each segment by a sum of all elements in the segment * Divide elements in each segment by a sum of all elements in the segment
...@@ -55,7 +55,7 @@ void SegmentsExample() ...@@ -55,7 +55,7 @@ void SegmentsExample()
* Print the data managed by the segments. * Print the data managed by the segments.
*/ */
std::cout << "Value of elements after dividing by sum in each segment:" << std::endl; std::cout << "Value of elements after dividing by sum in each segment:" << std::endl;
printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl;
} }
int main( int argc, char* argv[] ) int main( int argc, char* argv[] )
......
...@@ -36,7 +36,7 @@ void SegmentsExample() ...@@ -36,7 +36,7 @@ void SegmentsExample()
*/ */
std::cout << "Values of elements after intial setup: " << std::endl; std::cout << "Values of elements after intial setup: " << std::endl;
auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl;
/*** /***
* Compute sums of elements in each segment. * Compute sums of elements in each segment.
......
...@@ -32,7 +32,7 @@ void SegmentsExample() ...@@ -32,7 +32,7 @@ void SegmentsExample()
*/ */
auto data_view = data.getView(); auto data_view = data.getView();
auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; }; auto fetch = [=] __cuda_callable__ ( int globalIdx ) -> double { return data_view[ globalIdx ]; };
printSegments( segments, fetch, std::cout ); std::cout << segments.print( fetch ) << std::endl;
std::cout << std::endl; std::cout << std::endl;
} }
......
...@@ -135,6 +135,9 @@ class BiEllpack ...@@ -135,6 +135,9 @@ class BiEllpack
void load(File &file); void load(File &file);
template< typename Fetch >
SegmentsPrinter< BiEllpack, Fetch > print( Fetch&& fetch ) const;
void printStructure(std::ostream &str) const; void printStructure(std::ostream &str) const;
// TODO: nvcc needs this public because of lambda function used inside // TODO: nvcc needs this public because of lambda function used inside
......
...@@ -581,6 +581,19 @@ load( File& file ) ...@@ -581,6 +581,19 @@ load( File& file )
>> this->groupPointers; >> this->groupPointers;
} }
template< typename Device,
typename Index,
typename IndexAllocator,
ElementsOrganization Organization,
int WarpSize >
template< typename Fetch >
auto
BiEllpack< Device, Index, IndexAllocator, Organization, WarpSize >::
print( Fetch&& fetch ) const -> SegmentsPrinter< BiEllpack, Fetch >
{
return SegmentsPrinter< BiEllpack, Fetch >( *this, fetch );
}
template< typename Device, template< typename Device,
typename Index, typename Index,
typename IndexAllocator, typename IndexAllocator,
......
...@@ -138,6 +138,9 @@ class BiEllpackView ...@@ -138,6 +138,9 @@ class BiEllpackView
void load( File& file ); void load( File& file );
template< typename Fetch >
SegmentsPrinter< BiEllpackView, Fetch > print( Fetch&& fetch ) const;
void printStructure( std::ostream& str ) const; void printStructure( std::ostream& str ) const;
protected: protected:
......
...@@ -477,6 +477,18 @@ save( File& file ) const ...@@ -477,6 +477,18 @@ save( File& file ) const
<< this->groupPointers; << this->groupPointers;
} }
template< typename Device,
typename Index,
ElementsOrganization Organization,
int WarpSize >
template< typename Fetch >
auto
BiEllpackView< Device, Index, Organization, WarpSize >::
print( Fetch&& fetch ) const -> SegmentsPrinter< BiEllpackView, Fetch >
{
return SegmentsPrinter< BiEllpackView, Fetch >( *this, fetch );
}
template< typename Device, template< typename Device,
typename Index, typename Index,
ElementsOrganization Organization, ElementsOrganization Organization,
......
...@@ -486,6 +486,27 @@ class CSR ...@@ -486,6 +486,27 @@ class CSR
*/ */
void load( File& file ); void load( File& file );
/**
* \brief Return simple proxy object for insertion to output stream.
*
* The proxy object serves for wrapping segments with lambda function mediating access to data managed by the segments.
*
* \tparam Fetch is type of lambda function for data access.
* \param fetch is an instance of lambda function for data access. It is supposed to be defined as
*
* ```
* auto fetch = [=] __cuda_callable__ ( IndexType globalIdx ) -> ValueType { return data_view[ globalIdx ]; };
* ```
* \return Proxy object for insertion to output stream.
*
* \par Example
* \include Algorithms/Segments/SegmentsPrintingExample-2.cpp
* \par Output
* \include SegmentsPrintingExample-2.out
*/
template< typename Fetch >
SegmentsPrinter< CSR, Fetch > print( Fetch&& fetch ) const;
protected: protected:
OffsetsContainer offsets; OffsetsContainer offsets;
......
...@@ -368,6 +368,18 @@ load( File& file ) ...@@ -368,6 +368,18 @@ load( File& file )
this->kernel.init( this->offsets ); this->kernel.init( this->offsets );
} }
template< typename Device,
typename Index,
typename Kernel,
typename IndexAllocator >
template< typename Fetch >
auto
CSR< Device, Index, Kernel, IndexAllocator >::
print( Fetch&& fetch ) const -> SegmentsPrinter< CSR, Fetch >
{
return SegmentsPrinter< CSR, Fetch >( *this, fetch );
}
} // namespace Segments } // namespace Segments
} // namespace Algorithms } // namespace Algorithms
} // namespace TNL } // namespace TNL
...@@ -139,6 +139,9 @@ class CSRView ...@@ -139,6 +139,9 @@ class CSRView
void load( File& file ); void load( File& file );
template< typename Fetch >
SegmentsPrinter< CSRView, Fetch > print( Fetch&& fetch ) const;
protected: protected:
OffsetsView offsets; OffsetsView offsets;
......
...@@ -318,6 +318,18 @@ load( File& file ) ...@@ -318,6 +318,18 @@ load( File& file )
this->kernel.init( this->offsets ); this->kernel.init( this->offsets );
} }
template< typename Device,
typename Index,
typename Kernel >
template< typename Fetch >
auto
CSRView< Device, Index, Kernel >::
print( Fetch&& fetch ) const -> SegmentsPrinter< CSRView, Fetch >
{
return SegmentsPrinter< CSRView, Fetch >( *this, fetch );
}
} // namespace Segments } // namespace Segments
} // namespace Containers } // namespace Containers
} // namespace TNL } // namespace TNL
...@@ -131,6 +131,9 @@ class ChunkedEllpack ...@@ -131,6 +131,9 @@ class ChunkedEllpack
void load( File& file ); void load( File& file );
template< typename Fetch >
SegmentsPrinter< ChunkedEllpack, Fetch > print( Fetch&& fetch ) const;
void printStructure( std::ostream& str ); // TODO const; void printStructure( std::ostream& str ); // TODO const;
protected: protected:
......
...@@ -534,6 +534,18 @@ load( File& file ) ...@@ -534,6 +534,18 @@ load( File& file )
file.load( &this->numberOfSlices ); file.load( &this->numberOfSlices );
} }
template< typename Device,
typename Index,
typename IndexAllocator,
ElementsOrganization Organization >
template< typename Fetch >
auto
ChunkedEllpack< Device, Index, IndexAllocator, Organization >::
print( Fetch&& fetch ) const -> SegmentsPrinter< ChunkedEllpack, Fetch >
{
return SegmentsPrinter< ChunkedEllpack, Fetch >( *this, fetch );
}
template< typename Device, template< typename Device,
typename Index, typename Index,
typename IndexAllocator, typename IndexAllocator,
......
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