| 183 | } |
| 184 | |
| 185 | void LazyEvalTransformation::on_unregister() noexcept { |
| 186 | std::vector<LazyEvalValue::ref_t> lazy_vals; |
| 187 | for (auto&& weak_var : m_weak_vars) { |
| 188 | if (auto lazy_val = weak_var.lock()) { |
| 189 | lazy_vals.push_back(lazy_val); |
| 190 | } |
| 191 | } |
| 192 | CleanupGuard _{[this] { |
| 193 | m_graph.reset(); |
| 194 | m_weak_vars.clear(); |
| 195 | }}; |
| 196 | if (m_no_exec) { |
| 197 | for (auto&& lazy_val : lazy_vals) { |
| 198 | if (lazy_val->bound_data()) { |
| 199 | auto value = lazy_val->bound_data(); |
| 200 | lazy_val.reset(value); |
| 201 | } else { |
| 202 | lazy_val.reset(ErrorValue::make("no data bound")); |
| 203 | } |
| 204 | } |
| 205 | return; |
| 206 | } |
| 207 | std::mutex mtx; |
| 208 | std::vector<std::pair<LazyEvalValue::ref_t, DeviceTensorND>> values; |
| 209 | ComputingGraph::OutputSpec output_specs; |
| 210 | for (auto&& lazy_val : lazy_vals) { |
| 211 | auto* output = opr::OutputCallback::make( |
| 212 | {[lazy_val, &mtx, &values](DeviceTensorND data) { |
| 213 | MGB_LOCK_GUARD(mtx); |
| 214 | values.push_back({lazy_val, data}); |
| 215 | }}, |
| 216 | lazy_val->node()) |
| 217 | .node(); |
| 218 | output_specs.push_back({output, {}}); |
| 219 | } |
| 220 | if (m_io_link.node()) { |
| 221 | output_specs.push_back({m_io_link, {}}); |
| 222 | } |
| 223 | if (output_specs.empty()) { |
| 224 | return; |
| 225 | } |
| 226 | { |
| 227 | // set_priority_to_id |
| 228 | auto on_opr = [](mgb::cg::OperatorNodeBase* opr) { |
| 229 | if (opr->node_prop().attribute().priority == 0) { |
| 230 | opr->node_prop().attribute().priority = opr->id(); |
| 231 | } |
| 232 | }; |
| 233 | mgb::cg::DepOprIter dep_iter{on_opr}; |
| 234 | for (auto&& output_spec : output_specs) { |
| 235 | dep_iter.add(output_spec.first); |
| 236 | } |
| 237 | } |
| 238 | try { |
| 239 | auto exectuble = m_graph->compile(output_specs); |
| 240 | exectuble->execute(); |
| 241 | exectuble->wait(); |
| 242 | } catch (...) { |
nothing calls this directly
no test coverage detected