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

Commit b5f414d

Browse files
committed
add some documentation to sema/lexer/parser and tc2halide
1 parent ae93da7 commit b5f414d

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

tc/core/halide2isl.cc

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

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

6162
components.stmt.accept(&builder);
6263
// Get params from components.params which contain everything declared in
63-
// tcdef. However, the 0-D tensors are registered as both params and inputs,
64+
// TC Def. However, the 0-D tensors are registered as both params and inputs,
6465
// filter those out.
6566
for (auto kvp : components.params) {
6667
bool skip = false;
@@ -93,7 +94,7 @@ namespace {
9394
* Convert Halide binary expression "op" into a list of isl affine functions by
9495
* converting its LHS and RHS into lists of affs and concatenating those lists.
9596
* This is intended to be used with Min/Max operations in upper/lower bound
96-
* computations, respectively. Essentially, this allows for replacements
97+
* computations, respectively. Essentially, this allows for replacements
9798
* x < min(a,min(b,c)) <=> x < a AND x < b AND x < c
9899
* x > max(a,max(b,c)) <=> x > a AND x > b AND x > c
99100
*/

tc/core/tc2halide.cc

Lines changed: 8 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 is already converted to halide components
6972
if (params->find(p.ident().name()) != params->end()) {
7073
return;
7174
} else {
@@ -492,6 +495,8 @@ Expr reductionUpdate(Expr e) {
492495
return Call::make(e.type(), kReductionUpdate, {e}, Call::Intrinsic);
493496
}
494497

498+
// translate a single TC comprehension/statement to Halide component.
499+
// funcs, bounds, reductions will be populated
495500
void translateComprehension(
496501
const lang::Comprehension& c,
497502
const map<string, Parameter>& params,
@@ -737,6 +742,7 @@ void translateComprehension(
737742
stage.reorder(loop_nest);
738743
}
739744

745+
// translate a semantically checked TC def to Halide components struct
740746
HalideComponents translateDef(const lang::Def& def, bool throwWarnings) {
741747
map<string, Function> funcs;
742748
HalideComponents components;
@@ -956,6 +962,8 @@ translate(isl::ctx ctx, const lang::TreeRef& treeRef, bool throwWarnings) {
956962
lang::Def(lang::Sema().checkFunction(treeRef)), throwWarnings);
957963
}
958964

965+
// NOTE: there is no guarantee here that the tc string has only one def. It
966+
// could have many defs. Only first def will be converted in that case.
959967
HalideComponents
960968
translate(isl::ctx ctx, const std::string& tc, bool throwWarnings) {
961969
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 but by a very small codebase
354+
//
355+
// withType - associates 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)