Template Numerical Library version\ main:4e6e2c1
Loading...
Searching...
No Matches
TNL::Algorithms::Segments::AdaptiveCSRView< Device, Index > Class Template Reference

AdaptiveCSRView is provides a non-owning encapsulation of meta-data stored in the AdaptiveCSR segments. More...

#include <TNL/Algorithms/Segments/AdaptiveCSRView.h>

Inheritance diagram for TNL::Algorithms::Segments::AdaptiveCSRView< Device, Index >:
[legend]
Collaboration diagram for TNL::Algorithms::Segments::AdaptiveCSRView< Device, Index >:
[legend]

Public Types

using BlocksArray = Containers::StaticArray< detail::CSRAdaptiveKernelParameters<>::MaxValueSizeLog, BlocksType >
 Type for arrays of descriptor blocks of AdaptiveCSR.
using BlocksType = TNL::Containers::Vector< detail::CSRAdaptiveKernelBlockDescriptor< IndexType >, Device, IndexType >
 Type for descriptor blocks of AdaptiveCSR.
using BlocksView = typename BlocksType::ViewType
 View for the descriptor blocks of AdaptiveCSR.
using BlocksViewArray = Containers::StaticArray< detail::CSRAdaptiveKernelParameters<>::MaxValueSizeLog, BlocksView >
 Type for arrays of descriptor blocks view of AdaptiveCSR.
using ConstViewType = AdaptiveCSRView< Device, std::add_const_t< Index > >
 Type of constant segments view.
using OffsetsView = typename Base::OffsetsView
 View for the container holding CSR offsets.
template<typename Device_, typename Index_>
using ViewTemplate = AdaptiveCSRView< Device_, Index_ >
 Templated view type.
using ViewType = AdaptiveCSRView< Device, Index >
 Type of segments view.
Public Types inherited from TNL::Algorithms::Segments::CSRView< Device, Index >
using ConstViewType = CSRView< Device, std::add_const_t< Index > >
 Type of constant segments view.
template<typename Device_, typename Index_>
using ViewTemplate = CSRView< Device_, Index_ >
 Templated view type.
using ViewType = CSRView
 Type of segments view.
Public Types inherited from TNL::Algorithms::Segments::CSRBase< Device, Index >
using ConstOffsetsView = typename OffsetsView::ConstViewType
 The type for representing the constant vector view with segment offsets used in the CSR format.
using DeviceType = Device
 The device where the segments are operating.
using IndexType = std::remove_const_t< Index >
 The type used for indexing of segments elements.
using OffsetsView = Containers::VectorView< Index, DeviceType, IndexType >
 The type for representing the vector view with segment offsets used in the CSR format.
using SegmentViewType = SegmentView< IndexType, RowMajorOrder >
 Accessor type for one particular segment.

Public Member Functions

__cuda_callable__ AdaptiveCSRView ()=default
 Default constructor with no parameters to create empty segments view.
__cuda_callable__ AdaptiveCSRView (AdaptiveCSRView &&) noexcept
 Move constructor.
__cuda_callable__ AdaptiveCSRView (const AdaptiveCSRView &)
 Copy constructor.
__cuda_callable__ AdaptiveCSRView (const CSRView< Device, Index > &csrView, BlocksArray &blocks)
 Binds a new CSR view together with blocks of AdaptiveCSR.
__cuda_callable__ AdaptiveCSRView (const CSRView< Device, Index > &csrView, const BlocksViewArray &blocks)
 Binds a new CSR view together with blocks of AdaptiveCSR.
__cuda_callable__ void bind (AdaptiveCSRView view)
 Method for rebinding (reinitialization) to another view.
__cuda_callable__ void bind (OffsetsView offsets, BlocksArray &blocks)
 Method for rebinding (reinitialization) using another CSR offsets and AdaptiveCSR blocks.
__cuda_callable__ void bind (OffsetsView offsets, const BlocksViewArray &blocks)
 Method for rebinding (reinitialization) using another CSR offsets and AdaptiveCSR blocks.
