Skip to content

Commit

Permalink
Convert stmt_html output to use stmt_viz output (halide#7516)
Browse files Browse the repository at this point in the history
* Allow emitting `stmt_viz` without specifying `assembly`

TL;DR: if we request `stmt_viz` without `assembly`, just generate the latter to a temp file that we dispose of later; this wasn't feasible before since we were previously requiring the assembly output to be generated with the same directory and basename as stmt_viz, but that was fixed.

* Convert stmt_html output to use stmt_viz output

Per discussion on halide#7507, this entirely removes the "classic" stmt_html output and replaces it with the "new" StmtToViz output. Using `compile_to_lowered_stmt` or requesting `stmt_html` will now always output the new output, and requesting `stmt_viz` output is no longer legal.

(Note that this builds on top of halide#7515, which must be submitted first.)

It's not clear to me whether halide#7507 (comment) is a blocker for this change, or a request to add back already-lost functionality.

* Update Makefile

* Update Generator.cpp
  • Loading branch information
steven-johnson authored and ardier committed Mar 3, 2024
1 parent c363ca8 commit 7b4dacd
Show file tree
Hide file tree
Showing 10 changed files with 18 additions and 1,159 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,6 @@ SOURCE_FILES = \
SpirvIR.cpp \
SplitTuples.cpp \
StageStridedLoads.cpp \
StmtToHtml.cpp \
StmtToViz.cpp \
StorageFlattening.cpp \
StorageFolding.cpp \
Expand Down Expand Up @@ -739,7 +738,6 @@ HEADER_FILES = \
Solve.h \
SplitTuples.h \
StageStridedLoads.h \
StmtToHtml.h \
StmtToViz.h \
StorageFlattening.h \
StorageFolding.h \
Expand Down
2 changes: 1 addition & 1 deletion python_bindings/test/correctness/compile_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def main():
else:
assert os.path.isfile(os.path.join(tmpdir, "f_all.o"))

p = os.path.join(tmpdir, "f.html")
p = os.path.join(tmpdir, "f.stmt.html")
f.compile_to({hl.OutputFileType.stmt_html: p}, args, "f")
assert os.path.isfile(p)

Expand Down
23 changes: 9 additions & 14 deletions python_bindings/tutorial/lesson_03_debugging_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,15 @@ def main():
# of compilation, and also the llvm bitcode we generate at the
# end.

# If you'd prefer to read C code, the compile_to_c method emits C
# code that implements the Halide pipeline. It can't compile
# as-is without you also implementing some support functions, but
# it can be helpful for understanding what the Halide pipeline is
# doing. You pass it the name of the file, a list of arguments
# the generated function should take (none in this case), and the
# name of the generated function. Have a look inside gradient.cpp
# after compiling and running this lesson.
gradient.compile_to_c("gradient.cpp", [], "gradient")

# Using these two tricks -- setting HL_DEBUG_CODEGEN and calling
# compile_to_c -- you can usually figure out what code Halide is
# generating. In the next lesson we'll see how to snoop on Halide
# at runtime.
# Halide will also output an HTML version of this output, which
# supports syntax highlighting and code-folding, so it can be
# nicer to read for large pipelines. Open gradient.stmt.html" with your
# browser after running this tutorial.
gradient.compile_to_lowered_stmt("gradient.stmt.html", [], hl.StmtOutputFormat.HTML)

# You can usually figure out what code Halide is generating using
# this pseudocode. In the next lesson we'll see how to snoop on
# Halide at runtime.

print("Success!")
return 0
Expand Down
2 changes: 0 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ set(HEADER_FILES
Solve.h
SplitTuples.h
StageStridedLoads.h
StmtToHtml.h
StmtToViz.h
StorageFlattening.h
StorageFolding.h
Expand Down Expand Up @@ -329,7 +328,6 @@ set(SOURCE_FILES
SpirvIR.cpp
SplitTuples.cpp
StageStridedLoads.cpp
StmtToHtml.cpp
StmtToViz.cpp
StorageFlattening.cpp
StorageFolding.cpp
Expand Down
9 changes: 1 addition & 8 deletions src/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ gengen
-e A comma separated list of files to emit. Accepted values are:
[assembly, bitcode, c_header, c_source, cpp_stub, featurization,
llvm_assembly, object, python_extension, pytorch_wrapper, registration,
schedule, static_library, stmt, stmt_html, stmt_viz, compiler_log].
schedule, static_library, stmt, stmt_html, compiler_log].
If omitted, default value is [c_header, static_library, registration].
-p A comma-separated list of shared libraries that will be loaded before the
Expand Down Expand Up @@ -790,13 +790,6 @@ gengen
output_types.insert(OutputFileType::registration);
output_types.insert(OutputFileType::static_library);
} else {
// if emit_flags contains "stmt_viz" but not "assembly", throw an error
bool has_stmt_viz = std::find(emit_flags.begin(), emit_flags.end(), "stmt_viz") != emit_flags.end();
bool has_assembly = std::find(emit_flags.begin(), emit_flags.end(), "assembly") != emit_flags.end();

user_assert(!has_stmt_viz || has_assembly)
<< "Output flag `stmt_viz` requires the `assembly` flag to also be set.";

// Build a reverse lookup table. Allow some legacy aliases on the command line,
// to allow legacy build systems to work more easily.
std::map<std::string, OutputFileType> output_name_to_enum = {
Expand Down
16 changes: 5 additions & 11 deletions src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#include "LLVM_Runtime_Linker.h"
#include "Pipeline.h"
#include "PythonExtensionGen.h"
#include "StmtToHtml.h"
#include "StmtToViz.h"

namespace Halide {
Expand Down Expand Up @@ -50,7 +49,6 @@ std::map<OutputFileType, const OutputInfo> get_output_info(const Target &target)
{OutputFileType::static_library, {"static_library", is_windows_coff ? ".lib" : ".a", IsSingle}},
{OutputFileType::stmt, {"stmt", ".stmt", IsMulti}},
{OutputFileType::stmt_html, {"stmt_html", ".stmt.html", IsMulti}},
{OutputFileType::stmt_viz, {"stmt_viz", ".stmt.viz.html", IsMulti}},
};
return ext;
}
Expand Down Expand Up @@ -523,18 +521,14 @@ MetadataNameMap Module::get_metadata_name_map() const {
void Module::compile(const std::map<OutputFileType, std::string> &output_files) const {
validate_outputs(output_files);

// output stmt and html prior to resolving submodules. We need to
// output stmt prior to resolving submodules. We need to
// clear the output after writing it, otherwise the output will
// be overwritten by recursive calls after submodules are resolved.
if (contains(output_files, OutputFileType::stmt)) {
debug(1) << "Module.compile(): stmt " << output_files.at(OutputFileType::stmt) << "\n";
std::ofstream file(output_files.at(OutputFileType::stmt));
file << *this;
}
if (contains(output_files, OutputFileType::stmt_html)) {
debug(1) << "Module.compile(): stmt_html " << output_files.at(OutputFileType::stmt_html) << "\n";
Internal::print_to_html(output_files.at(OutputFileType::stmt_html), *this);
}

// Minor but worthwhile optimization: if all of the output files are of types that won't
// ever rely on submodules (e.g.: toplevel declarations in C/C++), don't bother resolving
Expand All @@ -553,7 +547,6 @@ void Module::compile(const std::map<OutputFileType, std::string> &output_files)
std::map<OutputFileType, std::string> output_files_copy = output_files;
output_files_copy.erase(OutputFileType::stmt);
output_files_copy.erase(OutputFileType::stmt_html);
output_files_copy.erase(OutputFileType::stmt_viz);
resolve_submodules().compile(output_files_copy);
return;
}
Expand Down Expand Up @@ -630,9 +623,10 @@ void Module::compile(const std::map<OutputFileType, std::string> &output_files)
}
}

if (contains(output_files, OutputFileType::stmt_viz)) {
debug(1) << "Module.compile(): stmt_viz " << output_files.at(OutputFileType::stmt_viz) << "\n";
Internal::print_to_viz(output_files.at(OutputFileType::stmt_viz), *this, assembly_path);
if (contains(output_files, OutputFileType::stmt_html)) {
internal_assert(!assembly_path.empty());
debug(1) << "Module.compile(): stmt_html " << output_files.at(OutputFileType::stmt_html) << "\n";
Internal::print_to_viz(output_files.at(OutputFileType::stmt_html), *this, assembly_path);
}
if (contains(output_files, OutputFileType::function_info_header)) {
debug(1) << "Module.compile(): function_info_header " << output_files.at(OutputFileType::function_info_header) << "\n";
Expand Down
1 change: 0 additions & 1 deletion src/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ enum class OutputFileType {
static_library,
stmt,
stmt_html,
stmt_viz,
};

/** Type of linkage a function in a lowered Halide module can have.
Expand Down
Loading

0 comments on commit 7b4dacd

Please sign in to comment.