Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Commit 6937685

Browse files
prigoyalftynse
authored andcommitted
add some documentation to sema/lexer/parser and tc2halide
1 parent cc4b1eb commit 6937685

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

tc/core/halide2isl.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ using namespace tc::polyhedral::detail;
3434

3535
SymbolTable makeSymbolTable(const tc2halide::HalideComponents& components) {
3636
// const Stmt& s) {
37-
// Collect and categorize all the Variable symbols
37+
// Collect and categorize all the Halide Variable symbols as reduction
38+
// or index variables
3839
class BuildSymbolTable : public IRVisitor {
3940
using IRVisitor::visit;
4041
std::set<std::string> included;
@@ -59,7 +60,7 @@ SymbolTable makeSymbolTable(const tc2halide::HalideComponents& components) {
5960

6061
components.stmt.accept(&builder);
6162
// Get params from components.params which contain everything declared in
62-
// tcdef. However, the 0-D tensors are registered as both params and inputs,
63+
// TC Def. However, the 0-D tensors are registered as both params and inputs,
6364
// filter those out.
6465
for (auto kvp : components.params) {
6566
bool skip = false;

tc/core/tc2halide.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,13 @@ Type translateScalarType(int tcType) {
6262
}
6363
}
6464

65+
// Translate the TC def input params to corresponding Halide components.
66+
// params, inputs will be populated here.
6567
void translateParam(
6668
const lang::Param& p,
6769
map<string, Parameter>* params,
6870
vector<ImageParam>* inputs) {
71+
// Check if the param has already been converted to halide components.
6972
if (params->find(p.ident().name()) != params->end()) {
7073
return;
7174
} else {
@@ -488,6 +491,9 @@ Expr reductionUpdate(Expr e) {
488491
return Call::make(e.type(), kReductionUpdate, {e}, Call::Intrinsic);
489492
}
490493

494+
// Translate a single TC comprehension/statement to Halide components: funcs,
495+
// bounds, reductions.
496+
//
491497
// Note that the function definitions created by translateComprehension may
492498
// contain kReductionUpdate intrinsics. These may have to be removed
493499
// in order to be able to apply internal Halide analysis passes on them.
@@ -736,6 +742,7 @@ void translateComprehension(
736742
stage.reorder(loop_nest);
737743
}
738744

745+
// Translate a semantically checked TC def to HalideComponents struct.
739746
HalideComponents translateDef(const lang::Def& def, bool throwWarnings) {
740747
map<string, Function> funcs;
741748
HalideComponents components;
@@ -895,6 +902,8 @@ translate(isl::ctx ctx, const lang::TreeRef& treeRef, bool throwWarnings) {
895902
lang::Def(lang::Sema().checkFunction(treeRef)), throwWarnings);
896903
}
897904

905+
// NOTE: there is no guarantee here that the tc string has only one def. It
906+
// could have many defs. Only first def will be converted in that case.
898907
HalideComponents
899908
translate(isl::ctx ctx, const std::string& tc, bool throwWarnings) {
900909
LOG_IF(INFO, tc::FLAGS_debug_halide) << tc;

tc/core/tc2halide.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ namespace tc2halide {
2727
// of the input and output tensors. We do not explicitly enumerate the
2828
// scalar params.
2929
struct HalideComponents {
30-
lang::TreeRef
31-
def; // post-semantic analaysis tree, used for later error reporting
30+
// post-semantic analaysis tree, used for later error reporting
31+
lang::TreeRef def;
3232
Halide::Internal::Stmt stmt;
3333
std::vector<Halide::ImageParam> inputs;
3434
std::map<std::string, Halide::Internal::Parameter> params;

tc/lang/sema.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,21 @@ struct Sema {
339339
throw ErrorReport(exp) << "NYI - semantic checking for " << exp;
340340
}
341341
}
342+
// This is the entry function for semantic analysis. It is called by
343+
// tc2halide to associate type with each node of the tree and to also make
344+
// sure that the tree is sematically correct. For example: a variable
345+
// may not be input two times. Parser only verifies for the syntax but does
346+
// not check the semantics.
347+
//
348+
// It converts the TK_APPLY nodes to TK_ACCESS or TK_BUILT_IN
349+
//
350+
// The reduction variables are deduced and the objects are created for them
351+
// and they are appended to the tree
352+
//
353+
// Type checking is also done by small amount of code
354+
//
355+
// The method 'withType' can be used to associate the type with a given node
356+
//
342357
TreeRef checkFunction(TreeRef func_) {
343358
auto func = Def(func_);
344359
auto params_ =
@@ -350,6 +365,10 @@ struct Sema {
350365
}
351366
}
352367

368+
// Everything has to be input or output. Keep track of the variables that
369+
// are either input/output. We will check that the statements have variables
370+
// from this list. If not, then throw error that temporaries are not yet
371+
// implemented.
353372
for (auto p : func.params()) {
354373
nonTemporaries.insert(p.ident().name());
355374
inputParameters.insert(p.ident().name());
@@ -437,6 +456,7 @@ struct Sema {
437456
return checkRangeConstraint(RangeConstraint(ref));
438457
}
439458
}
459+
// Semantic checking for the statements/comprehensions in a TC Def.
440460
TreeRef checkStmt(TreeRef stmt_) {
441461
auto stmt = Comprehension(stmt_);
442462

0 commit comments

Comments
 (0)