cuda::experimental::graph_node_ref

Defined in include/cuda/experimental/__graph/graph_node_ref.cuh

struct graph_node_ref

A reference wrapper for a CUDA graph node.

This structure provides an interface to manage and interact with a CUDA graph node within a CUDA graph. It includes functionality for swapping, retrieving node information, and managing dependencies between nodes.

Public Functions

graph_node_ref() = default

Default constructor.

graph_node_ref(int, int = 0) = delete

Disallow construction from an int, e.g., 0.

graph_node_ref(cuda::std::nullptr_t, cuda::std::nullptr_t = nullptr) = delete

Disallow construction from nullptr.

inline explicit constexpr graph_node_ref(cudaGraphNode_t __node, cudaGraph_t __graph) noexcept

Constructs a graph_node_ref with a given CUDA graph node and graph.

Parameters
  • __node – The CUDA graph node.

  • __graph – The CUDA graph containing the node.

Pre

Both of __node and __graph are non-null.

Post

get() == __node

inline explicit constexpr operator bool() const noexcept

Checks if the graph node reference is valid.

This operator allows the graph node reference to be used in a boolean context to determine if it is valid. A valid graph node reference is one where the internal node pointer is not null.

Returns

true if the internal node pointer is not null, otherwise false.

inline constexpr auto operator!() const noexcept -> bool

Checks if the graph node reference is not null.

Returns

true if the internal node pointer is null, otherwise false.

inline constexpr void swap(graph_node_ref &__other) noexcept

Swaps the contents of this graph_node_ref with another.

Parameters

__other – The other graph_node_ref to swap with.

inline constexpr auto get() const noexcept -> cudaGraphNode_t

Retrieves the underlying CUDA graph node.

Returns

The CUDA graph node.

inline auto type() const -> graph_node_type

Retrieves the type of the CUDA graph node.

Throws

If – the CUDA API call to retrieve the node type fails.

Returns

The type of the graph node as a graph_node_type.

Pre

The internal graph node handle is not null.

template<class ..._Nodes>
inline constexpr void depends_on(const _Nodes&... __nodes)

Establishes dependencies between this node and other nodes. This function sets up dependencies such that this node depends on the provided nodes.

Template Parameters

_Nodes – Variadic template parameter for the types of the dependent nodes.

Parameters

__nodes – The nodes that this node depends on.

Throws

If – the CUDA API call to add dependencies fails.

Pre

The internal graph node handle is not null.

template<size_t _Extent>
inline constexpr void depends_on(cuda::std::span<cudaGraphNode_t, _Extent> __deps)

Establishes dependencies between this node and other nodes. This function sets up dependencies such that this node depends on the provided nodes.

  • This function first initializes an array of “dependant” nodes, where all dependant nodes correspond to this node.

  • The function then uses the CUDA API cudaGraphAddDependencies to establish the dependencies between this node and the nodes provided in the __deps span.

  • 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

__deps – A span of cudaGraphNode_t representing the dependencies of this node. Each node in the span will become a dependency of this node.

Throws

cuda::std::cuda_error – If the CUDA API call cudaGraphAddDependencies fails.

Friends

inline friend bool operator==(const graph_node_ref &__lhs, const graph_node_ref &__rhs) noexcept

Compares two graph_node_ref objects for equality.

Parameters
Returns

true if both graph_node_ref objects are equal, false otherwise.

inline friend bool operator!=(const graph_node_ref &__lhs, const graph_node_ref &__rhs) noexcept

Compares two graph_node_ref objects for inequality.

Parameters
Returns

true if both graph_node_ref objects are not equal, false otherwise.

inline friend bool operator==(cuda::std::nullptr_t, const graph_node_ref &__rhs) noexcept

Test whether a graph_node_ref object is null.

Returns

true if __rhs is null, false otherwise.

inline friend bool operator==(const graph_node_ref &__lhs, cuda::std::nullptr_t) noexcept

Test whether a graph_node_ref object is null.

Returns

true if __rhs is null, false otherwise.

inline friend bool operator!=(cuda::std::nullptr_t, const graph_node_ref &__rhs) noexcept

Test whether a graph_node_ref object is not null.

Returns

true if __rhs is not null, false otherwise.

inline friend bool operator!=(const graph_node_ref &__lhs, cuda::std::nullptr_t) noexcept

Test whether a graph_node_ref object is not null.

Returns

true if __lhs is not null, false otherwise.

inline friend void swap(graph_node_ref &__left, graph_node_ref &__right) noexcept

Swaps the contents of two graph_node_ref objects.

Parameters