Template Class HostBlock¶
Defined in File block_traits.hpp
Class Documentation¶
-
template<typename
T
, size_tDimensions
>
classripple
::
HostBlock
¶ Definition of a host block class which stores multidimensional data on the host.
Implementation of a host block class which stores multidimensional data on the host.
This will store the data in a strided format if the type T implements the StridableLayout interface and the descriptor for the storage for the type has a StorageLayout::StridedView type, otherwise this will store the data in a contiguous format.
This will store the data in a strided format if the type T implements the StriableLayout interface and the descriptor for the storage for the type has a StorageLayout::strided_view type, otherwise this will store the data in a contiguous format.
- Template Parameters
T
: The type of the data stored in the tensor.Dimensions
: The number of dimensions in the tensor.
- Template Parameters
T
: The type of the data stored in the tensor.Dimensions
: The number of dimensions in the tensor.
Public Types
-
using
Padding
= typename Space::Padding¶ Defines the type of the padding.
-
using
AllocatorPtr
= MultiarchAllocator*¶ Defines the type of the pointer to the allocator.
Public Functions
-
HostBlock
() noexcept = default¶ Default constructor.This constructor is available so that an unsized block can be instanciated and then resized at runtime.
-
HostBlock
(MultiarchAllocator *allocator) noexcept¶ Constructor to set the allocator for the block.
-
~HostBlock
() noexcept¶ Destructor for the block, which cleans up the block resources.
-
template<typename ...
Sizes
, all_arithmetic_size_enable_t<Dimensions, Sizes...> = 0>HostBlock
(Sizes&&... sizes) noexcept¶ Initializes the size of each of the dimensions of the block.
- Note
This is only enabled when the number of arguments matches the dimensionality of the block and the sizes are arithmetic types.
- Note
This also allocated the data for the block.
- Parameters
sizes
: The sizes of the dimensions for the block.
- Template Parameters
Sizes
: The types of other dimension sizes.
-
template<typename ...
Sizes
, all_arithmetic_size_enable_t<Dimensions, Sizes...> = 0>HostBlock
(Padding padding, Sizes&&... sizes)¶ Initializes the size of each of the dimensions of the block, as well as the padding for the block.
- Note
This is only enabled when the number of size arguments matches the dimensionality of the block and the sizes are arithmetic types.
- Note
This also allocates data for the block.
- Note
The amount of padding specified adds the given amount to each side of each dimension.
- Parameters
padding
: The amount of padding for the block.sizes
: The sizes of the dimensions for the block.
- Template Parameters
Sizes
: The types of other dimension sizes.
-
HostBlock
(const HostBlock &other)¶ Copy constructor to create the block from another block.
- Parameters
other
: The other block to create this block from.
-
HostBlock
(HostBlock &&other) noexcept¶ Constructor to move the other block into this one.
The other block will no longer have valid data, and it’s size is meaningless.
- Parameters
other
: The other block to move to this one.
-
HostBlock
(const DeviceBlock &other, BlockOpKind op_kind = BlockOpKind::synchronous)¶ Constructor to create the block from a device block.
- Parameters
other
: The other block to create this block from.op_kind
: The kind of the memory operations for the block.
-
template<typename ...
Sizes
, all_arithmetic_size_enable_t<Dimensions, Sizes...> = 0>HostBlock
(BlockOpKind op_kind, Sizes&&... sizes)¶ Initializes the size of each of the dimensions of the block, as well as providing an option to enable asynchronous functionality for the block.
- Note
This is only enabled when the number of size arguments matches the dimensionality of the tensor, and the sizes are arithmetic types.
- Parameters
op_kind
: The kind of operation for the block.sizes
: The sizes of the dimensions for the tensor.
- Template Parameters
Sizes
: The types of other dimension sizes.
-
template<typename ...
Sizes
, all_arithmetic_size_enable_t<Dimensions, Sizes...> = 0>HostBlock
(BlockOpKind op_kind, size_t padding, Sizes&&... sizes)¶ Initializes the size of each of the dimensions of the block, the padding for the block, and provides an option to enable asynchronous functionality for the block.
- Note
This is only enabled when the number of size arguments matches the dimensionality of the block, and the izes are arithmetic types.
- Parameters
op_kind
: The operation kind for the block.padding
: The amount of padding for the tensor.sizes
: The sizes of the dimensions for the tensor.
- Template Parameters
Sizes
: The types of other dimension sizes.
-
auto
operator=
(const HostBlock &other) -> HostBlock&¶ Overload of copy assignment operator to create this block from another.
- Return
A reference to the created block.
- Parameters
other
: The other block to create this block from.
-
auto
operator=
(HostBlock &&other) noexcept -> HostBlock&¶ Overload of move assignment operator to move another block into this block.
- Return
A reference to the created block.
- Parameters
other
: The other block to create this block from.
-
auto
operator=
(const DeviceBlock &other) -> HostBlock&¶ Overload of copy assignment operator to create this block from the other block.
- Return
A reference to the created block.
- Parameters
other
: The other block to create this block from.op_kind
: The kind of the memory operations for the block.
-
template<typename ...
Indices
>
autooperator()
(Indices&&... is) noexcept -> Iter¶ Overload of operator() to get an iterator to the element at the location specified by the indices.
- Return
An iterator pointing to the element defined by the indices.
- Parameters
is
: The indices to get the element at.
- Template Parameters
Indices
: The types of the indices.
-
template<typename ...
Indices
>
autooperator()
(Indices&&... is) const noexcept -> ConstIter¶ Overload of operator() to get a constant iterator to the element at the location specified by the indices.
- Return
A const iterator pointing to the element defined by the indices.
- Parameters
is
: The indices to get the element at.
- Template Parameters
Indices
: The types of the indices.
-
auto
as_device
() const -> DeviceBlock¶ Creates a device block with the data from this host block.
- Return
A device block with the data and properties of this block.
-
auto
copy_data
(const DeviceBlock &other) noexcept -> void¶ Copies the data from the device block into this block.
- Parameters
other
: The other block to copy the data from.
-
auto
begin
() noexcept -> Iter¶ Gets an iterator to the beginning of the block.
- Note
The returned iterator points to the first valid cell (i.e is is offset over the padding).
- Return
An iterator to the first element in the block.
-
auto
begin
() const -> ConstIter¶ Gets a constant iterator to the beginning of the block.
- Note
The returned iterator points to the first valid cell (i.e is is offset over the padding).
- Return
A constant iterator to the first element in the block.
-
auto
reallocate
() -> void¶ Reallocates the data for the block.
-
template<typename ...
Args
>
autoreallocate_and_init
(Args&&... args) -> void¶ Reallocates the data and initializes the data using the givenargs for the construction of the elements.
- Parameters
args
: The arguments for the constructor.
- Template Parameters
Args
: The type of the arguments.
-
template<typename
Dim
>
autoresize_dim
(Dim &&dim, size_t size) noexcept -> void¶ Resizes the dimension to the given size.
- Note
This does not reallocate, since multiple resizings would then then make multiple allocations. Call reallocate to reallocate after resizing.
- Note
The resize does not include padding, padding for the dimension is in addition to this size.
- Parameters
dim
: The dimension to resize.size
: The size to resize the dimension to. \tparm Dim The type of the dimension specifier.
-
template<typename ...
Sizes
>
autoresize
(Sizes&&... sizes) -> void¶ Resizes each of the dimensions specified to the given size.
- Note
This does reallocate the data after the resize, since it is assumed that no further resizing is necessary since all dimension sizes are specified in this call.
- Note
If less sizes are provided than there are dimensions in the block, the the first sizeof…(Sizes) dimensions will be resized.
- Parameters
sizes
: The sizes to resize the dimensions to.
- Template Parameters
Sizes
: The type of the sizes.
-
auto
size
() const noexcept -> size_t¶ Gets the total number of * valid* elements in the block, therefore this size excludes padding elements.
- See
- Return
The total number of valid elements in the block.
-
template<typename
Dim
>
autosize
(Dim &&dim) const noexcept -> size_t¶ Gets the total number of valid elements in the dimension, therefore this excludes the padding elements for the dimension.
- See
- Return
The number of valid elements in the dimension.
- Parameters
dim
: The dimension to get the size of.Dim
: The type of the dimension specifier.
-
template<typename
Dim
>
constexpr autopitch
(Dim &&dim) const noexcept -> size_t¶ Gets the pitch of the block in the given dimension, which is the total number of elements in the dimension including padding.
- Return
The total number of elements for the dimension including padding elements.
- Parameters
dim
: The dimension to get the pitch for.
- Template Parameters
Dim
: The type of the dimension specifier.
-
constexpr auto
dimensions
() const noexcept -> size_t¶ Gets the number of dimensions for the block.
- Return
The number of dimensions for the block.
-
auto
set_op_kind
(BlockOpKind op_kind) noexcept -> void¶ Sets the operation kind of the block to either synchronous or asynchronous.
- Parameters
op_kind
: The type of operation for the block.
-
auto
set_padding
(Padding padding) noexcept -> void¶ Sets the amount of padding for a single side of a single dimension for the block.
This padding amount will be applied to all sides of all dimensions.
- Note
This does not reallocate the memory for the block, so a call to reallocate should be made when the data should be reallocated.
- Parameters
padding
: The amount of padding.
-
auto
padding
() const noexcept -> Padding¶ Gets the amount of padding for the block.
- Note
This padding amount is for a single side of a single dimension of the block.
- Return
The amount of padding for the block.
-
auto
mem_requirement
() const noexcept -> size_t¶ Gets the number of bytes required to allocate memory to hold all data for the block.
- Return
The number of bytes required for the block.