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

Adding MIGRAPHX_TIME_MATCHERS #3500

Open
wants to merge 20 commits into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion 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 @@ -401,6 +402,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 @@ -409,7 +411,9 @@
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;
timer match_timer{};
each_args(
[&](auto&& m) {
const auto& matcher_name = get_type_name(m);
Expand All @@ -421,7 +425,15 @@
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(time_matchers or trace_for)
{
const auto match_time = match_timer.record<std::chrono::duration<double, std::micro>>();

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

View check run for this annotation

Codecov / codecov/patch

src/include/migraphx/matcher.hpp#L432

Added line #L432 was not covered by tests
std::cout << "Matching for " << matcher_name << " took " << match_time << "us."
<< std::endl;
}

if(r.result == get_module(mod).end())
return;
if(trace > 0 or trace_for)
Expand All @@ -431,7 +443,14 @@
}
// If its already invalid dont validate it again
bool invalidated = validate and get_module(mod).validate() != get_module(mod).end();
m.apply(mod, r);
auto apply_time =
time<std::chrono::duration<double, std::micro>>([&] { m.apply(mod, r); });
if(time_matchers or trace_for)
{
std::cout << "Apply for " << matcher_name << " took " << apply_time << "us."
<< std::endl;
}

if(validate and not invalidated)
{
auto invalid = get_module(mod).validate();
Expand Down
Loading