cuda::experimental::graph_builder_ref#
-
struct graph_builder_ref#
An owning wrapper type for a cudaGraph_t handle.
The
graph_builderclass provides a high-level interface for creating, managing, and manipulating CUDA graphs. It ensures proper resource management and simplifies the process of working with CUDA graph APIs.Features:
Supports construction, destruction, and copying of CUDA graphs.
Provides methods for adding nodes and dependencies to the graph.
Allows instantiation of the graph into an executable form.
Ensures proper cleanup of CUDA resources.
Usage:
Create an instance of
graph_builderto represent a CUDA graph.Use the
addmethods to add nodes and dependencies to the graph.Instantiate the graph using the
instantiatemethod to obtain an executable graph.Use the
resetmethod to release resources when the graph is no longer needed.
Thread Safety:
This class is not thread-safe. Concurrent access to the same
graph_builerobject must be synchronized externally.
Exception Safety:
Methods that interact with CUDA APIs may throw
cuda::std::cuda_errorif the underlying CUDA operation fails.Move operations leave the source object in a valid but unspecified state.
Subclassed by cuda::experimental::graph_builder
Public Functions
- inline constexpr graph_builder_ref(
- cudaGraph_t __graph,
- device_ref __dev,
Constructs a new, empty CUDA graph.
- Parameters:
__dev – The device on which graph nodes will execute.
- Throws:
cuda::std::cuda_error – if
cudaGraphCreatefails.
-
inline explicit constexpr operator bool() const noexcept#
Checks if the graph handle is valid.
This operator allows the graph builder to be used in a boolean context to determine if it is valid. A valid graph builder is one where the internal node pointer is not
nullptr.- Returns:
trueif the internal node pointer is notnullptr, otherwisefalse.
-
inline constexpr auto operator!() const noexcept -> bool#
Checks if the graph is not null.
- Returns:
trueif the internal graph handle is null, otherwisefalse.
-
inline constexpr void swap(graph_builder_ref &__other) noexcept#
Swaps the contents of this
graph_builderwith another.- Parameters:
__other – The
graph_builderobject to swap with.- Throws:
None –
-
inline constexpr auto get() const noexcept -> cudaGraph_t#
Retrieves the underlying CUDA graph object.
- Throws:
None –
- Returns:
The
cudaGraph_thandle.
-
inline constexpr auto get_device() const noexcept -> device_ref#
Retrieves the device on which the graph is built.
- Returns:
The device on which the graph is built.
-
template<class _Node>
inline constexpr auto add( - _Node __node,
Adds a new root node to the graph.
- Template Parameters:
_Node – The type of the node to add.
- Parameters:
__node – The descriptor of the node to add to the graph.
- Throws:
cuda::std::cuda_error – if adding the node fails.
- Returns:
A
graph_node_refrepresenting the added node. The graph object owns the new node.
-
template<class _Node, size_t _Np>
inline constexpr auto add(
) -> graph_node_ref# Adds a new node to the graph with specified dependencies.
This function creates a new node in the graph and establishes dependencies between the newly created node and the provided dependency nodes.
The function first creates a new node in the graph using the provided
_Nodeobject.It initializes an array of “dependant” nodes, where all dependant nodes correspond to the newly created node.
The function then uses the CUDA API
cudaGraphAddDependenciesto establish the dependencies between the newly created node and the nodes provided in the__depsspan.If the number of dependencies is small, a stack-allocated buffer is used; otherwise, a dynamically allocated array is used to store the dependant nodes.
- Template Parameters:
_Node – The type of the node to be added.
_Extent – The extent of the span representing the dependencies.
- Parameters:
__node – The descriptor of the node to be added to the graph.
__deps – An array of
cudaGraphNode_thandles representing the dependencies of the new node. Each node in this span will become a dependency of the newly created node.
- Throws:
cuda::std::cuda_error – If the CUDA API call
cudaGraphAddDependenciesfails.- Returns:
A
graph_node_refobject representing the newly created node in the graph. The graph object owns the new node.
-
template<class _Node, size_t _Extent>
inline constexpr auto add(
) -> graph_node_ref# This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
-
inline size_t node_count() const#
Retrieves the number of nodes in the graph.
- Throws:
cuda::std::cuda_error – if
cudaGraphGetNodesfails.- Returns:
The number of nodes in the graph.
Friends
- inline friend bool operator==(
- const graph_builder_ref &__lhs,
- const graph_builder_ref &__rhs,
Compares two
graph_builderobjects for equality.- Parameters:
__lhs – The left-hand side
graph_builderobject to compare.__rhs – The right-hand side
graph_builderobject to compare.
- Returns:
trueif bothgraph_builderobjects are equal,falseotherwise.
- inline friend bool operator!=(
- const graph_builder_ref &__lhs,
- const graph_builder_ref &__rhs,
Compares two
graph_builderobjects for inequality.- Parameters:
__lhs – The left-hand side
graph_builderobject to compare.__rhs – The right-hand side
graph_builderobject to compare.
- Returns:
trueif bothgraph_builderobjects are not equal,falseotherwise.
- inline friend bool operator==(
- ::cuda::std::nullptr_t,
- const graph_builder_ref &__rhs,
Test whether a
graph_builderobject is null.- Returns:
trueif__rhsis null,falseotherwise.
- inline friend bool operator==(
- const graph_builder_ref &__lhs,
- ::cuda::std::nullptr_t,
Test whether a
graph_builderobject is null.- Returns:
trueif__rhsis null,falseotherwise.
- inline friend bool operator!=(
- ::cuda::std::nullptr_t,
- const graph_builder_ref &__rhs,
Test whether a
graph_builderobject is not null.- Returns:
trueif__rhsis not null,falseotherwise.
- inline friend bool operator!=(
- const graph_builder_ref &__lhs,
- ::cuda::std::nullptr_t,
Test whether a
graph_builderobject is not null.- Returns:
trueif__lhsis not null,falseotherwise.