| 632 | } |
| 633 | |
| 634 | SymbolVar ImmutableTensor::make_from_value( |
| 635 | ComputingGraph& graph, const Value& val, |
| 636 | const std::shared_ptr<Value>& val_refkeep, const OperatorNodeConfig& config) { |
| 637 | auto ud = graph.options() |
| 638 | .user_data.get_user_data_or_create<DevValueCache::VarNodeCache>( |
| 639 | std::make_shared<DevValueCache::VarNodeCache>); |
| 640 | SymbolVar& var = ud->val2var[&val]; |
| 641 | |
| 642 | if (!var.node()) { |
| 643 | var = graph.insert_opr(std::make_unique<ImmutableTensor>(graph, val, config)) |
| 644 | ->output(0); |
| 645 | if (val_refkeep) { |
| 646 | auto&& opr = var.node()->owner_opr()->cast_final<ImmutableTensor>(); |
| 647 | mgb_assert(&opr.m_value == val_refkeep.get() && !opr.m_value_refkeep); |
| 648 | opr.m_value_refkeep = val_refkeep; |
| 649 | } |
| 650 | } |
| 651 | #if !MGB_BUILD_SLIM_SERVING |
| 652 | // FIXME: make() of immutable tensor would return immediately instead of |
| 653 | // calling insert_opr() when hitting cache, so we need call it munually. |
| 654 | // see MGE-81 |
| 655 | else { |
| 656 | if (graph.options().eager_evaluation) { |
| 657 | auto&& opr = var.node()->owner_opr(); |
| 658 | graph.insert_opr(std::unique_ptr<OperatorNodeBase>(opr)); |
| 659 | } |
| 660 | } |
| 661 | #endif |
| 662 | return var; |
| 663 | } |
| 664 | |
| 665 | void ImmutableTensor::init_output_comp_node() { |
| 666 | comp_node(m_value.dev().comp_node()); |