Shortcuts

Class Graph

Class Documentation

class ripple::Graph

The Graph class is a collection of nodes and the connectivity between them.

Public Functions

Graph() = default

Creates a graph.

Graph(ExecutionKind exec_kind) noexcept

Creates a graph with all nodes having a default execution kind defined by the given execution kind.

Parameters
  • exec_kind: The kind of the execution for the graph nodes.

~Graph() noexcept

Destructor recycles the nodes into the pool if they are valid.

Graph(Graph &&other) noexcept

Move constructor which just moves all graph infromation from the other graph into thos one.

Parameters
  • other: The other graph to move into this one.

Graph(const Graph&) = delete

Copy constructor deleted because graphs can’t be copied.

auto operator=(Graph &&other) noexcept -> Graph&

Overload of move assignment operator to move the other graph into this one.

Return

A reference to the newly created graph.

Parameters
  • other: The other graph to move into this one.

auto operator=(const Graph &other) = delete

Copy assignment operator deleted because graphs can’t be copied.

auto reset() noexcept -> void

Resets the graph, returning all allocated nodes to the allocator.

auto clone() const noexcept -> Graph

Clones the graph by allocates new nodes for the new graph and then copying the others into it.

Note

This is not designed to be fast, and it is not thread safe.

Return

The new graph.

auto size() const -> size_t

Gets the number of nodes in the graph.

Return

The number of nodes in the graph.

auto allocation_pool_size() const noexcept -> size_t

Gets the maximum number of nodes which can be allocated for all graphs.

Return

The size of the allocation pool.

auto find(std::string name) noexcept -> std::optional<NodeType*>

Gets an optional type which may point to the node with the given name.

Return

A valid pointer wrapped in an optional on success.

Parameters
  • name: The name of the node to find.

auto find_last_of(std::string name) noexcept -> std::optional<NodeType*>

Finds the last instance of a node with the given name.

Return

A valid optional if the node was found.

Parameters
  • name: The name of the node to find.

template<typename F, typename ...Args, non_node_enable_t<F> = 0>
auto emplace(F &&callable, Args&&... args) -> Graph&

Emplaces a node onto the graph, returning a reference to the modified graph.

Return

A reference to the modified graph.

Parameters
  • callable: The callable which defines the node’s operation.

  • args: Arguments for the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The types of the arguments.

template<typename F, typename ...Args, non_node_enable_t<F> = 0>
auto emplace_named(NodeInfo info, F &&callable, Args&&... args) -> Graph&

Emplaces a node onto the graph using the given info, returning a reference to the modified graph.

Return

A reference to the modified graph.

Parameters
  • info: The info for the node.

  • callable: The callable which defines the node’s operation.

  • args: Arguments for the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The types of the arguments.

template<typename ...Nodes, all_same_enable_t<NodeType, std::decay_t<Nodes>...> = 0>
auto emplace(Nodes&&... nodes) -> Graph&

Emplaces all the nodes onto the graph at the same level such that they can execute in parallel.

Return

A reference to the modified graph.

Parameters
  • nodes: The nodes to emplace.

Template Parameters
  • Nodes: The types of the nodes.

auto emplace(Graph &graph) noexcept -> Graph&

Emplaces the given graph as a subgraph in this graph, which executes after any nodes currently in the graph.

Return

A reference to the modified graph.

Parameters
  • graph: The graph to emplace as a subgraph in this graph.

template<typename F, typename ...Args, non_node_enable_t<F> = 0>
auto sync(F &&callable, Args&&... args) -> Graph&

Emplaces a node into the graph which creates a sync point in the graph.

Note

This does not flush all gpu work, it simply ensures that all GPU work is submitted by this point, to flush and wait for all GPU work to finish,

See

sync_gpus.

Return

A reference to the modified graph.

Parameters
  • callable: The callable which defines the node’s operation.

  • args: Arguments for the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The types of the arguments.

template<typename F, typename ...Args, non_node_enable_t<F> = 0>
auto gpu_fence(F &&callable, Args&&... args) -> Graph&

Emplaces a node into the graph which creates a sync point in the graph which synchronizes all streams on all GPUs.

To create only a submission synchronization point,

See

sync.

Note

