1#include <muda/compute_graph/compute_graph.h>
5MUDA_INLINE ComputeGraphPhase ComputeGraphBuilder::current_phase()
7 auto ins = instance().m_current_graph;
9 return ins->current_graph_phase();
11 return ComputeGraphPhase::None;
14MUDA_INLINE
void ComputeGraphBuilder::capture(CaptureAction&& cap)
16 MUDA_ASSERT(instance().current_graph(),
"Error current graph = nullptr!");
17 instance().current_graph()->capture(std::move(cap));
20MUDA_INLINE
void ComputeGraphBuilder::capture(std::string_view name, CaptureAction&& cap)
22 MUDA_ASSERT(instance().current_graph(),
"Error current graph = nullptr!");
23 instance().current_graph()->capture(name, std::move(cap));
26MUDA_INLINE
bool ComputeGraphBuilder::is_phase_none()
28 return current_phase() == ComputeGraphPhase::None;
31MUDA_INLINE
bool ComputeGraphBuilder::is_phase_serial_launching()
33 return current_phase() == ComputeGraphPhase::SerialLaunching;
36MUDA_INLINE
bool ComputeGraphBuilder::is_topo_building()
38 return current_phase() == ComputeGraphPhase::TopoBuilding;
41MUDA_INLINE
bool ComputeGraphBuilder::is_building()
43 return current_phase() == ComputeGraphPhase::Building;
46MUDA_INLINE
bool ComputeGraphBuilder::is_direct_launching()
48 return is_phase_serial_launching() || is_phase_none();
51MUDA_INLINE
bool ComputeGraphBuilder::is_caturing()
53 return is_building() && instance().m_current_graph->m_is_capturing;
56MUDA_INLINE
void ComputeGraphBuilder::invoke_phase_actions(PhaseAction&& do_when_direct_launching,
57 PhaseAction&& do_when_set_node,
58 PhaseAction&& do_when_topo_building)
60 MUDA_ASSERT(do_when_direct_launching,
"do_when_direct_launching is null");
61 MUDA_ASSERT(do_when_set_node,
"do_when_set_node is null");
62 MUDA_ASSERT(do_when_topo_building,
"do_when_topo_building is null");
63 if(is_direct_launching())
64 do_when_direct_launching();
65 else if(is_building())
67 else if(is_topo_building())
68 do_when_topo_building();
71MUDA_INLINE
void ComputeGraphBuilder::invoke_phase_actions(PhaseAction&& do_when_direct_launching,
72 PhaseAction&& do_when_set_node)
74 MUDA_ASSERT(do_when_direct_launching,
"do_when_direct_launching is null");
75 MUDA_ASSERT(do_when_set_node,
"do_when_set_node is null");
77 if(is_direct_launching())
78 do_when_direct_launching();
79 else if(is_building() || is_topo_building())
83MUDA_INLINE
void ComputeGraphBuilder::invoke_phase_actions(PhaseAction&& do_in_every_phase)
85 if(is_direct_launching() || is_building() || is_topo_building())
89MUDA_INLINE
void ComputeGraphBuilder::current_graph(ComputeGraph* graph)
91 instance().m_current_graph = graph;
94MUDA_INLINE ComputeGraphBuilder& muda::ComputeGraphBuilder::instance()
96 thread_local static ComputeGraphBuilder builder;