Taskflow  2.4-master-branch
cuda_task.hpp
1 #pragma once
2 
3 #include "cuda_graph.hpp"
4 
5 namespace tf {
6 
12 class cudaTask {
13 
14  friend class cudaFlow;
15 
16  public:
17 
21  cudaTask() = default;
22 
26  cudaTask(const cudaTask&) = default;
27 
31  cudaTask& operator = (const cudaTask&) = default;
32 
42  template <typename... Ts>
43  cudaTask& precede(Ts&&... tasks);
44 
54  template <typename... Ts>
55  cudaTask& succeed(Ts&&... tasks);
56 
64  cudaTask& name(const std::string& name);
65 
69  const std::string& name() const;
70 
74  size_t num_successors() const;
75 
79  bool empty() const;
80 
81  private:
82 
83  cudaTask(cudaNode*);
84 
85  cudaNode* _node {nullptr};
86 
88  template <typename T>
89  void _precede(T&&);
90 
92  template <typename T, typename... Ts>
93  void _precede(T&&, Ts&&...);
94 
96  template <typename T>
97  void _succeed(T&&);
98 
99  // @private
100  template <typename T, typename... Ts>
101  void _succeed(T&&, Ts&&...);
102 };
103 
104 // Constructor
105 inline cudaTask::cudaTask(cudaNode* node) : _node {node} {
106 }
107 
108 // Function: precede
109 template <typename... Ts>
110 cudaTask& cudaTask::precede(Ts&&... tasks) {
111  _precede(std::forward<Ts>(tasks)...);
112  return *this;
113 }
114 
116 // Procedure: precede
117 template <typename T>
118 void cudaTask::_precede(T&& other) {
119  _node->_precede(other._node);
120 }
121 
123 // Procedure: _precede
124 template <typename T, typename... Ts>
125 void cudaTask::_precede(T&& task, Ts&&... others) {
126  _precede(std::forward<T>(task));
127  _precede(std::forward<Ts>(others)...);
128 }
129 
130 // Function: succeed
131 template <typename... Ts>
132 cudaTask& cudaTask::succeed(Ts&&... tasks) {
133  _succeed(std::forward<Ts>(tasks)...);
134  return *this;
135 }
136 
138 // Procedure: _succeed
139 template <typename T>
140 void cudaTask::_succeed(T&& other) {
141  other._node->_precede(_node);
142 }
143 
145 // Procedure: _succeed
146 template <typename T, typename... Ts>
147 void cudaTask::_succeed(T&& task, Ts&&... others) {
148  _succeed(std::forward<T>(task));
149  _succeed(std::forward<Ts>(others)...);
150 }
151 
152 // Function: empty
153 inline bool cudaTask::empty() const {
154  return _node == nullptr;
155 }
156 
157 // Function: name
158 inline cudaTask& cudaTask::name(const std::string& name) {
159  _node->_name = name;
160  return *this;
161 }
162 
163 // Function: name
164 inline const std::string& cudaTask::name() const {
165  return _node->_name;
166 }
167 
168 // Function: num_successors
169 inline size_t cudaTask::num_successors() const {
170  return _node->_successors.size();
171 }
172 
173 } // end of namespace tf -----------------------------------------------------
cudaTask & precede(Ts &&... tasks)
adds precedence links from this to other tasks
Definition: cuda_task.hpp:110
cudaTask & succeed(Ts &&... tasks)
adds precedence links from other tasks to this
Definition: cuda_task.hpp:132
Definition: error.hpp:9
methods for building a CUDA task dependency graph.
Definition: cuda_flow.hpp:18
bool empty() const
queries if the task is associated with a cudaNode
Definition: cuda_task.hpp:153
handle to a node in a cudaGraph
Definition: cuda_task.hpp:12
cudaTask()=default
constructs an empty cudaTask
size_t num_successors() const
queries the number of successors
Definition: cuda_task.hpp:169
cudaTask & operator=(const cudaTask &)=default
copy-assigns a cudaTask
const std::string & name() const
queries the name of the task
Definition: cuda_task.hpp:164