DynamicView#

Header file: <Kokkos_DynamicView.hpp>

Description#

template<typename DataType, typename ...P>
class DynamicView : public Kokkos::ViewTraits<DataType, P...>#

A potentially reference-counted rank 1 array, without layout, that can be dynamically resized on the host.

Public Member Variables

static constexpr bool reference_type_is_lvalue_reference#

Whether the reference type is a C++ lvalue reference.

Public Nested Typedefs

typedef Kokkos::ViewTraits<DataType, P...> traits#

Kokkos::ViewTraits parent class type.

array_type#

DynamicView type templated on traits::data_type and traits::device_type.

const_type#

DynamicView type templated on traits::const_data_type and traits::device_type.

non_const_type#

DynamicView type templated on traits::non_const_data_type and traits::device_type.

HostMirror#

The compatible view type with the same DataType and LayoutType stored in host accessible memory space.

Public Data Handle Types

reference_type#

The return type of the view access operators.

pointer_type#

The pointer to scalar type.

Constructors

DynamicView()#

The default Constructor. No allocations are made, no reference counting happens. All extents are zero and its data pointer is NULL.

DynamicView(const DynamicView<RT, RP...> &rhs)#

The copy constructor from a compatible View. Follows View assignment rules.

DynamicView(DynamicView &&rhs)#

The move constructor.

DynamicView(const std::string &arg_label, const unsigned min_chunk_size, const unsigned max_extent)#

The standard allocating constructor.

Parameters:
  • arg_label – a user-provided label, which is used for profiling and debugging purposes. Names are not required to be unique.

  • min_chunk_size – a user-provided minimum chunk size needed for memory allocation, will be raised to nearest power-of-two for more efficient memory access operations.

  • max_extent – a user-provided maximum size, required to allocate a chunk-pointer array.

The resize_serial method must be called after construction to reserve the desired amount of memory, bound by max_extent.

Public Data Access Functions

KOKKOS_INLINE_FUNCTION reference_type operator()(const I0 &i0, const Args&... args) const#
Return:

A value of reference_type which may or not be referenceable itself. The number of index arguments must be 1 (for non-deprecated code).

Data Resizing, Dimensions, Strides

template<typename IntType>
inline void resize_serial(IntType const &n)#

Resizes the DynamicView with sufficient chunks of memory of chunk_size to store the requested number of elements n. This method can only be called outside of parallel regions. n is restricted to be smaller than the max_extent value passed to the DynamicView constructor. This method must be called after the construction of the DynamicView as the constructor sets the requested sizes for chunk_size and max_extent, but does not take input for the actual amount of memory to be used.

KOKKOS_INLINE_FUNCTION size_t allocation_extent() const noexcept;#
Return:

The total size of the product of the number of chunks multiplied by the chunk size. This may be larger than size as this includes the total size for the total number of complete chunks of memory.

KOKKOS_INLINE_FUNCTION size_t chunk_size() const noexcept;#
Return:

The number of entries a chunk of memory may store, always a power of two.

KOKKOS_INLINE_FUNCTION size_t size() const noexcept;#
Return:

The number of entries available in the allocation based on the number passed to resize_serial. This number is bound by allocation_extent.

template<typename iType>
KOKKOS_INLINE_FUNCTION size_t extent(const iType &dim) const;#
Return:

The extent of the specified dimension. iType must be an integral type, and dim must be smaller than rank. Returns 1 for rank > 1.

template<typename iType>
KOKKOS_INLINE_FUNCTION int extent_int(const iType &dim) const;#
Return:

The extent of the specified dimension as an int. iType must be an integral type, and dim must be smaller than rank. Compared to extent this function can be useful on architectures where int operations are more efficient than size_t. It also may eliminate the need for type casts in applications that otherwise perform all index operations with int. Returns 1 for rank > 1.

template<typename iType>
KOKKOS_INLINE_FUNCTION void stride(const iType &dim) const;#
Return:

The stride of the specified dimension, always returns 0 for DynamicView.

KOKKOS_INLINE_FUNCTION constexpr size_t stride_0() const;#
Return:

The stride of dimension 0, always returns 0 for DynamicView s.

KOKKOS_INLINE_FUNCTION constexpr size_t stride_1() const;#
Return:

The stride of dimension 1, always returns 0 for DynamicView s.

KOKKOS_INLINE_FUNCTION constexpr size_t stride_2() const;#
Return:

The stride of dimension 2, always returns 0 for DynamicView s.

KOKKOS_INLINE_FUNCTION constexpr size_t stride_3() const;#
Return:

The stride of dimension 3, always returns 0 for DynamicView s.

KOKKOS_INLINE_FUNCTION constexpr size_t stride_4() const;#
Return:

The stride of dimension 4, always returns 0 for DynamicView s.

KOKKOS_INLINE_FUNCTION constexpr size_t stride_5() const;#
Return:

The stride of dimension 5, always returns 0 for DynamicView s.

KOKKOS_INLINE_FUNCTION constexpr size_t stride_6() const;#
Return:

The stride of dimension 6, always returns 0 for DynamicView s.

KOKKOS_INLINE_FUNCTION constexpr size_t stride_7() const;#
Return:

The stride of dimension 7, always returns 0 for DynamicView s.

KOKKOS_INLINE_FUNCTION constexpr size_t span() const;#
Return:

Always returns 0 for DynamicView s.

KOKKOS_INLINE_FUNCTION constexpr pointer_type data() const;#
Return:

The pointer to the underlying data allocation.

KOKKOS_INLINE_FUNCTION constexpr bool span_is_contiguous() const;#
Return:

The span is contiguous, always false for DynamicView s.

Other

KOKKOS_INLINE_FUNCTION int use_count() const;#
Return:

The current reference count of the underlying allocation.

inline const std::string label();#
Returns:

The label of the DynamicView.

bool is_allocated() const#
Returns:

True if the View points to a valid set of allocated memory chunks. Note that this will return false until resize_serial is called with a size greater than 0.

Example#

const int chunk_size = 16*1024;
Kokkos::Experimental::DynamicView<double*> view("v", chunk_size, 10*chunk_size);
view.resize_serial(3*chunk_size);
Kokkos::parallel_for("InitializeData", 3*chunk_size, KOKKOS_LAMBDA ( const int i) {
  view(i) = i;
});