__cuda_callable__ const BlocksViewArraygetBlocks () const
 Returns a view with blocks of AdaptiveCSR.
__cuda_callable__ ConstViewType getConstView () const
 Returns a constant view for this instance of segments which can by used for example in lambda functions running in GPU kernels.
__cuda_callable__ ViewType getView ()
 Returns a view for this instance of segments which can by used for example in lambda functions running in GPU kernels.
void load (File &file)
 Method for loading the segments from a file in a binary form.
AdaptiveCSRViewoperator= (const AdaptiveCSRView< Index, Device > &&kernelView)=delete
 Move-assignment operator.
AdaptiveCSRViewoperator= (const AdaptiveCSRView< Index, Device > &kernelView)=delete
 Copy-assignment operator.
void printBlocks (int idx=1, std::ostream &os=std::cout) const
 Print the blocks of AdaptiveCSR.
void save (File &file) const
 Method for saving the segments to a file in a binary form.
void setBlocks (BlocksType &blocks, int idx)
 Method for setting AdaptiveCSR blocks.
Public Member Functions inherited from TNL::Algorithms::Segments::CSRView< Device, Index >
__cuda_callable__ CSRView ()=default
 Default constructor with no parameters to create empty segments view.
__cuda_callable__ CSRView (const CSRView &)=default
 Copy constructor.
__cuda_callable__ CSRView (CSRView &&) noexcept=default
 Move constructor.
__cuda_callable__ CSRView (typename Base::OffsetsView offsets)
 Binds a new CSR view to an offsets vector.
__cuda_callable__ void bind (CSRView view)
 Method for rebinding (reinitialization) to another view.
__cuda_callable__ ConstViewType getConstView () const
 Returns a constant view for this instance of segments which can by used for example in lambda functions running in GPU kernels.
__cuda_callable__ ViewType getView ()
 Returns a view for this instance of segments which can by used for example in lambda functions running in GPU kernels.
void load (File &file)
 Method for loading the segments from a file in a binary form.
CSRViewoperator= (const CSRView &)=delete
 Copy-assignment operator.
CSRViewoperator= (CSRView &&)=delete
 Move-assignment operator.
void save (File &file) const
 Method for saving the segments to a file in a binary form.
Public Member Functions inherited from TNL::Algorithms::Segments::CSRBase< Device, Index >
__cuda_callable__ CSRBase ()=default
 Default constructor with no parameters to create empty segments view.
__cuda_callable__ CSRBase (const CSRBase &)=default
 Copy constructor.
__cuda_callable__ CSRBase (const OffsetsView &offsets)
 Binds a new CSR view to an offsets vector.
__cuda_callable__ CSRBase (CSRBase &&) noexcept=default
 Move constructor.
__cuda_callable__ CSRBase (OffsetsView &&offsets)
 Binds a new CSR view to an offsets vector.
template<typename Function>
void forAllElements (Function function) const
 Call TNL::Algorithms::Segments::CSR::forElements for all elements of the segments.
template<typename Condition, typename Function>
void forAllElementsIf (Condition condition, Function function) const
template<typename Function>
void forAllSegments (Function &&function) const
 Call TNL::Algorithms::Segments::CSR::forSegments for all segments.
template<typename Array, typename Function>
void forElements (const Array &segmentIndexes, Function function) const
template<typename Array, typename Function>
void forElements (const Array &segmentIndexes, Index begin, Index end, Function function) const
template<typename Function>
void forElements (IndexType begin, IndexType end, Function function) const
 Iterate over all elements of given segments in parallel and call given lambda function.
template<typename Condition, typename Function>
void forElementsIf (IndexType begin, IndexType end, Condition condition, Function function) const
template<typename Function>
void forSegments (IndexType begin, IndexType end, Function &&function) const
 Iterate over all segments in parallel and call given lambda function.
__cuda_callable__ IndexType getElementCount () const
 Returns the number of elements managed by all segments.
