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

Method trace_input

imperative/src/impl/transformations/trace.cpp:606–658  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

604}
605
606ValueRef CompiledTransformation::trace_input(size_t id, ValueRef value) {
607 try {
608 auto& var = m_vars[id];
609 auto& var_accessor = m_var_accessors[id];
610 switch (var.kind) {
611 case VarKind::External: {
612 trace_assert(
613 !value.is(m_value_type), "expect external node, got internal");
614 if (var.bound_data) {
615 assert_tensor_equal(var.bound_data, value);
616 } else {
617 DType dtype = *value.dtype();
618 CompNode device = *value.device();
619 trace_assert(
620 *var.dtype == dtype, "dtype mismatch: %s vs %s",
621 var.dtype->name(), dtype.name());
622 trace_assert(
623 *var.device == device, "comp_node mismatch: %s vs %s",
624 var.device->to_string().c_str(),
625 device.to_string().c_str());
626 }
627 if (m_setted_extern.find(id) == m_setted_extern.end()) {
628 var_accessor.data_setter(value.dev_tensor()->as_nd());
629 m_setted_extern.insert(id);
630 }
631 return value;
632 }
633 case VarKind::Constant: {
634 // expect host value here
635 mgb_assert(var.bound_data, "const var without data bound");
636 assert_tensor_equal(var.bound_data, value);
637 // TODO: use value
638 return var.bound_data;
639 }
640 case VarKind::Internal: {
641 trace_assert(
642 value.is(m_value_type), "expect internal node, got external");
643 auto& traced_value = value.cast(m_value_type);
644 trace_assert(traced_value.id() == id, "input id mismatch");
645 return traced_value.get_imperative_value();
646 }
647 default:
648 trace_assert(false, "unknown var kind");
649 }
650 } catch (TraceError&) {
651 throw;
652 } catch (const std::exception& exc) {
653 mgb_log_error("unexpected error %s", exc.what());
654 throw;
655 } catch (...) {
656 mgb_assert(false, "unexpected error");
657 }
658}
659
660auto CompiledTransformation::trace_output(size_t id, ValueRef value)
661 -> TracedValue::ref_t {

Callers

nothing calls this directly

Calls 14

as_ndMethod · 0.80
get_imperative_valueMethod · 0.80
isMethod · 0.45
dtypeMethod · 0.45
deviceMethod · 0.45
nameMethod · 0.45
to_stringMethod · 0.45
findMethod · 0.45
endMethod · 0.45
dev_tensorMethod · 0.45
insertMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected