cuda-api-wrappers
Thin C++-flavored wrappers for the CUDA Runtime API
node.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 #ifndef CUDA_API_WRAPPERS_NODE_HPP
8 #define CUDA_API_WRAPPERS_NODE_HPP
9 
10 #if CUDA_VERSION >= 10000
11 
12 #include "../types.hpp"
13 
14 namespace cuda {
15 
16 namespace graph {
17 
19 class node_t;
20 class template_t;
21 class instance_t;
23 
24 namespace node {
25 
26 node_t wrap(template_::handle_t graph_handle, handle_t handle) noexcept;
27 
28 namespace detail_ {
29 
30 ::std::string identify(const node_t &node);
31 
32 } // namespace detail_
33 
34 using type_t = CUgraphNodeType;
35 
36 } // namespace node
37 
51 class node_t {
52 public: // data types
53  using handle_type = node::handle_t;
54  using dependencies_type = ::std::vector<node_t>;
55  using dependents_type = ::std::vector<node_t>;
56  using type_type = node::type_t;
57  using size_type = size_t;
58 
59 // TODO: WRITEME
60 public:
61  handle_type handle() const noexcept { return handle_; }
62  template_t containing_graph() const noexcept;
63  template_::handle_t containing_graph_handle() const noexcept { return graph_template_handle_; }
64  type_type type_() const
65  {
66  type_type result;
67  auto status = cuGraphNodeGetType(handle_, &result);
68  throw_if_error_lazy(status, "Obtaining the type of " + node::detail_::identify(*this));
69  return result;
70  }
71 
72  size_t num_dependencies() const
73  {
74  size_t num_dependencies_;
75  auto status = cuGraphNodeGetDependencies(handle_, nullptr, &num_dependencies_);
76  throw_if_error_lazy(status, "Obtaining the number of nodes on which " + node::detail_::identify(*this) + " is dependent");
77  return num_dependencies_;
78  }
79 
80  size_t num_dependents() const
81  {
82  size_t num_dependents_;
83  auto status = cuGraphNodeGetDependentNodes(handle_, nullptr, &num_dependents_);
84  throw_if_error_lazy(status, "Obtaining the number of nodes dependent on " + node::detail_::identify(*this));
85  return num_dependents_;
86  }
87 
88  dependencies_type dependencies() const
89  {
90  size_type num_dependencies_ {num_dependencies() } ;
91  ::std::vector<node::handle_t> node_handles {num_dependencies_ };
92  auto status = cuGraphNodeGetDependencies(handle_, node_handles.data(), &num_dependencies_);
93  throw_if_error_lazy(status, "Obtaining the set nodes on which " + node::detail_::identify(*this) + " is dependent");
94  dependencies_type result;
95  for (const auto& node_handle : node_handles) {
96  result.emplace_back(node::wrap(graph_template_handle_, node_handle));
97  }
98  return result;
99  }
100 
101  dependencies_type dependents() const
102  {
103  size_type num_dependents_ { num_dependents() } ;
104  ::std::vector<node::handle_t> node_handles {num_dependents_ };
105  auto status = cuGraphNodeGetDependentNodes(handle_, node_handles.data(), &num_dependents_);
106  throw_if_error_lazy(status, "Obtaining the set nodes dependent on " + node::detail_::identify(*this));
107  dependencies_type result;
108  for (const auto& node_handle : node_handles) {
109  result.emplace_back(node::wrap(graph_template_handle_, node_handle));
110  }
111  return result;
112  }
113 
114 protected: // constructors and destructors
115  node_t(template_::handle_t graph_template_handle, handle_type handle) noexcept
116  : graph_template_handle_(graph_template_handle), handle_(handle) { }
117 
118 public: // friendship
119  friend node_t node::wrap(template_::handle_t graph_handle, node::handle_t handle) noexcept;
120 
121 public: // constructors and destructors
122  node_t(const node_t&) noexcept = default; // It's a reference type, so copying is not a problem
123  node_t(node_t&&) noexcept = default; // It's a reference type, so copying is not a problem
124 
125  node_t& operator=(node_t other) noexcept
126  {
127  graph_template_handle_ = other.graph_template_handle_;
128  handle_ = other.handle_;
129  return *this;
130  }
131 
132 protected:
133  template_::handle_t graph_template_handle_;
134  handle_type handle_;
135 };
136 
137 namespace node {
138 
139 inline node_t wrap(template_::handle_t graph_handle, handle_t handle) noexcept
140 {
141  return { graph_handle, handle };
142 }
143 
144 } // namespace node
145 
146 } // namespace graph
147 
148 } // namespace cuda
149 
150 #endif // CUDA_VERSION >= 10000
151 
152 #endif //CUDA_API_WRAPPERS_NODE_HPP
Definitions and functionality wrapping CUDA APIs.
Definition: array.hpp:22
::std::size_t size_t
A size type for use throughout the wrappers library (except when specific API functions limit the siz...
Definition: types.hpp:81
#define throw_if_error_lazy(status__,...)
A macro for only throwing an error if we&#39;ve failed - which also ensures no string is constructed unle...
Definition: error.hpp:316
CUarray handle_t
Raw CUDA driver handle for arrays (of any dimension)
Definition: array.hpp:34
array_t< T, NumDimensions > wrap(device::id_t device_id, context::handle_t context_handle, handle_t handle, dimensions_t< NumDimensions > dimensions) noexcept
Wrap an existing CUDA array in an array_t instance.
Definition: array.hpp:264
type_t
The CUDA execution ecosystem involves different memory spaces in their relation to a GPU device or th...
Definition: pointer.hpp:41