Template Numerical Library version\ main:bb09b17
Loading...
Searching...
No Matches
TNL::Containers::NDArrayView< Value, Device, Indexer > Class Template Reference

Simple data structure which provides a non-owning encapsulation of N-dimensional array data. More...

#include <TNL/Containers/NDArrayView.h>

Inheritance diagram for TNL::Containers::NDArrayView< Value, Device, Indexer >:
Collaboration diagram for TNL::Containers::NDArrayView< Value, Device, Indexer >:

Public Types

using ConstViewType = NDArrayView< std::add_const_t< ValueType >, DeviceType, IndexerType >
 Compatible constant NDArrayView type.
 
using DeviceType = Device
 Type of the device used for running operations on the array.
 
using IndexerType = Indexer
 Type of the N-dimensional indexer, NDArrayIndexer.
 
using IndexType = typename Indexer::IndexType
 Type of indices used for addressing the array elements.
 
using OverlapsType = typename Indexer::OverlapsType
 Sequence of integers representing the overlaps in each dimension of a distributed N-dimensional array.
 
using PermutationType = typename Indexer::PermutationType
 Permutation that is applied to indices when accessing the array elements.
 
using SizesHolderType = typename Indexer::SizesHolderType
 Type of the underlying object which represents the sizes of the N-dimensional array.
 
using StridesHolderType = typename Indexer::StridesHolderType
 Type of the base class which represents the strides of the N-dimensional array.
 
using ValueType = Value
 Type of the values stored in the array.
 
using ViewType = NDArrayView< ValueType, DeviceType, IndexerType >
 Compatible NDArrayView type.
 

Public Member Functions

__cuda_callable__ NDArrayView ()=default
 Constructs an array view with zero size.
 
__cuda_callable__ NDArrayView (const NDArrayView &)=default
 A shallow-copy copy-constructor.
 
__cuda_callable__ NDArrayView (NDArrayView &&) noexcept=default
 Move constructor for initialization from rvalues.
 
__cuda_callable__ NDArrayView (Value *data, IndexerType indexer)
 Constructs an array view initialized by a raw data pointer and an indexer.
 
__cuda_callable__ NDArrayView (Value *data, SizesHolderType sizes, StridesHolderType strides=StridesHolderType{}, OverlapsType overlaps=OverlapsType{})
 Constructs an array view initialized by a raw data pointer, sizes, strides and overlaps.
 
__cuda_callable__ void bind (NDArrayView view)
 Re-binds (re-initializes) the array view to a different view.
 
__cuda_callable__ void bind (Value *data)
 Re-binds (re-initializes) the array view to the given raw pointer and preserves the current indexer.
 
__cuda_callable__ void bind (Value *data, IndexerType indexer)
 Re-binds (re-initializes) the array view to the given raw pointer and changes the indexer.
 
