MUDA
Loading...
Searching...
No Matches
compute_graph_closure.inl
1#include <muda/compute_graph/compute_graph_var_manager.h>
2#include <muda/compute_graph/compute_graph.h>
3
4namespace muda
5{
6MUDA_INLINE span<const ComputeGraphDependency> ComputeGraphClosure::deps() const
7{
8 return m_graph->dep_span(m_deps_begin, m_deps_count);
9}
10MUDA_INLINE void ComputeGraphClosure::graphviz_id(std::ostream& o,
11 const ComputeGraphGraphvizOptions& options) const
12{
13 o << "node_g" << options.graph_id << "_n" << clousure_id();
14}
15
16MUDA_INLINE void ComputeGraphClosure::graphviz_def(std::ostream& o,
17 const ComputeGraphGraphvizOptions& options) const
18{
19 graphviz_id(o, options);
20 o << "[";
21 o << "label=\"";
22
23 // "closure | { node1 | node2 | ... }"
24 if(!name().empty())
25 {
26 o << name();
27 }
28 else
29 {
30 graphviz_id(o, options);
31 }
32 if(options.show_all_graph_nodes_in_a_closure)
33 {
34
35 o << "|{";
36 for(auto& node : m_graph_nodes)
37 {
38 o << node->name();
39 if(&node != &m_graph_nodes.back())
40 o << "|";
41 }
42 o << "}";
43 }
44 o << "\", ";
45 if(options.show_all_graph_nodes_in_a_closure)
46 {
47 o << options.all_nodes_closure_style;
48 }
49 else
50 {
51 o << options.node_style;
52 }
53 o << "]";
54}
55
56MUDA_INLINE void ComputeGraphClosure::graphviz_var_usages(std::ostream& o,
57 const ComputeGraphGraphvizOptions& options) const
58{
59 for(auto&& [var_id, usage] : var_usages())
60 {
61 auto var = m_graph->m_var_manager->m_vars[var_id.value()];
62 var->graphviz_id(o, options);
63 o << "->";
64 graphviz_id(o, options);
65 if(usage == ComputeGraphVarUsage::ReadWrite)
66 o << "[" << options.read_write_style << "]";
67 else
68 o << "[" << options.read_style << "]";
69 o << "\n";
70 }
71}
72
73MUDA_INLINE void ComputeGraphClosure::set_deps_range(size_t begin, size_t count)
74{
75 m_deps_begin = begin;
76 m_deps_count = count;
77}
78} // namespace muda