MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / ExecContext

Method ExecContext

src/core/impl/graph/cg_impl_seq.cpp:117–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115};
116
117ComputingGraphImpl::ComputingSequence::ExecContext::ExecContext(
118 ComputingSequence* comp_seq)
119 : m_comp_seq{comp_seq},
120 m_owner_graph{comp_seq->m_owner_graph},
121 m_first_exec{comp_seq->m_first_exec},
122 m_fake_next_exec{comp_seq->m_owner_graph->options().fake_next_exec},
123 m_have_parent_graph{comp_seq->m_have_parent_graph} {
124 {
125 // lock the device memory manager to detect concurrent usage
126 auto dev_mem_mgr = m_comp_seq->m_owner_graph->var_node_mem_manager()
127 .static_device_memory_manager()
128 .get();
129 dev_mem_mgr->exec_enter();
130 m_cleanup_callback.add([dev_mem_mgr]() { dev_mem_mgr->exec_exit(); });
131 }
132
133 if (!m_have_parent_graph) {
134 // preprocess() would re-init static var mem plan and reallocate static
135 // memory if needed, but async var mem release depends on chunk refcnt
136 // which would be reset to one if mem plan is initialized, so we wait
137 // for previous run (including async var mem release) to finish before
138 // calling preprocess()
139 m_comp_seq->do_wait(false);
140 }
141
142 m_comp_seq->preprocess(this);
143
144 if (m_fake_next_exec) {
145 if (!m_enable_comp_node_seq_recorder) {
146 // fake exec is just for graph init; it has finished now
147 m_need_perform = false;
148 return;
149 }
150 // if m_enable_comp_node_seq_recorder and m_fake_next_exec are both
151 // true, we warm up by directly recording into CompNodeSeqRecorder; this
152 // is for best achievable efficiency. This requires var sanity check to
153 // be disabled and this should also be the first exec
154 mgb_assert(
155 !has_var_sanity_check() &&
156 (m_first_exec ||
157 m_owner_graph->options().comp_node_seq_record_level >= 2),
158 "if m_fake_next_exec and m_enable_comp_node_seq_recorder are "
159 "both set, they can only be set at the first run and var "
160 "sanity check should be disabled");
161 }
162
163 if (m_enable_comp_node_seq_recorder) {
164 // reset m_comp_node_seq_recorder and create new recorder if needed
165 try_reset_recorder();
166 }
167
168 if (m_fake_next_exec) {
169 // m_fake_next_exec without comp seq recorders has been handled
170 // above; so reaching here means both m_fake_next_exec and comp
171 // seq recorder are enabled.
172 warmup_for_fake_exec_with_recorder();
173 }
174}

Callers

nothing calls this directly

Calls 7

exec_enterMethod · 0.80
exec_exitMethod · 0.80
do_waitMethod · 0.80
getMethod · 0.45
addMethod · 0.45
preprocessMethod · 0.45

Tested by

no test coverage detected