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

Commit 639ee29

Browse files
authored
Merge pull request #483 from facebookresearch/pr/fix_462
MappedScop::detectReductions: avoid inserting filters that turn out to be empty
2 parents d443b59 + 3f00a50 commit 639ee29

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

tc/core/polyhedral/cuda/mapped_scop.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void fixThreadsBelow(
189189
}
190190

191191
/*
192-
* Try and order the other statements in "domain" (if any)
192+
* Try and order the other active statements at "tree" (if any)
193193
* away from the "updates" statements, returning true is the operation succeeds.
194194
* In particular, only do this if it doesn't violate any dependences.
195195
* Anything that depends on an update statement is ordered after
@@ -198,8 +198,8 @@ void fixThreadsBelow(
198198
bool separatedOut(
199199
Scop& scop,
200200
detail::ScheduleTree* tree,
201-
isl::union_set domain,
202201
isl::union_set updates) {
202+
auto domain = activeDomainPoints(scop.scheduleRoot(), tree);
203203
auto other = domain.subtract(updates);
204204
if (other.is_empty()) {
205205
return true;
@@ -271,7 +271,7 @@ bool MappedScop::detectReductions(detail::ScheduleTree* tree) {
271271
// Order the other statements (if any) before the update statements
272272
// to ensure the band from which the reduction band has been split off
273273
// only contains update statements.
274-
if (!separatedOut(scop(), tree, domain, updates)) {
274+
if (!separatedOut(scop(), tree, updates)) {
275275
return false;
276276
}
277277
reductionBandUpdates_.emplace(tree, Reduction(updateIds));

test/test_cuda_mapper.cc

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,29 @@ def fun(float(N) I) -> (O) {
10221022
ASSERT_TRUE(code.find("__ldg(&I") != std::string::npos) << code; // yes
10231023
}
10241024

1025+
/*
1026+
* Check that isolating the update statements does not introduce
1027+
* an empty mapping filter.
1028+
*/
1029+
TEST_F(PolyhedralMapperTest, EmptyMappingFilter) {
1030+
constexpr static auto tc = R"TC(
1031+
def var_2D_1D(float(N, K) I, float(N) mean) -> (var)
1032+
{
1033+
var(n) +=! I(n, r_k) * I(n, r_k)
1034+
var(n) = var(n) / (K) - mean(n) * mean(n)
1035+
}
1036+
)TC";
1037+
auto mappingOptions = DefaultOptions()
1038+
.fixParametersBeforeScheduling(false)
1039+
.matchLibraryCalls(true)
1040+
.mapToThreads(256);
1041+
auto scop = Prepare(tc);
1042+
scop->fixParameters<int>({{"N", 1024}, {"K", 36864}});
1043+
auto mscop = MappedScop::makeWithOuterBlockInnerThreadStrategy(
1044+
std::move(scop), mappingOptions);
1045+
mscop->codegen(specializedName);
1046+
}
1047+
10251048
int main(int argc, char** argv) {
10261049
::testing::InitGoogleTest(&argc, argv);
10271050
::gflags::ParseCommandLineFlags(&argc, &argv, true);

0 commit comments

Comments
 (0)