Skip to content
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

matcher logger #3500

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
47 changes: 28 additions & 19 deletions src/include/migraphx/matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <migraphx/time.hpp>

#ifndef MIGRAPHX_USE_TYPE_ERASED_MATCHERS
#define MIGRAPHX_USE_TYPE_ERASED_MATCHERS 0
Expand Down Expand Up @@ -395,6 +396,7 @@
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TRACE_MATCHES)
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TRACE_MATCHES_FOR)
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_VALIDATE_MATCHES)
MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TIME_MATCHERS)

/// Find matches for an instruction in the module for per section of matchers
template <class Mod, class... Ms>
Expand All @@ -403,6 +405,7 @@
const int trace = value_of(MIGRAPHX_TRACE_MATCHES{});
const bool validate = enabled(MIGRAPHX_VALIDATE_MATCHES{});
const auto trace_filter = string_value_of(MIGRAPHX_TRACE_MATCHES_FOR{});
const bool time_matchers = enabled(MIGRAPHX_TIME_MATCHERS{});
bool match = false;
each_args(
[&](auto&& m) {
Expand All @@ -415,29 +418,35 @@
return;
if(trace > 1 and trace_for)
std::cout << "Match: " << matcher_name << std::endl;
auto r = match_instruction(get_module(mod), ins, m.matcher());
if(r.result == get_module(mod).end())
auto elapsed_time = time<std::chrono::nanoseconds>([&] {
auto r = match_instruction(get_module(mod), ins, m.matcher());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should only be timing the match and apply methods. We should also print out the time for each.

if(r.result == get_module(mod).end())
return;
if(trace > 0 or trace_for)
{
std::cout << "Matched by " << matcher_name << std::endl;
get_module(mod).debug_print(ins);
}
// If its already invalid dont validate it again
bool invalidated = validate and get_module(mod).validate() != get_module(mod).end();
m.apply(mod, r);
if(validate and not invalidated)
{
auto invalid = get_module(mod).validate();
if(invalid != get_module(mod).end())
if(trace > 0 or trace_for)

Check warning on line 425 in src/include/migraphx/matcher.hpp

View workflow job for this annotation

GitHub Actions / tidy

misleading indentation: statement is indented too deeply [readability-misleading-indentation,-warnings-as-errors]

Check warning on line 425 in src/include/migraphx/matcher.hpp

View workflow job for this annotation

GitHub Actions / tidy

misleading indentation: statement is indented too deeply [readability-misleading-indentation,-warnings-as-errors]

Check warning on line 425 in src/include/migraphx/matcher.hpp

View workflow job for this annotation

GitHub Actions / tidy

misleading indentation: statement is indented too deeply [readability-misleading-indentation,-warnings-as-errors]

Check warning on line 425 in src/include/migraphx/matcher.hpp

View workflow job for this annotation

GitHub Actions / tidy

misleading indentation: statement is indented too deeply [readability-misleading-indentation,-warnings-as-errors]

Check warning on line 425 in src/include/migraphx/matcher.hpp

View workflow job for this annotation

GitHub Actions / tidy

misleading indentation: statement is indented too deeply [readability-misleading-indentation,-warnings-as-errors]

Check warning on line 425 in src/include/migraphx/matcher.hpp

View workflow job for this annotation

GitHub Actions / tidy

misleading indentation: statement is indented too deeply [readability-misleading-indentation,-warnings-as-errors]

Check warning on line 425 in src/include/migraphx/matcher.hpp

View workflow job for this annotation

GitHub Actions / tidy

misleading indentation: statement is indented too deeply [readability-misleading-indentation,-warnings-as-errors]

Check warning on line 425 in src/include/migraphx/matcher.hpp

View workflow job for this annotation

GitHub Actions / tidy

misleading indentation: statement is indented too deeply [readability-misleading-indentation,-warnings-as-errors]

Check warning on line 425 in src/include/migraphx/matcher.hpp

View workflow job for this annotation

GitHub Actions / tidy

misleading indentation: statement is indented too deeply [readability-misleading-indentation,-warnings-as-errors]

Check warning on line 425 in src/include/migraphx/matcher.hpp

View workflow job for this annotation

GitHub Actions / tidy

misleading indentation: statement is indented too deeply [readability-misleading-indentation,-warnings-as-errors]
{
std::cout << "Invalid program from match: " << matcher_name << std::endl;
std::cout << "Invalid instructions: " << std::endl;
get_module(mod).debug_print(invalid->inputs());
get_module(mod).debug_print(invalid);
std::cout << "Matched by " << matcher_name << std::endl;
get_module(mod).debug_print(ins);

Check warning on line 428 in src/include/migraphx/matcher.hpp

View check run for this annotation

Codecov / codecov/patch

src/include/migraphx/matcher.hpp#L428

Added line #L428 was not covered by tests
}
// If its already invalid dont validate it again
bool invalidated = validate and get_module(mod).validate() != get_module(mod).end();
m.apply(mod, r);
if(validate and not invalidated)
{
auto invalid = get_module(mod).validate();
if(invalid != get_module(mod).end())

Check warning on line 436 in src/include/migraphx/matcher.hpp

View check run for this annotation

Codecov / codecov/patch

src/include/migraphx/matcher.hpp#L435-L436

Added lines #L435 - L436 were not covered by tests
{
std::cout << "Invalid program from match: " << matcher_name << std::endl;
std::cout << "Invalid instructions: " << std::endl;
get_module(mod).debug_print(invalid->inputs());
get_module(mod).debug_print(invalid);

Check warning on line 441 in src/include/migraphx/matcher.hpp

View check run for this annotation

Codecov / codecov/patch

src/include/migraphx/matcher.hpp#L440-L441

Added lines #L440 - L441 were not covered by tests
}
}
match = true;
});
if(time_matchers and trace_for)
{
std::cout << "Matcher " << matcher_name << " took " << elapsed_time << "ns." << std::endl;
}
match = true;
},
ms...);
}
Expand Down
Loading