-
Notifications
You must be signed in to change notification settings - Fork 6
/
scheduler.py
749 lines (583 loc) · 41.2 KB
/
scheduler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
'''!
@brief This file contains all schedulers in DASH-Sim
Scheduler class is defined in this file which contains different types of scheduler as a member function.
Developers can add thier own algorithms here and implement in DASH-Sim by add a function caller in DASH_Sim_core.py
'''
import networkx as nx
import numpy as np
import copy
import common # The common parameters used in DASH-Sim are defined in common_parameters.py
import DTPM_power_models
import pickle
class Scheduler:
'''!
The Scheduler class constains all schedulers implemented in DASH-Sim
'''
def __init__(self, env, resource_matrix, name, PE_list, jobs):
'''!
@param env: Pointer to the current simulation environment
@param resource_matrix: The data structure that defines power/performance characteristics of the PEs for each supported task
@param name : The name of the requested scheduler
@param PE_list: The PEs available in the current SoCs
@param jobs: The list of all jobs given to DASH-Sim
'''
self.env = env
self.resource_matrix = resource_matrix
self.name = name
self.PEs = PE_list
self.jobs = jobs
self.assigned = [0] * (len(self.PEs))
# At the end of this function, the scheduler class has a copy of the
# the power/performance characteristics of the resource matrix and
# name of the requested scheduler name
# end def __init__(self, env, resource_matrix, scheduler_name)
# Specific scheduler instances can be defined below
def CPU_only(self, list_of_ready):
'''!
This scheduler always select the resource with ID 0 (CPU) to execute all outstanding tasks without any comparison between
available resources
@param list_of_ready: The list of ready tasks
'''
for task in list_of_ready:
task.PE_ID = 0
# end def CPU_only(list_of_ready):
def MET(self, list_of_ready):
'''!
This scheduler compares the execution times of the current task for available resources and returns the ID of the resource
with minimum execution time for the current task.
@param list_of_ready: The list of ready tasks
'''
# Initialize a list to record number of assigned tasks to a PE
# for every scheduling instance
assigned = [0]*(len(self.PEs))
# go over all ready tasks for scheduling and make a decision
for task in list_of_ready:
exec_times = [np.inf]*(len(self.PEs)) # Initialize a list to keep execution times of task for each PE
for i in range(len(self.resource_matrix.list)):
if self.PEs[i].enabled:
if (task.name in self.resource_matrix.list[i].supported_functionalities):
ind = self.resource_matrix.list[i].supported_functionalities.index(task.name)
exec_times[i] = self.resource_matrix.list[i].performance[ind]
min_of_exec_times = min(exec_times) # $min_of_exec_times is the minimum of execution time of the task among all PEs
count_minimum = exec_times.count(min_of_exec_times) # also, record how many times $min_of_exec_times is seen in the list
#print(count_minimum)
# if there are two or more PEs satisfying minimum execution
# then we should try to utilize all those PEs
if (count_minimum > 1):
# if there are tow or more PEs satisfying minimum execution
# populate the IDs of those PEs into a list
min_PE_IDs = [i for i, x in enumerate(exec_times) if x == min_of_exec_times]
# then check whether those PEs are busy or idle
PE_check_list = [True if not self.PEs[index].idle else False for i, index in enumerate(min_PE_IDs)]
# assign tasks to the idle PEs instead of the ones that are currently busy
if (True in PE_check_list) and (False in PE_check_list):
for PE in PE_check_list:
# if a PE is currently busy remove that PE from $min_PE_IDs list
# to schedule the task to a idle PE
if (PE == True):
min_PE_IDs.remove(min_PE_IDs[PE_check_list.index(PE)])
# then compare the number of the assigned tasks to remaining PEs
# and choose the one with the lowest number of assigned tasks
assigned_tasks = [assigned[x] for i, x in enumerate(min_PE_IDs)]
PE_ID_index = assigned_tasks.index(min(assigned_tasks))
# finally, choose the best available PE for the task
task.PE_ID = min_PE_IDs[PE_ID_index]
# =============================================================================
# # assign tasks to the idle PEs instead of the ones that are currently busy
# if (True in PE_check_list) and (False in PE_check_list):
# for PE in PE_check_list:
# # if a PE is currently busy remove that PE from $min_PE_IDs list
# # to schedule the task to a idle PE
# if (PE == True):
# min_PE_IDs.remove(min_PE_IDs[PE_check_list.index(PE)])
#
#
# # then compare the number of the assigned tasks to remaining PEs
# # and choose the one with the lowest number of assigned tasks
# assigned_tasks = [assigned[x] for i, x in enumerate(min_PE_IDs)]
# PE_ID_index = assigned_tasks.index(min(assigned_tasks))
# =============================================================================
# finally, choose the best available PE for the task
task.PE_ID = min_PE_IDs[PE_ID_index]
else:
task.PE_ID = exec_times.index(min_of_exec_times)
# end of if count_minimum >1:
# since one task is just assigned to a PE, increase the number by 1
assigned[task.PE_ID] += 1
if (task.PE_ID == -1):
print ('[E] Time %s: %s can not be assigned to any resource, please check SoC.**.txt file'
% (self.env.now,task.name))
print ('[E] or job_**.txt file')
assert(task.PE_ID >= 0)
else:
if (common.INFO_SCH):
print ('[I] Time %s: The scheduler assigns the %s task to resource PE-%s: %s'
%(self.env.now, task.ID, task.PE_ID,
self.resource_matrix.list[task.PE_ID].type))
# end of if task.PE_ID == -1:
# end of for task in list_of_ready:
# At the end of this loop, we should have a valid (non-negative ID)
# that can run next_task
# end of MET(list_of_ready)
def EFT(self, list_of_ready):
'''!
This scheduler compares the execution times of the current task for available resources and also considers if a resource has
already a task running. it picks the resource which will give the earliest finish time for the task
@param list_of_ready: The list of ready tasks
'''
for task in list_of_ready:
comparison = [np.inf]*len(self.PEs) # Initialize the comparison vector
comm_ready = [0]*len(self.PEs) # A list to store the max communication times for each PE
if (common.DEBUG_SCH):
print ('[D] Time %s: The scheduler function is called with task %s'
%(self.env.now, task.ID))
for i in range(len(self.resource_matrix.list)):
if self.PEs[i].enabled:
# if the task is supported by the resource, retrieve the index of the task
if (task.name in self.resource_matrix.list[i].supported_functionalities):
ind = self.resource_matrix.list[i].supported_functionalities.index(task.name)
# $PE_comm_wait_times is a list to store the estimated communication time
# (or the remaining communication time) of all predecessors of a task for a PE
# As simulation forwards, relevant data is being sent after a task is completed
# based on the time instance, one should consider either whole communication
# time or the remaining communication time for scheduling
PE_comm_wait_times = []
# $PE_wait_time is a list to store the estimated wait times for a PE
# till that PE is available if the PE is currently running a task
PE_wait_time = []
job_ID = -1 # Initialize the job ID
# Retrieve the job ID which the current task belongs to
for ii, job in enumerate(self.jobs.list):
if job.name == task.jobname:
job_ID = ii
for predecessor in self.jobs.list[job_ID].task_list[task.base_ID].predecessors:
# data required from the predecessor for $ready_task
c_vol = self.jobs.list[job_ID].comm_vol[predecessor, task.base_ID]
# retrieve the real ID of the predecessor based on the job ID
real_predecessor_ID = predecessor + task.ID - task.base_ID
# Initialize following two variables which will be used if
# PE to PE communication is utilized
predecessor_PE_ID = -1
predecessor_finish_time = -1
for completed in common.TaskQueues.completed.list:
if completed.ID == real_predecessor_ID:
predecessor_PE_ID = completed.PE_ID
predecessor_finish_time = completed.finish_time
#print(predecessor, predecessor_finish_time, predecessor_PE_ID)
if (common.PE_to_PE):
# Compute the PE to PE communication time
PE_to_PE_band = common.ResourceManager.comm_band[predecessor_PE_ID, i]
PE_to_PE_comm_time = int(c_vol/PE_to_PE_band)
PE_comm_wait_times.append(max((predecessor_finish_time + PE_to_PE_comm_time - self.env.now), 0))
if (common.DEBUG_SCH):
print('[D] Time %s: Estimated communication time between PE %s to PE %s from task %s to task %s is %d'
%(self.env.now, predecessor_PE_ID, i, real_predecessor_ID, task.ID, PE_comm_wait_times[-1]))
if (common.shared_memory):
# Compute the communication time considering the shared memory
# only consider memory to PE communication time
# since the task passed the 1st phase (PE to memory communication)
# and its status changed to ready
#PE_to_memory_band = common.ResourceManager.comm_band[predecessor_PE_ID, -1]
memory_to_PE_band = common.ResourceManager.comm_band[self.resource_matrix.list[-1].ID, i]
shared_memory_comm_time = int(c_vol/memory_to_PE_band)
PE_comm_wait_times.append(shared_memory_comm_time)
if (common.DEBUG_SCH):
print('[D] Time %s: Estimated communication time between memory to PE %s from task %s to task %s is %d'
%(self.env.now, i, real_predecessor_ID, task.ID, PE_comm_wait_times[-1]))
# $comm_ready contains the estimated communication time
# for the resource in consideration for scheduling
# maximum value is chosen since it represents the time required for all
# data becomes available for the resource.
comm_ready[i] = (max(PE_comm_wait_times))
# end of for for predecessor in self.jobs.list[job_ID].task_list[ind].predecessors:
# if a resource currently is executing a task, then the estimated remaining time
# for the task completion should be considered during scheduling
PE_wait_time.append(max((self.PEs[i].available_time - self.env.now), 0))
# update the comparison vector accordingly
comparison[i] = self.resource_matrix.list[i].performance[ind] + max(comm_ready[i], PE_wait_time[-1])
# end of if (task.name in...
# end of for i in range(len(self.resource_matrix.list)):
# after going over each resource, choose the one which gives the minimum result
task.PE_ID = comparison.index(min(comparison))
if task.PE_ID == -1:
print ('[E] Time %s: %s can not be assigned to any resource, please check SoC.**.txt file'
% (self.env.now,task.ID))
print ('[E] or job_**.txt file')
assert(task.PE_ID >= 0)
else:
if (common.DEBUG_SCH):
print('[D] Time %s: Estimated execution times for each PE with task %s, respectively'
%(self.env.now, task.ID))
print('%12s'%(''), comparison)
print ('[D] Time %s: The scheduler assigns task %s to resource %s: %s'
%(self.env.now, task.ID, task.PE_ID, self.resource_matrix.list[task.PE_ID].type))
# Finally, update the estimated available time of the resource to which
# a task is just assigned
self.PEs[task.PE_ID].available_time = self.env.now + comparison[task.PE_ID]
# At the end of this loop, we should have a valid (non-negative ID)
# that can run next_task
# end of for task in list_of_ready:
#end of EFT(list_of_ready)
def STF(self, list_of_ready):
'''!
This scheduler compares the execution times of the current task for available resources and returns the ID of the resource
with minimum execution time for the current task. The only difference between STF and MET is the order in which the tasks
are scheduled onto resources
@param list_of_ready: The list of ready tasks
'''
ready_list = copy.deepcopy(list_of_ready)
# Iterate through the list of ready tasks until all of them are scheduled
while (len(ready_list) > 0) :
shortest_task_exec_time = np.inf
shortest_task_pe_id = -1
for task in ready_list:
min_time = np.inf # Initialize the best performance found so far as a large number
for i in range(len(self.resource_matrix.list)):
if self.PEs[i].enabled:
if (task.name in self.resource_matrix.list[i].supported_functionalities):
ind = self.resource_matrix.list[i].supported_functionalities.index(task.name)
if (self.resource_matrix.list[i].performance[ind] < min_time): # Found resource with smaller execution time
min_time = self.resource_matrix.list[i].performance[ind] # Update the best time found so far
resource_id = self.resource_matrix.list[i].ID # Record the ID of the resource
#task.PE_ID = i # Record the corresponding resource
#print('[INFO] Task - %d, Resource - %d, Time - %d' %(task.ID, resource_id, min_time))
# Obtain the ID and resource for the shortest task in the current iteration
if (min_time < shortest_task_exec_time) :
shortest_task_exec_time = min_time
shortest_task_pe_id = resource_id
shortest_task = task
# end of if (min_time < shortest_task_exec_time)
# end of for task in list_of_ready:
# At the end of this loop, we should have the minimum execution time
# of a task across all resources
# Assign PE ID of the shortest task
index = [i for i,x in enumerate(list_of_ready) if x.ID == shortest_task.ID][0]
list_of_ready[index].PE_ID = shortest_task_pe_id
shortest_task.PE_ID = shortest_task_pe_id
if (common.DEBUG_SCH):
print ('[I] Time %s: The scheduler function found task %d to be shortest on resource %d with %.1f'
%(self.env.now, shortest_task.ID, shortest_task.PE_ID, shortest_task_exec_time))
if list_of_ready[index].PE_ID == -1:
print ('[E] Time %s: %s can not be assigned to any resource, please check SoC.**.txt file'
% (self.env.now,shortest_task.name))
print ('[E] or job_**.txt file')
assert(shortest_task.PE_ID >= 0)
else:
if (common.INFO_SCH):
print ('[I] Time %s: The scheduler assigns the %s task to resource PE-%s: %s'
%(self.env.now, shortest_task.ID, shortest_task.PE_ID,
self.resource_matrix.list[shortest_task.PE_ID].type))
# end of if shortest_task.PE_ID == -1:
# Remove the task which got a schedule successfully
for i, task in enumerate(ready_list) :
if task.ID == shortest_task.ID :
ready_list.remove(task)
# end of for task in list_of_ready:
# At the end of this loop, all ready tasks are assigned to the resources
# on which the execution times are minimum. The tasks will execute
# in the order of increasing execution times
# end of STF(list_of_ready)
def ETF_LB(self, list_of_ready):
'''!
This scheduler compares the execution times of the current task for available resources and also considers if a resource has
already a task running. it picks the resource which will give the earliest finish time for the task. Additionally, the task
with the lowest earliest finish time is scheduled first
@param list_of_ready: The list of ready tasks
'''
ready_list = copy.deepcopy(list_of_ready)
task_counter = 0
assigned = self.assigned
# Iterate through the list of ready tasks until all of them are scheduled
while len(ready_list) > 0:
shortest_task_exec_time = np.inf
shortest_task_pe_id = -1
shortest_comparison = [np.inf] * len(self.PEs)
for task in ready_list:
comparison = [np.inf] * len(self.PEs) # Initialize the comparison vector
comm_ready = [0] * len(self.PEs) # A list to store the max communication times for each PE
if (common.DEBUG_SCH):
print('[D] Time %s: The scheduler function is called with task %s'
% (self.env.now, task.ID))
for i in range(len(self.resource_matrix.list)):
if self.PEs[i].enabled:
# if the task is supported by the resource, retrieve the index of the task
if (task.name in self.resource_matrix.list[i].supported_functionalities):
ind = self.resource_matrix.list[i].supported_functionalities.index(task.name)
# $PE_comm_wait_times is a list to store the estimated communication time
# (or the remaining communication time) of all predecessors of a task for a PE
# As simulation forwards, relevant data is being sent after a task is completed
# based on the time instance, one should consider either whole communication
# time or the remaining communication time for scheduling
PE_comm_wait_times = []
# $PE_wait_time is a list to store the estimated wait times for a PE
# till that PE is available if the PE is currently running a task
PE_wait_time = []
job_ID = -1 # Initialize the job ID
# Retrieve the job ID which the current task belongs to
for ii, job in enumerate(self.jobs.list):
if job.name == task.jobname:
job_ID = ii
for predecessor in self.jobs.list[job_ID].task_list[task.base_ID].predecessors:
# data required from the predecessor for $ready_task
c_vol = self.jobs.list[job_ID].comm_vol[predecessor, task.base_ID]
# retrieve the real ID of the predecessor based on the job ID
real_predecessor_ID = predecessor + task.ID - task.base_ID
# Initialize following two variables which will be used if
# PE to PE communication is utilized
predecessor_PE_ID = -1
predecessor_finish_time = -1
for completed in common.TaskQueues.completed.list:
if completed.ID == real_predecessor_ID:
predecessor_PE_ID = completed.PE_ID
predecessor_finish_time = completed.finish_time
# print(predecessor, predecessor_finish_time, predecessor_PE_ID)
break
if (common.PE_to_PE):
# Compute the PE to PE communication time
PE_to_PE_band = common.ResourceManager.comm_band[predecessor_PE_ID, i]
PE_to_PE_comm_time = int(c_vol / PE_to_PE_band)
PE_comm_wait_times.append(max((predecessor_finish_time + PE_to_PE_comm_time - self.env.now), 0))
if (common.DEBUG_SCH):
print('[D] Time %s: Estimated communication time between PE-%s to PE-%s from task %s to task %s is %d'
% (self.env.now, predecessor_PE_ID, i, real_predecessor_ID, task.ID, PE_comm_wait_times[-1]))
if (common.shared_memory):
# Compute the communication time considering the shared memory
# only consider memory to PE communication time
# since the task passed the 1st phase (PE to memory communication)
# and its status changed to ready
# PE_to_memory_band = common.ResourceManager.comm_band[predecessor_PE_ID, -1]
memory_to_PE_band = common.ResourceManager.comm_band[self.resource_matrix.list[-1].ID, i]
shared_memory_comm_time = int(c_vol / memory_to_PE_band)
PE_comm_wait_times.append(shared_memory_comm_time)
if (common.DEBUG_SCH):
print('[D] Time %s: Estimated communication time between memory to PE-%s from task %s to task %s is %d'
% (self.env.now, i, real_predecessor_ID, task.ID, PE_comm_wait_times[-1]))
# $comm_ready contains the estimated communication time
# for the resource in consideration for scheduling
# maximum value is chosen since it represents the time required for all
# data becomes available for the resource.
comm_ready[i] = max(PE_comm_wait_times)
# end of for for predecessor in self.jobs.list[job_ID].task_list[ind].predecessors:
# if a resource currently is executing a task, then the estimated remaining time
# for the task completion should be considered during scheduling
PE_wait_time.append(max((self.PEs[i].available_time - self.env.now), 0))
# update the comparison vector accordingly
comparison[i] = self.resource_matrix.list[i].performance[ind] * (1 + DTPM_power_models.compute_DVFS_performance_slowdown(common.ClusterManager.cluster_list[self.PEs[i].cluster_ID])) + max(comm_ready[i], PE_wait_time[-1])
# end of if (task.name in...
# end of for i in range(len(self.resource_matrix.list)):
if min(comparison) < shortest_task_exec_time:
resource_id = comparison.index(min(comparison))
shortest_task_exec_time = min(comparison)
# print(shortest_task_exec_time, comparison)
count_minimum = comparison.count(shortest_task_exec_time) # also, record how many times $min_of_exec_times is seen in the list
# if there are two or more PEs satisfying minimum execution
# then we should try to utilize all those PEs
if (count_minimum > 1):
# if there are two or more PEs satisfying minimum execution
# populate the IDs of those PEs into a list
min_PE_IDs = [i for i, x in enumerate(comparison) if x == shortest_task_exec_time]
# then compare the number of the assigned tasks to remaining PEs
# and choose the one with the lowest number of assigned tasks
assigned_tasks = [assigned[x] for i, x in enumerate(min_PE_IDs)]
PE_ID_index = assigned_tasks.index(min(assigned_tasks))
# finally, choose the best available PE for the task
task.PE_ID = min_PE_IDs[PE_ID_index]
# print(count_minimum, task.PE_ID)
else:
task.PE_ID = comparison.index(shortest_task_exec_time)
# end of if count_minimum >1:
# since one task is just assigned to a PE, increase the number by 1
assigned[task.PE_ID] += 1
resource_id = task.PE_ID
shortest_task_pe_id = resource_id
shortest_task = task
shortest_comparison = copy.deepcopy(comparison)
# assign PE ID of the shortest task
index = [i for i, x in enumerate(list_of_ready) if x.ID == shortest_task.ID][0]
list_of_ready[index].PE_ID = shortest_task_pe_id
list_of_ready[index], list_of_ready[task_counter] = list_of_ready[task_counter], list_of_ready[index]
shortest_task.PE_ID = shortest_task_pe_id
if shortest_task.PE_ID == -1:
print('[E] Time %s: %s can not be assigned to any resource, please check SoC.**.txt file'
% (self.env.now, shortest_task.ID))
print('[E] or job_**.txt file')
assert (task.PE_ID >= 0)
else:
if (common.DEBUG_SCH):
print('[D] Time %s: Estimated execution times for each PE with task %s, respectively'
% (self.env.now, shortest_task.ID))
print('%12s' % (''), comparison)
print('[D] Time %s: The scheduler assigns task %s to PE-%s: %s'
% (self.env.now, shortest_task.ID, shortest_task.PE_ID, self.resource_matrix.list[shortest_task.PE_ID].name))
# Finally, update the estimated available time of the resource to which
# a task is just assigned
index_min_available_time = self.PEs[shortest_task.PE_ID].available_time_list.index(min(self.PEs[shortest_task.PE_ID].available_time_list))
self.PEs[shortest_task.PE_ID].available_time_list[index_min_available_time] = self.env.now + shortest_comparison[shortest_task.PE_ID]
self.PEs[shortest_task.PE_ID].available_time = min(self.PEs[shortest_task.PE_ID].available_time_list)
# Remove the task which got a schedule successfully
for i, task in enumerate(ready_list):
if task.ID == shortest_task.ID:
ready_list.remove(task)
task_counter += 1
# At the end of this loop, we should have a valid (non-negative ID)
# that can run next_task
# end of while len(ready_list) > 0 :
# end of ETF_LB( list_of_ready)
def ETF(self, list_of_ready):
'''
This scheduler compares the execution times of the current
task for available resources and also considers if a resource has
already a task running. it picks the resource which will give the
earliest finish time for the task. Additionally, the task with the
lowest earliest finish time is scheduled first
'''
ready_list = copy.deepcopy(list_of_ready)
task_counter = 0
# Iterate through the list of ready tasks until all of them are scheduled
while len(ready_list) > 0 :
shortest_task_exec_time = np.inf
shortest_task_pe_id = -1
shortest_comparison = [np.inf] * len(self.PEs)
for task in ready_list:
comparison = [np.inf]*len(self.PEs) # Initialize the comparison vector
comm_ready = [0]*len(self.PEs) # A list to store the max communication times for each PE
if (common.DEBUG_SCH):
print ('[D] Time %s: The scheduler function is called with task %s'
%(self.env.now, task.ID))
for i in range(len(self.resource_matrix.list)):
# if the task is supported by the resource, retrieve the index of the task
if (task.name in self.resource_matrix.list[i].supported_functionalities):
ind = self.resource_matrix.list[i].supported_functionalities.index(task.name)
# $PE_comm_wait_times is a list to store the estimated communication time
# (or the remaining communication time) of all predecessors of a task for a PE
# As simulation forwards, relevant data is being sent after a task is completed
# based on the time instance, one should consider either whole communication
# time or the remaining communication time for scheduling
PE_comm_wait_times = []
# $PE_wait_time is a list to store the estimated wait times for a PE
# till that PE is available if the PE is currently running a task
PE_wait_time = []
job_ID = -1 # Initialize the job ID
# Retrieve the job ID which the current task belongs to
for ii, job in enumerate(self.jobs.list):
if job.name == task.jobname:
job_ID = ii
for predecessor in self.jobs.list[job_ID].task_list[task.base_ID].predecessors:
# data required from the predecessor for $ready_task
c_vol = self.jobs.list[job_ID].comm_vol[predecessor, task.base_ID]
# retrieve the real ID of the predecessor based on the job ID
real_predecessor_ID = predecessor + task.ID - task.base_ID
# Initialize following two variables which will be used if
# PE to PE communication is utilized
predecessor_PE_ID = -1
predecessor_finish_time = -1
for completed in common.TaskQueues.completed.list:
if (completed.ID == real_predecessor_ID):
predecessor_PE_ID = completed.PE_ID
predecessor_finish_time = completed.finish_time
#print(predecessor, predecessor_finish_time, predecessor_PE_ID)
if (common.PE_to_PE):
# Compute the PE to PE communication time
#PE_to_PE_band = self.resource_matrix.comm_band[predecessor_PE_ID, i]
PE_to_PE_band = common.ResourceManager.comm_band[predecessor_PE_ID, i]
PE_to_PE_comm_time = int(c_vol/PE_to_PE_band)
PE_comm_wait_times.append(max((predecessor_finish_time + PE_to_PE_comm_time - self.env.now), 0))
if (common.DEBUG_SCH):
print('[D] Time %s: Estimated communication time between PE-%s to PE-%s from task %s to task %s is %d'
%(self.env.now, predecessor_PE_ID, i, real_predecessor_ID, task.ID, PE_comm_wait_times[-1]))
if (common.shared_memory):
# Compute the communication time considering the shared memory
# only consider memory to PE communication time
# since the task passed the 1st phase (PE to memory communication)
# and its status changed to ready
#PE_to_memory_band = self.resource_matrix.comm_band[predecessor_PE_ID, -1]
memory_to_PE_band = common.ResourceManager.comm_band[self.resource_matrix.list[-1].ID, i]
shared_memory_comm_time = int(c_vol/memory_to_PE_band)
PE_comm_wait_times.append(shared_memory_comm_time)
if (common.DEBUG_SCH):
print('[D] Time %s: Estimated communication time between memory to PE-%s from task %s to task %s is %d'
%(self.env.now, i, real_predecessor_ID, task.ID, PE_comm_wait_times[-1]))
# $comm_ready contains the estimated communication time
# for the resource in consideration for scheduling
# maximum value is chosen since it represents the time required for all
# data becomes available for the resource.
comm_ready[i] = (max(PE_comm_wait_times))
# end of for for predecessor in self.jobs.list[job_ID].task_list[ind].predecessors:
# if a resource currently is executing a task, then the estimated remaining time
# for the task completion should be considered during scheduling
PE_wait_time.append(max((self.PEs[i].available_time - self.env.now), 0))
# update the comparison vector accordingly
comparison[i] = self.resource_matrix.list[i].performance[ind] + max(comm_ready[i], PE_wait_time[-1])
# after going over each resource, choose the one which gives the minimum result
resource_id = comparison.index(min(comparison))
#print('aa',comparison)
# end of if (task.name in self.resource_matrix.list[i]...
# obtain the task ID, resource for the task with earliest finish time
# based on the computation
#print('bb',comparison)
if min(comparison) < shortest_task_exec_time :
shortest_task_exec_time = min(comparison)
shortest_task_pe_id = resource_id
shortest_task = task
shortest_comparison = comparison
# end of for i in range(len(self.resource_matrix.list)):
# end of for task in ready_list:
# assign PE ID of the shortest task
index = [i for i,x in enumerate(list_of_ready) if x.ID == shortest_task.ID][0]
list_of_ready[index].PE_ID = shortest_task_pe_id
list_of_ready[index], list_of_ready[task_counter] = list_of_ready[task_counter], list_of_ready[index]
shortest_task.PE_ID = shortest_task_pe_id
if shortest_task.PE_ID == -1:
print ('[E] Time %s: %s can not be assigned to any resource, please check DASH.SoC.**.txt file'
% (self.env.now, shortest_task.ID))
print ('[E] or job_**.txt file')
assert(task.PE_ID >= 0)
else:
if (common.DEBUG_SCH):
print('[D] Time %s: Estimated execution times for each PE with task %s, respectively'
%(self.env.now, shortest_task.ID))
print('%12s'%(''), comparison)
print ('[D] Time %s: The scheduler assigns task %s to PE-%s: %s'
%(self.env.now, shortest_task.ID, shortest_task.PE_ID,
self.resource_matrix.list[shortest_task.PE_ID].name))
# Finally, update the estimated available time of the resource to which
# a task is just assigned
self.PEs[shortest_task.PE_ID].available_time = self.env.now + shortest_comparison[shortest_task.PE_ID]
# Remove the task which got a schedule successfully
for i, task in enumerate(ready_list) :
if task.ID == shortest_task.ID :
ready_list.remove(task)
task_counter += 1
# At the end of this loop, we should have a valid (non-negative ID)
# that can run next_task
# end of while len(ready_list) > 0 :
#end of ETF( list_of_ready)
def CP(self, list_of_ready):
'''!
This scheduler utilizes a look-up table for scheduling tasks to a particular processor
@param list_of_ready: The list of ready tasks
'''
for task in list_of_ready:
ind = 0
base = 0
for item in common.ilp_job_list:
if item[0] == task.jobID:
ind = common.ilp_job_list.index(item)
break
previous_job_list = list(range(ind))
for job in previous_job_list:
selection = common.ilp_job_list[job][1]
num_of_tasks = len(self.jobs.list[selection].task_list)
base += num_of_tasks
#print(task.jobID, base, task.base_ID)
for i, schedule in enumerate(common.table):
if len(common.table) > base:
if (task.base_ID + base) == i:
task.PE_ID = schedule[0]
task.order = schedule[1]
else:
if ( task.ID%num_of_tasks == i):
task.PE_ID = schedule[0]
task.order = schedule[1]
list_of_ready.sort(key=lambda x: x.order, reverse=False)
# def CP_(self, list_of_ready):