This is less restrictive than a barrier, which fully synchronizes each device. This just places a synchronization point into the graph.

Parameters
  • callable: The callable which defines the node’s operation.

  • args: Arguments for the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The types of the arguments.

auto gpu_barrier() -> Graph&

Emplaces a node into the graph which creates a barrier for each gpu, which will block until all gpus have finished their currently submitted work.

Parameters
  • callable: The callable which defines the node’s operation.

  • args: Arguments for the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The types of the arguments.

template<typename F, typename ...Args, non_node_enable_t<F> = 0>
auto then(F &&callable, Args&&... args) -> Graph&

Emplaces a node onto the graph which runs after all currently emplaced nodes, i.e the operations being emplaced run synchronously with the previously emplaced nodes.

Graph g;
g.emplace([] { printf("A\n"); })
 .then([] { printf("B\n"); });

This will run B after A finishes.

Return

A reference to the modified graph.

Parameters
  • callable: The callable which defines the node’s operation.

  • args: Arguments for the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The types of the arguments.

template<typename ...Nodes, all_same_enable_t<NodeType, std::decay_t<Nodes>...> = 0>
auto then(Nodes&&... nodes) -> Graph&

Emplaces nodes onto the graph which run asynchronously with each other, but synchronously with all previous nodes.

Graph g;
g.emplace([] { printf("A\n"); })
 .then(
   Graph::make_node([] { printf("B\n"); }),
   Graph::make_node([] { printf("C\n"); }),
   Graph::make_node([] { printf("D\n"); }));

This will run A, and then B, C, and D will run after A, but may run in parallel with each other.

Note

This is only enabled when all the template types are the same and are Node types.

Return

A reference to the modified graph.

Parameters
  • nodes: The nodes to emplace.

Template Parameters
  • Nodes: The types of the nodes.

auto then(Graph &graph) noexcept -> Graph&

Emplaces the given graph as a subgraph in this graph, which executes after any nodes currently in the graph.

Note

Any changes to the given graph before this node executes will be reflected during execution.

Return

A reference to the modified graph.

Parameters
  • graph: The graph to emplace as a subgraph in this graph.

template<typename Pred, typename ...Args>
auto conditional(Pred &&pred, Args&&... args) -> Graph&

Adds a conditional node to the graph, where execution depends on the predicate.

Return

A reference to the modified graph.

Parameters
  • pred: The predicate which returns if the execution must end.

  • args: The arguments for the predicate.

Template Parameters
  • Pred: The type of the predicate.

  • Args: The type of the predicate arguments.

template<typename F, typename ...Args>
auto split(F &&callable, Args&&... args) noexcept -> Graph&

Creates a split in the graph by parallelising the callable over the args.

For any of the args which are tensors, this creates a node per partition in the tensor. Additionally, if any of the modifiers are used, this may place additional nodes into the graph for data transfer of padding data for neighbouring tensor partitions.

Note

This uses the default execution kind of the graph, so the nodes will be executed on the CPU or GPU based on the graph execution kind.

Return

A reference to the modified graph.

Parameters
  • callable: The operations for each node in the split.

  • args: The arguments to the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The types of the arguments for the callable.

template<typename F, typename ...Args>
auto split(ExecutionKind exec_kind, F &&callable, Args&&... args) noexcept -> Graph&

Creates a split in the graph by parallelising the callable over the args.

For any of the args which are tensors, this creates a node per partition in the tensor. Additionally, if any of the modifiers are used, this may place additional nodes into the graph for data transfer of padding data for neighbouring tensor partitions.

Return

A reference to the modified graph.

Parameters
  • exec_kind: The kind of execution for the nodes.

  • callable: The operations for each node in the split.

  • args: The arguments to the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The types of the arguments for the callable.

template<typename F, typename ...Args>
auto then_split(F &&callable, Args&&... args) noexcept -> Graph&

Creates a split in the graph by parallelising the callable over the args.

For any of the args which are tensors, this creates a node per partition in the tensor. Additionally, if any of the modifiers are used, this may place additional nodes into the graph for data transfer of padding data for neighbouring tensor partitions.

This will add all emplaced nodes such that they are only executed after any nodes in the previous levels.

Note

