Gromacs  2024.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Types | Public Member Functions
gmx::ArrayRefWithPadding< typename > Class Template Reference

#include <gromacs/math/include/gromacs/math/arrayrefwithpadding.h>

Description

template<typename>
class gmx::ArrayRefWithPadding< typename >

Interface to a C array of T (or part of a std container of T), that includes padding that is suitable for the kinds of SIMD operations GROMACS uses.

High level code e.g. in the force calculation routines need to hold a non-owning view of memory and be able to create ArrayRef objects that view padded or unpadded memory, suitable for the various component routines. This class implements that non-owning view, and the only available functionality refers to its size, and the methods to create such ArrayRef objects.

STL-like interface to a C array of T (or part of a std container of T).

Template Parameters
TValue type of elements.

This class provides an interface similar to std::vector<T, A>, with the following main differences:

This class is useful for writing wrappers that expose a view of the internal data stored as a single vector/array, which can be a whole or part of the underlying storage.

Methods in this class do not throw, except where indicated.

Note that due to a Doxygen limitation, the constructor that takes a C array whose size is known at compile time does not appear in the documentation.

To refer to const data of type T, ArrayRef<const T> is used. For both const and non-const std::vector and std::array an ArrayRef view can be created. Attempting to create a non-const ArrayRef of a const vector/array will result in a compiler error in the respective constructor.

For SIMD types there is template specialization available (e.g. ArrayRef<SimdReal>) in gromacs/simd/simd_memory.h which should have the same functionality as much as possible.

Todo:
This class is not complete. There are likely also methods missing (not required for current usage).

Public Types

using value_type = T
 Type of values stored in the reference.
 
using size_type = Index
 Type for representing size of the reference.
 
using const_pointer = const T *
 Const pointer to an element.
 
using const_iterator = const T *
 Const iterator type to an element.
 
using pointer = T *
 Pointer to an element.
 
using iterator = T *
 Iterator type to an element.
 

Public Member Functions

 ArrayRefWithPadding ()
 Constructs an empty reference.
 
 ArrayRefWithPadding (pointer begin, pointer end, pointer paddedEnd)
 Constructs a reference to a particular range. More...
 
 ArrayRefWithPadding (const ArrayRefWithPadding &o)
 Copy constructor.
 
 ArrayRefWithPadding (ArrayRefWithPadding &&o) noexcept
 Move constructor.
 
template<typename U , typename = std::enable_if_t<std::is_same<value_type, const typename std::remove_reference_t<U>::value_type>::value>>
 ArrayRefWithPadding (U &&o)
 Convenience overload constructor to make an ArrayRefWithPadding<const T> from a non-const one. More...
 
ArrayRefWithPaddingoperator= (ArrayRefWithPadding const &o)
 Copy assignment operator.
 
ArrayRefWithPaddingoperator= (ArrayRefWithPadding &&o) noexcept
 Move assignment operator.
 
size_type size () const
 Return the size of the view, i.e with the padding.
 
bool empty () const
 Whether the reference refers to no memory.
 
ArrayRef< T > unpaddedArrayRef ()
 Returns an ArrayRef of elements that does not include the padding region.
 
ArrayRef< const T > unpaddedConstArrayRef () const
 Returns an ArrayRef of const elements that does not include the padding region.
 
ArrayRef< T > paddedArrayRef ()
 Returns an ArrayRef of elements that does include the padding region.
 
ArrayRef< const T > paddedConstArrayRef () const
 Returns an ArrayRef of const elements that does include the padding region.
 
ArrayRefWithPadding< const T > constArrayRefWithPadding () const
 Returns an identical ArrayRefWithPadding that refers to const elements.
 
void swap (ArrayRefWithPadding< T > &other)
 Swaps referenced memory with the other object. More...
 

Constructor & Destructor Documentation

template<typename >
gmx::ArrayRefWithPadding< typename >::ArrayRefWithPadding ( pointer  begin,
pointer  end,
pointer  paddedEnd 
)
inline

Constructs a reference to a particular range.

Parameters
[in]beginPointer to the beginning of a range.
[in]endPointer to the end of a range without padding.
[in]paddedEndPointer to the end of a range including padding.

Passed pointers must remain valid for the lifetime of this object.

template<typename >
template<typename U , typename = std::enable_if_t<std::is_same<value_type, const typename std::remove_reference_t<U>::value_type>::value>>
gmx::ArrayRefWithPadding< typename >::ArrayRefWithPadding ( U &&  o)
inline

Convenience overload constructor to make an ArrayRefWithPadding<const T> from a non-const one.

Todo:
Use std::is_same_v when CUDA 11 is a requirement.

Member Function Documentation

template<typename >
void gmx::ArrayRefWithPadding< typename >::swap ( ArrayRefWithPadding< T > &  other)
inline

Swaps referenced memory with the other object.

The actual memory areas are not modified, only the references are swapped.


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