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

Commit d10d66e

Browse files
author
Sven Verdoolaege
committed
replace findFirstReductionDim by isReductionMember
The original implementation would essentially take any band member that looks like a reduction and simply take the outermost of those. Later on, the choice of reduction schedule dimension was made more stringent to appear at a specific position. Instead of looking for the first reduction member and then checking if it is in the right position, simply take the member in the right position and check if it corresponds to a reduction.
1 parent a54ec29 commit d10d66e

File tree

3 files changed

+17
-23
lines changed

3 files changed

+17
-23
lines changed

tc/core/polyhedral/cuda/mapped_scop.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,9 @@ bool MappedScop::detectReductions(detail::ScheduleTree* tree) {
220220
});
221221
// The reduction member needs to appear right underneath
222222
// the coincident members.
223-
auto reductionDim = findFirstReductionDim(band->mupa_, scop());
224-
if (reductionDim != nCoincident) {
223+
auto reductionDim = nCoincident;
224+
auto member = band->mupa_.get_union_pw_aff(reductionDim);
225+
if (!isReductionMember(member, updates, scop())) {
225226
return false;
226227
}
227228
auto reductionTree = bandSplitOut(scop_->scheduleRoot(), tree, reductionDim);

tc/core/polyhedral/reduction_matcher.cc

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -167,23 +167,14 @@ std::pair<isl::union_set, isl::union_set> reductionInitsUpdates(
167167
return std::pair<isl::union_set, isl::union_set>(initUnion, update);
168168
}
169169

170-
int findFirstReductionDim(isl::multi_union_pw_aff islMupa, const Scop& scop) {
171-
auto mupa = isl::MUPA(islMupa);
172-
int reductionDim = -1;
173-
int currentDim = 0;
174-
for (auto const& upa : mupa) {
175-
for (auto const& pa : upa) {
176-
if (isAlmostIdentityReduction(pa.pa, scop)) {
177-
reductionDim = currentDim;
178-
break;
179-
}
180-
}
181-
if (reductionDim != -1) {
182-
break;
183-
}
184-
++currentDim;
185-
}
186-
return reductionDim;
170+
bool isReductionMember(
171+
isl::union_pw_aff member,
172+
isl::union_set domain,
173+
const Scop& scop) {
174+
return domain.every_set([member, &scop](isl::set set) {
175+
auto pa = member.extract_on_domain(set.get_space());
176+
return isAlmostIdentityReduction(pa, scop);
177+
});
187178
}
188179

189180
} // namespace polyhedral

tc/core/polyhedral/schedule_tree_matcher.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ std::pair<isl::union_set, isl::union_set> reductionInitsUpdates(
3535
isl::union_set domain,
3636
const Scop& scop);
3737

38-
// Find the first band member that corresponds to a reduction.
39-
// TODO: heuristic to choose the "best" band member in presence of multiple
40-
// reductions.
41-
int findFirstReductionDim(isl::multi_union_pw_aff islMupa, const Scop& scop);
38+
// Does the band member with the given partial schedule correspond
39+
// to a reduction on all statements with a domain in "domain"?
40+
bool isReductionMember(
41+
isl::union_pw_aff member,
42+
isl::union_set domain,
43+
const Scop& scop);
4244

4345
} // namespace polyhedral
4446
} // namespace tc

0 commit comments

Comments
 (0)