Shortcuts

Template Class Tensor

Class Documentation

template<typename T, size_t Dimensions>
class ripple::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
  • T: The type of the data for the grid.

  • Dimensions: The number of dimensions for the grid

  • T: The data type for the Tensor.

  • Dimensions: The number of dimensions for the Tensor data.

Public Types

using Size = uint32_t

Defines the size type used.

using BlockSplit = std::array<Size, dims>

Defines the type of the block split specifier.

using Partitions = std::array<Size, dims>

Defines the type to store partition information.

using Elements = std::array<Size, dims>

Container to hold a number of elements.

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 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 ...Indices>
auto operator()(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

IndexedIterator, BlockIterator

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>
auto size(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

pitch

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>
auto pitch(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

size

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>
auto set_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>
auto set_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>
auto resize_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>
auto blocks_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.

Friends

friend auto swap(Tensor &lhs, Tensor &rhs) noexcept -> void

Swaps the two tensors.

Note

this goes through each block and swaps the data for each block.

Parameters
  • lhs: The left tensor to swap.

  • rhs: The right tensor to swap.

Docs

Access comprehensive developer documentation for Ripple

View Docs

Tutorials

Get tutorials to help with understand all features

View Tutorials

Examples

Find examples to help get started

View Examples