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

Method process_one_task

imperative/src/impl/interpreter/interpreter_impl.cpp:1201–1403  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1199}
1200
1201void ChannelImpl::process_one_task(Command& icmd) {
1202 using namespace ranges;
1203 using namespace ranges::views;
1204 auto& state = get_worker_state();
1205 auto& options = state.options;
1206 // TODO: remove std::visit for support osx 10.12
1207 auto cmd_visitor = [&](const auto& cmd) {
1208 using T = std::decay_t<decltype(cmd)>;
1209 if constexpr (std::is_same_v<T, Put>) {
1210 MGB_RECORD_EVENT(TensorCommandEvent, cmd.dest->id, TensorCommandKind::Put);
1211 MGB_RECORD_EVENT_IF(
1212 (Profiler::get_option("profile_device", 0)), RecordDeviceEvent,
1213 Timer::record_device(cmd.value.comp_node()));
1214 auto value = cmd.no_cache ? std::make_shared<Tensor>(cmd.value)
1215 : Tensor::make(cmd.value);
1216 MGB_RECORD_EVENT_IF(
1217 (Profiler::get_option("profile_device", 0)), RecordDeviceEvent,
1218 Timer::record_device(cmd.value.comp_node()));
1219 produce_tensor(cmd.dest, std::move(value));
1220 MGB_RECORD_EVENT(
1221 TensorCommandFinishEvent, cmd.dest->id, TensorCommandKind::Put);
1222 sample_on_device(cmd.dest->desc.comp_node, false);
1223 } else if constexpr (std::is_same_v<T, ApplyOp>) {
1224 for (auto& i : cmd.inputs) {
1225 if (mgb_unlikely(i->invalid)) {
1226 MGB_LOCK_GUARD(m_mutex);
1227 for (auto& i : cmd.outputs) {
1228 i->invalid = true;
1229 }
1230 return;
1231 }
1232 }
1233 if (state.options.enable_dtr_auto_drop) {
1234 m_apply_stack.push({cmd, 0, nullptr, "cmd"});
1235 flush_apply_stack();
1236 for (size_t i = 0; i < cmd.outputs.size(); ++i) {
1237 auto output = cmd.outputs[i];
1238 if (output == nullptr) {
1239 continue;
1240 }
1241 output->dsu_ptr = std::make_shared<DsuNode>(output->compute_time);
1242 }
1243 } else {
1244 do_apply_op(cmd, "cmd");
1245 }
1246 if (state.options.enable_drop && state.options.record_computing_path) {
1247 auto is_inplace = [](std::tuple<TensorInfo*, TensorInfo*> tuple2) {
1248 auto& input = std::get<0>(tuple2);
1249 auto& output = std::get<1>(tuple2);
1250 if (!input->ptr || !output->ptr) {
1251 return false;
1252 }
1253 return input->ptr->blob()->storage() ==
1254 output->ptr->blob()->storage();
1255 };
1256 // FIXME: do not use opname as identifier
1257 auto get_name = [](const OpDef& opdef) {
1258 if (auto attr = opdef.try_cast_final<OprAttr>()) {

Callers

nothing calls this directly

Calls 15

get_optionFunction · 0.85
get_nameFunction · 0.85
freeFunction · 0.85
storageMethod · 0.80
blobMethod · 0.80
is_bad_opMethod · 0.80
detach_producerMethod · 0.80
size_exceeds_thdMethod · 0.80
fetch_valueMethod · 0.80
set_optionMethod · 0.80

Tested by

no test coverage detected