Nodes assosciated with the same partition are the only nodes with dependencies, for example, nodes associated with paritions 0 and 1 will not have any dependencies, and can run in parallel, unless there are padding data transfers required.

Note

This uses the default execution kind of the graph, so the nodes will be executed on the CPU or GPU based on the graph execution kind.

Return

A reference to the modified graph.

Parameters
  • callable: The operations for each node in the split.

  • args: The arguments to the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The types of the arguments for the callable.

template<typename F, typename ...Args>
auto then_split(ExecutionKind exec_kind, F &&callable, Args&&... args) noexcept -> Graph&

Creates a split in the graph by parallelising the callable over the args.

For any of the args which are tensors, this creates a node per partition in the tensor. Additionally, if any of the modifiers are used, this may place additional nodes into the graph for data transfer of padding data for neighbouring tensor partitions.

This will add all emplaced nodes such that they are only executed after any nodes in the previous levels.

Note

Nodes assosciated with the same partition are the only nodes with dependencies, for example, nodes associated with paritions 0 and 1 will not have any dependencies, and can run in parallel, unless there are padding data transfers required.

Return

A reference to the modified graph.

Parameters
  • exec_kind: The kind of the execution for the operations.

  • callable: The operations for each node in the split.

  • args: The arguments to the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The types of the arguments for the callable.

template<typename ...Args>
auto memcopy_padding(Args&&... args) noexcept -> Graph&

Performs a copy of the data between the partitions of the data, if the data is a tensor and has partitions, otherwise does not emplace any nodes into the graph.

Note

If the tensor is wrapped in any modifiers, these are applied as well to ensure that the dependencies between nodes are created.

Note

This uses the default execution kind of the graph.

Return

A reference to the modified graph.

Parameters
  • args: The arguments to the apply the memcopies to.

Template Parameters
  • Args: The types of the arguments.

template<typename ...Args>
auto then_memcopy_padding(Args&&... args) noexcept -> Graph&

Performs a copy of the data between the partitions of the data, if the data is a tensor and has partitions, otherwise does not emplace any nodes into the graph.

This operation will only perform the call to start the memcopy operations once all previosuly submitted operations have been executed.

Note

If the tensor is wrapped in any modifiers, these are applied as well to ensure that the dependencies between nodes are created.

Note

This uses the default execution kind of the graph.

Return

A reference to the modified graph.

Parameters
  • args: The arguments to the apply the memcopies to.

Template Parameters
  • Args: The types of the arguments.

template<typename ...Args>
auto memcopy_padding(ExecutionKind exec, Args&&... args) noexcept -> Graph&

Performs a copy of the data between the partitions of the data, if the data is a tensor and has partitions, otherwise does not emplace any nodes into the graph.

Note

If the tensor is wrapped in any modifiers, these are applied as well to ensure that the dependencies between nodes are created.

Return

A reference to the modified graph.

Parameters
  • args: The arguments to the apply the memcopies to.

  • exec: The kind of the execution of the memory copying, i.e, if the memcopy is required for the host or device data.

Template Parameters
  • Args: The types of the arguments.

template<typename ...Args>
auto then_memcopy_padding(ExecutionKind exec, Args&&... args) noexcept -> Graph&

Performs a copy of the data between the partitions of the data, if the data is a tensor and has partitions, otherwise does not emplace any nodes into the graph.

This operation will only perform the call to start the memcopy operations once all previosuly submitted operations have been executed.

Note

If the tensor is wrapped in any modifiers, these are applied as well to ensure that the dependencies between nodes are created.

Return

A reference to the modified graph.

Parameters
  • args: The arguments to the apply the memcopies to.

  • exec: The kind of the execution of the memory copying, i.e, if the memcopy is required for the host or device data.

Template Parameters
  • Args: The types of the arguments.

template<typename T, size_t Dims, typename Pred, typename ...Args>
auto reduce(Tensor<T, Dims> &data, ReductionResult<T> &result, Pred &&pred, Args&&... args) noexcept -> Graph&

Performs a reduction of the data using the given predicate.

Note

This performs a reduction per partition of the tensor, and then accumulates the result in the given reduction result.

Note

This uses the execution kind of the graph as the execution kind of the reduction operations.

Return

A reference to the modified graph.