__cuda_callable__ IndexType getGlobalIndex (Index segmentIdx, Index localIdx) const
 Computes the global index of an element managed by the segments.
__cuda_callable__ OffsetsView getOffsets ()
 Returns a modifiable vector view with segment offsets used in the CSR format.
__cuda_callable__ ConstOffsetsView getOffsets () const
 Returns a constant vector view with segment offsets used in the CSR format.
__cuda_callable__ IndexType getSegmentCount () const
 Returns the number of segments.
__cuda_callable__ IndexType getSegmentsCount () const
 Returns the number of segments. Deprecated, use getSegmentCount().
__cuda_callable__ IndexType getSegmentSize (IndexType segmentIdx) const
 Returns the size of a particular segment denoted by segmentIdx.
__cuda_callable__ SegmentViewType getSegmentView (IndexType segmentIdx) const
 Returns a segment view (i.e., a segment accessor) for the specified segment index.
__cuda_callable__ IndexType getSize () const
 Returns the number of elements managed by all segments.
__cuda_callable__ IndexType getStorageSize () const
 Returns number of elements that needs to be allocated by a container connected to this segments.
CSRBaseoperator= (const CSRBase &)=delete
 Copy-assignment operator.
CSRBaseoperator= (CSRBase &&)=delete
 Move-assignment operator.
template<typename Function>
void sequentialForAllSegments (Function &&function) const
 Call TNL::Algorithms::Segments::CSR::sequentialForSegments for all segments.
template<typename Function>
void sequentialForSegments (IndexType begin, IndexType end, Function &&function) const
 Call TNL::Algorithms::Segments::CSR::forSegments sequentially for particular segments.

Static Public Member Functions

static std::string getSegmentsType ()
 Returns string with the segments type.
static std::string getSerializationType ()
 Returns string with the serialization type.
static int getSizeValueLog (const int &i)
static constexpr int MaxValueSizeLog ()
Static Public Member Functions inherited from TNL::Algorithms::Segments::CSRBase< Device, Index >
static constexpr ElementsOrganization getOrganization ()
 Returns the data layout for the CSR format (it is always row-major order).
static std::string getSegmentsType ()
 Returns string with the segments type.
static std::string getSerializationType ()
 Returns string with the serialization type.
static constexpr bool havePadding ()
 This function denotes that the CSR format does not use padding elements.

Protected Attributes

BlocksViewArray blocksArray
Protected Attributes inherited from TNL::Algorithms::Segments::CSRBase< Device, Index >
OffsetsView offsets
 Vector view with row offsets used in the CSR format.

Additional Inherited Members

Protected Member Functions inherited from TNL::Algorithms::Segments::CSRBase< Device, Index >
__cuda_callable__ void bind (OffsetsView offsets)
 Re-initializes the internal attributes of the base class.

Detailed Description

template<typename Device, typename Index>
class TNL::Algorithms::Segments::AdaptiveCSRView< Device, Index >

AdaptiveCSRView is provides a non-owning encapsulation of meta-data stored in the AdaptiveCSR segments.

See TNL::Algorithms::Segments::AdaptiveCSR for more details about AdaptiveCSR segments.

Template Parameters
Deviceis type of device where the segments will be operating.
Indexis type for indexing of the elements managed by the segments.

Member Typedef Documentation

◆ ViewTemplate

template<typename Device, typename Index>
template<typename Device_, typename Index_>
using TNL::Algorithms::Segments::AdaptiveCSRView< Device, Index >::ViewTemplate = AdaptiveCSRView< Device_, Index_ >

Templated view type.

Template Parameters
Device_is alternative device type for the view.
Index_is alternative index type for the view.

Member Function Documentation

◆ getSegmentsType()

template<typename Device, typename Index>
std::string TNL::Algorithms::Segments::AdaptiveCSRView< Device, Index >::getSegmentsType ( )
staticnodiscard

Returns string with the segments type.

