Skip to content

Commit 82f0cdb

Browse files
committed
Mapping: add braces for occupied counts; rename constants to constexpr k*; rename congestion penalty constants
1 parent 45944ff commit 82f0cdb

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

lib/NeuraDialect/Mapping/mapping_util.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ using namespace mlir;
1515
using namespace mlir::neura;
1616

1717
// Constants for award calculation.
18-
static const int AWARD_PROXIMITY_SCALE = 1;
19-
static const int AWARD_BACKWARD_PROXIMITY_SCALE = 1;
20-
static const int AWARD_BASE_MULTIPLIER = 1;
21-
static const int AWARD_CRITICAL_BONUS_DIV = 1;
18+
static constexpr int kAwardProximityScale = 1;
19+
static constexpr int kAwardBackwardProximityScale = 1;
20+
static constexpr int kAwardBaseMultiplier = 1;
21+
static constexpr int kAwardCriticalBonusDiv = 1;
2222

2323
// Congestion penalty coefficients (tunable).
24-
static const int STRONG_CONGESTION_PENALTY = 60; // used for high fan-in ops (>=3)
25-
static const int WEAK_CONGESTION_PENALTY = 15; // used for low fan-in ops
24+
static constexpr int kStrongCongestionPenalty = 60; // used for high fan-in ops (>=3)
25+
static constexpr int kWeakCongestionPenalty = 15; // used for low fan-in ops
2626

2727
namespace mlir {
2828
namespace neura {
@@ -968,7 +968,7 @@ mlir::neura::calculateAward(Operation *op, std::set<Operation *> &critical_ops,
968968
(architecture.getPerCgraRows() + architecture.getPerCgraColumns() - 2);
969969
int max_hops = static_cast<int>(producers.size()) * kMaxDist;
970970
int proximity_bonus =
971-
std::max(0, max_hops - hops_to_producers) * AWARD_PROXIMITY_SCALE;
971+
std::max(0, max_hops - hops_to_producers) * kAwardProximityScale;
972972
tile_award += proximity_bonus;
973973

974974
// Computes proximity bonus to backward users. Closer is better for
@@ -979,7 +979,7 @@ mlir::neura::calculateAward(Operation *op, std::set<Operation *> &critical_ops,
979979
int backward_hops = std::abs(backward_tile->getX() - tile->getX()) +
980980
std::abs(backward_tile->getY() - tile->getY());
981981
tile_award += std::max(0, (kMaxDist - backward_hops) *
982-
AWARD_BACKWARD_PROXIMITY_SCALE);
982+
kAwardBackwardProximityScale);
983983
}
984984
}
985985

@@ -988,11 +988,11 @@ mlir::neura::calculateAward(Operation *op, std::set<Operation *> &critical_ops,
988988
// Keep the original critical bonuses but allow tuning via division.
989989
tile_award += (mapping_state.getII() +
990990
static_cast<int>(tile->getDstTiles().size())) /
991-
std::max(1, AWARD_CRITICAL_BONUS_DIV);
991+
std::max(1, kAwardCriticalBonusDiv);
992992
}
993993

994994
// Apply base multiplier to amplify or dampen tile-based award.
995-
tile_award *= AWARD_BASE_MULTIPLIER;
995+
tile_award *= kAwardBaseMultiplier;
996996

997997
// === Time-based award ===
998998
for (int t = earliest_start_time_step; t < latest_end_time_step; t += 1) {
@@ -1027,12 +1027,14 @@ mlir::neura::calculateAward(Operation *op, std::set<Operation *> &critical_ops,
10271027
int occupied_out = 0;
10281028

10291029
for (auto *link : tile->getInLinks()) {
1030-
if (!mapping_state.isAvailableAcrossTime({link, t}))
1030+
if (!mapping_state.isAvailableAcrossTime({link, t})) {
10311031
occupied_in++;
1032+
}
10321033
}
10331034
for (auto *link : tile->getOutLinks()) {
1034-
if (!mapping_state.isAvailableAcrossTime({link, t}))
1035+
if (!mapping_state.isAvailableAcrossTime({link, t})) {
10351036
occupied_out++;
1037+
}
10361038
}
10371039

10381040
float in_ratio = (total_in > 0) ? (float)occupied_in / total_in : 0;
@@ -1043,8 +1045,8 @@ mlir::neura::calculateAward(Operation *op, std::set<Operation *> &critical_ops,
10431045
// - Use weak penalty (15) for low fan-in ops
10441046
// This optimizes fuse-pattern (II=11 target) without breaking iter-merge
10451047
int base_penalty_coeff = (producers.size() >= 3)
1046-
? STRONG_CONGESTION_PENALTY
1047-
: WEAK_CONGESTION_PENALTY;
1048+
? kStrongCongestionPenalty
1049+
: kWeakCongestionPenalty;
10481050

10491051
int congestion_penalty = static_cast<int>(in_ratio * in_ratio * base_penalty_coeff) +
10501052
static_cast<int>(out_ratio * out_ratio * base_penalty_coeff);

0 commit comments

Comments
 (0)