Unverified Commit f5980619 authored by Charlie Lin's avatar Charlie Lin Committed by GitHub
Browse files

Instruction distance check fix (#1237)



* Use custom distance function

* Pass module, skip order check if other module

* Change other valid()

* Remove unnecessary declaration

* test multiple module dependency

* Refactor to make more clear

* Code cleanup

* Simplify fix

* Test EXPECT
Co-authored-by: default avatarPaul Fultz II <pfultz2@yahoo.com>
parent e16faac2
...@@ -81,6 +81,7 @@ bool instruction::valid(instruction_ref start, bool check_order) const ...@@ -81,6 +81,7 @@ bool instruction::valid(instruction_ref start, bool check_order) const
bool ret = self != i->outputs().end(); bool ret = self != i->outputs().end();
if(check_order) if(check_order)
{ {
// check arguments for this instruction before this instruction
ret = ret and (std::distance(start, i) < std::distance(start, *self)); ret = ret and (std::distance(start, i) < std::distance(start, *self));
} }
return ret; return ret;
......
...@@ -510,9 +510,8 @@ instruction_ref module::validate() const ...@@ -510,9 +510,8 @@ instruction_ref module::validate() const
return std::find_if( return std::find_if(
impl->instructions.begin(), impl->instructions.end(), [&](const instruction& i) { impl->instructions.begin(), impl->instructions.end(), [&](const instruction& i) {
auto inputs = i.inputs(); auto inputs = i.inputs();
bool check_order = std::all_of(inputs.begin(), inputs.end(), [&](auto in) { bool check_order = std::all_of(
return contains(impl->instructions, *in); inputs.begin(), inputs.end(), [&](auto in) { return has_instruction(in); });
});
return !i.valid(impl->instructions.begin(), check_order); return !i.valid(impl->instructions.begin(), check_order);
}); });
} }
......
...@@ -312,4 +312,18 @@ TEST_CASE(module_without_bypass) ...@@ -312,4 +312,18 @@ TEST_CASE(module_without_bypass)
EXPECT(found); EXPECT(found);
} }
TEST_CASE(multiple_module_dependency)
{
// Test when an instruction from a submodule depends on previous module
migraphx::program p;
auto* mm = p.get_main_module();
auto* sub = p.create_module("sub");
auto l1 = mm->add_literal(migraphx::literal(3));
// second same literal to make sure instruction_ref is being compared, rather than the
// instructions
sub->add_literal(migraphx::literal(3));
sub->add_instruction(sum_op{}, l1, l1);
EXPECT((sub->validate() == sub->end()));
}
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