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

Method assign_dev_tensor_from_tensor

src/core/impl/graph/var_node.cpp:382–408  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

380}
381
382void VarNode::assign_dev_tensor_from_tensor(const DeviceTensorND& value) {
383 mgb_assert(
384 (value.layout().is_contiguous() || value.empty()) &&
385 m_dev_tensor.dtype() == value.dtype() &&
386 m_dev_tensor.format() == value.format());
387 if (value.empty()) {
388 mgb_assert(value.shape_valid() && value.layout().is_empty());
389 bool allow_empty = contain_flag(VarNode::Flag::ALLOW_EMPTY_SHAPE);
390 auto&& recv = owner_graph()->var_receiver_in_current_comp_seq(this);
391 mgb_throw_if(
392 !allow_empty || !recv.is_empty_allowed(), GraphError,
393 "assign empty tensor to var %s, but allowed=%d, receiver=%s",
394 cg::dump_var_info({this}).c_str(), allow_empty,
395 recv.to_string().c_str());
396 }
397 if (cg::is_static_var_shape(this)) {
398 mgb_assert(
399 shape().eq_shape(value.shape()),
400 "shape mismatch for static inferrable var when setting dev "
401 "tensor: var=%s new_shape=%s",
402 cg::dump_var_info({this}).c_str(), value.shape().to_string().c_str());
403 }
404 m_dev_tensor.reset(value.storage(), value.layout());
405 m_dev_tensor.comp_node(comp_node());
406 m_prev_dev_ptr = value.raw_ptr();
407 mgb_assert(dev_tensor_valid());
408}
409
410VarNode& VarNode::add_rt_force_dynamic_mem_alloc_imply_chain(VarNode* dest) {
411 mgb_assert(

Callers 2

init_output_tensorMethod · 0.80
ensure_input_layoutMethod · 0.80

Calls 15

is_static_var_shapeFunction · 0.85
comp_nodeFunction · 0.85
is_empty_allowedMethod · 0.80
storageMethod · 0.80
shapeFunction · 0.70
is_contiguousMethod · 0.45
layoutMethod · 0.45
emptyMethod · 0.45
dtypeMethod · 0.45
formatMethod · 0.45
shape_validMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected