Unverified Commit 4ef8ae15 authored by Paul Fultz II's avatar Paul Fultz II Committed by GitHub
Browse files

Updates for module name (#737)



* Update module name

* Formatting

* Add const ref

* Fix tidy warning
Co-authored-by: default avatarmvermeulen <5479696+mvermeulen@users.noreply.github.com>
Co-authored-by: default avatarShucai Xiao <shucai@gmail.com>
parent 549cfe72
...@@ -28,7 +28,7 @@ using parameter_map = std::unordered_map<std::string, argument>; ...@@ -28,7 +28,7 @@ using parameter_map = std::unordered_map<std::string, argument>;
*/ */
struct module struct module
{ {
module(); module(const std::string& name = "");
// move constructor // move constructor
module(module&&) noexcept; module(module&&) noexcept;
...@@ -41,7 +41,7 @@ struct module ...@@ -41,7 +41,7 @@ struct module
~module() noexcept; ~module() noexcept;
std::string name() const { return module_name; } std::string name() const;
template <class... Ts> template <class... Ts>
instruction_ref add_instruction(operation op, Ts... args) instruction_ref add_instruction(operation op, Ts... args)
...@@ -133,7 +133,6 @@ struct module ...@@ -133,7 +133,6 @@ struct module
private: private:
void assign(const module& m); void assign(const module& m);
std::unique_ptr<module_impl> impl; std::unique_ptr<module_impl> impl;
std::string module_name;
}; };
} // namespace MIGRAPHX_INLINE_NS } // namespace MIGRAPHX_INLINE_NS
......
...@@ -25,6 +25,7 @@ struct module_impl ...@@ -25,6 +25,7 @@ struct module_impl
// A list is used to keep references to an instruction stable // A list is used to keep references to an instruction stable
std::list<instruction> instructions; std::list<instruction> instructions;
std::vector<std::string> input_names; std::vector<std::string> input_names;
std::string name;
}; };
const operation& get_operation(instruction_ref ins) { return ins->get_operator(); } const operation& get_operation(instruction_ref ins) { return ins->get_operator(); }
...@@ -61,7 +62,10 @@ static void print_instruction(std::ostream& os, ...@@ -61,7 +62,10 @@ static void print_instruction(std::ostream& os,
os << " -> " << ins->get_shape(); os << " -> " << ins->get_shape();
} }
module::module() : impl(std::make_unique<module_impl>()) {} module::module(const std::string& name) : impl(std::make_unique<module_impl>())
{
impl->name = name;
}
module::module(module&&) noexcept = default; module::module(module&&) noexcept = default;
module::~module() noexcept = default; module::~module() noexcept = default;
...@@ -76,6 +80,8 @@ module& module::operator=(module m) ...@@ -76,6 +80,8 @@ module& module::operator=(module m)
return *this; return *this;
} }
std::string module::name() const { return impl->name; }
void module::assign(const module& m) void module::assign(const module& m)
{ {
// clean the current module // clean the current module
...@@ -88,6 +94,7 @@ void module::assign(const module& m) ...@@ -88,6 +94,7 @@ void module::assign(const module& m)
impl->instructions.clear(); impl->instructions.clear();
} }
impl->input_names = m.impl->input_names; impl->input_names = m.impl->input_names;
impl->name = m.impl->name;
std::unordered_map<instruction_ref, instruction_ref> ins_map; std::unordered_map<instruction_ref, instruction_ref> ins_map;
for(auto ins : iterator_for(m)) for(auto ins : iterator_for(m))
......
...@@ -62,7 +62,7 @@ static void print_instruction(std::ostream& os, ...@@ -62,7 +62,7 @@ static void print_instruction(std::ostream& os,
os << " -> " << ins->get_shape(); os << " -> " << ins->get_shape();
} }
program::program() : impl(std::make_unique<program_impl>()) { impl->modules["main"] = {}; } program::program() : impl(std::make_unique<program_impl>()) { impl->modules["main"] = {"main"}; }
program::program(program&&) noexcept = default; program::program(program&&) noexcept = default;
program::~program() noexcept = default; program::~program() noexcept = default;
...@@ -325,7 +325,7 @@ void program::from_value(const value& v) ...@@ -325,7 +325,7 @@ void program::from_value(const value& v)
{ {
const auto& key = vv.get_key(); const auto& key = vv.get_key();
auto val = vv.without_key(); auto val = vv.without_key();
module modl; module modl{key};
modl.from_value(val); modl.from_value(val);
impl->modules[key] = modl; impl->modules[key] = modl;
} }
...@@ -506,9 +506,9 @@ void program::annotate(std::ostream& os, const std::function<void(instruction_re ...@@ -506,9 +506,9 @@ void program::annotate(std::ostream& os, const std::function<void(instruction_re
} }
} }
module* program::get_main_module() { return &impl->modules["main"]; } module* program::get_main_module() { return &impl->modules.at("main"); }
const module* program::get_main_module() const { return &impl->modules["main"]; } const module* program::get_main_module() const { return &impl->modules.at("main"); }
program& program::sort() program& program::sort()
{ {
......
...@@ -85,4 +85,22 @@ TEST_CASE(module_annotate) ...@@ -85,4 +85,22 @@ TEST_CASE(module_annotate)
EXPECT(ss1.str() == ss2.str()); EXPECT(ss1.str() == ss2.str());
} }
TEST_CASE(module_name)
{
migraphx::module m1("name");
EXPECT(m1.name() == "name");
auto m2 = m1; // NOLINT
EXPECT(m2.name() == "name");
migraphx::module m3;
m3 = m1;
EXPECT(m3.name() == "name");
}
TEST_CASE(module_name_main)
{
migraphx::program p;
auto* mm = p.get_main_module();
EXPECT(mm->name() == "main");
}
int main(int argc, const char* argv[]) { test::run(argc, argv); } int main(int argc, const char* argv[]) { test::run(argc, argv); }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment