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

Method copy_from_fixlayout

lite/src/mge/tensor_impl.cpp:393–431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

391}
392
393void 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
433void TensorImplDft::copy_from_mge_tensor(const mgb::DeviceTensorND& dv) {
434 if (is_host()) {

Callers 15

as_tensorMethod · 0.80
TensorMethod · 0.80
apply_on_physical_tensorFunction · 0.80
apply_on_physical_tensorFunction · 0.80
apply_on_physical_tensorFunction · 0.80
dispatch_default_cpuMethod · 0.80
make_complex_tensorMethod · 0.80
apply_transformationMethod · 0.80
scn_do_executeMethod · 0.80
applyMethod · 0.80
TESTFunction · 0.80

Calls 6

is_hostMethod · 0.80
comp_nodeMethod · 0.45
layoutMethod · 0.45
syncMethod · 0.45
copy_fromMethod · 0.45

Tested by 14

TESTFunction · 0.64
run_comp_seq_rec_basicFunction · 0.64
run<multi_recorder_run>Function · 0.64
run_noncontig_testFunction · 0.64
TESTFunction · 0.64
do_trainMethod · 0.64
TESTFunction · 0.64
TESTFunction · 0.64
TESTFunction · 0.64
scn_do_executeFunction · 0.64
TESTFunction · 0.64