Template Numerical Library: TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation > Class Template Reference

Template Numerical Library version\ main:16b9213d5

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Protected Attributes | List of all members
TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation > Class Template Reference
N-dimensional arrays

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, Permutation >:
[legend]
Collaboration diagram for TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >:
[legend]

## Public Types
using | ConstStorageArrayViewType = ArrayView< std::add_const_t< ValueType >, DeviceType, IndexType >
| Constant view type of the underlying one-dimensional array storing the elements.
using | ConstViewType = NDArrayView< std::add_const_t< ValueType >, DeviceType, IndexerType, PermutationType >
| 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 = Permutation
| Permutation that determines the internal memory layout of the N-dimensional array.
using | SizesHolderType = typename Indexer::SizesHolderType
| Type of the underlying object which represents the sizes of the N-dimensional array.
using | StorageArrayViewType = ArrayView< ValueType, DeviceType, IndexType >
| View type of the underlying one-dimensional array storing the elements.
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, PermutationType >
| 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.
ConstStorageArrayViewType | getConstStorageArrayView () const
| Returns a non-modifiable view of the underlying storage array.
__cuda_callable__ ConstViewType | getConstView () const
| Returns a non-modifiable view of the array.
__cuda_callable__ ValueType * | getData ()
| 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.
template<typename... IndexTypes>
ValueType | getElement (IndexTypes &&... indices) const
| A "safe" accessor for array elements.
__cuda_callable__ const IndexerType & | getIndexer () const
| Returns a const-qualified reference to the underlying indexer.
StorageArrayViewType | getStorageArrayView ()
| Returns a modifiable view of the underlying storage array.
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__ ValueType & | operator() (IndexTypes &&... indices)
| Accesses an element of the array.
template<typename... IndexTypes>
__cuda_callable__ const ValueType & | operator() (IndexTypes &&... indices) const
| Accesses an element of the array.
TNL_NVCC_HD_WARNING_DISABLE __cuda_callable__ NDArrayView & | operator= (const NDArrayView &other)
| Copy-assignment operator for deep-copying data from another array.
template<typename OtherView>
TNL_NVCC_HD_WARNING_DISABLE __cuda_callable__ NDArrayView & | operator= (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__ ValueType & | operator[] (IndexType &&index)
| Accesses an element in a one-dimensional array.
__cuda_callable__ const ValueType & | operator[] (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, typename Permutation>
class TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >

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

Template Parameters

  Value | Type of the values stored in the array.
  Device | Type of the device that will be used for running operations on the array.
  Type | of the N-dimensional indexer, NDArrayIndexer.

## Constructor & Destructor Documentation

## ◆ NDArrayView()

template<typename Value, typename Device, typename Indexer, typename Permutation>

__cuda_callable__ TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::NDArrayView | ( | const NDArrayView< Value, Device, Indexer, Permutation > & |  | ) |
| 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, typename Permutation>
template<typename Device2 = DeviceType, typename Func>

void TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::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, typename Permutation>
template<typename Device2 = DeviceType, typename SkipBegins, typename SkipEnds, typename Func>

void TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::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, typename Permutation>
template<typename Device2 = DeviceType, typename Func>

void TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::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, typename Permutation>
template<typename Device2 = DeviceType, typename Begins, typename Ends, typename Func>

void TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::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, typename Permutation>
template<typename Device2 = DeviceType, typename Func>

void TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::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 );

## ◆ getElement()

template<typename Value, typename Device, typename Indexer, typename Permutation>
template<typename... IndexTypes>

ValueType TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::getElement | ( | IndexTypes &&... | indices | ) | const
| inlinenodiscard

A "safe" accessor for array elements.

It can be called only from the host code and it will do a slow copy from the device.

## ◆ getSubarrayView()

template<typename Value, typename Device, typename Indexer, typename Permutation>
template<std::size_t... Dimensions, typename... IndexTypes>

__cuda_callable__ auto TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::getSubarrayView | ( | IndexTypes &&... | indices | ) |
| inlinenodiscard

Returns a modifiable view of a subarray.

Template Parameters

  Dimensions | Sequence of integers representing the dimensions of the array which selects the subset of dimensions to appear in the subarray.

Parameters

  indices | Indices 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, typename Permutation>
template<typename... IndexTypes>

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

Accesses an element of the array.

Parameters

  indices | Indices 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, typename Permutation>
template<typename... IndexTypes>

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

Accesses an element of the array.

Parameters

  indices | Indices 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, typename Permutation>

TNL_NVCC_HD_WARNING_DISABLE __cuda_callable__ NDArrayView & TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::operator= | ( | const NDArrayView< Value, Device, Indexer, Permutation > & | 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, typename Permutation>

__cuda_callable__ ValueType & TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::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

  index | Index of the element in the one-dimensional array.

Returns
  Reference to the array element.

## ◆ operator[]() [2/2]

template<typename Value, typename Device, typename Indexer, typename Permutation>

__cuda_callable__ const ValueType & TNL::Containers::NDArrayView< Value, Device, Indexer, Permutation >::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

  index | Index 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:

- src/TNL/Containers/NDArrayView.h