Commit 95f2cdb9 authored by umangyadav's avatar umangyadav
Browse files

Changes from fix_sorting

parent a07c28e4
...@@ -222,12 +222,17 @@ struct MIGRAPHX_EXPORT module ...@@ -222,12 +222,17 @@ struct MIGRAPHX_EXPORT module
void annotate(std::ostream& os, std::function<void(instruction_ref)> a) const; void annotate(std::ostream& os, std::function<void(instruction_ref)> a) const;
std::vector<module_ref> get_sub_modules(bool shallow = false) const; std::vector<module_ref> get_sub_modules(bool shallow = false) const;
// sorts the module in reverse-post order DFS order /* sorts the module in topological order aka reverse-post order (RPO) DFS order
it takes last instruction or @return as the root and walks back the graph and moves inputs
of the each instruction such that it appears before the instruction itself.
*/
module& sort(); module& sort();
// if the instruction has the module arguments then all the parameters/instructions used by that /* Any instruction "X" can have module arguments and those modules inside them can use any other
// module from the main/parent module must be calculated before the instruction can be executed. * instruction "Y" from predecessor modules of the instruction "X". Such instruction "Y" inside
// therefore, apart from the input instructions, those other instructions are implicit * module args are not listed as input instructions to "X". But those instructions "Y" must be
// dependencies * evaluted before the instruction "X" can. Therefore such "Y" instructions are considered
* implicit dependency to "X".
*/
ins_dep_map calc_implicit_deps() const; ins_dep_map calc_implicit_deps() const;
MIGRAPHX_EXPORT friend std::ostream& operator<<(std::ostream& os, const module& m); MIGRAPHX_EXPORT friend std::ostream& operator<<(std::ostream& os, const module& m);
......
...@@ -41,12 +41,12 @@ ...@@ -41,12 +41,12 @@
#include <migraphx/marker.hpp> #include <migraphx/marker.hpp>
#include <migraphx/supported_segments.hpp> #include <migraphx/supported_segments.hpp>
#include <iostream> #include <iostream>
#include <queue>
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#include <set> #include <set>
#include <unordered_map> #include <unordered_map>
#include <utility> #include <utility>
#include <unordered_set> #include <unordered_set>
#include <map> #include <map>
#include <cassert> #include <cassert>
...@@ -1198,11 +1198,19 @@ void program::remove_unused_modules() ...@@ -1198,11 +1198,19 @@ void program::remove_unused_modules()
program& program::sort() program& program::sort()
{ {
for(auto& pp : this->impl->modules) std::queue<migraphx::module_ref> mqueue;
mqueue.push(get_main_module());
while(!mqueue.empty())
{
module_ref current_mod = mqueue.front();
current_mod->sort();
mqueue.pop();
auto child_mods = current_mod->get_sub_modules(true);
for(auto& sub_mod : child_mods)
{ {
pp.second.sort(); mqueue.push(sub_mod);
}
} }
return *this; return *this;
} }
......
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