Example
#include <iostream>
#include <functional>
#include <TNL/Algorithms/Segments/CSR.h>
#include <TNL/Algorithms/Segments/Ellpack.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Segments >
void
SegmentsExample()
{
/***
* Create segments and print the segments type.
*/
Segments segments;
std::cout << "The segments type is: " << segments.getSegmentsType() << '\n';
}
int
main( int argc, char* argv[] )
{
std::cout << "Example of CSR segments on host:\n";
SegmentsExample< TNL::Algorithms::Segments::CSR< TNL::Devices::Host, int > >();
std::cout << "Example of Ellpack segments on host:\n";
SegmentsExample< TNL::Algorithms::Segments::Ellpack< TNL::Devices::Host, int > >();
#ifdef __CUDACC__
std::cout << "Example of CSR segments on CUDA GPU:\n";
SegmentsExample< TNL::Algorithms::Segments::CSR< TNL::Devices::Cuda, int > >();
std::cout << "Example of Ellpack segments on CUDA GPU:\n";
SegmentsExample< TNL::Algorithms::Segments::Ellpack< TNL::Devices::Cuda, int > >();
#endif
return EXIT_SUCCESS;
}
Namespace for the segments data structures.
Definition _NamespaceDoxy.h:7
Output
Example of CSR segments on host:
The segments type is: CSR
Example of Ellpack segments on host:
The segments type is: Ellpack
Example of CSR segments on CUDA GPU:
The segments type is: CSR
Example of Ellpack segments on CUDA GPU:
The segments type is: Ellpack

◆ getSerializationType()

template<typename Device, typename Index>
std::string TNL::Algorithms::Segments::AdaptiveCSRView< Device, Index >::getSerializationType ( )
staticnodiscard

Returns string with the serialization type.

Example
#include <iostream>
#include <functional>
#include <TNL/Algorithms/Segments/CSR.h>
#include <TNL/Algorithms/Segments/Ellpack.h>
#include <TNL/Devices/Host.h>
#include <TNL/Devices/Cuda.h>
template< typename Segments >
void
SegmentsExample()
{
/***
* Create segments and print the serialization type.
*/
Segments segments;
std::cout << "The serialization type is: " << segments.getSerializationType() << '\n';
}
int
main( int argc, char* argv[] )
{
std::cout << "Example of CSR segments on host:\n";
SegmentsExample< TNL::Algorithms::Segments::CSR< TNL::Devices::Host, int > >();
std::cout << "Example of Ellpack segments on host:\n";
SegmentsExample< TNL::Algorithms::Segments::Ellpack< TNL::Devices::Host, int > >();
#ifdef __CUDACC__
std::cout << "Example of CSR segments on CUDA GPU:\n";
SegmentsExample< TNL::Algorithms::Segments::CSR< TNL::Devices::Cuda, int > >();
std::cout << "Example of Ellpack segments on CUDA GPU:\n";
SegmentsExample< TNL::Algorithms::Segments::Ellpack< TNL::Devices::Cuda, int > >();
#endif
return EXIT_SUCCESS;
}
Output
Example of CSR segments on host:
The serialization type is: CSR< int >
Example of Ellpack segments on host:
The serialization type is: Ellpack< int, RowMajorOrder, 32 >
Example of CSR segments on CUDA GPU:
The serialization type is: CSR< int >
Example of Ellpack segments on CUDA GPU:
The serialization type is: Ellpack< int, ColumnMajorOrder, 32 >

◆ load()

template<typename Device, typename Index>
void TNL::Algorithms::Segments::AdaptiveCSRView< Device, Index >::load ( File & file)

Method for loading the segments from a file in a binary form.

Parameters
fileis the source file.

◆ save()

template<typename Device, typename Index>
void TNL::Algorithms::Segments::AdaptiveCSRView< Device, Index >::save ( File & file) const

Method for saving the segments to a file in a binary form.

Parameters
fileis the target file.

The documentation for this class was generated from the following file: