| 569 | /*********************** Common Impl ***********************/ |
| 570 | |
| 571 | TensorPtr ProxyGraph::as_tensor(cg::OperatorNodeBase* opr, bool share) { |
| 572 | // TODO : maybe some tensor should copy value from origin opr rather than |
| 573 | // share the RawStorage |
| 574 | mgb_assert(share, "can't share memory with opr %s", opr->cname()); |
| 575 | if (opr->same_type<opr::ImmutableTensor>()) { |
| 576 | auto&& dv = opr->cast_final_safe<opr::ImmutableTensor>().value(); |
| 577 | HostTensorND hv(dv.comp_node(), dv.shape(), dv.dtype()); |
| 578 | const DeviceTensorND* cpu_value; |
| 579 | // get host value |
| 580 | if (opr->owner_graph() == m_graph.get()) { |
| 581 | CUR_OPR_GUARD(opr); |
| 582 | m_static_infer_manager->update(); |
| 583 | cpu_value = m_static_infer_manager->infer_value_fallible(opr->output(0)); |
| 584 | } else { |
| 585 | cpu_value = opr->owner_graph()->static_infer_manager().infer_value_fallible( |
| 586 | opr->output(0)); |
| 587 | } |
| 588 | mgb_assert(cpu_value); |
| 589 | mgb_assert(cpu_value->comp_node() == CompNode::default_cpu()); |
| 590 | // default_cpu is synchronous with respect to caller |
| 591 | hv.proxy_to_default_cpu().copy_from_fixlayout(*cpu_value); |
| 592 | return Tensor::make(dv, hv); |
| 593 | } else if (opr->same_type<opr::SharedDeviceTensor>()) { |
| 594 | return Tensor::make( |
| 595 | opr->cast_final_safe<opr::SharedDeviceTensor>().get_dev_tensor()); |
| 596 | } else { |
| 597 | return {}; |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | thread_local std::unique_ptr<MegBrainError> ProxyGraph::tm_async_error; |
| 602 |
nothing calls this directly
no test coverage detected