Template Numerical Library version\ main:8b8c8226
|
Data structure for CSR segments format. More...
#include <TNL/Algorithms/Segments/CSR.h>
Public Types | |
using | ConstViewType = CSRView< Device, std::add_const_t< IndexType >, KernelType > |
Type of constant segments view. | |
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 | KernelType = Kernel |
Type of kernel used for reduction operations. | |
using | OffsetsContainer = Containers::Vector< Index, DeviceType, IndexType, IndexAllocator > |
Type of container storing offsets of particular rows. | |
using | SegmentViewType = SegmentView< IndexType, RowMajorOrder > |
Accessor type fro one particular segment. | |
template<typename Device_ , typename Index_ > | |
using | ViewTemplate = CSRView< Device_, Index_, KernelType > |
Templated view type. More... | |
using | ViewType = CSRView< Device, Index, KernelType > |
Type of segments view.1. | |
Public Member Functions | |
CSR ()=default | |
Construct with no parameters to create empty segments. | |
CSR (const CSR &segments)=default | |
Copy constructor. More... | |
template<typename SizesContainer > | |
CSR (const SizesContainer &segmentsSizes) | |
Construct with segments sizes. More... | |
template<typename ListIndex > | |
CSR (const std::initializer_list< ListIndex > &segmentsSizes) | |
Construct with segments sizes in initializer list.. More... | |
CSR (CSR &&segments) noexcept=default | |
Move constructor. More... | |
template<typename Function > | |
void | forAllElements (Function &&function) const |
Call TNL::Algorithms::Segments::CSR::forElements for all elements of the segments. More... | |
template<typename Function > | |
void | forAllSegments (Function &&function) const |
Call TNL::Algorithms::Segments::CSR::forSegments for all segments. More... | |
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. More... | |
template<typename Function > | |
void | forSegments (IndexType begin, IndexType end, Function &&function) const |
Iterate over all segments in parallel and call given lambda function. More... | |
ConstViewType | getConstView () const |
Getter of a view object for constants instances. More... | |
__cuda_callable__ IndexType | getGlobalIndex (Index segmentIdx, Index localIdx) const |
Computes the global index of an element managed by the segments. More... | |
KernelType & | getKernel () |
const KernelType & | getKernel () const |
OffsetsContainer & | getOffsets () |
Returns reference on vector with row offsets used in the CSR format. More... | |
const OffsetsContainer & | getOffsets () const |
Returns reference on constant vector with row offsets used in the CSR format. More... | |
__cuda_callable__ IndexType | getSegmentsCount () const |
Getter of number of segments. More... | |
__cuda_callable__ IndexType | getSegmentSize (IndexType segmentIdx) const |
Returns size of particular segment. More... | |
__cuda_callable__ SegmentViewType | getSegmentView (IndexType segmentIdx) const |
Returns segment view (i.e. segment accessor) of segment with given index. More... | |
__cuda_callable__ IndexType | getSize () const |
__cuda_callable__ IndexType | getStorageSize () const |
Returns number of elements that needs to be allocated by a container connected to this segments. More... | |
ViewType | getView () |
Getter of a view object. More... | |
void | load (File &file) |
Method for loading the segments from a file in a binary form. More... | |
CSR & | operator= (const CSR &source)=default |
Assignment operator. More... | |
template<typename Device_ , typename Index_ , typename Kernel_ , typename IndexAllocator_ > | |
CSR & | operator= (const CSR< Device_, Index_, Kernel_, IndexAllocator_ > &source) |
Assignment operator with CSR segments with different template parameters. More... | |
template<typename Device_ , typename Index_ , typename Kernel_ , typename IndexAllocator_ > | |
CSR< Device, Index, Kernel, IndexAllocator > & | operator= (const CSR< Device_, Index_, Kernel_, IndexAllocator_ > &source) |
template<typename Fetch > | |
SegmentsPrinter< CSR, Fetch > | print (Fetch &&fetch) const |
Return simple proxy object for insertion to output stream. More... | |
template<typename Fetch > | |
auto | print (Fetch &&fetch) const -> SegmentsPrinter< CSR, Fetch > |
template<typename Fetch , typename Reduce , typename Keep , typename Value > | |
void | reduceAllSegments (Fetch &fetch, const Reduce &reduce, Keep &keep, const Value &zero) const |
Call TNL::Algorithms::Segments::CSR::reduceSegments for all segments. More... | |
template<typename Fetch , typename Reduce , typename Keep , typename Value > | |
void | reduceSegments (IndexType begin, IndexType end, Fetch &fetch, const Reduce &reduce, Keep &keep, const Value &zero) const |
Compute reduction in each segment. More... | |
void | reset () |
Reset the segments to empty states. More... | |
void | save (File &file) const |
Method for saving the segments to a file in a binary form. More... | |
template<typename Function > | |
void | sequentialForAllSegments (Function &&f) const |
Call TNL::Algorithms::Segments::CSR::sequentialForSegments for all segments. More... | |
template<typename Function > | |
void | sequentialForSegments (IndexType begin, IndexType end, Function &&function) const |
Call TNL::Algorithms::Segments::CSR::forSegments sequentially for particular segments. More... | |
template<typename SizesContainer > | |
void | setSegmentsSizes (const SizesContainer &segmentsSizes) |
Set sizes of particular segments. More... | |
template<typename SizesHolder > | |
void | setSegmentsSizes (const SizesHolder &sizes) |
Static Public Member Functions | |
static constexpr ElementsOrganization | getOrganization () |
This functions says that CSR format is always organised in row-major order. | |
static String | getSegmentsType () |
Returns string with segments type. More... | |
static std::string | getSerializationType () |
Returns string with serialization type. More... | |
static constexpr bool | havePadding () |
This function says that CSR format does not use padding elements. | |
Protected Attributes | |
KernelType | kernel |
OffsetsContainer | offsets |
Data structure for CSR segments format.
See TNL::Algorithms::Segments for more details about segments.
Device | is type of device where the segments will be operating. |
Index | is type for indexing of the elements managed by the segments. |
Kernel | is type of kernel used for parallel operations with segments. It can be any of the following: CSRAdaptiveKernel, CSRHybridKernel, CSRScalarKernel, CSRVectorKernel. |
IndexAllocator | is allocator for supporting index containers. |
using TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::ViewTemplate = CSRView< Device_, Index_, KernelType > |
Templated view type.
Device_ | is alternative device type for the view. |
Index_ | is alternative index type for the view. |
TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::CSR | ( | const SizesContainer & | segmentsSizes | ) |
Construct with segments sizes.
The number of segments is given by the size of segmentsSizes. Particular elements of this container define sizes of particular segments.
SizesContainer | is a type of container for segments sizes. It can be TNL::Containers::Array or TNL::Containers::Vector for example. |
segmentsSizes | is an instance of the container with the segments sizes. |
See the following example:
The result looks as follows:
TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::CSR | ( | const std::initializer_list< ListIndex > & | segmentsSizes | ) |
Construct with segments sizes in initializer list..
The number of segments is given by the size of segmentsSizes. Particular elements of this initializer list define sizes of particular segments.
ListIndex | is a type of indexes of the initializer list. |
segmentsSizes | is an instance of the container with the segments sizes. |
See the following example:
The result looks as follows:
|
default |
Copy constructor.
segments | are the source segments. |
|
defaultnoexcept |
Move constructor.
segments | are the source segments. |
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::forAllElements | ( | Function && | function | ) | const |
Call TNL::Algorithms::Segments::CSR::forElements for all elements of the segments.
See TNL::Algorithms::Segments::CSR::forElements for more details.
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::forAllSegments | ( | Function && | function | ) | const |
Call TNL::Algorithms::Segments::CSR::forSegments for all segments.
See TNL::Algorithms::Segments::CSR::forSegments for more details.
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::forElements | ( | IndexType | begin, |
IndexType | end, | ||
Function && | function | ||
) | const |
Iterate over all elements of given segments in parallel and call given lambda function.
Function | is a type of the lambda function to be performed on each element. |
begin | defines begining of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
end | defines end of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
function | is the lambda function to be applied on the elements of the segments. |
Declaration of the lambda function function is supposed to be
where segmentIdx is index of segment where given element belong to, localIdx is rank of the element within the segment and globalIdx is index of the element within the related container.
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::forSegments | ( | IndexType | begin, |
IndexType | end, | ||
Function && | function | ||
) | const |
Iterate over all segments in parallel and call given lambda function.
Function | is a type of the lambda function to be performed on each segment. |
begin | defines begining of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
end | defines end of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
function | is the lambda function to be applied on the elements of the segments. |
Declaration of the lambda function function is supposed to be
where segment represents given segment (see TNL::Algorithms::Segments::SegmentView). Its type is given by SegmentViewType.
auto TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::getConstView |
Getter of a view object for constants instances.
__cuda_callable__ auto TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::getGlobalIndex | ( | Index | segmentIdx, |
Index | localIdx | ||
) | const |
Computes the global index of an element managed by the segments.
The global index serves as a refernce on the element in its container.
segmentIdx | is index of a segment with the element. |
localIdx | is tha local index of the element within the segment. |
auto TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::getOffsets |
Returns reference on vector with row offsets used in the CSR format.
auto TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::getOffsets |
Returns reference on constant vector with row offsets used in the CSR format.
__cuda_callable__ auto TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::getSegmentsCount |
Getter of number of segments.
__cuda_callable__ auto TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::getSegmentSize | ( | IndexType | segmentIdx | ) | const |
Returns size of particular segment.
|
static |
Returns string with segments type.
The string has a form CSR< KernelType >
.
__cuda_callable__ auto TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::getSegmentView | ( | IndexType | segmentIdx | ) | const |
Returns segment view (i.e. segment accessor) of segment with given index.
segmentIdx | is index of the request segment. |
|
static |
Returns string with serialization type.
The string has a form Algorithms::Segments::CSR< IndexType, [any_device], [any_kernel], [any_allocator] >
.
__cuda_callable__ auto TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::getStorageSize |
Returns number of elements that needs to be allocated by a container connected to this segments.
CSR< Device, Index, Kernel, IndexAllocator >::ViewType TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::getView |
Getter of a view object.
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::load | ( | File & | file | ) |
Method for loading the segments from a file in a binary form.
file | is the source file. |
|
default |
Assignment operator.
It makes a deep copy of the source segments.
source | are the CSR segments to be assigned. |
CSR & TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::operator= | ( | const CSR< Device_, Index_, Kernel_, IndexAllocator_ > & | source | ) |
Assignment operator with CSR segments with different template parameters.
It makes a deep copy of the source segments.
Device_ | is device type of the source segments. |
Index_ | is the index type of the source segments. |
Kernel_ | is the kernel type of the source segments. |
IndexAllocator_ | is the index allocator of the source segments. |
source | is the source segments object. |
SegmentsPrinter< CSR, Fetch > TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::print | ( | Fetch && | fetch | ) | const |
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.
Fetch | is type of lambda function for data access. |
fetch | is an instance of lambda function for data access. It is supposed to be defined as |
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::reduceAllSegments | ( | Fetch & | fetch, |
const Reduce & | reduce, | ||
Keep & | keep, | ||
const Value & | zero | ||
) | const |
Call TNL::Algorithms::Segments::CSR::reduceSegments for all segments.
See TNL::Algorithms::Segments::CSR::reduceSegments for more details.
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::reduceSegments | ( | IndexType | begin, |
IndexType | end, | ||
Fetch & | fetch, | ||
const Reduce & | reduce, | ||
Keep & | keep, | ||
const Value & | zero | ||
) | const |
Compute reduction in each segment.
Fetch | is type of lambda function for data fetching. |
Reduce | is a reduction operation. |
Keep | is lambda function for storing results from particular segments. |
begin | defines begining of an interval [ begin, end ) of segments in which we want to perform the reduction. |
end | defines and of an interval [ begin, end ) of segments in which we want to perform the reduction. |
fetch | is a lambda function for fetching of data. It is suppos have one of the following forms:
|
reduce | is a lambda function representing the reduction opeartion. It is supposed to be defined as: |
where a and b are values to be reduced and the lambda function returns result of the reduction.
keep | is a lambda function for saving results from particular segments. It is supposed to be defined as: |
where segmentIdx is an index of the segment and value is the result of the reduction in given segment to be stored.
zero | is the initial value for the reduction operation. |
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::reset |
Reset the segments to empty states.
It means that there is no segment in the CSR segments.
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::save | ( | File & | file | ) | const |
Method for saving the segments to a file in a binary form.
file | is the target file. |
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::sequentialForAllSegments | ( | Function && | f | ) | const |
Call TNL::Algorithms::Segments::CSR::sequentialForSegments for all segments.
See TNL::Algorithms::Segments::CSR::sequentialForSegments for more details.
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::sequentialForSegments | ( | IndexType | begin, |
IndexType | end, | ||
Function && | function | ||
) | const |
Call TNL::Algorithms::Segments::CSR::forSegments sequentially for particular segments.
With this method, the given segments are processed sequentially one-by-one. This is usefull for example for printing of segments based data structures or for debugging reasons.
begin | defines begining of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
end | defines end of an interval [ begin, end ) of segments on elements of which we want to apply the lambda function. |
function | is the lambda function to be applied on the elements of the segments. |
See TNL::Algorithms::Segments::CSR::forSegments for more details.
void TNL::Algorithms::Segments::CSR< Device, Index, Kernel, IndexAllocator >::setSegmentsSizes | ( | const SizesContainer & | segmentsSizes | ) |
Set sizes of particular segments.
SizesContainer | is a container with segments sizes. It can be TNL::Containers::Array or TNL::Containers::Vector for example. |
segmentsSizes | is an instance of the container with segments sizes. |