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 15 commits into
base: develop
Choose a base branch
from
16 changes: 16 additions & 0 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 @@ match::matcher_result find_match(module& modl, M&& m)
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 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M
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,7 +418,11 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M
return;
if(trace > 1 and trace_for)
std::cout << "Match: " << matcher_name << std::endl;

timer match_timer;
auto r = match_instruction(get_module(mod), ins, m.matcher());
auto match_time = match_timer.record<std::chrono::nanoseconds>();
aarushjain29 marked this conversation as resolved.
Show resolved Hide resolved

if(r.result == get_module(mod).end())
return;
if(trace > 0 or trace_for)
Expand All @@ -425,7 +432,11 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M
}
// If its already invalid dont validate it again
bool invalidated = validate and get_module(mod).validate() != get_module(mod).end();

timer apply_timer;
m.apply(mod, r);
auto apply_time = apply_timer.record<std::chrono::nanoseconds>();
aarushjain29 marked this conversation as resolved.
Show resolved Hide resolved

if(validate and not invalidated)
{
auto invalid = get_module(mod).validate();
Expand All @@ -438,6 +449,11 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M
}
}
match = true;
if(time_matchers)
aarushjain29 marked this conversation as resolved.
Show resolved Hide resolved
{
std::cout << "Matching for " << matcher_name << " took " << match_time << "ns." << std::endl;
aarushjain29 marked this conversation as resolved.
Show resolved Hide resolved
std::cout << "Apply for " << matcher_name << " took " << apply_time << "ns." << std::endl;
aarushjain29 marked this conversation as resolved.
Show resolved Hide resolved
}
},
ms...);
}
Expand Down
Loading