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

Commit 3fedb21

Browse files
author
Sven Verdoolaege
committed
tightenLaunchBounds: remove special casing for unmapped identifiers
tightenLaunchBounds was checking for bounds on all block/thread identifiers, resulting in special cases for those identifiers that are not used in the mapping. Only consider the proper identifiers to avoid this special casing.
1 parent e003639 commit 3fedb21

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

tc/core/polyhedral/cuda/tighten_launch_bounds.cc

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,6 @@ std::pair<size_t, size_t> rangeOfMappingParameter(
6464

6565
/*
6666
* Compute the maximal value attained by the mapping parameter "id".
67-
* Return std::numeric_limits<size_t>::max() if this value cannot
68-
* be determined.
6967
*/
7068
template <typename MappingIdType>
7169
size_t maxValue(const Scop& scop, const MappingIdType& id) {
@@ -90,12 +88,26 @@ size_t maxValue(const Scop& scop, const MappingIdType& id) {
9088
LOG_IF(WARNING, min > 0)
9189
<< "Opportunity for tightening launch bounds with shifting -> min:"
9290
<< min;
91+
TC_CHECK(max < sizetMax) << "missing mapping to " << id << *root;
9392
// Inclusive range needs + 1 to translate to sizes
94-
if (max < sizetMax) { // avoid overflow
95-
return max + 1;
93+
return max + 1;
94+
}
95+
96+
/*
97+
* Take grid or block launch bounds "size" and replace them
98+
* by the tightened, actual, launch bounds used in practice.
99+
*/
100+
template <typename MappingIdType, typename Size>
101+
Size launchBounds(const Scop& scop, Size size) {
102+
Size tightened;
103+
104+
for (size_t i = 0; i < size.view.size(); ++i) {
105+
tightened.view[i] = maxValue(scop, MappingIdType::makeId(i));
96106
}
97-
return sizetMax;
107+
108+
return tightened;
98109
}
110+
99111
} // namespace
100112

101113
// Takes grid/block launch bounds that have been passed to mapping and
@@ -105,16 +117,9 @@ std::pair<tc::Grid, tc::Block> tightenLaunchBounds(
105117
const Scop& scop,
106118
const tc::Grid& grid,
107119
const tc::Block& block) {
108-
USING_MAPPING_SHORT_NAMES(BX, BY, BZ, TX, TY, TZ);
109-
// Corner case: take the min with the current size to avoid degenerate
110-
// range in the unbounded case.
111120
return std::make_pair(
112-
tc::Grid({std::min(maxValue(scop, BX), BX.mappingSize(grid)),
113-
std::min(maxValue(scop, BY), BY.mappingSize(grid)),
114-
std::min(maxValue(scop, BZ), BZ.mappingSize(grid))}),
115-
tc::Block({std::min(maxValue(scop, TX), TX.mappingSize(block)),
116-
std::min(maxValue(scop, TY), TY.mappingSize(block)),
117-
std::min(maxValue(scop, TZ), TZ.mappingSize(block))}));
121+
launchBounds<mapping::BlockId>(scop, grid),
122+
launchBounds<mapping::ThreadId>(scop, block));
118123
}
119124
} // namespace polyhedral
120125
} // namespace tc

0 commit comments

Comments
 (0)