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

Method load_tensor

src/serialization/impl/serializer_oss_v2.cpp:613–639  ·  view source on GitHub ↗

the opr loader should make sure the exist of tensors and the number of tensor, here just assert it.

Source from the content-addressed store, hash-verified

611//! the opr loader should make sure the exist of tensors and the number of
612//! tensor, here just assert it.
613std::shared_ptr<HostTensorND> GraphLoaderOSSV2::OprLoadContextImpl::load_tensor() {
614 mgb_assert(
615 m_current_opr->tensors() &&
616 m_cur_opr_tensor_cnt < m_current_opr->tensors()->size());
617 auto tensor = m_current_opr->tensors()->Get(m_cur_opr_tensor_cnt++);
618 auto comp_node = load_comp_node(tensor->comp_node());
619 auto layout = load_tensor_layout_without_format(tensor);
620 auto ret = std::make_shared<HostTensorND>(comp_node, layout);
621
622 auto&& loader = m_loader->m_cur_load_config->tensor_value_loader;
623 if (tensor->data() && tensor->data()->size() > 0) {
624 fill_tensor_memory(
625 *ret, tensor->data()->data(), tensor->data()->size(),
626 m_loader->m_file->is_shared_memory(), loader);
627 }
628 if (tensor->name()) {
629 m_tensor_map[tensor->name()->str()] = ret;
630 }
631 if (auto&& mod = m_loader->m_cur_load_config->tensor_modifier) {
632 bool has_value = false;
633 if (tensor && tensor->data()) {
634 has_value = tensor->data()->size() != 0;
635 }
636 mod(tensor->name() ? tensor->name()->str() : "", has_value, *ret);
637 }
638 return ret;
639}
640
641std::shared_ptr<DeviceTensorND> GraphLoaderOSSV2::OprLoadContextImpl::
642 load_tensor_shared(bool copy_immediatly) {

Callers

nothing calls this directly

Calls 9

tensorsMethod · 0.80
modFunction · 0.50
sizeMethod · 0.45
comp_nodeMethod · 0.45
dataMethod · 0.45
is_shared_memoryMethod · 0.45
nameMethod · 0.45
strMethod · 0.45

Tested by

no test coverage detected