Shortcuts

Template Struct Block

Inheritance Relationships

Base Type

Struct Documentation

template<typename T, size_t Dimensions>
struct ripple::Block : public ripple::MultiBlock<Block<T, Dimensions>>

Defines a type which wraps a host and device block into a single type, and which has a state for the different regions of data in the parition.

This class is designed to partition both the computational space as well as the memory spaces, and to be used as a building block for the Tensor class.

Template Parameters
  • T: The type of the data for the block.

  • Dimensions: The number of dimensions for the block.

Public Types

using Traits = MultiBlockTraits<Block<T, Dimensions>>

Defines the traits for the block.

using Index = std::array<uint32_t, Dimensions>

Defines the type of the type for the block index.

using HostBlock = HostBlock<T, Dimensions>

Defines the type of the host block for the block.

using DeviceBlock = DeviceBlock<T, Dimensions>

Defines the type of the device block for the block.

using Iterator = typename Traits::Iterator

Defines the type of the host iterator.

using SharedIterator = typename Traits::SharedIterator

Defines the type of the iterator over shared memory.

using Stream = typename DeviceBlock::Stream

Defines the type of the stream.

Public Functions

Block() = default

Default constructor for the block.

~Block() = default

Destructor defaulted.

auto ensure_device_data_available() noexcept -> void

Ensures that the data is available on the device.

Note

This will make a copy from the host to the device if the data is not already on the device.

auto ensure_host_data_available() noexcept -> void

Ensures that the data is available on the host.

Note

This will make a copy from the device to the host if the data is not already on the host.

auto has_padding() const noexcept -> bool

Determines if the block has padding.

Return

true if the block has padding, otherwise false.

auto set_padding(size_t amount) noexcept -> void

Sets the padding for the block to be the given amount.

Note

The amount here is the number of elements of a single side of a single dimension, which will be applied to all sides of all dimensions.

Parameters
  • amount: The amount of padding.

auto padding() const noexcept -> size_t

Gets the amount of padding for a single side of a single dimension for the block.

Return

The amount of padding 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 for the block.

auto device_iterator(int padding_mod = 0) const noexcept -> Iterator

Gets an iterator to the device data for the block.

This creates an interator which points to the first valid cell (i.e not in the padding), unless padding_mod is not zero, in which case the iterator points to the element offset by padding_mod amount in each dimension.

For example, padding_mod = 1 will return an iterator to what is effectively cell (-1, -1, -1).

Return

An iterator to the first valid (non-padding) element in the block.

Parameters
  • padding_mod: Amount of padding to offset into.

auto host_iterator() const noexcept -> Iterator

Gets an iterator to the host data.

Return

An iterator to the first valid (non-padding) element in the block.

auto stream() const noexcept -> Stream

Returns the stream for this block, which is used for compute operations.

Return

The stream for the block.

auto transfer_stream() const noexcept -> Stream

Returns the stream for this block, which is used for transfer operations.

Note

If the transfer stream has not been set, this returns the compute stream.

Return

The transfer stream for the block.

auto set_transfer_stream(Stream stream) noexcept -> void

Sets the transfer stream to the given stream.

Parameters
  • stream: The stream to set the transfer stream to.

auto synchronize() noexcept -> void

Synchronizes the block’s stream.

Todo:

Change this to sync both compute and copy streams.

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

Returns the total number of elements in the given dimension.

Return

The number of elements in teh given dimenion, excluding padding for the dimsnion

Parameters
  • dim: The dimension to get the size of.

  • Dim: The type of the dimension specifier.

template<typename Dim>
auto last_in_dim(Dim &&dim) const noexcept -> bool

Determines if the block is the last block in the given dimension.

Return

true if this block is the last block in the dimension.

Parameters
  • dim: The dimension to check if this is the last block in.

Template Parameters
  • Dim: The type of the dimension specifier.

template<typename Dim>
auto first_in_dim(Dim &&dim) const noexcept -> bool

Returns true if the block is the first block in the given dimension.

Return

true if this block is the first block in the dimension.

Parameters
  • dim: The dimension to check if this is the last block in.

Template Parameters
  • Dim: The type of the dimension specifier.

template<size_t Dim, FaceLocation Location, Mapping Map>
auto fill_padding(Block &other, CopySpecifier<Dim, Location, Map> dst_face, ExecutionKind exec_kind, TransferKind transfer_kind = TransferKind::synchronous) noexcept -> void

Fills the padding for this block using the other block, for the specified face.

Note

Whether this copies the data from the inside of the domain or from the padding of the other block depending on the mapping.

Note

When the exec_kind specifies gpu, ie the transfer is between gpus or between a gpu and the host, then transfer_kind specifies if the operations are placed on the same stream as compute operations (i.e they are synchronous with respect to compute) or the transfer stream and can happen asynchronously with respect to compute.

Parameters
  • other: The other block to use to fill the padding.

  • dst_face: The destination face to fill.

  • exec_kind: The kind of the execution to fill the padding.

  • transfer_kind: The kind of the transfer operation.

Template Parameters
  • Dim: The dimension of the destination face.

  • Location: The location of the face to fill the padding for.

  • Map: The padding for the face.

template<typename Pred, typename ...As>
auto reduce(ExecutionKind exec, Pred &&pred, As&&... as) noexcept -> T

Performs a reduction on either the host or the device, depending on the kind of the exection.

Return

The results of the reduction of the data.

Parameters
  • exe: The kind of the execution.

  • pred: The predicate for the reduction.

  • as: Arguments for the predicate.

Template Parameters
  • Pred: The type of the predicate.

  • As: The type of the predicate arguments.

template<typename Pred, typename ...Args>
auto reduce_on_device(Pred &&pred, Args&&... args) noexcept -> T

Performs a reduction of the block device data, returning the result.

Note

If the data is currently on the host then this will first copy the data to the device.

Return

The result of the reduction of the data.

Parameters
  • pred: The predicate for the reduction.

  • args: Arguments for the predicate.

Template Parameters
  • Pred: The type of the predicate.

  • Args: The type of the predicate arguments.

template<typename Pred, typename ...Args>
auto reduce_on_host(Pred &&pred, Args&&... args) noexcept -> T

Performs a reduction of the host device data, returning the result.

Note

If the data is curently on the device then this will first copy the data to the host.

Return

The result of the reduction of the data.

Parameters
  • pred: The predicate for the reduction.

  • args: Arguments for the predicate.

Template Parameters
  • Pred: The type of the predicate.

  • Args: The type of the predicate arguments.

Public Members

HostBlock host_data

Host block data.

DeviceBlock device_data

Device block data.

Index indices = {}

Indices of the block.

Index block_sizes = {}

Sizes of the blocks.

Index global_sizes = {}

Global sizes.

Index max_indices = {}

Max indices for each dimension.

uint32_t gpu_id = 0

Device index.

DataState data_state = DataState::invalid

Data state.

Public Static Attributes

constexpr size_t dims = Dimensions

Defines the number of dimension for the block.

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