Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
c9bd6d9
placeholder for IR visualization work from Darya Verzhbinsky
Sep 28, 2022
939a115
placeholder for IR visualization work from Darya Verzhbinsky
Sep 28, 2022
67dcf1a
Merge branch 'darya-ver/ir-viz' of https://github.com/halide/Halide i…
Oct 28, 2022
27fcd0a
New Feature: Halide Program IR Visualizer (#7056)
darya-ver Jan 31, 2023
2ac9e97
Merge branch 'main' into darya-ver/ir-viz
maaz139 Jan 31, 2023
46b2662
Refactor 1/N: Moved all static html, css and js code outside of the c…
maaz139 Feb 3, 2023
064b88e
Refactor 2/N: Broke down StmtToViz Class to two simpler classes
maaz139 Feb 7, 2023
f1fefa7
Refactor 3/N: Minor stylesheet and javascript improvements
maaz139 Feb 7, 2023
d7cacaf
Fixed resize bars not working properly
maaz139 Feb 7, 2023
12f7ddf
Refactoring Viz tab (WIP)
maaz139 Feb 9, 2023
8ba15e3
Refactored 4/N: Visualization tab complete
maaz139 Feb 17, 2023
9c426ac
Refactor 5/N: Javascript and css cleanup
maaz139 Feb 17, 2023
969b1a2
Refactor 6/N: JS and CSS refactor complete
maaz139 Feb 20, 2023
101d2e7
Refactor 7/N: Added assembly support
maaz139 Feb 20, 2023
a778f8a
Refactor 8/N: Deleted info bar
maaz139 Feb 20, 2023
941cdd3
Refactor 9/N: Deleting code
maaz139 Feb 20, 2023
148a48a
Remove stale files from build
maaz139 Mar 10, 2023
422a603
Refactor 10/N: Cost model simplified and re-activated
maaz139 Mar 10, 2023
18aba0d
Delete stale cost model code
maaz139 Mar 12, 2023
06ab0bd
Refactor 11/N: Reintegrate cost model into visualization
maaz139 Mar 12, 2023
17dc8bf
Merge branch 'main' into darya-ver/ir-viz
maaz139 Mar 13, 2023
e0e61af
Minor fixes
maaz139 Mar 14, 2023
fc3bfc5
Update CMakeLists.txt
maaz139 Mar 14, 2023
b9f4db3
Merge branch 'main' into darya-ver/ir-viz
maaz139 Mar 14, 2023
860ba44
Deleting more stale files
maaz139 Mar 14, 2023
e57ea25
Improved documentation for new code in Codegen_LLVM
maaz139 Mar 14, 2023
520bcb2
Static HTML, CSS and JS is now stored as large strings
maaz139 Mar 14, 2023
90383ba
Fix: Build error for unused variable
maaz139 Mar 14, 2023
e985c7b
Deleting dead code
maaz139 Mar 15, 2023
ea3c0c7
Stmt visualizer should not run on submodules
maaz139 Mar 15, 2023
0a906a2
Ran clang-format on the PR
maaz139 Mar 15, 2023
96ef0ff
Ran clang-tidy on the PR
maaz139 Mar 15, 2023
5738852
Merge branch 'main' into darya-ver/ir-viz
steven-johnson Mar 16, 2023
09ba88b
Move boilerplate JS/CSS code into template files
maaz139 Mar 17, 2023
a255e5e
CMake Build fix: Typo
maaz139 Mar 17, 2023
deb4a0b
Merge branch 'main' into darya-ver/ir-viz
steven-johnson Mar 17, 2023
73bb7e4
Minor bug fix
maaz139 Mar 17, 2023
20e9cf1
Renamed variable to avoid any keyword conflict
maaz139 Mar 24, 2023
f3abb38
Merge branch 'main' into darya-ver/ir-viz
maaz139 Mar 24, 2023
5a04472
Style fixes
maaz139 Mar 29, 2023
aa53568
Replacing `internal_assert(false) << ...` with `internal_error << ...`
maaz139 Mar 29, 2023
8144e0d
Style improvement: std prefix consistency
maaz139 Mar 29, 2023
164dbca
Minor fix: variable had greater scope than necessary
maaz139 Mar 29, 2023
512b91d
Renamed `datamovement` to `data_movement` for readability
maaz139 Mar 29, 2023
3e33c5b
Constructor fixes for HTMLCodePrinter, HTMLVizualizationPrinter and I…
maaz139 Mar 29, 2023
6e4a2c2
Typo
maaz139 Mar 30, 2023
a6bc22c
Merge branch 'main' into darya-ver/ir-viz
maaz139 Mar 30, 2023
acb3c2f
Clang-formatting
maaz139 Apr 4, 2023
7a48103
Merge branch 'main' into darya-ver/ir-viz
maaz139 Apr 4, 2023
97892aa
Undo accidental Makefile change
maaz139 Apr 5, 2023
e174e23
Improved comments
maaz139 Apr 6, 2023
1ed6445
Replaced spaces with underscores in regex markers printed in assembly
maaz139 Apr 6, 2023
4ce21a6
Minor bug fix for Halide IR Visualizer
maaz139 Apr 6, 2023
45b6f65
Merge branch 'main' into darya-ver/ir-viz
maaz139 Apr 6, 2023
ba37117
Clang format fix
maaz139 Apr 6, 2023
1454828
Assign deterministic node IDs for reproducability
maaz139 Apr 8, 2023
267b6da
clang-format and clang-tidy
maaz139 Apr 8, 2023
299b864
Update StmtToViz.cpp
maaz139 Apr 8, 2023
5de7fde
Merge branch 'darya-ver/ir-viz' of https://github.com/halide/Halide i…
maaz139 Apr 8, 2023
c2b2006
Minor formatting fix
maaz139 Apr 8, 2023
0be9118
Merge branch 'darya-ver/ir-viz' of https://github.com/halide/Halide i…
maaz139 Apr 8, 2023
799be03
Merge branch 'main' into darya-ver/ir-viz
maaz139 Apr 11, 2023
b2825b3
Bug fix: ProducerConsumer IDs were not generated correctly
maaz139 Apr 11, 2023
937d2b9
Merge branch 'main' into darya-ver/ir-viz
maaz139 Apr 11, 2023
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
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ SOURCE_FILES = \
SplitTuples.cpp \
StageStridedLoads.cpp \
StmtToHtml.cpp \
StmtToViz.cpp \
StorageFlattening.cpp \
StorageFolding.cpp \
StrictifyFloat.cpp \
Expand All @@ -585,6 +586,11 @@ SOURCE_FILES = \
CodeGen_C_prologue \
CodeGen_C_vectors

HTML_TEMPLATE_FILES = \
StmtToViz_dependencies \
StmtToViz_javascript \
StmtToViz_stylesheet

# The externally-visible header files that go into making Halide.h.
# Don't include anything here that includes llvm headers.
# Also *don't* include anything that's only used internally (eg SpirvIR.h).
Expand Down Expand Up @@ -734,6 +740,7 @@ HEADER_FILES = \
SplitTuples.h \
StageStridedLoads.h \
StmtToHtml.h \
StmtToViz.h \
StorageFlattening.h \
StorageFolding.h \
StrictifyFloat.h \
Expand Down Expand Up @@ -889,6 +896,7 @@ INITIAL_MODULES = $(RUNTIME_CPP_COMPONENTS:%=$(BUILD_DIR)/initmod.%_32.o) \
$(RUNTIME_CPP_COMPONENTS:%=$(BUILD_DIR)/initmod.%_64_debug.o) \
$(RUNTIME_EXPORTED_INCLUDES:$(INCLUDE_DIR)/%.h=$(BUILD_DIR)/initmod.%_h.o) \
$(C_TEMPLATE_FILES:%=$(BUILD_DIR)/c_template.%.o) \
$(HTML_TEMPLATE_FILES:%=$(BUILD_DIR)/html_template.%.o) \
$(BUILD_DIR)/initmod.inlined_c.o \
$(RUNTIME_LL_COMPONENTS:%=$(BUILD_DIR)/initmod.%_ll.o) \
$(PTX_DEVICE_INITIAL_MODULES:libdevice.%.bc=$(BUILD_DIR)/initmod_ptx.%_ll.o)
Expand Down Expand Up @@ -1131,6 +1139,9 @@ $(BUILD_DIR)/initmod_ptx.%_ll.cpp: $(BIN_DIR)/binary2cpp $(SRC_DIR)/runtime/nvid
$(BUILD_DIR)/c_template.%.cpp: $(BIN_DIR)/binary2cpp $(SRC_DIR)/%.template.cpp
./$(BIN_DIR)/binary2cpp halide_c_template_$* < $(SRC_DIR)/$*.template.cpp > $@

$(BUILD_DIR)/html_template.%.cpp: $(BIN_DIR)/binary2cpp $(SRC_DIR)/irvisualizer/%.template.html
./$(BIN_DIR)/binary2cpp halide_html_template_$* < $(SRC_DIR)/irvisualizer/$*.template.html > $@

$(BIN_DIR)/binary2cpp: $(ROOT_DIR)/tools/binary2cpp.cpp
@mkdir -p $(@D)
$(CXX) $< -o $@
Expand All @@ -1148,6 +1159,9 @@ $(BUILD_DIR)/initmod.%.o: $(BUILD_DIR)/initmod.%.cpp
$(BUILD_DIR)/c_template.%.o: $(BUILD_DIR)/c_template.%.cpp
$(CXX) -c $< -o $@ -MMD -MP -MF $(BUILD_DIR)/$*.d -MT $(BUILD_DIR)/$*.o

$(BUILD_DIR)/html_template.%.o: $(BUILD_DIR)/html_template.%.cpp
$(CXX) -c $< -o $@ -MMD -MP -MF $(BUILD_DIR)/$*.d -MT $(BUILD_DIR)/$*.o

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.cpp $(BUILD_DIR)/llvm_ok
@mkdir -p $(@D)
$(CXX) $(CXX_FLAGS) -c $< -o $@ -MMD -MP -MF $(BUILD_DIR)/$*.d -MT $(BUILD_DIR)/$*.o
Expand Down
23 changes: 21 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ set(HEADER_FILES
SplitTuples.h
StageStridedLoads.h
StmtToHtml.h
StmtToViz.h
StorageFlattening.h
StorageFolding.h
StrictifyFloat.h
Expand Down Expand Up @@ -329,6 +330,7 @@ set(SOURCE_FILES
SplitTuples.cpp
StageStridedLoads.cpp
StmtToHtml.cpp
StmtToViz.cpp
StorageFlattening.cpp
StorageFolding.cpp
StrictifyFloat.cpp
Expand All @@ -350,11 +352,17 @@ set(SOURCE_FILES
WrapCalls.cpp
)

set(TEMPLATE_FILES
set(C_TEMPLATE_FILES
CodeGen_C_prologue
CodeGen_C_vectors
)

set(HTML_TEMPLATE_FILES
StmtToViz_dependencies
StmtToViz_javascript
StmtToViz_stylesheet
)

##
# Build and import the runtime.
##
Expand All @@ -366,7 +374,7 @@ add_subdirectory(runtime)
##

add_library(Halide_c_templates OBJECT)
foreach (f IN LISTS TEMPLATE_FILES)
foreach (f IN LISTS C_TEMPLATE_FILES)
set(SRC "$<SHELL_PATH:${CMAKE_CURRENT_SOURCE_DIR}/${f}.template.cpp>")
set(DST "c_template.${f}.template.cpp")

Expand All @@ -377,6 +385,17 @@ foreach (f IN LISTS TEMPLATE_FILES)
target_sources(Halide_c_templates PRIVATE ${DST})
endforeach ()

foreach (f IN LISTS HTML_TEMPLATE_FILES)
set(SRC "$<SHELL_PATH:${CMAKE_CURRENT_SOURCE_DIR}/irvisualizer/${f}.template.html>")
set(DST "html_template.${f}.template.cpp")

add_custom_command(OUTPUT "${DST}"
COMMAND binary2cpp "halide_html_template_${f}" < "${SRC}" > "${DST}"
DEPENDS "${SRC}" binary2cpp
VERBATIM)
target_sources(Halide_c_templates PRIVATE ${DST})
endforeach ()

##
# Build the Halide mono-header.
##
Expand Down
13 changes: 9 additions & 4 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3660,11 +3660,13 @@ void CodeGen_LLVM::return_with_error_code(llvm::Value *error_code) {
}

void CodeGen_LLVM::visit(const ProducerConsumer *op) {
producer_consumer_id++;

string name;
if (op->is_producer) {
name = std::string("produce ") + op->name;
name = std::to_string(producer_consumer_id) + std::string("_produce_") + op->name;
} else {
name = std::string("consume ") + op->name;
name = std::to_string(producer_consumer_id) + std::string("_consume_") + op->name;
}
BasicBlock *produce = BasicBlock::Create(*context, name, function);
builder->CreateBr(produce);
Expand All @@ -3690,9 +3692,12 @@ void CodeGen_LLVM::visit(const For *op) {
BasicBlock *preheader_bb = builder->GetInsertBlock();

// Make a new basic block for the loop
BasicBlock *loop_bb = BasicBlock::Create(*context, std::string("for ") + op->name, function);
for_loop_id++;
BasicBlock *loop_bb = BasicBlock::Create(
*context, std::to_string(for_loop_id) + std::string("_for_") + op->name, function);
// Create the block that comes after the loop
BasicBlock *after_bb = BasicBlock::Create(*context, std::string("end for ") + op->name, function);
BasicBlock *after_bb = BasicBlock::Create(
*context, std::to_string(for_loop_id) + std::string("_end_for_") + op->name, function);

// If min < max, fall through to the loop bb
Value *enter_condition = builder->CreateICmpSLT(min, max);
Expand Down
7 changes: 7 additions & 0 deletions src/CodeGen_LLVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,13 @@ class CodeGen_LLVM : public IRVisitor {
*/
int effective_vscale;

/** Assign a unique ID to each producer-consumer and for-loop node. The IDs
* are printed as comments in assembly and used to link visualizations with
* the generated assembly code within `StmtToViz`
*/
int producer_consumer_id = 0;
int for_loop_id = 0;

/** Embed an instance of halide_filter_metadata_t in the code, using
* the given name (by convention, this should be ${FUNCTIONNAME}_metadata)
* as extern "C" linkage. Note that the return value is a function-returning-
Expand Down
9 changes: 8 additions & 1 deletion 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, compiler_log].
schedule, static_library, stmt, stmt_html, stmt_viz, 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,6 +790,13 @@ 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
8 changes: 8 additions & 0 deletions src/Module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Pipeline.h"
#include "PythonExtensionGen.h"
#include "StmtToHtml.h"
#include "StmtToViz.h"

namespace Halide {
namespace Internal {
Expand Down Expand Up @@ -49,6 +50,7 @@ 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 @@ -551,6 +553,7 @@ 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 @@ -610,6 +613,11 @@ void Module::compile(const std::map<OutputFileType, std::string> &output_files)
compile_llvm_module_to_llvm_assembly(*llvm_module, *out);
}
}

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);
}
if (contains(output_files, OutputFileType::function_info_header)) {
debug(1) << "Module.compile(): function_info_header " << output_files.at(OutputFileType::function_info_header) << "\n";
std::ofstream file(output_files.at(OutputFileType::function_info_header));
Expand Down
1 change: 1 addition & 0 deletions src/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ 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