From b741d9c5b2705c45fd7c8462eb0b4bfa35a3e6d8 Mon Sep 17 00:00:00 2001 From: Martijn Courteaux Date: Tue, 16 Jul 2024 17:34:53 +0200 Subject: [PATCH] Adaptive Dark colorscheme for Stmt HTML. Ability to programmatically export conceptual stmt files. (#8327) * A few color tweaks for a darker colorscheme. * Dark color scheme for Stmt HTML. Ability to programatically export the conceptual stmt files. * Toolbar for HTML Stmt viewer with various settings. * Cleanup. --- python_bindings/src/halide/halide_/PyFunc.cpp | 5 + .../src/halide/halide_/PyPipeline.cpp | 5 + src/Func.cpp | 7 + src/Func.h | 8 + src/Pipeline.cpp | 8 + src/Pipeline.h | 8 + src/StmtToHTML.cpp | 34 + src/irvisualizer/generate_palettes.py | 42 +- src/irvisualizer/html_template_StmtToHTML.css | 756 +++++++++++------- src/irvisualizer/html_template_StmtToHTML.js | 70 +- ...html_template_StmtToHTML_dependencies.html | 68 +- 11 files changed, 700 insertions(+), 311 deletions(-) diff --git a/python_bindings/src/halide/halide_/PyFunc.cpp b/python_bindings/src/halide/halide_/PyFunc.cpp index bcc889b6d9ce..495187581aaa 100644 --- a/python_bindings/src/halide/halide_/PyFunc.cpp +++ b/python_bindings/src/halide/halide_/PyFunc.cpp @@ -287,6 +287,11 @@ void define_func(py::module &m) { f.compile_to_lowered_stmt(filename, args, fmt, to_aot_target(target)); }, py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) + .def( + "compile_to_conceptual_stmt", [](Func &f, const std::string &filename, const std::vector &args, StmtOutputFormat fmt, const Target &target) { + f.compile_to_conceptual_stmt(filename, args, fmt, to_aot_target(target)); + }, + py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) .def( "compile_to_file", [](Func &f, const std::string &filename_prefix, const std::vector &args, const std::string &fn_name, const Target &target) { f.compile_to_file(filename_prefix, args, fn_name, to_aot_target(target)); diff --git a/python_bindings/src/halide/halide_/PyPipeline.cpp b/python_bindings/src/halide/halide_/PyPipeline.cpp index a87ffcedf39d..aeac06fe8092 100644 --- a/python_bindings/src/halide/halide_/PyPipeline.cpp +++ b/python_bindings/src/halide/halide_/PyPipeline.cpp @@ -139,6 +139,11 @@ void define_pipeline(py::module &m) { p.compile_to_lowered_stmt(filename, args, fmt, to_aot_target(target)); }, py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) + .def( + "compile_to_conceptual_stmt", [](Pipeline &p, const std::string &filename, const std::vector &args, StmtOutputFormat fmt, const Target &target) { + p.compile_to_conceptual_stmt(filename, args, fmt, to_aot_target(target)); + }, + py::arg("filename"), py::arg("arguments"), py::arg("fmt") = Text, py::arg("target") = Target()) .def( "compile_to_file", [](Pipeline &p, const std::string &filename_prefix, const std::vector &args, const std::string &fn_name, const Target &target) { p.compile_to_file(filename_prefix, args, fn_name, to_aot_target(target)); diff --git a/src/Func.cpp b/src/Func.cpp index 3373348d37a9..29c1427274bc 100644 --- a/src/Func.cpp +++ b/src/Func.cpp @@ -3542,6 +3542,13 @@ void Func::compile_to_lowered_stmt(const string &filename, pipeline().compile_to_lowered_stmt(filename, args, fmt, target); } +void Func::compile_to_conceptual_stmt(const string &filename, + const vector &args, + StmtOutputFormat fmt, + const Target &target) { + pipeline().compile_to_conceptual_stmt(filename, args, fmt, target); +} + void Func::print_loop_nest() { pipeline().print_loop_nest(); } diff --git a/src/Func.h b/src/Func.h index f63195beb082..32d8f1e58c69 100644 --- a/src/Func.h +++ b/src/Func.h @@ -954,6 +954,14 @@ class Func { StmtOutputFormat fmt = Text, const Target &target = get_target_from_environment()); + /** Write out a conceptual representation of lowered code, before any parallel loop + * get factored out into separate functions, or GPU loops are offloaded to kernel code.r + * Useful for analyzing and debugging scheduling. Can emit html or plain text. */ + void compile_to_conceptual_stmt(const std::string &filename, + const std::vector &args, + StmtOutputFormat fmt = Text, + const Target &target = get_target_from_environment()); + /** Write out the loop nests specified by the schedule for this * Function. Helpful for understanding what a schedule is * doing. */ diff --git a/src/Pipeline.cpp b/src/Pipeline.cpp index 79d1701a2593..9109c0dd4ac1 100644 --- a/src/Pipeline.cpp +++ b/src/Pipeline.cpp @@ -356,6 +356,14 @@ void Pipeline::compile_to_lowered_stmt(const string &filename, m.compile(single_output(filename, m, fmt == HTML ? OutputFileType::stmt_html : OutputFileType::stmt)); } +void Pipeline::compile_to_conceptual_stmt(const string &filename, + const vector &args, + StmtOutputFormat fmt, + const Target &target) { + Module m = compile_to_module(args, "", target); + m.compile(single_output(filename, m, fmt == HTML ? OutputFileType::conceptual_stmt_html : OutputFileType::conceptual_stmt)); +} + void Pipeline::compile_to_static_library(const string &filename_prefix, const vector &args, const std::string &fn_name, diff --git a/src/Pipeline.h b/src/Pipeline.h index 37537db04fb7..ef3e5f11eca3 100644 --- a/src/Pipeline.h +++ b/src/Pipeline.h @@ -281,6 +281,14 @@ class Pipeline { StmtOutputFormat fmt = Text, const Target &target = get_target_from_environment()); + /** Write out a conceptual representation of lowered code, before any parallel loop + * get factored out into separate functions, or GPU loops are offloaded to kernel code.r + * Useful for analyzing and debugging scheduling. Can emit html or plain text. */ + void compile_to_conceptual_stmt(const std::string &filename, + const std::vector &args, + StmtOutputFormat fmt = Text, + const Target &target = get_target_from_environment()); + /** Write out the loop nests specified by the schedule for this * Pipeline's Funcs. Helpful for understanding what a schedule is * doing. */ diff --git a/src/StmtToHTML.cpp b/src/StmtToHTML.cpp index 79cf6563551e..0811f38175de 100644 --- a/src/StmtToHTML.cpp +++ b/src/StmtToHTML.cpp @@ -2378,7 +2378,10 @@ class PipelineHTMLInspector { void generate_body(const Module &m) { stream << "\n"; stream << "
\n"; + generate_toolbar(m); + stream << "
\n"; generate_visualization_panes(m); + stream << "
\n"; stream << "
\n"; #if INLINE_TEMPLATES stream << " - - -