Skip to content

Commit

Permalink
Adding comment on missing pure vars
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreinking committed Dec 13, 2024
1 parent 8b87a09 commit faeede6
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,17 @@ Func Stage::rfactor(const vector<pair<RVar, Var>> &preserved) {
}
}

// Add missing pure vars to the REDUCING func just before outermost
// Add missing pure vars to the REDUCING func just before outermost.
// This is necessary whenever the update does not reference one of the
// pure variables. For instance, factoring a histogram (clamps elided):
// g(x) = 0; g(f(r.x, r.y)) += 1;
// Func intm = g.rfactor(r.y, u);
// Here we generate an intermediate func intm that looks like:
// intm(x, u) = 0; intm(f(r.x, u), u) += 1;
// And we need the reducing func to be:
// g(x) += intm(x, r.y);
// But x was not referenced in the original update definition, so that
// dimension is added here.
for (size_t i = 0; i < dim_vars.size(); i++) {
if (!expr_uses_var(definition.args()[i], dim_vars[i].name())) {
Dim d = {dim_vars[i].name(), ForType::Serial, DeviceAPI::None, DimType::PureVar, Partition::Auto};
Expand Down

0 comments on commit faeede6

Please sign in to comment.