Skip to content

Commit

Permalink
New Feature: Halide Program IR Visualizer (#7056)
Browse files Browse the repository at this point in the history
Thanks for the feedback everyone! I will merge this into the ir-viz branch and work on it to get it ready for a PR into main.

* initial commit

* updates

* added curr_loop_depth and changed throws for assert(false)

* split into header/cpp file and added test file

* adding changes to move to adobe laptop

* added git ignore to ignore .vscode

* attemping to get add_custom_lowering_pass() to work, not working yet

* Can now compile to stmt_viz files

* moved files into main src folder and added them to Makefile

* fixed lesson_01_basics.cpp

* pushed updates - very messy code

* got side colors working and hiararchy tree. ready for code cleanup

* cleaned up code. ready for split into .h/.cpp files

* quick comment change

* switched everything into .h/.cpp files

* added CostPreProcessor class and removed def of mutate

* removed definitions of mutate

* added data movement costs and bar at the top

* changed location of tooltip so it doesn't overflow left

* updated cost function for laod/store based on vector size and type

* updated colors of hiararchy tree

* logic for deciding context of variables (messy)

* cleaned up code. waiting for marcos

* added context coloring. cleaned up code a bit

* collapse/expand on hiararchy working

* got depth expansion working for hiararchy

* cleaned up code

* cleaned up code and renamed some funcs/vars

* fixed let hierarchy code and added down arrow to button

* dependency graph stuff (still massive and busy)

* Minor fixes -- please review

* prod/cons built with if stmts and for loops

* exit early if running on a module w/ >1 func

* added var dependency button to mail html

* fixed `add` benchmark and made error printing better

* changed `m_assert` to `internal_error`

* cleanedup dependency graph

* added error for non concrete bounds in prodcons hier

* made arrows change btwn up/down depending on sit.

* fixed text for ConsProd tables to have strings

* added logic for non-set bounds for for loop

* added TODO

* added syntax highlight to strings and ints

* added dotdotdot logic for collapsed children

* fixed small bug where 2nd tree wasn't starting correctly

* changed colors of ... nodes based on parent color

* added if flowchart

* added bools for printing different HTML parts of code

* added different background colors per object

* cleaned up borders of objects

* fixed prodCons spacing and started allocate logic

* removed border for ifthenelse table

* implemented anchoring for prodcons tables

* fixed empty if-stmts

* open and close anchor are now right after one another

* added filename logic for anchors and add blocks for func args

* pass in FindStmtCost instead of reruning traversal

* fixed comment

* heatmap for prodConsHierarchy

* fixed consume values (i think) and changed block colors

* fixed allocate "!is_const_one(op->condition" error

* fixed StmtSizes::visit(const For *op) (variables were Add)

* removed nested-ifs logic (edge case we don't have to worry about)

* changed table headers to only show loop interations and no bubbling up

* get unique values for loads with ramp<int, int, int> only

* fixed !is_const_one(op->condition) in Allocate

* changed allocate table to Dim-1, Dim-2, etc

* (1) store: changed cost (2) load: added global/local (3) allocate: vized memtype (4) prodConsTable: changed to read/write

* BOOTSTAP! added navigation pannel at top

* line numbers!!! and removed tooltip (for now)

* changed style of info buttons

* adjusted and added icons for see-code and info buttons

* removed a comment

* condensed cost color classes

* fixed ifthenelse line numbers

* fixed if if-else anchor names

* changed prodCons from table to div

* adding cost colors for prodConsViz to the left side of div

* made long conditions "..." in ProdConsViz

* adding spacing for prodCons start viz and dependency graph viz

* tooltip!!!! (still a little ugly, but functioning!!)

* removed tooltip arrow and changed background to white

* removed arrow for tooltip and added if-stmt condition tooltip

* added more tooltips to prodCons

* getStmtHierarchy popup implemented :) !!

* moved css var definitions to respective files

* added bubble_up() and multiple modules

* converted some stringstream to string + reordered module functions in viz

* added getStmtHierarchy js working for expanding/collapsing

* calculate color ranges once and not every time

* should be added to previous commit

* changed everything from IRMutator -> IRVisitor

* side by side view on main page

* added expand code / viz buttons functionality

* attempting to switch GetStmtHierarchy to 1 tree with colors on side

* should revert this change later, but need to for now (merging with main)

* added Reinterpret + fixed double graph in StmtHierarchy

* removed omg!!!! for reinterpret

* changed border colors of stmtHierarchy + removed print statements

* visualized assert + added colors to assert + made all info buttons next to colors

* added resize bar

* removed navigation code (sticking to 2col layout)

* changed colors spans to buttons (removed segfault???)

* visualize entire LetStmt and cleaned up GetStmtHierarchy.cpp

* added more info in info-buttons

* added hover to side colors in stmthierarchy

* made collapse buttons resizeBar icons + put see_code_button top right of div

* (1) added code to viz buttons (2) display all if-stmts, even if they are empty (3) fixed store highlight cost span

* added scrollTo for function buttons within modules

* changed info-button style

* (1) added hover over for colors in stmtHierarchy (2) removed =default constructor/destructor (3) changed getStmtHierarchy to string html instead of stringstream

* made sure updated StmtToHtml code was in StmtToViz code

* small style changes

* added see code/viz buttons for module functions

* (1) loop size -> loop span (2) made function names  big in viz (3) load types in name

* removed inline style tags

* added VectorReduce code for stmt hierarchy

* removed scopeName hack to fix previous scope error (hope it's not happening anymore)

* fixed scrollTo if code is hidden

* removed commented out includes

* changed costs to inclusive vs exclusive (still might be a bit broken)

* removed print statements

* fixed loop_depth = 0 error

* (1) tooltips include inclusive and exclusive sizes (2) moved tooltip HTML to FindStmtCost.cpp

* reworked tooltip style

* (1) made getStmtHierarchy *exclusive* costs (2) viuslizing costs for IfThenElse blocks

* visualize For and ProducerConsumer blocks

* got collapse of code to show cumulative color cost

* removed context span button

* removed bubble up code and associated logic (now only read/write for loads and stores)

* change some variables to read/write instead of prod/cons

* fixed range bug

* dense/strided vector load

* removed inline TODO comments

* added loop var for for loops

* made loading MUCHHHH faster!!!!

* (1) fixed function box width in viz (2) fixed collapse/expand button for functions in code

* compile assembly if stmt_viz flag is given

* starting assembly stuff

* got assembly code button working (button is still ugly)

* (1) made assembly button prettier (2) started information bar at top (need to fill in content of info popup)

* added content to information bar button popup

* (1) fixed if statement costs (2) added percentages to cost tables instead of values

* removed output_file_name from ProducerConsumerHierarchy.h and related code in StmtToViz.cpp

* fixed IfThenElse cost if there are nested ifs

* removed dependency graph logic and files

* made tooltip table input vector of pairs so that we can specify order

* made tooltip table input vector of pairs so that we can specify order

* added collapse/expand to viz on right

* (1) collapseCode works now (2) search works in assembly tab

* changed codemirror to ARM assembly highlighting

* start of refactor: commenting and cleanup

* fixed bug!!!!! i think. i hope !!!

* removed Stmt function versions (never run this code on Stmt input, only module)

* changed ProdCons stuff to IRViz

* removed print line for strided vectors (seems to be working now)

* fixed bug!!!!!! changed things back to stringstream, because that wasn't the issue

* have helper functions return strings isntead of being void

* end of refactor (for now) - changed variables from camelCase to snake_case

* fix ... error for collapsing nodes

* fixed div issue + tooltips not being correct location

* added error message for multiple modulse (doesn't currently support)

* fixed spacing for boxBody divs

* removed submodules logic because it's not supported right now

* made assembly marker generation more accurate (added counters to have marker names be unique)

* got 3 columns resizing mostly working (just a little glitchy, good enough for now)

* got assembly button to populate assembly, kind of working

* added assemblyInfoViz.h to makefile

* fixed resize bars for 3 different visualizations

* fixed linewrapping issue with codemirror

* updated spacing for IRVisualization buttons in header

* (1) fixed functionBox button sizing (2) dense vector load -> [Dense, Vector] load

* fixed informationBar spacing

* updated InformationBar content

* removed current_loop_depth from consideration of cost

* changed cost table tooltip: inclusive: show %, exclusive: show raw cost

* simplified cost model

* (1) updated InformationBar w/ info for assembly (2) added assembly by default to third col

* added logic to collapseVizAssembly if curson passes resizeBar

* moved all color range + tooltip logic into IRVisualization

* fixed get_combined_color_range() error

* reordered js/css strings

* changed format and slighly changed content of cost tooltips

* refactor: .h and .cpp files have same order

* refactor: added comments

* refactor: updated internal_error messages

* fixed small import / #ifndef typo

* updated get_loop_iterator to include more binary ops for extent

* reverting some changes I made to get ready for PR

* adding CMake build

* refactoring namespace scoping

* refactoring "endl"

* refactoring header guards and includes

* const vector reference

* ostringstream all the things!

* having a symbol for "canIgnoreVariableName"

* string -> char*, with raw string literal

* internal_error -> internal_assert()

* clang-format

* if-else chain to switch-case block

* Upgrade wabt to 1.0.30 (#7058)

* Add support for float16 buffer in python extension (#7060)

* run clang-tidy and clang-format

* run clang-tidy & clang-format

* run clang-tidy and clang-format, again

* run clang-tidy and clang-format, Phaze III

* Minor PR Revision

- If `stmt_viz` flag is used without the `assembly` flag, the compiler throws an error.
- GetAssemblyInfoViz.cpp: replace regex with replace_all
- GetSttmtHierarchy.cpp: Bug fix (line 721). Use raw strings for large literals
- Restricted scope of default statement values
- Added enum type for StmtCostModel. A single cost model config value is specified, instead of multiple booleans.

* reminder for later

---------

Co-authored-by: Darya Verzhbinsky <[email protected]>
Co-authored-by: Maaz Ahmad <[email protected]>
Co-authored-by: Marcos Slomp <[email protected]>
Co-authored-by: Steven Johnson <[email protected]>
Co-authored-by: Steve Suzuki <[email protected]>
Co-authored-by: Marcos Slomp <[email protected]>
  • Loading branch information
7 people committed Jan 31, 2023
1 parent 67dcf1a commit 27fcd0a
Show file tree
Hide file tree
Showing 17 changed files with 6,597 additions and 5 deletions.
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,16 @@ SOURCE_FILES = \
FastIntegerDivide.cpp \
FindCalls.cpp \
FindIntrinsics.cpp \
FindStmtCost.cpp \
FlattenNestedRamps.cpp \
Float16.cpp \
Func.cpp \
Function.cpp \
FuseGPUThreadLoops.cpp \
FuzzFloatStores.cpp \
Generator.cpp \
GetAssemblyInfoViz.cpp \
GetStmtHierarchy.cpp \
HexagonOffload.cpp \
HexagonOptimize.cpp \
ImageParam.cpp \
Expand All @@ -491,6 +494,7 @@ SOURCE_FILES = \
IROperator.cpp \
IRPrinter.cpp \
IRVisitor.cpp \
IRVisualization.cpp \
JITModule.cpp \
Lambda.cpp \
Lerp.cpp \
Expand Down Expand Up @@ -561,6 +565,7 @@ SOURCE_FILES = \
SpirvIR.cpp \
SplitTuples.cpp \
StmtToHtml.cpp \
StmtToViz.cpp \
StorageFlattening.cpp \
StorageFolding.cpp \
StrictifyFloat.cpp \
Expand Down Expand Up @@ -647,6 +652,7 @@ HEADER_FILES = \
FastIntegerDivide.h \
FindCalls.h \
FindIntrinsics.h \
FindStmtCost.h \
FlattenNestedRamps.h \
Float16.h \
Func.h \
Expand All @@ -655,6 +661,8 @@ HEADER_FILES = \
FuseGPUThreadLoops.h \
FuzzFloatStores.h \
Generator.h \
GetAssemblyInfoViz.h \
GetStmtHierarchy.h \
HexagonOffload.h \
HexagonOptimize.h \
ImageParam.h \
Expand All @@ -673,6 +681,7 @@ HEADER_FILES = \
IROperator.h \
IRPrinter.h \
IRVisitor.h \
IRVisualization.h \
WasmExecutor.h \
JITModule.h \
Lambda.h \
Expand Down Expand Up @@ -727,6 +736,7 @@ HEADER_FILES = \
Solve.h \
SplitTuples.h \
StmtToHtml.h \
StmtToViz.h \
StorageFlattening.h \
StorageFolding.h \
StrictifyFloat.h \
Expand Down
10 changes: 10 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ set(HEADER_FILES
FastIntegerDivide.h
FindCalls.h
FindIntrinsics.h
FindStmtCost.h
FlattenNestedRamps.h
Float16.h
Func.h
Expand All @@ -75,6 +76,8 @@ set(HEADER_FILES
FuseGPUThreadLoops.h
FuzzFloatStores.h
Generator.h
GetAssemblyInfoViz.h
GetStmtHierarchy.h
HexagonOffload.h
HexagonOptimize.h
ImageParam.h
Expand All @@ -93,6 +96,7 @@ set(HEADER_FILES
IROperator.h
IRPrinter.h
IRVisitor.h
IRVisualization.h
JITModule.h
Lambda.h
Lerp.h
Expand Down Expand Up @@ -146,6 +150,7 @@ set(HEADER_FILES
Solve.h
SplitTuples.h
StmtToHtml.h
StmtToViz.h
StorageFlattening.h
StorageFolding.h
StrictifyFloat.h
Expand Down Expand Up @@ -231,13 +236,16 @@ set(SOURCE_FILES
FastIntegerDivide.cpp
FindCalls.cpp
FindIntrinsics.cpp
FindStmtCost.cpp
FlattenNestedRamps.cpp
Float16.cpp
Func.cpp
Function.cpp
FuseGPUThreadLoops.cpp
FuzzFloatStores.cpp
Generator.cpp
GetAssemblyInfoViz.cpp
GetStmtHierarchy.cpp
HexagonOffload.cpp
HexagonOptimize.cpp
ImageParam.cpp
Expand All @@ -255,6 +263,7 @@ set(SOURCE_FILES
IROperator.cpp
IRPrinter.cpp
IRVisitor.cpp
IRVisualization.cpp
JITModule.cpp
Lambda.cpp
Lerp.cpp
Expand Down Expand Up @@ -325,6 +334,7 @@ set(SOURCE_FILES
SpirvIR.cpp
SplitTuples.cpp
StmtToHtml.cpp
StmtToViz.cpp
StorageFlattening.cpp
StorageFolding.cpp
StrictifyFloat.cpp
Expand Down
14 changes: 10 additions & 4 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3666,11 +3666,13 @@ void CodeGen_LLVM::return_with_error_code(llvm::Value *error_code) {
}

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

string name;
if (op->is_producer) {
name = std::string("produce ") + op->name;
name = std::to_string(producer_consumer_count) + std::string("_produce ") + op->name;
} else {
name = std::string("consume ") + op->name;
name = std::to_string(producer_consumer_count) + std::string("_consume ") + op->name;
}
BasicBlock *produce = BasicBlock::Create(*context, name, function);
builder->CreateBr(produce);
Expand All @@ -3679,6 +3681,8 @@ void CodeGen_LLVM::visit(const ProducerConsumer *op) {
}

void CodeGen_LLVM::visit(const For *op) {
for_loop_count++;

Value *min = codegen(op->min);
Value *extent = codegen(op->extent);
const Acquire *acquire = op->body.as<Acquire>();
Expand All @@ -3696,9 +3700,11 @@ 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);
BasicBlock *loop_bb = BasicBlock::Create(
*context, std::to_string(for_loop_count) + 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_count) + 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
4 changes: 4 additions & 0 deletions src/CodeGen_LLVM.h
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,10 @@ class CodeGen_LLVM : public IRVisitor {
// @}

private:
// used for mapping IR nodes to llvm markers in StmtToViz.cpp
int producer_consumer_count = 0;
int for_loop_count = 0;

/** All the values in scope at the current code location during
* codegen. Use sym_push and sym_pop to access. */
Scope<llvm::Value *> symbol_table;
Expand Down
Loading

0 comments on commit 27fcd0a

Please sign in to comment.