Template Class Tensor¶
Defined in File tensor.hpp
Class Documentation¶
-
template<typename
T
, size_tDimensions
>
classripple
::
Tensor
¶ Implementation of a tensor class for an N-dimensional container for which the data resides on both the host and the device.
Forward declaration of a tensor class for an N-dimensional container.
- Template Parameters
Public Types
-
using
Size
= uint32_t¶ Defines the size type used.
-
using
BlockIter
= typename block_traits_t<Blocks>::Iter¶ Defines the type of an iterator over the blocks.
Public Functions
-
Tensor
() noexcept¶ Default constructor.
This does not initialize or allocate any data for the tensor. This constructor allows the tensor to be sized dynamically and then allocated, for cases where the sizes of the dimensions are not know beforehand.
-
template<typename ...
Sizes
, all_arithmetic_size_enable_t<dims, Sizes...> = 0>Tensor
(Sizes&&... sizes)¶ Contructor to intialize the tensor from only the dimension sizes.
This will parition across the largest dimension.
- Parameters
sizes
: The sizes of the dimensions for the tensor.
-
template<typename ...
Sizes
, all_arithmetic_size_enable_t<dims, Sizes...> = 0>Tensor
(Partitions partitions_per_dim, Sizes&&... sizes)¶ Constuctor to create the tensor with size specification and number of partitions per dimension.
- Note
This is only enabled if the number of dimension sizes match the number of dimensions.
- Parameters
partitions_per_dim
: Partitions pus per dimension.sizes
: The sizes for each dimension.
- Template Parameters
Sizes
: The types of the sizes of the dimensions.
-
template<typename ...
Sizes
, all_arithmetic_size_enable_t<Dimensions, Sizes...> = 0>Tensor
(Partitions partitions_per_dim, uint32_t padding, Sizes&&... sizes)¶ Constuctor to create the tensor with a size specification, the number of partitiosn per dimension, and a padding amount.
- Note
This is only enabled if the number of dimension sizes match the number of dimensions.
- Parameters
partitions_per_dim
: Partitions pus per dimension.padding
: The amount of padding for the tensor.sizes
: The sizes for each dimension.
- Template Parameters
Sizes
: The types of the sizes of the dimensions.
-
template<typename ...
Sizes
, all_arithmetic_size_enable_t<Dimensions, Sizes...> = 0>Tensor
(Partitions partitions_per_dim, BlockSplit blocks_per_partition, Sizes&&... sizes)¶ Constuctor to create the tensor with size specification, the number of partitions per dimension, and the number of blocks per partition.
- Note
This is only enabled if the number of dimension sizes match the number of dimensions.
- Parameters
gpus_per_partition
: The number of partitions per dimension.blocks_per_partition
: Blocks per partition for each dimension.sizes
: The sizes for each dimension.
- Template Parameters
Sizes
: The types of the sizes of the dimensions.
-
template<typename ...
Sizes
, all_arithmetic_size_enable_t<Dimensions, Sizes...> = 0>Tensor
(Partitions partitions_per_dim, BlockSplit blocks_per_partition, uint32_t padding, Sizes&&... sizes)¶ Constuctor to create the tensor with size specification, the number of gpus per dimension, and the number of blocks per gpu, and an amount of padding for the tensor.
- Note
This is only enabled if the number of dimension sizes match the number of dimensions.
- Parameters
gpus_per_partition
: The number of partitions per dimension.blocks_per_partition
: Blocks per partition for each dimensionpadding
: The amount of padding for the tensor.sizes
: The sizes for each dimension.
- Template Parameters
Sizes
: The types of the sizes of the dimensions.
-
template<typename ...
Indices
>
autooperator()
(Indices&&... indices) const noexcept -> HostBlockIter¶ Gets a host iterator to an element at the given location.
- Note
Since the tensor data is divided into blocks, the iterator is only valid for the block in which the elements exists.
- See
- Note
This may be a slow operation if the data is on the device, since the block data will then need to be copied to the host before returning the value.
- Note
This function is provided mainly for validation of tensor data.
- Return
An iterator to the block in which the element resides, pointing to the element.
- Parameters
indices
: The indices of the element to get.
- Template Parameters
Indices
: The types of teh indices.
-
template<typename
Dim
>
autosize
(Dim &&dim) const noexcept -> size_t¶ Gets the size of the tensor in the given dimension.
This size is the number of elements in the dimension excluding padding.
- See
- Return
The number of elements for the given dimension.
- Parameters
dim
: The dimension to get the size of.
- Template Parameters
Dim
: The type of the dimension specifier.
-
template<typename
Dim
>
autopitch
(Dim &&dim) const noexcept -> size_t¶ Gets the pitch of the tensor in the given dimension.
This pitch is the number of elements in the dimension including padding.
- See
- Return
The number of elements for the given dimension including padding.
- Parameters
dim
: The dimension to get the pitch of.
- Template Parameters
Dim
: The type of the dimension specifier.
-
auto
padding
() const noexcept -> size_t¶ Gets the amount of padding for the tensor.
- Return
The amount of padding for the tensor.
-
template<typename
Dim
>
autoset_partitions
(Dim &&dim, size_t partitions) noexcept -> void¶ Sets the number of partitions for the given dimension.
This will divide the tensor in the dimension into the given number of partitions.
- Parameters
dim
: The dimension to set the number of partitions for.partitions
: The number of partitions for the dimension.
- Template Parameters
Dim
: The dimension type.
-
template<typename
Dim
>
autoset_sub_partitions
(Dim &&dim, size_t sub_partitions) noexcept -> void¶ Sets the number of sub partitions for the dimension, which is the number of blocks per partitions for the dimension.
- Parameters
dim
: The dimension to set the sub partitions for.sub_partitions
: The number of sub partitions.
- Template Parameters
Dim
: The type of the dimension specifier.
-
template<typename
Dim
>
autoresize_dim
(Dim &&dim, size_t size) noexcept -> void¶ Resizes the dimension to contain the given number of elements in the dimension.
- Note
This excludes the padding.
- Parameters
dim
: The dimension to resize.size
: The size for the dimension (number of elements).
- Template Parameters
Dim
: The type of the dimension specifier.
-
auto
set_padding
(size_t padding) noexcept -> void¶ Sets the padding for the tensor to the given amount.
- Note
This amount is the amount of padding per side of each dimension, and is applied to each side of each dimension.
- Parameters
padding
: The amount of padding for the tensor.
-
auto
reallocate
(const ripple::StreamMap &stream_map = ripple::StreamMap()) -> void¶ Reallocates (or allocates if unallocated) the data for the tensor.
- Parameters
stream_map
: A map of gpu indicies to stream inidices which specifies which streams to use for which gpu.
-
auto
partitions
() const noexcept -> Size¶ Computes the number of partitions for the tensor.
- Note
The tensor will maps partitions to gpus, so this can also be used to determine the number of gpus.
- Return
The total number of partitions for the tensor.
-
auto
partition_size
() const -> Size¶ Computes the total number of elements per partition.
- Return
The total number of elements per partition.
-
template<typename
Dim
>
autoblocks_in_dim
(Dim &&dim) const noexcept -> size_t¶ Computes the number of blocks in the given dimension.
- Return
The number of blocks in the dimension.
- Parameters
dim
: The dimension to get the number of blocks for.
- Template Parameters
Dim
: The type of the dimension specifier.
-
auto
begin
() noexcept -> BlockIter¶ Gets an iterator to the blocks for the tensor.
- Return
A multi-dimensional iterator over the blocks for the tensor.
-
auto
diagonal_blocks
() const noexcept -> size_t¶ Computes the number of blocks diagonally across the tensor, i.e, the hypotenuse of the computational space which the tensor defines.
- Return
The number of blocks diagonally for the tensor.
-
auto
diagonal_block_size
() const noexcept -> size_t¶ Computes the number of elements per block diagonally.
- Return
The number of elements in each block of the tensor, diagonally.
-
auto
diagonal_size
() const noexcept -> size_t¶ Computes the number of cells in the tensor, diagonally.
- Note
This excludes padding data.
- Return
The number of elements in the tensor, diagonally.