RAJA
RAJA provides a collection of platform portability abstractions for C++ HPC applications.
DepGraphNode.hpp
Go to the documentation of this file.
1 
12 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
13 // Copyright (c) Lawrence Livermore National Security, LLC and other
14 // RAJA Project Developers. See top-level LICENSE and COPYRIGHT
15 // files for dates and other details. No copyright assignment is required
16 // to contribute to RAJA.
17 //
18 // SPDX-License-Identifier: (BSD-3-Clause)
19 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~//
20 
21 #ifndef RAJA_DepGraphNode_HPP
22 #define RAJA_DepGraphNode_HPP
23 
24 #include "RAJA/config.hpp"
25 
26 #include <atomic>
27 #include <cstdlib>
28 #include <iosfwd>
29 #include <thread>
30 
31 #include "RAJA/util/types.hpp"
32 
33 namespace RAJA
34 {
35 
44 class RAJA_ALIGNED_ATTR(256) DepGraphNode
45 {
46 public:
55  static const int _MaxDepTasks_ = 8;
56 
60  DepGraphNode()
61  : m_num_dep_tasks(0),
62  m_semaphore_reload_value(0),
63  m_semaphore_value(0)
64  {}
65 
70  std::atomic<int>& semaphoreValue() { return m_semaphore_value; }
71 
76  int& semaphoreReloadValue() { return m_semaphore_reload_value; }
77 
81  void reset() { m_semaphore_value.store(m_semaphore_reload_value); }
82 
86  void satisfyOne()
87  {
88  if (m_semaphore_value > 0)
89  {
90  --m_semaphore_value;
91  }
92  }
93 
97  void wait()
98  {
99  while (m_semaphore_value > 0)
100  {
101  // TODO: an efficient wait would be better here, but the standard
102  // promise/future is not good enough
103  std::this_thread::yield();
104  }
105  }
106 
111  int& numDepTasks() { return m_num_dep_tasks; }
112 
118  int& depTaskNum(int tidx) { return m_dep_task[tidx]; }
119 
123  void print(std::ostream& os) const;
124 
125 private:
126  int m_dep_task[_MaxDepTasks_];
127  int m_num_dep_tasks;
128  int m_semaphore_reload_value;
129  std::atomic<int> m_semaphore_value;
130 };
131 
132 } // namespace RAJA
133 
134 #endif // closing endif for header file include guard
Definition: AlignedRangeIndexSetBuilders.cpp:35
class RAJA_ALIGNED_ATTR(256) DepGraphNode
Class defining a simple semephore-based data structure for managing a node in a dependency graph.
Definition: DepGraphNode.hpp:44
Header file for RAJA type definitions.