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

Method dump

imperative/src/impl/transformations/trace.cpp:28–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26namespace imperative {
27
28VarNodeArray TraceResult::dump(
29 ComputingGraph& graph,
30 std::vector<std::tuple<size_t, std::string, TensorShape>> inputs,
31 std::vector<std::pair<size_t, std::string>> outputs, bool prefer_input_names) {
32 // var -> VarNode
33 std::vector<VarNode*> nodes(vars.size(), nullptr);
34 auto get_compnode = [](const VarInfo& info) -> CompNode {
35 auto& orig_cn = *(info.device);
36 std::string device_name_prefix =
37 orig_cn.locator_logical().to_string().substr(0, 3);
38 if (device_name_prefix == "cpu" || device_name_prefix == "gpu" ||
39 device_name_prefix == "xpu") {
40 return CompNode::load("xpux");
41 }
42 return orig_cn;
43 };
44 // make h2d node for each input
45 for (auto&& [input, name, shape] : inputs) {
46 auto& var = vars[input];
47 auto& node = nodes[input];
48
49 auto host =
50 std::make_shared<HostTensorND>(get_compnode(var), shape, *var.dtype);
51 OperatorNodeConfig config;
52 // if prefer_input_names, prefer names from dump args
53 // else prefer names got from trace procedure
54 if (prefer_input_names && !name.empty()) {
55 config.name(name);
56 } else if (!var.name.empty()) {
57 config.name(var.name);
58 } else if (!name.empty()) {
59 config.name(name);
60 }
61 node = opr::Host2DeviceCopy::make(graph, host, {}, config).node();
62 }
63 // make const node for each constant
64 for (size_t i = 0; i < vars.size(); ++i) {
65 auto& var = vars[i];
66 auto& node = nodes[i];
67 if (!node) {
68 if (var.kind != VarKind::Internal) {
69 if (!var.bound_data) {
70 continue;
71 }
72 if (!var.name.empty()) {
73 node = opr::ImmutableTensor::make(
74 graph, var.bound_data.numpy()->as_nd(), {var.name})
75 .node();
76 } else {
77 node = opr::ImmutableTensor::make(
78 graph, var.bound_data.numpy()->as_nd())
79 .node();
80 }
81 }
82 }
83 }
84 std::unordered_map<std::string, std::vector<cg::OperatorNodeBase*>> name2ops;
85 // iterate over opr_seq

Callers

nothing calls this directly

Calls 15

as_ndMethod · 0.80
loadFunction · 0.50
makeFunction · 0.50
apply_on_var_nodeFunction · 0.50
sizeMethod · 0.45
to_stringMethod · 0.45
locator_logicalMethod · 0.45
emptyMethod · 0.45
nameMethod · 0.45
nodeMethod · 0.45
numpyMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected