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

HTML Stmt IR with conceptual code and device code. #7843

Merged
merged 26 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
877791b
WIP: Conceptual Stmt IR and HTML cleanup.
mcourteaux Sep 1, 2023
1470acf
WIP: Lots of progress on Stmt HTML. Cleanup almost complete.
mcourteaux Sep 3, 2023
4854587
Support scrolling to device code.
mcourteaux Sep 10, 2023
f30e05e
Resizing works decent enough for me. Fix cost-model allocate block co…
mcourteaux Sep 10, 2023
4721018
Print better vector_reduce calls.
mcourteaux Sep 10, 2023
245527e
Merge branch 'halide:main' into pseudo-stmt-ir
mcourteaux Sep 12, 2023
c1fed17
Optionally enable VizTree through an env variable.
mcourteaux Sep 12, 2023
dd0038a
Merge branch 'pseudo-stmt-ir' of ssh://github.com/mcourteaux/halide i…
mcourteaux Sep 12, 2023
214d106
Fix the device code tab for non-PTX.
mcourteaux Sep 12, 2023
0394963
StmtHTML: Tabs renamed to panes. Fix linter warnings. Cut trailing 0 …
mcourteaux Sep 14, 2023
10051e2
Fix clang-format.
mcourteaux Sep 14, 2023
de1970f
Fixed typos and copy paste error.
mcourteaux Sep 15, 2023
b6aa957
Fix HL_EXTRA_OUTPUTS behaviour to respect the defaults.
mcourteaux Sep 15, 2023
95230a1
Nuked VizTree
mcourteaux Sep 15, 2023
134615c
Finalize StmtToViz nuke and rename StmtToHTML.
mcourteaux Sep 15, 2023
43925bc
Improved HTML correctness by running output through an online validat…
mcourteaux Sep 15, 2023
c27592c
Cost model visualization improvement. Fix button not being allowed in…
mcourteaux Sep 15, 2023
e33cf2c
Fix collapsing being triggered by jump-to-xxx buttons.
mcourteaux Sep 16, 2023
e245bb6
How did this work?
mcourteaux Sep 17, 2023
3e46bbc
Process Andrew's feedback.
mcourteaux Oct 5, 2023
b5573fc
Merge branch 'halide:main' into pseudo-stmt-ir
mcourteaux Oct 5, 2023
29e73ad
Process Andrew's feedback.
mcourteaux Oct 5, 2023
1ef5583
Merge branch 'halide:main' into pseudo-stmt-ir
mcourteaux Oct 5, 2023
d14e4ea
Process Andrew's feedback, part 3.
mcourteaux Oct 5, 2023
5d32813
Improve color palette. Few minor improvements.
mcourteaux Oct 6, 2023
014a232
Clang-format...
mcourteaux Oct 6, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ xcuserdata
# Vim
.clang_complete

# NeoVim + clangd
.cache

# Emacs
tags
TAGS
Expand Down
14 changes: 7 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ SOURCE_FILES = \
SpirvIR.cpp \
SplitTuples.cpp \
StageStridedLoads.cpp \
StmtToViz.cpp \
StmtToHTML.cpp \
StorageFlattening.cpp \
StorageFolding.cpp \
StrictifyFloat.cpp \
Expand All @@ -641,9 +641,9 @@ SOURCE_FILES = \
CodeGen_C_vectors

HTML_TEMPLATE_FILES = \
StmtToViz_dependencies \
StmtToViz_javascript \
StmtToViz_stylesheet
StmtToHTML_dependencies.html \
StmtToHTML.js \
StmtToHTML.css

