Skip to content

Commit

Permalink
Optimized Dynamic Discretization OPT pass (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
alindkhare authored Apr 12, 2024
1 parent a146e5a commit c563d61
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 50 deletions.
99 changes: 50 additions & 49 deletions schedulers/tetrisched/src/OptimizationPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,65 +699,66 @@ void DiscretizationSelectorOptimizationPass::runPass(
// - minOccupancyTime] << std::endl;
// }

// changing the STRL expressions
// changing the STRL expressions
// for (auto &[discreteTimeRange, discreteGranularity] : timeRangeToGranularities)
// Find Max expressions over NCK and remove NCK expressions with redundant
// start times
for (auto &[discreteTimeRange, discreteGranularity] :
timeRangeToGranularities) {
auto startTime = discreteTimeRange.first;
auto endTime = discreteTimeRange.second;
for (auto maxNckExpr : maxOverNckExprs) {
// find ncks within startTime and endTime for this Max expr
std::vector<ExpressionPtr> ncksWithinTimeRange;
{
TETRISCHED_SCOPE_NECESSARY_TIMER("DiscretizationSelectorOptimizationPass::runPass:NckRemoval");
for (auto maxNckExpr : maxOverNckExprs){
std::vector<ExpressionPtr> savedChildren;
// only keep one nck within every time range
auto expressionChildren = maxNckExpr->getChildren();
ExpressionPtr minStartTimeNckExpr = nullptr;
ExpressionPtr prevSolutionNckExpr = nullptr;
for (auto child = expressionChildren.rbegin();
child != expressionChildren.rend(); ++child) {
auto startTimeNck = (*child)->getTimeBounds().startTimeRange.first;
if (startTimeNck >= startTime && startTimeNck < endTime) {
ncksWithinTimeRange.push_back(*child);
if (prevSolutionNckExpr == nullptr &&
(*child)->isPreviouslySatisfied()) {
prevSolutionNckExpr = *child;
}
if (minStartTimeNckExpr != nullptr) {
if (minStartTimeNckExpr->getTimeBounds().startTimeRange.first >
startTimeNck) {
auto child = expressionChildren.begin();
for (auto &[discreteTimeRange, discreteGranularity] : timeRangeToGranularities)
{
auto startTime = discreteTimeRange.first;
auto endTime = discreteTimeRange.second;
// find ncks within startTime and endTime for this Max expr
// std::vector<ExpressionPtr> ncksWithinTimeRange;

ExpressionPtr minStartTimeNckExpr = nullptr;
ExpressionPtr prevSolutionNckExpr = nullptr;
for (; child != expressionChildren.end(); ++child) {
auto startTimeNck = (*child)->getTimeBounds().startTimeRange.first;
if (startTimeNck >= startTime && startTimeNck < endTime) {
// ncksWithinTimeRange.push_back(*child);
if (prevSolutionNckExpr == nullptr &&
(*child)->isPreviouslySatisfied()) {
prevSolutionNckExpr = *child;
// break;
}
if (minStartTimeNckExpr != nullptr) {
if (minStartTimeNckExpr->getTimeBounds().startTimeRange.first >
startTimeNck) {
minStartTimeNckExpr = *child;
}
} else {
minStartTimeNckExpr = *child;
}
} else {
minStartTimeNckExpr = *child;
} else{
if (startTimeNck < startTime)
{
throw exceptions::RuntimeException("No ncks for MAX expression: NckExpr: NckExpr(" + child->get()->getId() + ", " + child->get()->getName() + ")");
}
break;
}
}
}
ExpressionPtr chosenNckExpr = nullptr;
if (prevSolutionNckExpr != nullptr) {
chosenNckExpr = prevSolutionNckExpr;
// std::cout << "\t ***** "
// << "[" << minOccupancyTime << "]"
// << "[DiscretizationSelectorOptimizationPassDiscreteTime]
// Not Removing Previous Solution: "
// << chosenNckExpr->getDescriptiveName() << " Start Time: "
// << chosenNckExpr->getTimeBounds().startTimeRange.first <<
// std::endl;
} else {
chosenNckExpr = minStartTimeNckExpr;
}
if (ncksWithinTimeRange.size() > 1) {
// if more than one nck found within the time range, remove it as only
ExpressionPtr chosenNckExpr = nullptr;
if (prevSolutionNckExpr != nullptr) {
chosenNckExpr = prevSolutionNckExpr;
} else {
chosenNckExpr = minStartTimeNckExpr;
}
// one nck within granularity is sufficient. Nck with minimum start
// time is kept within this time range
for (auto redundantNckExpr : ncksWithinTimeRange) {
if (redundantNckExpr->getId() != chosenNckExpr->getId()) {
maxNckExpr->removeChild(redundantNckExpr);
// std::cout << "[DiscretizationSelectorOptimizationPassRemoveNck]
// Removing NCK: " + redundantNckExpr->getName() + " From Max: " +
// maxNckExpr->getName() << "Time Range: [" << startTime << ", "
// << endTime << "]";
}
if(chosenNckExpr != nullptr){
savedChildren.push_back(chosenNckExpr);
}
}
if (savedChildren.size() == 0){
throw exceptions::RuntimeException("No ncks for MAX expression: MaxExprName: MaxExpr(" + maxNckExpr->getId() + ", " + maxNckExpr->getName()+")");
}
maxNckExpr->replaceChildren(std::move(savedChildren));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion schedulers/tetrisched_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ def construct_task_strl(
# choice of this Task, and collate them under a MaxExpression.
task_choose_expressions = []
choice_placement_times_and_rewards = []
for placement_time, reward_for_this_placement in time_discretizations:
for placement_time, reward_for_this_placement in sorted(time_discretizations):
if placement_time < current_time:
# If the placement time is in the past, then we cannot
# place the task.
Expand Down

0 comments on commit c563d61

Please sign in to comment.