-
Notifications
You must be signed in to change notification settings - Fork 88
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fuse inputs with mlir #3010
Fuse inputs with mlir #3010
Changes from 26 commits
d39f832
d2d3bae
af83509
ac47954
c9407aa
ea41fb9
61d788c
cad9d3d
52a6a0e
66e9d31
9107b26
cbf3afc
3947949
ffdba3c
6f99033
48712c9
c3cf902
28b013e
f9df6fa
51d3ea9
0e60085
fd0b7f7
9c4d659
5eaaed3
1edac2d
4a825cb
1ebdaf1
d035f3b
271ea78
43e76f5
b357f94
5e848ba
ee50c26
5a7f247
dd7985f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,6 +245,21 @@ struct MIGRAPHX_EXPORT module | |
const std::vector<instruction_ref>& splits1, | ||
const std::vector<instruction_ref>& splits2) const; | ||
|
||
// Fuse the instruction into the module by inserting the instructions and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it obvious to people who know the codebase what the inputs and outputs of these methods are? |
||
// parameters for any missing inputs. | ||
std::vector<instruction_ref> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need some unit-tests |
||
fuse(const std::vector<instruction_ref>& inss, | ||
std::unordered_map<instruction_ref, instruction_ref>* map_ins = nullptr, | ||
inserter insert = nullptr); | ||
|
||
// Fuse another module into this module by inserting the instructions and | ||
// parameters from the module | ||
std::vector<instruction_ref> | ||
fuse(const module& m, | ||
const std::vector<instruction_ref>& inputs, | ||
std::unordered_map<instruction_ref, instruction_ref>* map_ins = nullptr, | ||
inserter insert = nullptr); | ||
|
||
void debug_print() const; | ||
void debug_print(instruction_ref ins) const; | ||
void debug_print(instruction_ref ins, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,9 @@ | |
#include <migraphx/param_utils.hpp> | ||
#include <migraphx/instruction.hpp> | ||
#include <migraphx/builtin.hpp> | ||
#include <migraphx/module.hpp> | ||
#include <migraphx/ranges.hpp> | ||
#include <map> | ||
#include <cmath> | ||
|
||
namespace migraphx { | ||
|
@@ -49,5 +52,31 @@ void sort_params(std::vector<instruction_ref>& params) | |
})); | ||
} | ||
|
||
std::vector<instruction_ref> | ||
find_inputs(const std::unordered_map<instruction_ref, instruction_ref>& map_ins, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function needs a descriptive comment or no one else will ever be able to use it. |
||
const_module_ref parent, | ||
const_module_ref sub) | ||
{ | ||
std::vector<instruction_ref> result; | ||
std::map<std::string, instruction_ref> names; | ||
for(auto&& [input, param] : map_ins) | ||
{ | ||
if(sub != nullptr and not sub->has_instruction(param)) | ||
continue; | ||
if(param->name() != "@param") | ||
continue; | ||
if(parent != nullptr and not parent->has_instruction(input)) | ||
continue; | ||
auto v = param->get_operator().to_value(); | ||
auto name = v.at("parameter").to<std::string>(); | ||
names[name] = input; | ||
} | ||
std::transform(names.begin(), names.end(), std::back_inserter(result), [](const auto& p) { | ||
return p.second; | ||
}); | ||
assert(not sub or result.size() == sub->get_parameter_shapes().size()); | ||
umangyadav marked this conversation as resolved.
Show resolved
Hide resolved
Comment on lines
+74
to
+77
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Early return where? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just when it starts the body of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Then that will skip getting the parameters. Its meant to be optional. If |
||
return result; | ||
} | ||
|
||
} // namespace MIGRAPHX_INLINE_NS | ||
} // namespace migraphx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.