template<typename Device2 = DeviceType, typename Func >
void forAll (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all elements of the array view.
 
template<typename Device2 = DeviceType, typename SkipBegins , typename SkipEnds , typename Func >
void forBoundary (const SkipBegins &skipBegins, const SkipEnds &skipEnds, Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all elements of the array view outside the N-dimensional interval [skipBegins, skipEnds).
 
template<typename Device2 = DeviceType, typename Func >
void forBoundary (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all boundary elements of the array view.
 
template<typename Device2 = DeviceType, typename Begins , typename Ends , typename Func >
void forInterior (const Begins &begins, const Ends &ends, Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all elements of the array view inside the N-dimensional interval [begins, ends).
 
template<typename Device2 = DeviceType, typename Func >
void forInterior (Func f, const typename Device2::LaunchConfiguration &launch_configuration=typename Device2::LaunchConfiguration{}) const
 Evaluates the function f in parallel for all internal elements of the array view.
 
__cuda_callable__ ConstViewType getConstView () const
 Returns a non-modifiable view of the array.
 
__cuda_callable__ ValueTypegetData ()
 Returns a raw pointer to the data.
 
__cuda_callable__ std::add_const_t< ValueType > * getData () const
 Returns a const-qualified raw pointer to the data.
 
__cuda_callable__ const IndexerTypegetIndexer () const
 Returns a const-qualified reference to the underlying indexer.
 
template<std::size_t... Dimensions, typename... IndexTypes>
__cuda_callable__ auto getSubarrayView (IndexTypes &&... indices)
 Returns a modifiable view of a subarray.
 
__cuda_callable__ ViewType getView ()
 Returns a modifiable view of the array.
 
TNL_NVCC_HD_WARNING_DISABLE __cuda_callable__ bool operator!= (const NDArrayView &other) const
 Compares the array view with another N-dimensional array view.
 
template<typename... IndexTypes>
__cuda_callable__ ValueTypeoperator() (IndexTypes &&... indices)
 Accesses an element of the array.
 
template<typename... IndexTypes>
__cuda_callable__ const ValueTypeoperator() (IndexTypes &&... indices) const
 Accesses an element of the array.
 
TNL_NVCC_HD_WARNING_DISABLE __cuda_callable__ NDArrayViewoperator= (const NDArrayView &other)
 Copy-assignment operator for deep-copying data from another array.
 
template<typename OtherView >
TNL_NVCC_HD_WARNING_DISABLE __cuda_callable__ NDArrayViewoperator= (const OtherView &other)
 Templated copy-assignment operator for deep-copying data from another array.
 
TNL_NVCC_HD_WARNING_DISABLE __cuda_callable__ bool operator== (const NDArrayView &other) const
 Compares the array view with another N-dimensional array view.
 
__cuda_callable__ ValueTypeoperator[] (IndexType &&index)
 Accesses an element in a one-dimensional array.
 
__cuda_callable__ const ValueTypeoperator[] (IndexType index) const
 Accesses an element in a one-dimensional array.
 
__cuda_callable__ void reset ()
 Resets the array view to the empty state.
 

Protected Attributes

Value * array = nullptr
 Pointer to the first element of the bound N-dimensional array.
 
IndexerType indexer
 Object which transforms the multi-dimensional indices to a one-dimensional index.
 

Detailed Description

template<typename Value, typename Device, typename Indexer>
class TNL::Containers::NDArrayView< Value, Device, Indexer >

Simple data structure which provides a non-owning encapsulation of N-dimensional array data.

Template Parameters
ValueType of the values stored in the array.
DeviceType of the device that will be used for running operations on the array.
Typeof the N-dimensional indexer, NDArrayIndexer.

Constructor & Destructor Documentation

◆ NDArrayView()

template<typename Value , typename Device , typename Indexer >
__cuda_callable__ TNL::Containers::NDArrayView< Value, Device, Indexer >::NDArrayView ( const NDArrayView< Value, Device, Indexer > & )
default

A shallow-copy copy-constructor.

This allows views to be passed-by-value into CUDA kernels and be captured-by-value in cuda_callable lambda functions.

Member Function Documentation

◆ forAll()

template<typename Value , typename Device , typename Indexer >
template<typename Device2 = DeviceType, typename Func >
void TNL::Containers::NDArrayView< Value, Device, Indexer >::forAll ( Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all elements of the array view.

The function f is called as f(indices...), where indices... are substituted by the actual indices of all array elements. For example, given a 3D array view a with int as IndexType, the function can be defined and used as follows:

auto setter = [&a] ( int i, int j, int k )
{
a( i, j, k ) = 1;
};
a.forAll( setter );

◆ forBoundary() [1/2]

template<typename Value , typename Device , typename Indexer >
template<typename Device2 = DeviceType, typename SkipBegins , typename SkipEnds , typename Func >
void TNL::Containers::NDArrayView< Value, Device, Indexer >::forBoundary ( const SkipBegins & skipBegins,
const SkipEnds & skipEnds,
Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all elements of the array view outside the N-dimensional interval [skipBegins, skipEnds).

The function f is called as f(indices...), where indices... are substituted by the actual indices of all array view elements.

◆ forBoundary() [2/2]

template<typename Value , typename Device , typename Indexer >
template<typename Device2 = DeviceType, typename Func >
void TNL::Containers::NDArrayView< Value, Device, Indexer >::forBoundary ( Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all boundary elements of the array view.

The function f is called as f(indices...), where indices... are substituted by the actual indices of all array view elements. For example, given a 3D array view a with int as IndexType, the function can be defined and used as follows:

auto setter = [&a] ( int i, int j, int k )
{
a( i, j, k ) = 1;
};
a.forBoundary( setter );

◆ forInterior() [1/2]

template<typename Value , typename Device , typename Indexer >
template<typename Device2 = DeviceType, typename Begins , typename Ends , typename Func >
void TNL::Containers::NDArrayView< Value, Device, Indexer >::forInterior ( const Begins & begins,
const Ends & ends,
Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all elements of the array view inside the N-dimensional interval [begins, ends).

The function f is called as f(indices...), where indices... are substituted by the actual indices of all array view elements.

◆ forInterior() [2/2]

template<typename Value , typename Device , typename Indexer >
template<typename Device2 = DeviceType, typename Func >
void TNL::Containers::NDArrayView< Value, Device, Indexer >::forInterior ( Func f,
const typename Device2::LaunchConfiguration & launch_configuration = typename Device2::LaunchConfiguration{} ) const
inline

Evaluates the function f in parallel for all internal elements of the array view.

The function f is called as f(indices...), where indices... are substituted by the actual indices of all array elements. For example, given a 3D array view a with int as IndexType, the function can be defined and used as follows:

auto setter = [&a] ( int i, int j, int k )
{
a( i, j, k ) = 1;
};
a.forInterior( setter );

◆ getSubarrayView()

template<typename Value , typename Device , typename Indexer >
template<std::size_t... Dimensions, typename... IndexTypes>
__cuda_callable__ auto TNL::Containers::NDArrayView< Value, Device, Indexer >::getSubarrayView ( IndexTypes &&... indices)
inlinenodiscard

Returns a modifiable view of a subarray.

Template Parameters
DimensionsSequence of integers representing the dimensions of the array which selects the subset of dimensions to appear in the subarray.
Parameters
indicesIndices of the origin of the subarray in the whole array. The number of indices supplied must be equal to N, i.e. getDimension().
Returns
NDArrayView instantiated for ValueType, DeviceType and an NDArrayIndexer matching the specified dimensions and subarray sizes.

◆ operator()() [1/2]

template<typename Value , typename Device , typename Indexer >
template<typename... IndexTypes>
__cuda_callable__ ValueType & TNL::Containers::NDArrayView< Value, Device, Indexer >::operator() ( IndexTypes &&... indices)
inlinenodiscard

Accesses an element of the array.

Parameters
indicesIndices of the element in the N-dimensional array. The number of indices supplied must be equal to N, i.e. getDimension().
Returns
Reference to the array element.

◆ operator()() [2/2]

template<typename Value , typename Device , typename Indexer >
template<typename... IndexTypes>
__cuda_callable__ const ValueType & TNL::Containers::NDArrayView< Value, Device, Indexer >::operator() ( IndexTypes &&... indices) const
inlinenodiscard

Accesses an element of the array.

Parameters
indicesIndices of the element in the N-dimensional array. The number of indices supplied must be equal to N, i.e. getDimension().
Returns
Constant reference to the array element.

◆ operator=()

template<typename Value , typename Device , typename Indexer >
TNL_NVCC_HD_WARNING_DISABLE __cuda_callable__ NDArrayView & TNL::Containers::NDArrayView< Value, Device, Indexer >::operator= ( const NDArrayView< Value, Device, Indexer > & other)
inline

Copy-assignment operator for deep-copying data from another array.

This is just like the operator on a regular array, but the sizes must match (i.e. copy-assignment cannot resize).

Note that there is no move-assignment operator, so expressions like a = b.getView() are resolved as copy-assignment.

◆ operator[]() [1/2]

template<typename Value , typename Device , typename Indexer >
__cuda_callable__ ValueType & TNL::Containers::NDArrayView< Value, Device, Indexer >::operator[] ( IndexType && index)
inlinenodiscard

Accesses an element in a one-dimensional array.

Warning
This function can be used only when the dimension of the array is equal to 1.
Parameters
indexIndex of the element in the one-dimensional array.
Returns
Reference to the array element.

◆ operator[]() [2/2]

template<typename Value , typename Device , typename Indexer >
__cuda_callable__ const ValueType & TNL::Containers::NDArrayView< Value, Device, Indexer >::operator[] ( IndexType index) const
inlinenodiscard

Accesses an element in a one-dimensional array.

Warning
This function can be used only when the dimension of the array is equal to 1.
Parameters
indexIndex of the element in the one-dimensional array.
Returns
Constant reference to the array element.

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