| 604 | } |
| 605 | |
| 606 | ValueRef 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 | |
| 660 | auto CompiledTransformation::trace_output(size_t id, ValueRef value) |
| 661 | -> TracedValue::ref_t { |
nothing calls this directly
no test coverage detected