From ae56515533c765c6c5c2695ba373689d5bfe6b2c Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 20 Oct 2023 16:39:31 +0000 Subject: [PATCH 1/2] Add tracing to benchmark to show wich kernels are running and the time of every kernel --- src/targets/gpu/compile_ops.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/targets/gpu/compile_ops.cpp b/src/targets/gpu/compile_ops.cpp index 5b63a17c7a0..547e1025d8f 100644 --- a/src/targets/gpu/compile_ops.cpp +++ b/src/targets/gpu/compile_ops.cpp @@ -37,6 +37,7 @@ inline namespace MIGRAPHX_INLINE_NS { namespace gpu { MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_GPU_COMPILE_PARALLEL); +MIGRAPHX_DECLARE_ENV_VAR(MIGRAPHX_TRACE_BENCHMARKING); struct precompile_op { @@ -179,13 +180,24 @@ struct compile_plan MIGRAPHX_THROW("Multiple kernels without config"); std::cout << "Benchmarking " << preop.name() << ": " << results.size() << " configs" << std::endl; + if(enabled(MIGRAPHX_TRACE_BENCHMARKING{})) + std::cout << "Problem: " << config->problem << std::endl; std::vector times; times.reserve(results.size()); std::transform( - results.begin(), results.end(), std::back_inserter(times), [&](const auto& cr) { + results.begin(), results.end(), config->solutions.begin(), std::back_inserter(times), [&](const auto& cr, const auto& solution) { + if(enabled(MIGRAPHX_TRACE_BENCHMARKING{})) + std::cout << "Benchmarking solution: " << solution << std::endl; if(not cr.has_value()) + { + if(enabled(MIGRAPHX_TRACE_BENCHMARKING{})) + std::cout << "No binary" << std::endl; return std::numeric_limits::max(); - return time_op(*ctx, cr->replace.code_object, to_shapes(cr->ins->inputs()), 20); + } + auto t = time_op(*ctx, cr->replace.code_object, to_shapes(cr->ins->inputs()), 20); + if(enabled(MIGRAPHX_TRACE_BENCHMARKING{})) + std::cout << t << "ms" << std::endl; + return t; }); auto i = std::distance(times.begin(), std::min_element(times.begin(), times.end())); std::cout << "Fastest solution: " << config->solutions.at(i) << std::endl; From e462171bce25c2318129b7a6d2bdff09972e99e3 Mon Sep 17 00:00:00 2001 From: Paul Date: Fri, 20 Oct 2023 16:39:39 +0000 Subject: [PATCH 2/2] Format --- src/targets/gpu/compile_ops.cpp | 34 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/targets/gpu/compile_ops.cpp b/src/targets/gpu/compile_ops.cpp index 547e1025d8f..a7e2438e2e8 100644 --- a/src/targets/gpu/compile_ops.cpp +++ b/src/targets/gpu/compile_ops.cpp @@ -184,21 +184,25 @@ struct compile_plan std::cout << "Problem: " << config->problem << std::endl; std::vector times; times.reserve(results.size()); - std::transform( - results.begin(), results.end(), config->solutions.begin(), std::back_inserter(times), [&](const auto& cr, const auto& solution) { - if(enabled(MIGRAPHX_TRACE_BENCHMARKING{})) - std::cout << "Benchmarking solution: " << solution << std::endl; - if(not cr.has_value()) - { - if(enabled(MIGRAPHX_TRACE_BENCHMARKING{})) - std::cout << "No binary" << std::endl; - return std::numeric_limits::max(); - } - auto t = time_op(*ctx, cr->replace.code_object, to_shapes(cr->ins->inputs()), 20); - if(enabled(MIGRAPHX_TRACE_BENCHMARKING{})) - std::cout << t << "ms" << std::endl; - return t; - }); + std::transform(results.begin(), + results.end(), + config->solutions.begin(), + std::back_inserter(times), + [&](const auto& cr, const auto& solution) { + if(enabled(MIGRAPHX_TRACE_BENCHMARKING{})) + std::cout << "Benchmarking solution: " << solution << std::endl; + if(not cr.has_value()) + { + if(enabled(MIGRAPHX_TRACE_BENCHMARKING{})) + std::cout << "No binary" << std::endl; + return std::numeric_limits::max(); + } + auto t = time_op( + *ctx, cr->replace.code_object, to_shapes(cr->ins->inputs()), 20); + if(enabled(MIGRAPHX_TRACE_BENCHMARKING{})) + std::cout << t << "ms" << std::endl; + return t; + }); auto i = std::distance(times.begin(), std::min_element(times.begin(), times.end())); std::cout << "Fastest solution: " << config->solutions.at(i) << std::endl; pc.insert(preop.name(), config->problem, config->solutions.at(i));