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

Add a dump option to dump a fusion IR graph #3603

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions csrc/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ std::unordered_map<DebugDumpOption, std::vector<std::string>> Options<
{"expr_sort_verbose", DebugDumpOption::ExprSortVerbose},
{"ftrace", DebugDumpOption::FunctionTrace},
{"fusion_args", DebugDumpOption::FusionArgs},
{"fusion_ir_original", DebugDumpOption::FusionIrOriginal},
{"fusion_ir_concretized", DebugDumpOption::FusionIrConcretized},
{"fusion_ir_preseg", DebugDumpOption::FusionIrPreseg},
{"fusion_ir_presched", DebugDumpOption::FusionIrPresched},
{"fusion_ir", DebugDumpOption::FusionIr},
{"fusion_ir_concretized", DebugDumpOption::FusionIrConcretized},
{"fusion_ir_graph", DebugDumpOption::FusionIrGraph},
{"fusion_ir_math", DebugDumpOption::FusionIrMath},
{"fusion_ir_original", DebugDumpOption::FusionIrOriginal},
{"fusion_ir_presched", DebugDumpOption::FusionIrPresched},
{"fusion_ir_preseg", DebugDumpOption::FusionIrPreseg},
Comment on lines +116 to +121
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just changed to the alphabetical ordering

{"global_zeroed_memory", DebugDumpOption::GlobalZeroedMemory},
{"host_ir", DebugDumpOption::HostIr},
{"index_type", DebugDumpOption::IndexType},
Expand Down
1 change: 1 addition & 0 deletions csrc/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ enum class DebugDumpOption {
// TODO(wujingyue): name the following FusionIrSched
FusionIr, //!< Dump the Fusion IR before lowering. This is the Fusion IR fed
//!< to `KernelExecutor::compileFusion`.
FusionIrGraph, //!< Dump a GraphViz graph of the Fusion IR
FusionIrMath, //!< Dump just the compute (math) part of the above `FusionIr`
//!< for conciseness
KernelIr, //!< Dump the compiler Kernel IR
Expand Down
22 changes: 18 additions & 4 deletions csrc/runtime/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <global_allocator.h>
#include <instrumentation.h>
#include <ir/all_nodes.h>
#include <ir/graphviz.h>
#include <ir/utils.h>
#include <iter_visitor.h>
#include <kernel_ir.h>
Expand Down Expand Up @@ -304,6 +305,9 @@ void KernelExecutor::compile(
NVF_ERROR(
!fusion->outputs().empty(), "No output found for this kernel, aborting.");

createKernelId(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove

createKernelId(
scheduler_type, fusion_id_, concrete_id_, runtime_id_, group_id_);
? I don't think there's value to create twice.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just moved it here.

I also am not sure if this should be a stateful operation. It seems just returning a string seems sufficient, but didn't bother to do a further cleanup.

scheduler_type, fusion_id_, concrete_id_, runtime_id_, group_id_);

// TODO: refactor the options_ passed through
options_.device = c10::Device(c10::DeviceType::CUDA, args.getDeviceIndex());

Expand Down Expand Up @@ -346,10 +350,21 @@ void KernelExecutor::compile(
}
}

if (isDebugDumpEnabled(DebugDumpOption::FusionIrMath)) {
fusion->printMath();
}

if (isDebugDumpEnabled(DebugDumpOption::FusionIr)) {
fusion->print();
} else if (isDebugDumpEnabled(DebugDumpOption::FusionIrMath)) {
fusion->printMath();
}

if (isDebugDumpEnabled(DebugDumpOption::FusionIrGraph)) {
std::stringstream file_name;
file_name << "__tmp_fusion_ir_graph_" << kernel_id_ << ".dot";
IrGraphGenerator::print(
fusion,
file_name.str().c_str(),
IrGraphGenerator::DetailLevel::ComputeOnly);
}

//! Force index_type to int and disable magic zero if we detect that the
Expand Down Expand Up @@ -418,8 +433,7 @@ void KernelExecutor::compile(
for (const auto& hook : post_lowering_hooks_) {
hook(kernel);
}
createKernelId(
scheduler_type, fusion_id_, concrete_id_, runtime_id_, group_id_);

setUsedTVs();

if (isDebugDumpEnabled(DebugDumpOption::KernelIr)) {
Expand Down
Loading