-
Notifications
You must be signed in to change notification settings - Fork 89
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
Show mlir program when tracing benchmarking #2741
Changes from all commits
3b7de87
2ef5a25
3cd5bcc
9af7f32
7a53ebf
7c3a2ab
cbf7536
99404b0
e1e1d34
c9a7368
a851003
efbcb01
30e1e25
5572ba7
26f6742
7263ac2
cec1a18
c5a4040
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,12 @@ struct compiled_result | |
{ | ||
compiler_replace replace; | ||
instruction_ref ins; | ||
|
||
friend std::ostream& operator<<(std::ostream& os, const compiled_result& cr) | ||
{ | ||
cr.replace.trace(os, cr.ins); | ||
return os; | ||
} | ||
}; | ||
|
||
struct compile_plan | ||
|
@@ -153,22 +159,33 @@ struct compile_plan | |
insert_compiles(compiles, value{}, 0); | ||
} | ||
} | ||
std::string problem_string() const | ||
{ | ||
if(config) | ||
return to_string(config->problem); | ||
return "<no problem key>"; | ||
} | ||
|
||
const compiled_result& benchmark() const | ||
{ | ||
const auto trace_level = value_of(MIGRAPHX_TRACE_BENCHMARKING{}); | ||
if(trace_level > 0 and not results.empty()) | ||
{ | ||
std::cout << "Benchmarking " << preop.name() << ": " << results.size() << " configs" | ||
<< std::endl; | ||
} | ||
if(results.empty()) | ||
MIGRAPHX_THROW("No configs to tune"); | ||
MIGRAPHX_THROW("No valid tuned compilation for " + preop.name() + " with " + | ||
problem_string()); | ||
if(results.size() == 1) | ||
{ | ||
if(not results.front().has_value()) | ||
MIGRAPHX_THROW("No configs to tune"); | ||
MIGRAPHX_THROW("No valid tuned compilation for " + preop.name() + " with " + | ||
problem_string()); | ||
return *results.front(); | ||
} | ||
if(not config) | ||
MIGRAPHX_THROW("Multiple kernels without config"); | ||
if(trace_level > 0) | ||
std::cout << "Benchmarking " << preop.name() << ": " << results.size() << " configs" | ||
<< std::endl; | ||
MIGRAPHX_THROW("Multiple kernels without config for " + preop.name()); | ||
if(trace_level > 1) | ||
std::cout << "Problem: " << config->problem << std::endl; | ||
std::vector<double> times; | ||
|
@@ -186,6 +203,8 @@ struct compile_plan | |
std::cout << "No binary" << std::endl; | ||
return std::numeric_limits<double>::max(); | ||
} | ||
if(trace_level > 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add this option to documents |
||
std::cout << *cr << std::endl; | ||
/* | ||
create a small program with insturction being compiled and call "replace" | ||
on that which would insert all the compiled code objects, prefills etc. | ||
|
@@ -220,7 +239,7 @@ struct compile_plan | |
ctx->get_problem_cache().insert(preop.name(), config->problem, config->solutions.at(i)); | ||
if(not results[i].has_value()) | ||
MIGRAPHX_THROW("No valid tuned compilation for " + preop.name() + " with " + | ||
to_string(config->problem)); | ||
problem_string()); | ||
auto skipped = std::count_if( | ||
results.begin(), results.end(), [](const auto& cr) { return not cr.has_value(); }); | ||
if(skipped > 0) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -956,14 +956,6 @@ bool is_module_fusible(const module& m, const context& migraphx_ctx, const value | |
return mlirIsModuleFusible(mp.mmodule.get(), make_mlir_string_ref(*solution.if_string())); | ||
} | ||
|
||
std::string dump_mlir(const module& m) | ||
{ | ||
mlir_program mp; | ||
mp.parse(m); | ||
auto mod_op = mlirModuleGetOperation(mp.mmodule.get()); | ||
return mlir_print(&mlirOperationPrint, mod_op); | ||
} | ||
|
||
void adjust_param_shapes(module& m, const std::vector<shape>& inputs) | ||
{ | ||
auto names = m.get_parameter_names(); | ||
|
@@ -982,6 +974,24 @@ void adjust_param_shapes(module& m, const std::vector<shape>& inputs) | |
} | ||
} | ||
|
||
std::string dump_mlir(const module& m, const std::vector<shape>& inputs) | ||
{ | ||
module mm; | ||
const_module_ref mr = &m; | ||
if(not inputs.empty()) | ||
{ | ||
mm = m; | ||
mr = &mm; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does it require const_ref ? Shouldn't just copied module There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only want to copy the module if there is no input shapes because we wont be adjusting the parameters. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Module with empty input shape is unlikely case it would have been const-folded. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is better to assume inputs are not empty. it would be simpler There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is two overloads to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes but those input shapes parameter would be input arguments to the precompile_op instruction. If they are empty that means MLIR module also doesn't take any inputs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When the inputs are empty it means skip doing param adjustments. |
||
adjust_param_shapes(mm, inputs); | ||
} | ||
mlir_program mp; | ||
mp.parse(*mr); | ||
auto mod_op = mlirModuleGetOperation(mp.mmodule.get()); | ||
return mlir_print(&mlirOperationPrint, mod_op); | ||
} | ||
|
||
std::string dump_mlir(const module& m) { return dump_mlir(m, {}); } | ||
|
||
mlir_code_object compile_mlir(const context& migraphx_ctx, | ||
module m, | ||
const std::vector<shape>& in_shapes, | ||
|
@@ -1063,27 +1073,36 @@ tuning_config get_tuning_config_mlir(const context& migraphx_ctx, | |
mlir_program mp; | ||
mp.set_gpu_properties(migraphx_ctx); | ||
mp.parse(m); | ||
auto tc = mp.get_tuning_config(exhaustive); | ||
|
||
const bool trace = enabled(MIGRAPHX_TRACE_MLIR{}); | ||
static std::mutex mutex; | ||
if(trace) | ||
{ | ||
const std::lock_guard<std::mutex> lock(mutex); | ||
std::cout << "Problem: " << tc.problem << std::endl; | ||
auto mod_op = mlirModuleGetOperation(mp.mmodule.get()); | ||
std::cout << mlir_print(&mlirOperationPrint, mod_op) << std::endl; | ||
} | ||
return mp.get_tuning_config(exhaustive); | ||
return tc; | ||
} | ||
|
||
#else | ||
|
||
std::string dump_mlir(const module&) { return {}; } | ||
|
||
template <class T> | ||
void use(T&) | ||
{ | ||
} | ||
|
||
std::string dump_mlir(const module&) { return {}; } | ||
|
||
std::string dump_mlir(const module& m, const std::vector<shape>& inputs) | ||
{ | ||
use(m); | ||
use(inputs); | ||
return {}; | ||
} | ||
|
||
// Disabling clang-tidy warning on non-real useage. | ||
// NOLINTBEGIN(performance-unnecessary-value-param) | ||
mlir_code_object compile_mlir(const context&, module, const std::vector<shape>&, const value&) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest you consolidate some of these checks with
if ... or ...