# The externally-visible header files that go into making Halide.h.
# Don't include anything here that includes llvm headers.
Expand Down Expand Up @@ -796,7 +796,7 @@ HEADER_FILES = \
Solve.h \
SplitTuples.h \
StageStridedLoads.h \
StmtToViz.h \
StmtToHTML.h \
StorageFlattening.h \
StorageFolding.h \
StrictifyFloat.h \
Expand Down Expand Up @@ -1199,8 +1199,8 @@ $(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 > $@
$(BUILD_DIR)/html_template.%.cpp: $(BIN_DIR)/binary2cpp $(SRC_DIR)/irvisualizer/html_template_%
./$(BIN_DIR)/binary2cpp halide_html_template_$(subst .,_,$*) < $(SRC_DIR)/irvisualizer/html_template_$* > $@

$(BIN_DIR)/binary2cpp: $(ROOT_DIR)/tools/binary2cpp.cpp
@mkdir -p $(@D)
Expand Down
1 change: 0 additions & 1 deletion apps/bilateral_grid/bilateral_grid_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ class BilateralGrid : public Halide::Generator<BilateralGrid> {
// nothing
} else if (get_target().has_gpu_feature()) {
// 0.50ms on an RTX 2060

Var xi("xi"), yi("yi"), zi("zi");

// Schedule blurz in 8x8 tiles. This is a tile in
Expand Down
17 changes: 9 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ set(HEADER_FILES
Solve.h
SplitTuples.h
StageStridedLoads.h
StmtToViz.h
StmtToHTML.h
StorageFlattening.h
StorageFolding.h
StrictifyFloat.h
Expand Down Expand Up @@ -334,7 +334,7 @@ set(SOURCE_FILES
SpirvIR.cpp
SplitTuples.cpp
StageStridedLoads.cpp
StmtToViz.cpp
StmtToHTML.cpp
StorageFlattening.cpp
StorageFolding.cpp
StrictifyFloat.cpp
Expand Down Expand Up @@ -362,9 +362,9 @@ set(C_TEMPLATE_FILES
)

set(HTML_TEMPLATE_FILES
StmtToViz_dependencies
StmtToViz_javascript
StmtToViz_stylesheet
StmtToHTML_dependencies.html
StmtToHTML.js
StmtToHTML.css
)

##
Expand All @@ -390,11 +390,12 @@ foreach (f IN LISTS C_TEMPLATE_FILES)
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")
set(SRC "$<SHELL_PATH:${CMAKE_CURRENT_SOURCE_DIR}/irvisualizer/html_template_${f}>")
string(REPLACE "." "_" VARNAME "halide_html_template_${f}")
set(DST "html_template.${f}.cpp")

add_custom_command(OUTPUT "${DST}"
COMMAND binary2cpp "halide_html_template_${f}" < "${SRC}" > "${DST}"
COMMAND binary2cpp "${VARNAME}" < "${SRC}" > "${DST}"
DEPENDS "${SRC}" binary2cpp
VERBATIM)
target_sources(Halide_c_templates PRIVATE ${DST})
Expand Down
84 changes: 43 additions & 41 deletions src/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,7 +652,8 @@ 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, hlpipe].
schedule, static_library, stmt, stmt_html, conceptual_stmt,
conceptual_stmt_html, compiler_log, hlpipe, device_code].
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 All @@ -662,7 +663,7 @@ gengen
(Note that this does not change the default autoscheduler; use the -s flag
to set that value.)"

-r The name of a standalone runtime to generate. Only honors EMIT_OPTIONS 'o'
-r The name of a standalone runtime to generate. Only honors EMIT_OPTIONS 'o'
and 'static_library'. When multiple targets are specified, it picks a
runtime that is compatible with all of the targets, or fails if it cannot
find one. Flags across all of the targets that do not affect runtime code
Expand Down Expand Up @@ -773,6 +774,12 @@ gengen
std::set<OutputFileType> output_types;

std::string emit_flags_string = flags_info["-e"];

// If omitted or empty, assume .a and .h and registration.cpp
if (emit_flags_string.empty()) {
emit_flags_string = "c_header,registration,static_library";
}

// If HL_EXTRA_OUTPUTS is defined, assume it's extra outputs we want to generate
// (usually for temporary debugging purposes) and just tack it on to the -e contents.
std::string extra_outputs = get_env_variable("HL_EXTRA_OUTPUTS");
Expand All @@ -784,50 +791,45 @@ gengen
}

const std::vector<std::string> emit_flags = split_string(emit_flags_string, ",");
internal_assert(!emit_flags.empty()) << "Empty emit flags.\n";

// 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 = {
{"cpp", OutputFileType::c_source},
{"h", OutputFileType::c_header},
{"hlpipe", OutputFileType::hlpipe},
{"html", OutputFileType::stmt_html},
{"o", OutputFileType::object},
{"py.c", OutputFileType::python_extension},
};
// extensions won't vary across multitarget output
const Target t = args.targets.empty() ? Target() : args.targets[0];
const std::map<OutputFileType, const OutputInfo> output_info = get_output_info(t);
for (const auto &it : output_info) {
output_name_to_enum[it.second.name] = it.first;
}

