def doOffloadJob(experiment, source, destination): debug.out("OFFLOAD JOB", 'g') offloadJob = job(source, 5, hardwareAccelerated=True) decision = experiment.sharedAgent.possibleActions[destination.index] decision.updateDevice() print("target index", decision.targetDeviceIndex) offloadJob.setDecisionTarget(decision) experiment.addJob(source, offloadJob) print("offload 1 0") while destination.currentJob is not offloadJob: experiment.simulateTick() print('\n\n-\n') print("destination has job again") print("forward", counters.NUM_FORWARD, "backward", counters.NUM_BACKWARD) decision = offloading.offloadingDecision.possibleActions[-2] decision.updateDevice(destination) offloadJob.setDecisionTarget(decision) # batch 2 # time.sleep(1) print("\n\nshould activate now...") experiment.simulateTick() while destination.currentJob is not None or source.currentJob is not None: experiment.simulateTick() print('\n\n-\n') # assert offloadJob.immediate is False assert destination.currentJob is None
def doLocalJob(experiment, device): debug.out("LOCAL JOB", 'g') localJob = job(device, 5, hardwareAccelerated=True) decision = offloadingDecision.possibleActions[-1] print("decision is", decision) decision.updateDevice(device) localJob.setDecisionTarget(decision) experiment.addJob(device, localJob) experiment.simulateUntilJobDone() print("local done")
def doWaitJob(experiment, device): # fix decision to wait debug.out("\nWAIT JOB", 'g') waitJob = job(device, 5, hardwareAccelerated=True) decision = offloading.offloadingDecision.possibleActions[-2] decision.updateDevice(device) print("target index", decision.targetDeviceIndex) waitJob.setDecisionTarget(decision) experiment.addJob(device, waitJob) experiment.simulateTime(constants.PLOT_TD * 100) print("wait done") print("forward", counters.NUM_FORWARD, "backward", counters.NUM_BACKWARD)
def createNewJob(self, device, hardwareAccelerated=None): # if not set to hardwareAccelerate, use default if hardwareAccelerated is None: hardwareAccelerated = self.hardwareAccelerated # if still None, unknown behaviour assert (hardwareAccelerated is not None) # print("create job", self.tasks) # select task for this job task = self.tasks if isinstance(self.tasks, list): if len(self.tasks) > 1: task = [np.random.choice(self.tasks)] # print("chose task", task) newJob = job(device, self.jobCounter, constants.SAMPLE_SIZE.gen(), isEpisodeFinished=self.isEpisodeFinished, incrementCompletedJobs=self.incrementCompletedJobs, hardwareAccelerated=hardwareAccelerated, taskGraph=task) self.jobCounter += 1 # print(device.currentTime, device, "created", newJob) self.addJob(device, newJob) debug.out('creating %s on %s' % (newJob, device), 'r') debug.out("added job to device queue", 'p')
from sim import debug from sim.simulations import constants from sim.simulations.SimpleSimulation import SimpleSimulation, NEW_JOB, PROCESS_SUBTASK from sim.tasks.job import job from sim.tasks.subtask import reconfigureFPGA debug.enabled = True # constants.NUM_DEVICES = 2 exp = SimpleSimulation(autoJobs=False) exp.reset() dev = exp.devices[0] dev2 = exp.devices[1] # queue manual jobs firstJob = job(dev, 1, True, exp.isEpisodeFinished, exp.incrementCompletedJobs) firstJob.started = True firstJob.active = True firstJob.creator = dev firstJob.processingNode = dev firstJob.owner = dev dev.currentJob = firstJob # exp.queueTask(1, NEW_JOB, dev) # queue subtasks reconf = reconfigureFPGA(firstJob) # exp.queueTask(0.999, PROCESS_SUBTASK, dev, subtask=reconf) # queue offloaded task secondJob = job(dev, 1, True, exp.isEpisodeFinished, exp.incrementCompletedJobs)