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

Method apply_transformation

imperative/src/impl/transformations/eval.cpp:101–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101ValueRefList InterpreterTransformation::apply_transformation(
102 const Operator& op, Span<ValueRef> inputs) {
103 if (auto* op_val = op.as<ApplyOp>()) {
104 if (op_val->op().same_type<FastpathCopy>()) {
105 return inputs[0];
106 } else {
107 return apply_op(*op_val, inputs);
108 }
109 } else if (auto* get_attr = op.as<GetAttr>()) {
110 return apply_get_attr(*get_attr, inputs);
111 } else if (auto* create_tensor = op.as<CreateTensor>()) {
112 return apply_create_tensor(*create_tensor, inputs);
113 } else if (auto* dtr_command = op.as<DTRCommand>()) {
114 auto handle = inputs[0].cast(m_value_type).handle()->handle();
115 switch (dtr_command->kind()) {
116 case DTRCommand::Drop:
117 m_channel->drop(handle);
118 break;
119 default:
120 mgb_throw(AssertionError, "unknown DTRCommand %d", dtr_command->kind());
121 }
122 return {};
123 } else if (auto* rename_value = op.as<RenameValue>()) {
124 auto& input = inputs[0].cast(m_value_type);
125 return {m_value_type.make(input.handle(), rename_value->name())};
126 } else if (op.is<GetName>()) {
127 auto name = inputs[0].cast(m_value_type).name();
128 if (!name.empty()) {
129 return {StringValue::make(name)};
130 } else {
131 return {ValueRef()};
132 }
133 } else if (op.is<GetId>()) {
134 auto& val = inputs[0].cast(m_value_type);
135 int64_t id = val.id();
136 return {IntegerValue::make(id)};
137
138 } else if (op.is<DupTensor>()) {
139 auto& input = inputs[0].cast(m_value_type);
140 DeviceTensorND dev_tensor;
141 dev_tensor.copy_from(m_channel->get_dev_tensor(input.handle()->handle()));
142 return m_value_type.make(share_handle(m_channel->put(dev_tensor, {})));
143 } else if (auto push_scope = op.as<PushScope>()) {
144 m_channel->push_scope(push_scope->name, push_scope->type);
145 return {};
146 } else if (auto pop_scope = op.as<PopScope>()) {
147 m_channel->pop_scope(pop_scope->name, pop_scope->type);
148 return {};
149 } else {
150 return op.fallback(inputs);
151 }
152}
153
154} // namespace imperative
155} // namespace mgb

Callers 2

apply_releaseFunction · 0.45
ValueRefList apply_debugFunction · 0.45

Calls 15

get_dev_tensorMethod · 0.80
makeFunction · 0.50
ValueRefClass · 0.50
opMethod · 0.45
handleMethod · 0.45
castMethod · 0.45
kindMethod · 0.45
dropMethod · 0.45
makeMethod · 0.45
nameMethod · 0.45
emptyMethod · 0.45
idMethod · 0.45

Tested by

no test coverage detected