MCPcopy Create free account
hub / github.com/ROCm/AMDMIGraphX / assign

Method assign

src/module.cpp:157–215  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155void module::set_bypass(bool b) { impl->bypass = b; }
156
157void module::assign(const module& m)
158{
159 // copy the impl
160 if(not impl)
161 impl = std::make_unique<module_impl>();
162 *impl = *m.impl;
163
164 // clear instructions
165 if(not impl->instructions.empty())
166 {
167 impl->clear();
168 }
169
170 std::unordered_map<instruction_ref, instruction_ref> ins_map;
171 for(auto ins : iterator_for(m))
172 {
173 instruction_ref copy_ins{};
174 if(ins->name() == "@literal")
175 {
176 auto l = ins->get_literal();
177 copy_ins = impl->insert(impl->instructions.end(), instruction{l});
178 }
179 else if(ins->name() == "@param")
180 {
181 auto&& name = any_cast<builtin::param>(ins->get_operator()).parameter;
182 auto order = any_cast<builtin::param>(ins->get_operator()).order;
183 auto s = ins->get_shape();
184 copy_ins = impl->insert(impl->instructions.end(),
185 {builtin::param{name, order}, std::move(s), {}});
186 impl->nparams++;
187 }
188 else if(ins->name() == "@outline")
189 {
190 auto s = ins->get_shape();
191 copy_ins = impl->insert(impl->instructions.end(), {builtin::outline{s}, s, {}});
192 }
193 else
194 {
195 // if there are sub_module inputs, need to make a copy of the submodule
196 auto module_args = ins->module_inputs();
197 // retrieve its mapped input
198 auto inputs = ins->inputs();
199 std::vector<instruction_ref> copy_inputs(inputs.size());
200 std::transform(inputs.begin(), inputs.end(), copy_inputs.begin(), [&](auto i) {
201 return contains(ins_map, i) ? ins_map[i] : i;
202 });
203 if(ins->name() == "@return")
204 {
205 copy_ins = add_return(copy_inputs);
206 }
207 else
208 {
209 copy_ins = add_instruction(ins->get_operator(), copy_inputs, module_args);
210 }
211 }
212
213 ins_map[ins] = copy_ins;
214 }

Callers 15

TEST_CASEFunction · 0.45
TEST_CASEFunction · 0.45
TEST_CASEFunction · 0.45
TEST_CASEFunction · 0.45
TEST_CASEFunction · 0.45
TEST_CASEFunction · 0.45
TEST_CASEFunction · 0.45
run_progFunction · 0.45
TEST_CASEFunction · 0.45
run_progFunction · 0.45
TEST_CASEFunction · 0.45
TEST_CASEFunction · 0.45

Calls 14

iterator_forFunction · 0.85
containsFunction · 0.85
add_returnFunction · 0.85
transformFunction · 0.50
add_instructionFunction · 0.50
emptyMethod · 0.45
clearMethod · 0.45
nameMethod · 0.45
insertMethod · 0.45
endMethod · 0.45
get_shapeMethod · 0.45
inputsMethod · 0.45

Tested by 15

TEST_CASEFunction · 0.36
TEST_CASEFunction · 0.36
TEST_CASEFunction · 0.36
TEST_CASEFunction · 0.36
TEST_CASEFunction · 0.36
run_progFunction · 0.36
create_programMethod · 0.36
TEST_CASEFunction · 0.36
TEST_CASEFunction · 0.36
TEST_CASEFunction · 0.36
TEST_CASEFunction · 0.36
TEST_CASEFunction · 0.36