...
 
......@@ -7,12 +7,16 @@
#include "GreedyAlgorithm.h"
typedef enum {LATEST, AF, PRIO} StealType;
class TrueHeteroPrio : public GreedyAlgorithm {
private:
RankComputer ranker;
std::set<int, strictCompare> *taskSet;
Instance* ins;
std::vector<double> priorities;
StealType stealType = LATEST;
int GPUindex = 1;
public:
double compute(Instance &ins, SchedAction *action) override;
......
......@@ -9,8 +9,24 @@ using namespace std;
int TrueHeteroPrio::chooseTask(int worker, double now) {
int wType = ins->getType(worker);
if(wType == 0) {
// CPUs wait until GPUs have been served
int k = ins->nbWorkers[0];
bool idleGPU = false;
for(int i = 0; i < ins->nbWorkers[1]; ++i,++k){
if(runningTasks[k] < 0){
idleGPU = true;
break;
}
}
if(idleGPU && !taskSet->empty())
return -1;
}
if(taskSet->empty()) {
int bestTask = -1;
double bestScore = -1;
int chosenVictim = -1;
// Steal: copy/paste from GreedyPerType
for (int victim = 0; victim < ins->totalWorkers; victim++) {
......@@ -20,10 +36,16 @@ int TrueHeteroPrio::chooseTask(int worker, double now) {
&& ins->isValidType(wType, runningTasks[victim])
&& now + ins->execType(wType, runningTasks[victim]) < endTimesWorkers[victim]) {
int task = runningTasks[victim];
double taskAF = ins->execType(victimType, task) / ins->execType(wType, task);
double bestAF = ins->execType(victimType, bestTask) / ins->execType(wType, bestTask);
if (bestTask == -1 || (taskAF > bestAF) ) {
double score;
if(stealType == AF)
score = ins->execType(victimType, task) / ins->execType(wType, task);
else if (stealType == LATEST)
score = endTimesWorkers[victim];
else /* Steal by priority */
score = priorities[task];
if (bestTask == -1 || (score > bestScore) ) {
bestTask = task;
bestScore = score;
chosenVictim = victim;
}
}
......@@ -59,8 +81,14 @@ double TrueHeteroPrio::compute(Instance &ins, SchedAction *action) {
vector<double> accelFactors(ins.nbTasks);
for(int i = 0; i < ins.nbTasks; i++)
accelFactors[i] = ins.execType(0, i) / ins.execType(1, i);
rankCompare compareByAccelFactor = rankCompare(accelFactors);
strictCompare strict(&compareByAccelFactor, false);
rankCompare compareByAccelFactor(accelFactors, true);
priorities = ins.computeMinRank();
rankCompare compareByPriorities(priorities, true);
vector<intCompare*> list;
list.push_back(&compareByAccelFactor);
list.push_back(&compareByPriorities);
lexCompare combined(list);
strictCompare strict(&combined, true);
taskSet = new set<int, strictCompare>(strict);
this->ins = &ins;
......@@ -68,6 +96,17 @@ double TrueHeteroPrio::compute(Instance &ins, SchedAction *action) {
}
TrueHeteroPrio::TrueHeteroPrio(const AlgOptions &options) : GreedyAlgorithm(options), ranker(options) {
string steal = options.asString("steal", "latest");
if(steal == "latest")
stealType = LATEST;
else if(steal == "prio")
stealType = PRIO;
else if(steal == "af")
stealType = AF;
else {
cerr << "TrueHP: unknown steal type " << steal << ", defaulting to latest" << endl;
stealType = LATEST;
}
GPUindex = options.asInt("gpu", 1);
}