From eae2fa15e336fdc2ca9b30f52a2849f8e517da0c Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Thu, 3 Oct 2024 03:53:43 +0000 Subject: [PATCH 01/16] matcher logger --- src/simplify_algebra.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/simplify_algebra.cpp b/src/simplify_algebra.cpp index 7cae251c8b1..6d9034c8578 100644 --- a/src/simplify_algebra.cpp +++ b/src/simplify_algebra.cpp @@ -39,6 +39,15 @@ #include #include +namespace matcher_logger{ + template + void log(const Matcher& matcher){ + std::string matcher_name = typeid(matcher).name(); + std::cout<< "Mathcer applied: "<< matcher_name< Date: Fri, 11 Oct 2024 14:33:22 +0000 Subject: [PATCH 02/16] timing details for a matcher in microseconds --- src/simplify_algebra.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/simplify_algebra.cpp b/src/simplify_algebra.cpp index 6d9034c8578..9fe02c235ce 100644 --- a/src/simplify_algebra.cpp +++ b/src/simplify_algebra.cpp @@ -38,14 +38,7 @@ #include #include - -namespace matcher_logger{ - template - void log(const Matcher& matcher){ - std::string matcher_name = typeid(matcher).name(); - std::cout<< "Mathcer applied: "<< matcher_name< namespace migraphx { @@ -80,6 +73,9 @@ struct find_mul_conv void apply(module& m, const match::matcher_result& r) const { + // Start the timer for applying this matcher + auto elapsed_time = migraphx::time([&] { + auto ins = r.result; auto conv_ins = r.instructions["conv"]; auto a_ins = r.instructions["a"]; @@ -118,6 +114,8 @@ struct find_mul_conv auto new_conv = m.insert_instruction( ins, conv_ins->get_operator(), conv_ins->inputs().front(), new_mul); m.replace_instruction(ins, new_conv); + }); + std::cout << "Matcher find_mul_conv took: " << elapsed_time << " ms" << std::endl; } }; @@ -443,8 +441,8 @@ struct find_mul_add void apply(module& m, const match::matcher_result& r) const { - matcher_logger::log(*this); - auto ins = r.result; + auto elapsed_time = migraphx::time([&] { + auto ins = r.result; auto a_ins = r.instructions["a"]; auto b_ins = r.instructions["b"]; auto x_ins = r.instructions["x"]; @@ -453,6 +451,8 @@ struct find_mul_add auto ax_ins = m.insert_instruction(ins, make_op("mul"), a_ins, x_ins); auto ab_ins = m.insert_instruction(ins, make_op("mul"), a_ins, b_ins); m.replace_instruction(ins, make_op("add"), ax_ins, ab_ins); + }); + std::cout << "Matcher find_mul_conv took: " << elapsed_time << " ms" << std::endl; } }; From 4639d580133113692fd2dd0fac62b386246179d8 Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Fri, 11 Oct 2024 14:39:20 +0000 Subject: [PATCH 03/16] generic template for timing --- src/simplify_algebra.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/simplify_algebra.cpp b/src/simplify_algebra.cpp index 9fe02c235ce..28bfc1da21c 100644 --- a/src/simplify_algebra.cpp +++ b/src/simplify_algebra.cpp @@ -40,6 +40,12 @@ #include #include +template +void time_matcher(const std::string& matcher_name, Callable&& func) +{ + auto elapsed_time = migraphx::time(std::forward(func)); + std::cout << "Matcher " << matcher_name << " took: " << elapsed_time << " ns" << std::endl; +} namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { @@ -441,7 +447,9 @@ struct find_mul_add void apply(module& m, const match::matcher_result& r) const { - auto elapsed_time = migraphx::time([&] { + time_matcher("find_mul_conv", [&] { + + //auto elapsed_time = migraphx::time([&] { auto ins = r.result; auto a_ins = r.instructions["a"]; auto b_ins = r.instructions["b"]; @@ -452,7 +460,7 @@ struct find_mul_add auto ab_ins = m.insert_instruction(ins, make_op("mul"), a_ins, b_ins); m.replace_instruction(ins, make_op("add"), ax_ins, ab_ins); }); - std::cout << "Matcher find_mul_conv took: " << elapsed_time << " ms" << std::endl; + //std::cout << "Matcher find_mul_conv took: " << elapsed_time << " ms" << std::endl; } }; From 54657c7c6784d1bc86bdf05f2f9a40c2988006fd Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Fri, 11 Oct 2024 15:28:05 +0000 Subject: [PATCH 04/16] logging for all matcher --- src/simplify_algebra.cpp | 60 +++++++++++++++++++++++++++++++++++----- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/simplify_algebra.cpp b/src/simplify_algebra.cpp index 28bfc1da21c..f48a923ec9a 100644 --- a/src/simplify_algebra.cpp +++ b/src/simplify_algebra.cpp @@ -79,9 +79,7 @@ struct find_mul_conv void apply(module& m, const match::matcher_result& r) const { - // Start the timer for applying this matcher - auto elapsed_time = migraphx::time([&] { - + time_matcher("find_mul_conv", [&] { auto ins = r.result; auto conv_ins = r.instructions["conv"]; auto a_ins = r.instructions["a"]; @@ -121,7 +119,7 @@ struct find_mul_conv ins, conv_ins->get_operator(), conv_ins->inputs().front(), new_mul); m.replace_instruction(ins, new_conv); }); - std::cout << "Matcher find_mul_conv took: " << elapsed_time << " ms" << std::endl; + //std::cout << "Matcher find_mul_conv took: " << elapsed_time << " ms" << std::endl; } }; @@ -143,6 +141,7 @@ struct find_mul_slice_conv void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_mul_slice_conv", [&] { auto ins = r.result; auto slice_ins = r.instructions["slice"]; auto conv_ins = r.instructions["conv"]; @@ -214,6 +213,7 @@ struct find_mul_slice_conv for(auto output : outputs) if(output != slice_ins) instruction::replace_argument(output, conv_ins, new_conv); + }); } }; @@ -229,6 +229,7 @@ struct find_mul_dot void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_mul_dot", [&] { auto ins = r.result; auto dot_ins = r.instructions["dot"]; auto a_ins = dot_ins->inputs()[0]; @@ -276,6 +277,7 @@ struct find_mul_dot return; m.replace_instruction(ins, make_op("dot"), a_ins, b_ins); + }); } }; @@ -294,6 +296,7 @@ struct find_dot_slice void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_dot_slice", [&] { auto slice_ins = r.result; auto dot_ins = r.instructions["dot_ins"]; auto slice_op = slice_ins->normalized_operator().to_value(); @@ -359,6 +362,7 @@ struct find_dot_slice dot_inputs.at(1)); } m.replace_instruction(slice_ins, dot_ins->get_operator(), {slice_1, slice_2}); + }); } }; @@ -376,6 +380,7 @@ struct find_dot_mul void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_dot_mul", [&] { auto ins = r.result; auto a_ins = ins->inputs()[0]; auto b_ins = ins->inputs()[1]; @@ -422,6 +427,7 @@ struct find_dot_mul } m.replace_instruction(ins, make_op("dot"), a_ins, b_ins); + }); } }; @@ -447,9 +453,7 @@ struct find_mul_add void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_mul_conv", [&] { - - //auto elapsed_time = migraphx::time([&] { + time_matcher("find_mul_add", [&] { auto ins = r.result; auto a_ins = r.instructions["a"]; auto b_ins = r.instructions["b"]; @@ -479,6 +483,7 @@ struct find_dot_add void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_dot_add", [&] { auto ins = r.result; auto a_ins = r.instructions["a"]; auto b_ins = r.instructions["b"]; @@ -497,6 +502,7 @@ struct find_dot_add auto ax_ins = insert_dot(a_ins, x_ins); auto ab_ins = insert_dot(a_ins, b_ins); m.replace_instruction(ins, make_op("add"), ax_ins, ab_ins); + }); } }; @@ -514,6 +520,7 @@ struct find_conv_add void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_conv_add", [&] { auto ins = r.result; auto a_ins = r.instructions["a"]; auto x_ins = r.instructions["x"]; @@ -523,6 +530,7 @@ struct find_conv_add auto conv2 = m.insert_instruction(ins, ins->get_operator(), x_ins, w_ins); m.replace_instruction(ins, make_op("add"), conv1, conv2); + }); } }; @@ -536,6 +544,7 @@ struct find_add_lit_broadcast void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_add_lit_broadcast", [&] { auto ins = r.result; auto x_ins = r.instructions["x"]; auto a_ins = r.instructions["a"]; @@ -543,6 +552,7 @@ struct find_add_lit_broadcast auto sumab = m.insert_instruction(ins, make_op("add"), a_ins, b_ins); m.replace_instruction(ins, make_op("add"), x_ins, sumab); + }); } }; @@ -556,6 +566,7 @@ struct find_double_add_lit_broadcast void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_double_add_lit_broadcast", [&] { auto ins = r.result; auto x_ins = r.instructions["x"]; auto y_ins = r.instructions["y"]; @@ -580,6 +591,7 @@ struct find_double_add_lit_broadcast auto sumxy = m.insert_instruction(ins, make_op("add"), x_ins, y_ins); m.replace_instruction(ins, make_op("add"), sumxy, sumab); + }); } }; @@ -761,6 +773,7 @@ struct find_inner_broadcast void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_inner_broadcast", [&] { auto ins = r.result; const auto& broadcasts = ins->inputs(); if(broadcasts.empty()) @@ -809,6 +822,7 @@ struct find_inner_broadcast { apply_diff_broadcasts(m, ins); } + }); } }; @@ -821,6 +835,7 @@ struct find_dot_broadcast void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_dot_broadcast", [&] { auto ins = r.result; auto a = ins->inputs()[0]; auto b = ins->inputs()[1]; @@ -880,6 +895,7 @@ struct find_dot_broadcast auto broadcast = m.insert_instruction( ins, make_op("multibroadcast", {{"out_lens", ins->get_shape().lens()}}), dot); m.replace_instruction(ins, broadcast); + }); } }; @@ -926,6 +942,7 @@ struct find_concat_op void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_concat_op", [&] { auto ins = r.result; auto axis = any_cast(ins->get_operator()).axis; @@ -992,6 +1009,7 @@ struct find_concat_op m.replace_instruction(ins, args.front()); else m.replace_instruction(ins, make_op("concat", {{"axis", axis}}), args); + }); } }; @@ -1005,6 +1023,7 @@ struct find_concat_conv void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_concat_conv", [&] { auto ins = r.result; auto axis = ins->get_operator().to_value()["axis"].to(); if(axis != 1) @@ -1041,6 +1060,7 @@ struct find_concat_conv auto w = m.insert_instruction(ins, make_op("concat", {{"axis", 0}}), weights); conv.from_value({{"group", original_group * inputs.size()}}); m.replace_instruction(ins, conv, x, w); + }); } }; @@ -1239,6 +1259,7 @@ struct find_splits void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_splits", [&] { auto ins = r.result; auto splits = get_splits(ins); if(splits.empty()) @@ -1328,6 +1349,7 @@ struct find_splits } } } + }); } }; @@ -1348,6 +1370,7 @@ struct find_split_concat // Verifies that the slices meet several conditions: they must all output to the same // concat instruction, slice on the same (1 only) axis, and the end of one slice // must match the start of the next. + time_matcher("find_split_concat", [&] { auto ins = r.result; auto splits = get_splits(ins); @@ -1402,6 +1425,7 @@ struct find_split_concat m.replace_instruction(concat, args.front()); else m.replace_instruction(concat, concat->get_operator(), args); + }); } }; @@ -1446,6 +1470,7 @@ struct find_add_convs void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_add_convs", [&] { auto ins = r.result; auto a_conv = r.instructions["a"]; auto a_input = a_conv->inputs().at(0); @@ -1497,6 +1522,7 @@ struct find_add_convs auto concat_weights = m.insert_instruction(ins, make_op("concat", {{"axis", 1}}), a_weights, b_weights); m.replace_instruction(ins, new_op, concat_input, concat_weights); + }); } }; @@ -1520,6 +1546,7 @@ struct find_conv_dot_horiz_fusion void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_conv_dot_horiz_fusion", [&] { auto ins = r.result; auto pred = [](auto i, auto j) { @@ -1587,6 +1614,7 @@ struct find_conv_dot_horiz_fusion auto outputs = ins->outputs(); group_by(outputs.begin(), outputs.end(), each, pred); + }); } }; @@ -1599,6 +1627,7 @@ struct find_div_const void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_div_const", [&] { auto ins = r.result; auto c_ins = r.instructions["c"]; @@ -1610,6 +1639,7 @@ struct find_div_const auto args = ins->inputs(); m.replace_instruction(ins, make_op("mul"), args.front(), recip); + }); } }; @@ -1630,10 +1660,12 @@ struct find_unit_ops void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_unit_ops", [&] { auto ins = r.result; auto c_in = r.instructions["x"]; m.replace_instruction(ins, c_in); + }); } }; @@ -1652,11 +1684,13 @@ struct find_neg_unit_ops void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_neg_unit_ops", [&] { auto ins = r.result; auto c_in = r.instructions["x"]; auto neg = m.insert_instruction(ins, make_op("neg"), c_in); m.replace_instruction(ins, neg); + }); } }; @@ -1676,6 +1710,7 @@ struct eliminate_zero_point void apply(module& m, const match::matcher_result& r) const { + time_matcher("eliminate_zero_point", [&] { auto ins = r.result; auto x = r.instructions["x"]; auto scale = r.instructions["scale"]; @@ -1687,6 +1722,7 @@ struct eliminate_zero_point } auto qdq_ins = m.insert_instruction(ins, migraphx::make_op(ins->name(), op), {x, scale}); m.replace_instruction(ins, qdq_ins); + }); } }; @@ -1703,10 +1739,12 @@ struct find_zero_ops void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_zero_ops", [&] { auto ins = r.result; auto zero_ins = r.instructions["x"]; m.replace_instruction(ins, zero_ins); + }); } }; @@ -1719,6 +1757,7 @@ struct find_sub_const void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_sub_const", [&] { auto ins = r.result; auto c_ins = r.instructions["c"]; @@ -1727,6 +1766,7 @@ struct find_sub_const auto args = ins->inputs(); m.replace_instruction(ins, make_op("add"), args.front(), neg); + }); } }; @@ -1740,10 +1780,12 @@ struct find_rsqrt void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_rqrt", [&] { auto ins = r.result; auto x_ins = r.instructions["x"]; m.replace_instruction(ins, make_op("rsqrt"), x_ins); + }); } }; @@ -1765,6 +1807,7 @@ struct find_split_reshape void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_split_reshape", [&] { auto slc = r.instructions["slice"]; auto rsp = r.instructions["reshape"]; auto input = slc->inputs().front(); @@ -1919,6 +1962,7 @@ struct find_split_reshape {{"axes", {rsp_axis}}, {"starts", {new_starts[i]}}, {"ends", {new_ends[i]}}}), rsp_ins); } + }); } }; @@ -1932,6 +1976,7 @@ struct find_split_transpose void apply(module& m, const match::matcher_result& r) const { + time_matcher("find_split_transpose", [&] { auto slc = r.instructions["slice"]; auto trans = r.instructions["trans"]; @@ -1979,6 +2024,7 @@ struct find_split_transpose make_op("slice", {{"axes", {axis_new}}, {"starts", starts}, {"ends", ends}}), tr); } + }); } }; From 99414eee729ad3551ed871db361edbaafcb59d6f Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Wed, 23 Oct 2024 02:14:59 +0000 Subject: [PATCH 05/16] timing added in find_matches_for with env var --- src/include/migraphx/matcher.hpp | 56 +++++++++++++++++++------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index fdada026e66..f37c9dd0863 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -37,6 +37,7 @@ #include #include #include +#include #ifndef MIGRAPHX_USE_TYPE_ERASED_MATCHERS #define MIGRAPHX_USE_TYPE_ERASED_MATCHERS 0 @@ -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 @@ -403,7 +405,9 @@ 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) { const auto& matcher_name = get_type_name(m); @@ -413,31 +417,39 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M contains(matcher_name, trace_filter)); if(match) 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()) - 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()) + + auto elapsed_time = time([&] { + + 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()) + return; + if(trace > 0 or trace_for) { - 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); } + // 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()) + { + 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); + } + } + match = true; + }); + if(time_matchers) + { + std::cout << "Matcher " << matcher_name << " took " << elapsed_time << "ns." << std::endl; } - match = true; }, ms...); } From da7e088a6453ec0542afe89b245cd6d062b6c27f Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Wed, 23 Oct 2024 03:20:52 +0000 Subject: [PATCH 06/16] Revert "timing added in find_matches_for with env var" This reverts commit 99414eee729ad3551ed871db361edbaafcb59d6f. --- src/include/migraphx/matcher.hpp | 56 +++++++++++++------------------- 1 file changed, 22 insertions(+), 34 deletions(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index f37c9dd0863..fdada026e66 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -37,7 +37,6 @@ #include #include #include -#include #ifndef MIGRAPHX_USE_TYPE_ERASED_MATCHERS #define MIGRAPHX_USE_TYPE_ERASED_MATCHERS 0 @@ -396,7 +395,6 @@ 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 @@ -405,9 +403,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) { const auto& matcher_name = get_type_name(m); @@ -417,39 +413,31 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M contains(matcher_name, trace_filter)); if(match) return; - - auto elapsed_time = time([&] { - - 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()) - 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) + 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()) + 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()) { - auto invalid = get_module(mod).validate(); - if(invalid != get_module(mod).end()) - { - 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 << "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); } - match = true; - }); - if(time_matchers) - { - std::cout << "Matcher " << matcher_name << " took " << elapsed_time << "ns." << std::endl; } + match = true; }, ms...); } From e17cc79850407b8c6e2911f59985d80f78fa7d54 Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Wed, 23 Oct 2024 03:22:24 +0000 Subject: [PATCH 07/16] Remove timing from simplify_algebra --- src/simplify_algebra.cpp | 64 ---------------------------------------- 1 file changed, 64 deletions(-) diff --git a/src/simplify_algebra.cpp b/src/simplify_algebra.cpp index f48a923ec9a..7cae251c8b1 100644 --- a/src/simplify_algebra.cpp +++ b/src/simplify_algebra.cpp @@ -38,14 +38,6 @@ #include #include -#include - -template -void time_matcher(const std::string& matcher_name, Callable&& func) -{ - auto elapsed_time = migraphx::time(std::forward(func)); - std::cout << "Matcher " << matcher_name << " took: " << elapsed_time << " ns" << std::endl; -} namespace migraphx { inline namespace MIGRAPHX_INLINE_NS { @@ -79,7 +71,6 @@ struct find_mul_conv void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_mul_conv", [&] { auto ins = r.result; auto conv_ins = r.instructions["conv"]; auto a_ins = r.instructions["a"]; @@ -118,8 +109,6 @@ struct find_mul_conv auto new_conv = m.insert_instruction( ins, conv_ins->get_operator(), conv_ins->inputs().front(), new_mul); m.replace_instruction(ins, new_conv); - }); - //std::cout << "Matcher find_mul_conv took: " << elapsed_time << " ms" << std::endl; } }; @@ -141,7 +130,6 @@ struct find_mul_slice_conv void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_mul_slice_conv", [&] { auto ins = r.result; auto slice_ins = r.instructions["slice"]; auto conv_ins = r.instructions["conv"]; @@ -213,7 +201,6 @@ struct find_mul_slice_conv for(auto output : outputs) if(output != slice_ins) instruction::replace_argument(output, conv_ins, new_conv); - }); } }; @@ -229,7 +216,6 @@ struct find_mul_dot void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_mul_dot", [&] { auto ins = r.result; auto dot_ins = r.instructions["dot"]; auto a_ins = dot_ins->inputs()[0]; @@ -277,7 +263,6 @@ struct find_mul_dot return; m.replace_instruction(ins, make_op("dot"), a_ins, b_ins); - }); } }; @@ -296,7 +281,6 @@ struct find_dot_slice void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_dot_slice", [&] { auto slice_ins = r.result; auto dot_ins = r.instructions["dot_ins"]; auto slice_op = slice_ins->normalized_operator().to_value(); @@ -362,7 +346,6 @@ struct find_dot_slice dot_inputs.at(1)); } m.replace_instruction(slice_ins, dot_ins->get_operator(), {slice_1, slice_2}); - }); } }; @@ -380,7 +363,6 @@ struct find_dot_mul void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_dot_mul", [&] { auto ins = r.result; auto a_ins = ins->inputs()[0]; auto b_ins = ins->inputs()[1]; @@ -427,7 +409,6 @@ struct find_dot_mul } m.replace_instruction(ins, make_op("dot"), a_ins, b_ins); - }); } }; @@ -453,7 +434,6 @@ struct find_mul_add void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_mul_add", [&] { auto ins = r.result; auto a_ins = r.instructions["a"]; auto b_ins = r.instructions["b"]; @@ -463,8 +443,6 @@ struct find_mul_add auto ax_ins = m.insert_instruction(ins, make_op("mul"), a_ins, x_ins); auto ab_ins = m.insert_instruction(ins, make_op("mul"), a_ins, b_ins); m.replace_instruction(ins, make_op("add"), ax_ins, ab_ins); - }); - //std::cout << "Matcher find_mul_conv took: " << elapsed_time << " ms" << std::endl; } }; @@ -483,7 +461,6 @@ struct find_dot_add void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_dot_add", [&] { auto ins = r.result; auto a_ins = r.instructions["a"]; auto b_ins = r.instructions["b"]; @@ -502,7 +479,6 @@ struct find_dot_add auto ax_ins = insert_dot(a_ins, x_ins); auto ab_ins = insert_dot(a_ins, b_ins); m.replace_instruction(ins, make_op("add"), ax_ins, ab_ins); - }); } }; @@ -520,7 +496,6 @@ struct find_conv_add void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_conv_add", [&] { auto ins = r.result; auto a_ins = r.instructions["a"]; auto x_ins = r.instructions["x"]; @@ -530,7 +505,6 @@ struct find_conv_add auto conv2 = m.insert_instruction(ins, ins->get_operator(), x_ins, w_ins); m.replace_instruction(ins, make_op("add"), conv1, conv2); - }); } }; @@ -544,7 +518,6 @@ struct find_add_lit_broadcast void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_add_lit_broadcast", [&] { auto ins = r.result; auto x_ins = r.instructions["x"]; auto a_ins = r.instructions["a"]; @@ -552,7 +525,6 @@ struct find_add_lit_broadcast auto sumab = m.insert_instruction(ins, make_op("add"), a_ins, b_ins); m.replace_instruction(ins, make_op("add"), x_ins, sumab); - }); } }; @@ -566,7 +538,6 @@ struct find_double_add_lit_broadcast void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_double_add_lit_broadcast", [&] { auto ins = r.result; auto x_ins = r.instructions["x"]; auto y_ins = r.instructions["y"]; @@ -591,7 +562,6 @@ struct find_double_add_lit_broadcast auto sumxy = m.insert_instruction(ins, make_op("add"), x_ins, y_ins); m.replace_instruction(ins, make_op("add"), sumxy, sumab); - }); } }; @@ -773,7 +743,6 @@ struct find_inner_broadcast void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_inner_broadcast", [&] { auto ins = r.result; const auto& broadcasts = ins->inputs(); if(broadcasts.empty()) @@ -822,7 +791,6 @@ struct find_inner_broadcast { apply_diff_broadcasts(m, ins); } - }); } }; @@ -835,7 +803,6 @@ struct find_dot_broadcast void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_dot_broadcast", [&] { auto ins = r.result; auto a = ins->inputs()[0]; auto b = ins->inputs()[1]; @@ -895,7 +862,6 @@ struct find_dot_broadcast auto broadcast = m.insert_instruction( ins, make_op("multibroadcast", {{"out_lens", ins->get_shape().lens()}}), dot); m.replace_instruction(ins, broadcast); - }); } }; @@ -942,7 +908,6 @@ struct find_concat_op void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_concat_op", [&] { auto ins = r.result; auto axis = any_cast(ins->get_operator()).axis; @@ -1009,7 +974,6 @@ struct find_concat_op m.replace_instruction(ins, args.front()); else m.replace_instruction(ins, make_op("concat", {{"axis", axis}}), args); - }); } }; @@ -1023,7 +987,6 @@ struct find_concat_conv void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_concat_conv", [&] { auto ins = r.result; auto axis = ins->get_operator().to_value()["axis"].to(); if(axis != 1) @@ -1060,7 +1023,6 @@ struct find_concat_conv auto w = m.insert_instruction(ins, make_op("concat", {{"axis", 0}}), weights); conv.from_value({{"group", original_group * inputs.size()}}); m.replace_instruction(ins, conv, x, w); - }); } }; @@ -1259,7 +1221,6 @@ struct find_splits void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_splits", [&] { auto ins = r.result; auto splits = get_splits(ins); if(splits.empty()) @@ -1349,7 +1310,6 @@ struct find_splits } } } - }); } }; @@ -1370,7 +1330,6 @@ struct find_split_concat // Verifies that the slices meet several conditions: they must all output to the same // concat instruction, slice on the same (1 only) axis, and the end of one slice // must match the start of the next. - time_matcher("find_split_concat", [&] { auto ins = r.result; auto splits = get_splits(ins); @@ -1425,7 +1384,6 @@ struct find_split_concat m.replace_instruction(concat, args.front()); else m.replace_instruction(concat, concat->get_operator(), args); - }); } }; @@ -1470,7 +1428,6 @@ struct find_add_convs void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_add_convs", [&] { auto ins = r.result; auto a_conv = r.instructions["a"]; auto a_input = a_conv->inputs().at(0); @@ -1522,7 +1479,6 @@ struct find_add_convs auto concat_weights = m.insert_instruction(ins, make_op("concat", {{"axis", 1}}), a_weights, b_weights); m.replace_instruction(ins, new_op, concat_input, concat_weights); - }); } }; @@ -1546,7 +1502,6 @@ struct find_conv_dot_horiz_fusion void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_conv_dot_horiz_fusion", [&] { auto ins = r.result; auto pred = [](auto i, auto j) { @@ -1614,7 +1569,6 @@ struct find_conv_dot_horiz_fusion auto outputs = ins->outputs(); group_by(outputs.begin(), outputs.end(), each, pred); - }); } }; @@ -1627,7 +1581,6 @@ struct find_div_const void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_div_const", [&] { auto ins = r.result; auto c_ins = r.instructions["c"]; @@ -1639,7 +1592,6 @@ struct find_div_const auto args = ins->inputs(); m.replace_instruction(ins, make_op("mul"), args.front(), recip); - }); } }; @@ -1660,12 +1612,10 @@ struct find_unit_ops void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_unit_ops", [&] { auto ins = r.result; auto c_in = r.instructions["x"]; m.replace_instruction(ins, c_in); - }); } }; @@ -1684,13 +1634,11 @@ struct find_neg_unit_ops void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_neg_unit_ops", [&] { auto ins = r.result; auto c_in = r.instructions["x"]; auto neg = m.insert_instruction(ins, make_op("neg"), c_in); m.replace_instruction(ins, neg); - }); } }; @@ -1710,7 +1658,6 @@ struct eliminate_zero_point void apply(module& m, const match::matcher_result& r) const { - time_matcher("eliminate_zero_point", [&] { auto ins = r.result; auto x = r.instructions["x"]; auto scale = r.instructions["scale"]; @@ -1722,7 +1669,6 @@ struct eliminate_zero_point } auto qdq_ins = m.insert_instruction(ins, migraphx::make_op(ins->name(), op), {x, scale}); m.replace_instruction(ins, qdq_ins); - }); } }; @@ -1739,12 +1685,10 @@ struct find_zero_ops void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_zero_ops", [&] { auto ins = r.result; auto zero_ins = r.instructions["x"]; m.replace_instruction(ins, zero_ins); - }); } }; @@ -1757,7 +1701,6 @@ struct find_sub_const void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_sub_const", [&] { auto ins = r.result; auto c_ins = r.instructions["c"]; @@ -1766,7 +1709,6 @@ struct find_sub_const auto args = ins->inputs(); m.replace_instruction(ins, make_op("add"), args.front(), neg); - }); } }; @@ -1780,12 +1722,10 @@ struct find_rsqrt void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_rqrt", [&] { auto ins = r.result; auto x_ins = r.instructions["x"]; m.replace_instruction(ins, make_op("rsqrt"), x_ins); - }); } }; @@ -1807,7 +1747,6 @@ struct find_split_reshape void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_split_reshape", [&] { auto slc = r.instructions["slice"]; auto rsp = r.instructions["reshape"]; auto input = slc->inputs().front(); @@ -1962,7 +1901,6 @@ struct find_split_reshape {{"axes", {rsp_axis}}, {"starts", {new_starts[i]}}, {"ends", {new_ends[i]}}}), rsp_ins); } - }); } }; @@ -1976,7 +1914,6 @@ struct find_split_transpose void apply(module& m, const match::matcher_result& r) const { - time_matcher("find_split_transpose", [&] { auto slc = r.instructions["slice"]; auto trans = r.instructions["trans"]; @@ -2024,7 +1961,6 @@ struct find_split_transpose make_op("slice", {{"axes", {axis_new}}, {"starts", starts}, {"ends", ends}}), tr); } - }); } }; From c27d5478ed73feb2f27ba2eefa86a78a839bf8ce Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Wed, 23 Oct 2024 03:35:22 +0000 Subject: [PATCH 08/16] env variable added --- src/include/migraphx/matcher.hpp | 47 +++++++++++++++++++------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index fdada026e66..80bc25c273c 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -37,6 +37,7 @@ #include #include #include +#include #ifndef MIGRAPHX_USE_TYPE_ERASED_MATCHERS #define MIGRAPHX_USE_TYPE_ERASED_MATCHERS 0 @@ -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 @@ -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) { @@ -415,29 +418,35 @@ 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; - auto r = match_instruction(get_module(mod), ins, m.matcher()); - if(r.result == get_module(mod).end()) + auto elapsed_time = time([&] { + auto r = match_instruction(get_module(mod), ins, m.matcher()); + 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) { - 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); } + // 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()) + { + 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); + } + } + match = true; + }); + if(time_matchers) + { + std::cout << "Matcher " << matcher_name << " took " << elapsed_time << "ns." << std::endl; } - match = true; }, ms...); } From ffd393e9d32c1620df7e86d5ac423725058cc65a Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Wed, 23 Oct 2024 03:59:53 +0000 Subject: [PATCH 09/16] trace filter added --- src/include/migraphx/matcher.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index 80bc25c273c..811d37c58b6 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -443,7 +443,7 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M } match = true; }); - if(time_matchers) + if(time_matchers and trace_for) { std::cout << "Matcher " << matcher_name << " took " << elapsed_time << "ns." << std::endl; } From dc3e8f899cd0e7b7ce28ce05ab84b2c44ddf8145 Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Mon, 28 Oct 2024 20:14:08 +0000 Subject: [PATCH 10/16] timing for matching and apply --- src/include/migraphx/matcher.hpp | 55 ++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index 811d37c58b6..275b4c7b5c3 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -418,34 +418,41 @@ 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; - auto elapsed_time = time([&] { - auto r = match_instruction(get_module(mod), ins, m.matcher()); - if(r.result == get_module(mod).end()) + + timer match_timer; + auto r = match_instruction(get_module(mod), ins, m.matcher()); + auto match_time = match_timer.record(); + + 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) + 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(); + + timer apply_timer; + m.apply(mod, r); + auto apply_time = apply_timer.record(); + + if(validate and not invalidated) + { + auto invalid = get_module(mod).validate(); + if(invalid != get_module(mod).end()) { - auto invalid = get_module(mod).validate(); - if(invalid != get_module(mod).end()) - { - 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 << "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); } - match = true; - }); - if(time_matchers and trace_for) + } + match = true; + if(time_matchers) { - std::cout << "Matcher " << matcher_name << " took " << elapsed_time << "ns." << std::endl; + std::cout << "Matching for " << matcher_name << " took " << match_time << "ns." << std::endl; + std::cout << "Apply for " << matcher_name << " took " << apply_time << "ns." << std::endl; } }, ms...); From a27281b1288aae1666569502807f8a3f142def67 Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Tue, 29 Oct 2024 19:28:51 +0000 Subject: [PATCH 11/16] microseconds and changes --- src/include/migraphx/matcher.hpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index 275b4c7b5c3..526d21f0001 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -419,9 +419,14 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M if(trace > 1 and trace_for) std::cout << "Match: " << matcher_name << std::endl; - timer match_timer; + timer match_timer; auto r = match_instruction(get_module(mod), ins, m.matcher()); - auto match_time = match_timer.record(); + auto match_time = match_timer.record>(); + + if(time_matchers or trace_for) + { + std::cout << "Matching for " << matcher_name << " took " << match_time << "ns." << std::endl; + } if(r.result == get_module(mod).end()) return; @@ -433,10 +438,15 @@ 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(); - + auto apply_time = time>([&] { + m.apply(mod, r); + }); + + if(time_matchers or trace_for) + { + std::cout << "Apply for " << matcher_name << " took " << apply_time << "ns." << std::endl; + } + if(validate and not invalidated) { auto invalid = get_module(mod).validate(); @@ -449,11 +459,6 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M } } match = true; - if(time_matchers) - { - std::cout << "Matching for " << matcher_name << " took " << match_time << "ns." << std::endl; - std::cout << "Apply for " << matcher_name << " took " << apply_time << "ns." << std::endl; - } }, ms...); } From 436b3bfde3ec0814bda415172ba7e41c1894b812 Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Mon, 4 Nov 2024 15:47:01 +0000 Subject: [PATCH 12/16] default construct the result and assign in lambda --- src/include/migraphx/matcher.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index 526d21f0001..13e694c0edf 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -407,6 +407,8 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M 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); @@ -419,9 +421,8 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M 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>(); + const auto match_time = match_timer.record>(); if(time_matchers or trace_for) { From 766cf9215c9ce23c0a8c304863865872fc8bc4a7 Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Mon, 4 Nov 2024 16:57:11 +0000 Subject: [PATCH 13/16] ns to us --- src/include/migraphx/matcher.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index 13e694c0edf..bdcf939fc21 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -426,7 +426,7 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M if(time_matchers or trace_for) { - std::cout << "Matching for " << matcher_name << " took " << match_time << "ns." << std::endl; + std::cout << "Matching for " << matcher_name << " took " << match_time << "us." << std::endl; } if(r.result == get_module(mod).end()) @@ -445,7 +445,7 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M if(time_matchers or trace_for) { - std::cout << "Apply for " << matcher_name << " took " << apply_time << "ns." << std::endl; + std::cout << "Apply for " << matcher_name << " took " << apply_time << "us." << std::endl; } if(validate and not invalidated) From 51bc95761aeec71eab05a75ea12601ef8f3bbe5d Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Mon, 4 Nov 2024 20:13:29 +0000 Subject: [PATCH 14/16] Formatting --- src/include/migraphx/matcher.hpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index bdcf939fc21..5d014a758c6 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -408,7 +408,6 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M 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); @@ -423,10 +422,10 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M auto r = match_instruction(get_module(mod), ins, m.matcher()); const auto match_time = match_timer.record>(); - if(time_matchers or trace_for) { - std::cout << "Matching for " << matcher_name << " took " << match_time << "us." << std::endl; + std::cout << "Matching for " << matcher_name << " took " << match_time << "us." + << std::endl; } if(r.result == get_module(mod).end()) @@ -439,13 +438,13 @@ 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(); - auto apply_time = time>([&] { - m.apply(mod, r); - }); + auto apply_time = + time>([&] { m.apply(mod, r); }); if(time_matchers or trace_for) { - std::cout << "Apply for " << matcher_name << " took " << apply_time << "us." << std::endl; + std::cout << "Apply for " << matcher_name << " took " << apply_time << "us." + << std::endl; } if(validate and not invalidated) From a3a5fcc36f23ee81815e42f28cbae3ff67703b15 Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Tue, 5 Nov 2024 00:00:14 +0000 Subject: [PATCH 15/16] Formatting --- src/include/migraphx/matcher.hpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index 5d014a758c6..7d0d3047082 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -437,10 +437,8 @@ 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(); - auto apply_time = time>([&] { m.apply(mod, r); }); - if(time_matchers or trace_for) { std::cout << "Apply for " << matcher_name << " took " << apply_time << "us." From c6a6d3798bba512268eac21d2f14b389ae93f352 Mon Sep 17 00:00:00 2001 From: aarushjain29 Date: Fri, 7 Feb 2025 23:48:35 +0000 Subject: [PATCH 16/16] print timing info inside the loop --- src/include/migraphx/matcher.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/include/migraphx/matcher.hpp b/src/include/migraphx/matcher.hpp index 0573cabf6ba..4df6563aa54 100644 --- a/src/include/migraphx/matcher.hpp +++ b/src/include/migraphx/matcher.hpp @@ -427,9 +427,9 @@ void find_matches_for(source_location location, Mod& mod, instruction_ref ins, M std::cout << "Match: " << matcher_name << std::endl; auto r = match_instruction(get_module(mod), ins, m.matcher()); - const auto match_time = match_timer.record>(); if(time_matchers or trace_for) { + const auto match_time = match_timer.record>(); std::cout << "Matching for " << matcher_name << " took " << match_time << "us." << std::endl; }