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

Rewrite the rfactor scheduling directive #8490

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion python_bindings/src/halide/halide_/PyStage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ void define_stage(py::module &m) {
.def("dump_argument_list", &Stage::dump_argument_list)
.def("name", &Stage::name)

.def("rfactor", (Func(Stage::*)(std::vector<std::pair<RVar, Var>>)) & Stage::rfactor,
.def("rfactor", (Func(Stage::*)(const std::vector<std::pair<RVar, Var>> &)) & Stage::rfactor,
py::arg("preserved"))
.def("rfactor", (Func(Stage::*)(const RVar &, const Var &)) & Stage::rfactor,
py::arg("r"), py::arg("v"))
Expand Down
24 changes: 8 additions & 16 deletions src/BoundsInference.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <algorithm>
#include <iterator>
#include <numeric>

namespace Halide {
namespace Internal {
Expand Down Expand Up @@ -297,7 +298,6 @@ class BoundsInference : public IRMutator {
}

// Default case (no specialization)
vector<Expr> predicates = def.split_predicate();
for (const ReductionVariable &rv : def.schedule().rvars()) {
rvars.insert(rv);
}
Expand All @@ -308,23 +308,15 @@ class BoundsInference : public IRMutator {
}
vecs[1] = def.values();

vector<Expr> predicates = def.split_predicate();
for (size_t i = 0; i < result.size(); ++i) {
for (const Expr &val : vecs[i]) {
if (!predicates.empty()) {
Expr cond_val = Call::make(val.type(),
Internal::Call::if_then_else,
{likely(predicates[0]), val},
Internal::Call::PureIntrinsic);
for (size_t i = 1; i < predicates.size(); ++i) {
cond_val = Call::make(cond_val.type(),
Internal::Call::if_then_else,
{likely(predicates[i]), cond_val},
Internal::Call::PureIntrinsic);
}
result[i].emplace_back(const_true(), cond_val);
} else {
result[i].emplace_back(const_true(), val);
}
Expr cond_val = std::accumulate(
predicates.begin(), predicates.end(), val,
[](const auto &acc, const auto &pred) {
return Call::make(acc.type(), Call::if_then_else, {likely(pred), acc}, Call::PureIntrinsic);
});
result[i].emplace_back(const_true(), cond_val);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Derivative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ void ReverseAccumulationVisitor::propagate_halide_function_call(
// f(r.x) = ... && r is associative
// => f(x) = ...
if (var != nullptr && var->reduction_domain.defined() &&
var->reduction_domain.split_predicate().empty()) {
is_const_one(var->reduction_domain.predicate())) {
ReductionDomain rdom = var->reduction_domain;
int rvar_id = -1;
for (int rid = 0; rid < (int)rdom.domain().size(); rid++) {
Expand Down
Loading