muda
compute_graph_closure.h
1 #pragma once
2 #include <functional>
3 #include <map>
4 #include <muda/compute_graph/compute_graph_node_type.h>
5 #include <muda/compute_graph/compute_graph_node.h>
6 #include <muda/compute_graph/compute_graph_node_id.h>
7 #include <muda/compute_graph/compute_graph_var_usage.h>
8 #include <muda/compute_graph/compute_graph_var_id.h>
9 #include <muda/compute_graph/graphviz_options.h>
10 #include <muda/compute_graph/compute_graph_dependency.h>
11 
12 namespace muda
13 {
15 {
16  friend class details::ComputeGraphAccessor;
17 
18  public:
19  auto clousure_id() const { return m_clousure_id; }
20  auto type() const { return m_type; }
21  auto name() const { return std::string_view{m_name}; }
22  const auto& var_usages() const { return m_var_usages; }
23  span<const ComputeGraphDependency> deps() const;
24 
25  virtual void graphviz_id(std::ostream& o, const ComputeGraphGraphvizOptions& options) const;
26  virtual void graphviz_def(std::ostream& o, const ComputeGraphGraphvizOptions& options) const;
27  virtual void graphviz_var_usages(std::ostream& o,
28  const ComputeGraphGraphvizOptions& options) const;
29  virtual ~ComputeGraphClosure() = default;
30 
31  protected:
32  template <typename T>
33  using S = std::shared_ptr<T>;
34 
35  friend class ComputeGraph;
36  friend class ComputeGraphVarBase;
38  ClosureId clousure_id,
39  std::string_view name,
40  const std::function<void()> f)
41  : m_graph(graph)
42  , m_clousure_id(clousure_id)
43  , m_name(name)
44  , m_closure(f)
45  {
46  }
47 
48  std::function<void()> m_closure;
49  std::map<VarId, ComputeGraphVarUsage> m_var_usages;
50  ClosureId m_clousure_id;
51  uint64_t m_access_graph_index;
52  ComputeGraph* m_graph;
53  std::string m_name;
54  ComputeGraphNodeType m_type;
55  size_t m_deps_begin = 0;
56  size_t m_deps_count = 0;
57 
58  void operator()() { m_closure(); }
59 
60  std::vector<ComputeGraphNodeBase*> m_graph_nodes;
61  void set_deps_range(size_t begin, size_t count);
62 };
63 } // namespace muda
64 
65 #include "details/compute_graph_closure.inl"
Definition: compute_graph_var.h:16
Definition: compute_graph_closure_id.h:5
Definition: assert.h:13
Definition: graphviz_options.h:5
Definition: compute_graph_accessor.h:12
Definition: compute_graph.h:37
Definition: compute_graph_closure.h:14