Parameters
  • data: The data to reduce.

  • result: The result to place the final value into.

  • pred: The predicate for the reduction.

  • args: Additional arguments for the predicate.

Template Parameters
  • T: The data type for the tensor.

  • Dims: The number of dimensions for the tensor.

  • Pred: The type of the predicate.

  • Args: The type of the arguments for the predicate.

template<typename T, size_t Dims, typename Pred, typename ...Args>
auto reduce(ExecutionKind exec_kind, Tensor<T, Dims> &data, ReductionResult<T> &result, Pred &&pred, Args&&... args) noexcept -> Graph&

Performs a reduction of the data using the given predicate.

Note

This performs a reduction per partition of the tensor, and then accumulates the result in the given reduction result.

Return

A reference to the modified graph.

Parameters
  • exec_kind: The kind of the execution of the operations.

  • data: The data to reduce.

  • result: The result to place the final value into.

  • pred: The predicate for the reduction.

  • args: Additional arguments for the predicate.

Template Parameters
  • T: The data type for the tensor.

  • Dims: The number of dimensions for the tensor.

  • Pred: The type of the predicate.

  • Args: The type of the arguments for the predicate.

template<typename T, size_t Dims, typename Pred, typename ...Args>
auto then_reduce(Tensor<T, Dims> &data, ReductionResult<T> &result, Pred &&pred, Args&&... args) noexcept -> Graph&

Performs a reduction of the data using the given predicate.

This emplces the reduction onto the graph such that it executes after any previously emplaced nodes.

Note

This performs a reduction per partition of the tensor, and then accumulates the result in the given reduction result.

Note

This uses the execution kind of the graph as the execution kind of the reduction operations.

Return

A reference to the modified graph.

Parameters
  • data: The data to reduce.

  • result: The result to place the final value into.

  • pred: The predicate for the reduction.

  • args: Additional arguments for the predicate.

Template Parameters
  • T: The data type for the tensor.

  • Dims: The number of dimensions for the tensor.

  • Pred: The type of the predicate.

  • Args: The type of the arguments for the predicate.

template<typename T, size_t Dims, typename Pred, typename ...Args>
auto then_reduce(ExecutionKind exec_kind, Tensor<T, Dims> &data, ReductionResult<T> &result, Pred &&pred, Args&&... args) noexcept -> Graph&

Performs a reduction of the data using the given predicate.

This emplces the reduction onto the graph such that it executes after any previously emplaced nodes.

Note

This performs a reduction per partition of the tensor, and then accumulates the result in the given reduction result.

Note

This uses the execution kind of the graph as the execution kind of the reduction operations.

Return

A reference to the modified graph.

Parameters
  • exec_kind: The kind of execution for the operations.

  • data: The data to reduce.

  • result: The result to place the final value into.

  • pred: The predicate for the reduction.

  • args: Additional arguments for the predicate.

Template Parameters
  • T: The data type for the tensor.

  • Dims: The number of dimensions for the tensor.

  • Pred: The type of the predicate.

  • Args: The type of the arguments for the predicate.

auto num_executions() const noexcept -> size_t

Gets the number of times the graph has been executed.

Return

The number of times the graph has been executed.

Public Static Functions

auto set_allocation_pool_size(size_t nodes) noexcept -> bool

Sets the size of the allocation pool for all grphs combined.

Return

true when called for the first time, false otherwise.

Parameters
  • nodes: The number of nodes for the allocation pool.

template<typename F, typename ...Args>
auto make_node(F &&callable, Args&&... args) -> NodeType&

Makes a node with the given callable and args.

Return

A reference to the new node.

Parameters
  • callable: The callable which defines the node’s operation.

  • args: The args for the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The type of the args.

template<typename F, typename ...Args>
auto make_node(F &&callable, ExecutionKind exec_kind, Args&&... args) -> NodeType&

Makes a node with the given callable and args, with a specific execution kind.

Return

A reference to the new node.

Parameters
  • callable: The callable which defines the node’s operation.

  • exec_kind: The kind of the execution for the node.

  • args: The args for the callable.

Template Parameters
  • F: The type of the callable.

  • Args: The type of the args.

Public Static Attributes

constexpr size_t default_nodes = 1024

The default number of nodes per thread.

constexpr auto default_id = NodeInfo::default_id

Default id for a node.

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