| 391 | } |
| 392 | |
| 393 | void TensorImplDft::copy_from_fixlayout(const TensorImplBase* src_impl) { |
| 394 | auto src = static_cast<const TensorImplDft*>(src_impl); |
| 395 | if (is_host()) { |
| 396 | //! host to host |
| 397 | if (src->is_host()) { |
| 398 | m_host_tensor->copy_from_fixlayout(*src->m_host_tensor); |
| 399 | //! device to host |
| 400 | } else { |
| 401 | auto src_cn = src->m_dev_tensor->comp_node(); |
| 402 | auto dst_cn = m_host_tensor->comp_node(); |
| 403 | if (src_cn != dst_cn && m_host_tensor->layout().ndim > 0) { |
| 404 | LITE_WARN( |
| 405 | "The dst tensor memroy is alloced before coping, " |
| 406 | "then pinned memroy would not use to optmize the " |
| 407 | "copy performance."); |
| 408 | //! When D2H in megbrain and the compnode of src and dst is not |
| 409 | //! equal, there must be one compnode that is cpu-default, so |
| 410 | //! here, we use temp tensor for transition |
| 411 | auto tmp_impl = std::make_shared<TensorImplDft>(); |
| 412 | tmp_impl->set_mge_tensor_compnode(src_cn); |
| 413 | tmp_impl->m_host_tensor->copy_from(*src->m_dev_tensor).sync(); |
| 414 | m_host_tensor->copy_from_fixlayout(*tmp_impl->m_host_tensor); |
| 415 | } else { |
| 416 | //! if dst compnode is not valid(memory is not alloced), the |
| 417 | //! tensor is pinned host tensor |
| 418 | m_host_tensor->comp_node(src_cn, true); |
| 419 | m_host_tensor->copy_from_fixlayout(*src->m_dev_tensor).sync(); |
| 420 | } |
| 421 | } |
| 422 | } else { |
| 423 | //! host to device |
| 424 | if (src->is_host()) { |
| 425 | m_dev_tensor->copy_from_fixlayout(*src->m_host_tensor).sync(); |
| 426 | //! device to device |
| 427 | } else { |
| 428 | m_dev_tensor->copy_from_fixlayout(*src->m_dev_tensor).sync(); |
| 429 | } |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | void TensorImplDft::copy_from_mge_tensor(const mgb::DeviceTensorND& dv) { |
| 434 | if (is_host()) { |