Buffer

Header file: <libs/zarr/buffer.hpp> [source]

template<typename T>
struct Buffer

A class template for managing a buffer of elements of data type T.

This class provides functionality for initializing a buffer, copying elements of data into it and writing the buffer to a store.

Template Parameters:
  • The – type of the store object used by the buffer.

  • T – The type of elements stored in the buffer.

Public Types

using viewh_buffer = Kokkos::View<T*, HostSpace>

View of buffer type on host

using subviewh_buffer = Kokkos::Subview<viewh_buffer, kkpair_size_t>

Subview of host view

using mirrorviewd_buffer = Kokkos::View<T*, HostSpace::array_layout, ExecSpace>

mirror view of buffer view on device

Public Functions

inline explicit Buffer(const size_t chunksize)

Constructor for the Buffer class.

Initializes the buffer with size of given chunkshape.

Parameters:

chunksize – number of elements of data in 1 chunk of an array.

inline size_t get_chunksize() const

Gets the total chunk size of the buffer.

Returns:

The total chunk size.

inline size_t get_fill() const

Gets the number of elements currently in the buffer.

Returns:

The number of elements of buffer filled.

inline size_t get_space() const

Returns the number of empty spaces in the buffer.

Returns:

The number of spaces in the buffer currently not filled with data.

inline subviewh_buffer copy_to_buffer(const viewh_buffer h_data)

Copies as many elements as possible from data to buffer.

Copies “n_to_copy” elements from view of data such that either all the data is copied to the buffer or all the spaces in the buffer are filled. Returns a view of remaining data not copied to the buffer which is empty if all the data has been copied.

Parameters:

h_data – View containing the data to copy.

Returns:

Subview containing the remaining data not copied to the buffer.

inline void copy_to_buffer(const T data)

Copies maximum of 1 element of data to buffer.

Assert that there is space in the buffer, then copy 1 element of data to the buffer.

Parameters:

data – Data element to copy.

template<typename Store>
inline void write_buffer_to_chunk(Store &store, std::string_view name, const std::string &chunk_label)

Writes data from buffer to a chunk in a store.

Writes data from buffer to a chunk specified by “chunk_label” of an array called “name” in a memory store. Then resets the buffer.

Template Parameters:

Store – The type of the memory store.

Parameters:
  • store – Reference to the store object.

  • name – Name of the array in the store.

  • chunk_label – Name of the chunk of the array to write in the store.

Private Functions

inline void reset_buffer()

Parallel loop on host to fill buffer with NaN (numerical limit).

inline void copy_ndata_to_buffer(const size_t n_to_copy, const viewh_buffer h_data)

Parallel loop on host to fill buffer with data elements.

Parallel loop on host to fill buffer from index “fill” (i.e. start of empty spaces) with “n_to_copy” elements from view of data.

Parameters:
  • n_to_copy – maximum number of elements to copy to the buffer.

  • h_data – View containing the data to copy.

Private Members

const size_t chunksize

Total chunk size = product of shape of chunks

size_t fill

Number of elements of buffer currently filled

viewh_buffer buffer

View for buffer in host memory