if (emit_flags.empty() || (emit_flags.size() == 1 && emit_flags[0].empty())) {
// If omitted or empty, assume .a and .h and registration.cpp
output_types.insert(OutputFileType::c_header);
output_types.insert(OutputFileType::registration);
output_types.insert(OutputFileType::static_library);
} else {
// 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 = {
{"cpp", OutputFileType::c_source},
{"h", OutputFileType::c_header},
{"hlpipe", OutputFileType::hlpipe},
{"html", OutputFileType::stmt_html},
{"o", OutputFileType::object},
{"py.c", OutputFileType::python_extension},
};
// extensions won't vary across multitarget output
const Target t = args.targets.empty() ? Target() : args.targets[0];
const std::map<OutputFileType, const OutputInfo> output_info = get_output_info(t);
for (const auto &it : output_info) {
output_name_to_enum[it.second.name] = it.first;
}

for (const std::string &opt : emit_flags) {
auto it = output_name_to_enum.find(opt);
if (it == output_name_to_enum.end()) {
std::ostringstream o;
o << "Unrecognized emit option: " << opt << " is not one of [";
auto end = output_info.cend();
auto last = std::prev(end);
for (auto iter = output_info.cbegin(); iter != end; ++iter) {
o << iter->second.name;
if (iter != last) {
o << " ";
}
for (const std::string &opt : emit_flags) {
auto it = output_name_to_enum.find(opt);
if (it == output_name_to_enum.end()) {
std::ostringstream o;
o << "Unrecognized emit option: " << opt << " is not one of [";
auto end = output_info.cend();
auto last = std::prev(end);
for (auto iter = output_info.cbegin(); iter != end; ++iter) {
o << iter->second.name;
if (iter != last) {
o << " ";
}
o << "], ignoring.\n";
o << kUsage;
user_error << o.str();
}
output_types.insert(it->second);
o << "], ignoring.\n";
o << kUsage;
user_error << o.str();
}
output_types.insert(it->second);
}

return output_types;
};

Expand Down
17 changes: 8 additions & 9 deletions src/IRPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,25 +304,25 @@ ostream &operator<<(ostream &out, const ForType &type) {
ostream &operator<<(ostream &out, const VectorReduce::Operator &op) {
switch (op) {
case VectorReduce::Add:
out << "Add";
out << "add";
break;
case VectorReduce::SaturatingAdd:
out << "SaturatingAdd";
out << "saturating_add";
break;
case VectorReduce::Mul:
out << "Mul";
out << "mul";
break;
case VectorReduce::Min:
out << "Min";
out << "min";
break;
case VectorReduce::Max:
out << "Max";
out << "max";
break;
case VectorReduce::And:
out << "And";
out << "and";
break;
case VectorReduce::Or:
out << "Or";
out << "or";
break;
}
return out;
Expand Down Expand Up @@ -1087,8 +1087,7 @@ void IRPrinter::visit(const Shuffle *op) {
void IRPrinter::visit(const VectorReduce *op) {
stream << "("
<< op->type
<< ")vector_reduce("
<< op->op
<< ")vector_reduce_" << op->op << "("
<< ", "
<< op->value
<< ")";
Expand Down
3 changes: 3 additions & 0 deletions src/Lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,9 @@ void lower_impl(const vector<Function> &output_funcs,
}
}

// Make a copy of the Stmt code, before we lower anything to less human-readable code.
result_module.set_conceptual_code_stmt(s);

if (t.arch != Target::Hexagon && t.has_feature(Target::HVX)) {
debug(1) << "Splitting off Hexagon offload...\n";
s = inject_hexagon_rpc(s, t, result_module);
Expand Down
Loading