Shortcuts

Template Class DeviceBlock

Class Documentation

template<typename T, size_t Dimensions>
class ripple::DeviceBlock

Definition of a device block class which stores multidimensional data on the device.

Implementation of a device block class which stores multidimensional data on the device.

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::StridedView 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.

Note

While this class can be used directly, it’s designed as an implementation detail for the Tensor class.

See

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 used for padding.

using AllocatorPtr = MultiarchAllocator*

Defines the type of the pointer to the allocator.

Public Functions

DeviceBlock() noexcept

Default constructor.This constructor is available so that an unsized block can be instanciated and then resized at runtime.

DeviceBlock(Stream stream, AllocatorPtr allocator = nullptr) noexcept

Constructor which sets the stream for the block.

Parameters
  • stream: The stream for the device.

DeviceBlock(AllocatorPtr allocator) noexcept

Default constructor.This constructor is available so that an unsized block can be instanciated and then resized at runtime.

DeviceBlock(Stream stream) noexcept

Constructor which sets the stream for the block.

Parameters
  • stream: The stream for the device.

~DeviceBlock() noexcept

Destructor for the block, which cleans up the block resources.

template<typename ...Sizes, all_arithmetic_size_enable_t<Dimensions, Sizes...> = 0>
DeviceBlock(Sizes&&... sizes)

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>
DeviceBlock(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.

DeviceBlock(const DeviceBlock &other)

Copy constructor to create the block from another block.

Parameters
  • other: The other block to create this block from.

DeviceBlock(DeviceBlock &&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.

DeviceBlock(const HostBlock &other)

Constructor to create the block from a host block.

Note

This copies the memory from the host block into the device memory for this block.

Parameters
  • other: The host block to create this block from.

auto operator=(const DeviceBlock &other) -> DeviceBlock&

Overload of copy assignment to create the block from another block.

Note

This copies the data from the other block into this one.

Return

A reference to the created block.

Parameters
  • other: The other block to create this block from.

auto operator=(const HostBlock &other) -> DeviceBlock&

Overload of copy assignment to create the block from another block.

Note

This copies the data from the other block into this one.

Return

A reference to the created block.

Parameters
  • other: The other block to create this block from.

template<typename ...Indices>
auto operator()(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>
auto operator()(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_host(BlockOpKind op_kind = BlockOpKind::synchronous) const -> HostBlock

Create a host block with the data from this device block.

Return

A host block with the data and properties of this block.

Parameters
  • op_kind: The kind of the memory operations for the block.

auto copy_data(const HostBlock &other) noexcept -> void

Copies the data from the host block into this block.

Parameters
  • other: The other block to copy the data from.

auto begin(int padding_mod = 0) 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(int padding_mod = 0) const noexcept -> 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 Dim>
auto resize_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>
auto resize(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

pitch

Return

The total number of valid elements in the block.

template<typename Dim>
auto size(Dim &&dim) const -> size_t

Gets the total number of valid elements in the dimension, therefore this excludes the padding elements for the dimension.

See

pitch

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

auto set_device_id(uint32_t device_id) noexcept -> void

Sets the device id for the block.

Parameters
  • device_id: The id of the device to use for the block.

auto device_id() const noexcept -> uint32_t

Gets the device id for the block.

Return

The device id for this block.

auto stream() const noexcept -> Stream

Gets the stream used by the block.

Return

The stream for the block.

auto set_stream(Stream stream) noexcept -> void

Sets the stream for the block.

Parameters
  • stream: The stream to set for the block.

auto destroy_stream() noexcept -> void

Destroys the stream for the block.

template<typename Block>
constexpr auto get_copy_type() const noexcept -> cudaMemcpyKind

Returns the copy type required to copy from this block to another block with type Block.

Return

The type of the copy required to copy from this block.

Template Parameters
  • Block: The block to determine the copy type from.

Friends

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

Swaps the blocks lhs and rhs blocks.

Parameters
  • lhs: The left block to swap.

  • rhs: The right block 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