Skip to content

Adding MIGRAPHX_TIME_MATCHERS #3500

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

Merged
merged 32 commits into from
May 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eae2fa1
matcher logger
aarushjain29 Oct 3, 2024
a605697
timing details for a matcher in microseconds
aarushjain29 Oct 11, 2024
4639d58
generic template for timing
aarushjain29 Oct 11, 2024
54657c7
logging for all matcher
aarushjain29 Oct 11, 2024
99414ee
timing added in find_matches_for with env var
aarushjain29 Oct 23, 2024
da7e088
Revert "timing added in find_matches_for with env var"
aarushjain29 Oct 23, 2024
e17cc79
Remove timing from simplify_algebra
aarushjain29 Oct 23, 2024
c27d547
env variable added
aarushjain29 Oct 23, 2024
ffd393e
trace filter added
aarushjain29 Oct 23, 2024
dc3e8f8
timing for matching and apply
aarushjain29 Oct 28, 2024
a27281b
microseconds and changes
aarushjain29 Oct 29, 2024
436b3bf
default construct the result and assign in lambda
aarushjain29 Nov 4, 2024
766cf92
ns to us
aarushjain29 Nov 4, 2024
51bc957
Formatting
aarushjain29 Nov 4, 2024
a3a5fcc
Formatting
aarushjain29 Nov 5, 2024
70dbed0
Merge branch 'develop' into 3485-reduce-compile-time-for-migraphx
aarushjain29 Jan 15, 2025
90d61d0
Merge branch 'develop' into 3485-reduce-compile-time-for-migraphx
aarushjain29 Jan 15, 2025
f285b78
Merge branch 'develop' into 3485-reduce-compile-time-for-migraphx
aarushjain29 Jan 29, 2025
6562235
Merge branch 'develop' into 3485-reduce-compile-time-for-migraphx
aarushjain29 Feb 7, 2025
c6a6d37
print timing info inside the loop
aarushjain29 Feb 7, 2025
e4593bb
Merge branch 'develop' into 3485-reduce-compile-time-for-migraphx
aarushjain29 Apr 15, 2025
8e0bd2e
Merge branch 'develop' into 3485-reduce-compile-time-for-migraphx
CharlieL7 May 9, 2025
d7b3add
fix timing logic for matcher time
CharlieL7 May 9, 2025
229a5d9
Merge branch 'develop' of github.com:ROCm/AMDMIGraphX into 3485-reduc…
CharlieL7 May 9, 2025
9267928
formatting
CharlieL7 May 9, 2025
89b7113
Merge branch '3485-reduce-compile-time-for-migraphx' of github.com:RO…
CharlieL7 May 9, 2025
974bedb
formatting again
CharlieL7 May 9, 2025
9b8d4e5
more formatting
CharlieL7 May 9, 2025
6cdf24b
remove period on output
CharlieL7 May 9, 2025
3fea3f0
Merge branch 'develop' into 3485-reduce-compile-time-for-migraphx
aarushjain29 May 13, 2025
191e791
env variable added in doc
aarushjain29 May 13, 2025
f335157
formatting
CharlieL7 May 14, 2025
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
5 changes: 5 additions & 0 deletions docs/dev/env_vars.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@ Prints the compile pass and the program after the pass.
Set to "1", "enable", "enabled", "yes", or "true" to use.
Times the compile passes.

.. envvar:: MIGRAPHX_TIME_MATCHERS

Set to "1", "enable", "enabled", "yes", or "true" to use.
Times the matchers.

.. envvar:: MIGRAPHX_DISABLE_PASSES

Set to the name of the pass you want to skip. Comma separated list is supported
Expand Down
39 changes: 34 additions & 5 deletions src/include/migraphx/matcher.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#include <migraphx/type_name.hpp>
#include <migraphx/source_location.hpp>
#include <migraphx/config.hpp>
#include <migraphx/time.hpp>

#include <array>
#include <unordered_map>
#include <unordered_set>
Expand Down Expand Up @@ -402,6 +404,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 @@ -410,7 +413,8 @@
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{});
bool match = false;
const bool time_matchers = enabled(MIGRAPHX_TIME_MATCHERS{});
bool match = false;
each_args(
[&](auto&& m) {
const auto& matcher_name = get_type_name(m);
Expand All @@ -420,19 +424,44 @@
contains(matcher_name, trace_filter));
if(match)
return;
// print running matcher even if it doesn't match anything
if(trace > 1 and trace_for)
std::cout << "Match: " << matcher_name << std::endl;
auto r = match_instruction(get_module(mod), ins, m.matcher());
std::cout << "Running matcher: " << matcher_name << std::endl;

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

View check run for this annotation

Codecov / codecov/patch

src/include/migraphx/matcher.hpp#L429

Added line #L429 was not covered by tests

matcher_result r;
if(time_matchers or trace_for)
{
timer match_timer{};
r = match_instruction(get_module(mod), ins, m.matcher());

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L434 - L435 were not covered by tests
const auto match_time =
match_timer.record<std::chrono::duration<double, std::micro>>();
std::cout << "Matcher time for " << matcher_name << ": " << match_time << "us"

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

View check run for this annotation

Codecov / codecov/patch

src/include/migraphx/matcher.hpp#L437-L438

Added lines #L437 - L438 were not covered by tests
<< std::endl;
}

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

View check run for this annotation

Codecov / codecov/patch

src/include/migraphx/matcher.hpp#L440

Added line #L440 was not covered by tests
else
{
r = match_instruction(get_module(mod), ins, m.matcher());
}

// did not match any instruction
if(r.result == get_module(mod).end())
return;

if(trace > 0 or trace_for)
{
std::cout << "Matched by " << matcher_name << std::endl;
std::cout << "Matched by: " << matcher_name << std::endl;

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

View check run for this annotation

Codecov / codecov/patch

src/include/migraphx/matcher.hpp#L452

Added line #L452 was not covered by tests
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);
auto apply_time =
time<std::chrono::duration<double, std::micro>>([&] { m.apply(mod, r); });
if(time_matchers or trace_for)
{
std::cout << "Apply time for " << matcher_name << ": " << apply_time << "us"

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

View check run for this annotation

Codecov / codecov/patch

src/include/migraphx/matcher.hpp#L461

Added line #L461 was not covered by tests
<< std::endl;
}

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