Skip to content

Commit

Permalink
waters experiments, and minor modifications to previous exps
Browse files Browse the repository at this point in the history
  • Loading branch information
sohamm17 committed Feb 22, 2022
1 parent 46e7532 commit e0ff56d
Show file tree
Hide file tree
Showing 24 changed files with 589 additions and 145 deletions.
2 changes: 1 addition & 1 deletion Figures/increasing_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def main():
colors = ['#ff8080', '#ff9900', "#00cccc", 'r', 'blue', 'm', 'g']
patterns = ['o', 'x', '\\', '+', '.', 'O', '-']

with open("stage_stretch_factor.csv") as f:
with open("increasing_task.csv") as f:
strect_factors = [float(x) for x in f.readline().strip().rstrip('\n').split(" ")]
total_tasks = [int(x) for x in f.readline().strip().rstrip('\n').split(" ")]
for i in range(len(data)):
Expand Down
2 changes: 2 additions & 0 deletions Figures/waters_ar.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1.2 1.3 1.4 1.5 1.6 1.7 1.8
1000 1000 1000 1000 1000 1000 1000
64 changes: 64 additions & 0 deletions Figures/waters_ar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import numpy as np
import math
import matplotlib.pyplot as plt
import sys
from scipy.interpolate import splrep, splev, make_interp_spline

def get_smooth_x_y(list_x, list_y):
bspl = splrep(list_x,list_y,s=3)
bspl_y = splev(list_x,bspl)
return bspl_y
#X_Y_Spline = make_interp_spline(xticks, data[i])
#X_ = np.linspace(xticks.min(), xticks.max(), 50)
#Y_ = X_Y_Spline(X_)

def main():

strect_factors = []
data = [[], [], [], [], []]

markers = ["s", "D", "o", "*", "v", "^"]
linestyles = ['-', '--', ':', '--', '-', '--']
colors = ['#ff8080', '#ff9900', "#00cccc", 'r', 'blue', 'm', 'g']
patterns = ['o', 'x', '\\', '+', '.', 'O', '-']

with open("waters_ar.csv") as f:
strect_factors = [float(x) for x in f.readline().strip().rstrip('\n').split(" ")]
total_tasks = [int(x) for x in f.readline().strip().rstrip('\n').split(" ")]
for i in range(len(data)):
data[i] = [float(x) for x in f.readline().strip().rstrip('\n').split(" ")]

for i in range(len(data)):
data[i] = [100 * float(data[i][j]) / total_tasks[j] for j in range(len(total_tasks))]

#print (data)
fig = plt.figure(num=None, figsize=(6, 4.5), dpi=80, edgecolor='k')
plt.xlim(1.2, 1.82)
ax = fig.add_subplot(111)
plt.ylim(0, 105)
plt.xlabel("Normalized LBG", fontsize=18)
plt.ylabel("Acceptance Ratio [AR] (%)", fontsize=18)
labels = ["3 tasks", "5 tasks", "8 tasks", "10 tasks", "12 tasks", "15 tasks"]
xticks = strect_factors
plt.xticks(xticks)

for i in range(len(data)):
xticks = np.array(xticks)
data[i] = get_smooth_x_y(xticks, np.array(data[i]))
# X_Y_Spline = make_interp_spline(xticks, data[i])
# X_ = np.linspace(xticks.min(), xticks.max(), 50)
# Y_ = X_Y_Spline(X_)
ax.plot(xticks, data[i], color=colors[i], linestyle=linestyles[i], marker=markers[i], label=labels[i], linewidth=3.6, markersize=12)

plt.tick_params(axis='both', which='major', labelsize=14)
plt.tick_params(axis='both', which='minor', labelsize=14)

ax.legend(loc='upper left', bbox_to_anchor=(0.0, 1.02), prop={'size': 18})
plt.grid()
plt.tight_layout(pad=0.15)
# plt.show()
plt.savefig("increasing_task.pdf")


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions Figures/waters_avge2e.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1.2 1.3 1.4 1.5 1.6 1.7 1.8
1000 1000 1000 1000 1000 1000 1000
64 changes: 64 additions & 0 deletions Figures/waters_avge2e.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import numpy as np
import math
import matplotlib.pyplot as plt
import sys
from scipy.interpolate import splrep, splev, make_interp_spline

def get_smooth_x_y(list_x, list_y):
bspl = splrep(list_x,list_y,s=3)
bspl_y = splev(list_x,bspl)
return bspl_y
#X_Y_Spline = make_interp_spline(xticks, data[i])
#X_ = np.linspace(xticks.min(), xticks.max(), 50)
#Y_ = X_Y_Spline(X_)

def main():

strect_factors = []
data = [[], [], [], [], []]

markers = ["s", "D", "o", "*", "v", "^"]
linestyles = ['-', '--', ':', '--', '-', '--']
colors = ['#ff8080', '#ff9900', "#00cccc", 'r', 'blue', 'm', 'g']
patterns = ['o', 'x', '\\', '+', '.', 'O', '-']

with open("waters_avge2e.csv") as f:
strect_factors = [float(x) for x in f.readline().strip().rstrip('\n').split(" ")]
total_tasks = [int(x) for x in f.readline().strip().rstrip('\n').split(" ")]
for i in range(len(data)):
data[i] = [int(float(x)/1000000) for x in f.readline().strip().rstrip('\n').split(" ")]

# for i in range(len(data)):
# data[i] = [100 * float(data[i][j]) / total_tasks[j] for j in range(len(total_tasks))]

#print (data)
fig = plt.figure(num=None, figsize=(6, 4.5), dpi=80, edgecolor='k')
plt.xlim(1.2, 1.82)
ax = fig.add_subplot(111)
plt.ylim(0, 105)
plt.xlabel("Normalized LBG", fontsize=18)
plt.ylabel("Avg E2E Delay (ms)", fontsize=18)
labels = ["3 tasks", "5 tasks", "8 tasks", "10 tasks", "12 tasks", "15 tasks"]
xticks = strect_factors
plt.xticks(xticks)

for i in range(len(data)):
xticks = np.array(xticks)
data[i] = get_smooth_x_y(xticks, np.array(data[i]))
# X_Y_Spline = make_interp_spline(xticks, data[i])
# X_ = np.linspace(xticks.min(), xticks.max(), 50)
# Y_ = X_Y_Spline(X_)
ax.plot(xticks, data[i], color=colors[i], linestyle=linestyles[i], marker=markers[i], label=labels[i], linewidth=3.6, markersize=12)

plt.tick_params(axis='both', which='major', labelsize=14)
plt.tick_params(axis='both', which='minor', labelsize=14)

ax.legend(loc='upper left', bbox_to_anchor=(0.0, 1.02), prop={'size': 18})
plt.grid()
plt.tight_layout(pad=0.15)
# plt.show()
plt.savefig("waters_avge2e.pdf")


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Paper results are summarized in `Figures/accept.csv`.
*The results may vary a bit depending on the changes in the random dataset, but
the basic overview of the result should remains same as the result in the paper and in `Figures` folder.*

#### Both End-to-end and Loss-rate Constraints
#### Both End-to-end Delay and Loss-rate Constraints

1. Generate CoPi data points by the following script:
```
Expand Down
1 change: 1 addition & 0 deletions accepted_lr_copi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions accepted_time_lr.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0
1 change: 1 addition & 0 deletions accepted_time_waters.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
388 0 0 0 194 196 0 0 158 8 6 9 17 11 12 12 0 0 0 0 0 0 0 119 6 9 6 11 10 11 12 50 42 37 43 18 0 0 0 41 17 37 0 6 11 6 11 12 20 18 19 55 49 34 16 0 0 0 0 0 0 16 7 11 11 11 12 12 41 44 6 15 13 13 14 13 43 44 38 43 58 0 140 93 93 87 0 0 150 142 136 0 0 0 209 205 214 0 0 0 385 290 281 0 0 0
6 changes: 6 additions & 0 deletions accepted_waters_avge2e.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
544683 784655 810448 905034 1024977 1086043
2298565 2589989 2840398 3159804 3345324 3601636
7587018 8152941 8396228 8717911 9223395 9511626
9948477 11797184 13010960 13693499 14135225 14576953
16786435 17691684 19012063 20121746 20770835 21419924
26959160 27359890 29848372 31297391 32306988 33316578
6 changes: 6 additions & 0 deletions accepted_waters_copi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
7 17 24 33 51 70
9 22 45 90 141 1000
27 42 101 196 1000 1000
14 50 137 1000 1000 1000
12 36 166 1000 1000 1000
10 45 236 1000 1000 1000
154 changes: 12 additions & 142 deletions copi_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,155 +3,24 @@
End-to-end delay and utilization bound constraint is always there.
'''
import task_generator as task_gen
from copi_lib import *

import numpy as np
import math
import matplotlib.pyplot as plt
import sys, os, pickle, getopt
from utility import *
from pipeline import *
import copy, random
import random
from timeit import default_timer as timer

Loss_Rate = 50 # In Percentage
Loss_UB = float(Loss_Rate) / 100

def optimize_alpha(single_set, budgets, equal_period, e2e_delay, starting_alpha=1.7):
global Loss_Rate, Loss_UB
alpha = starting_alpha
step = 0.01
schedulable = False
initial_budgets = budgets

# Main Loop consisting of Stage 2 and 3
while alpha > 1.0 and not schedulable:
# print ("NEW ITER")
increased_period = int(alpha * equal_period)

taskset = [(b, increased_period) for b in budgets]
# print ("Scaled alpha: ", taskset, alpha, end_to_end_delay_durr(taskset), loss_rate_ub(taskset, initial_budgets), get_total_util(taskset) * 100)

is_second_stage_sched = False

# the following variable keeps track of whether at least one pipe was changed.
at_least_one_pipe_changed = False
# print ("\nNew Iter Second Stage: ", taskset, "bound:", e2e_delay, end_to_end_delay_durr(taskset), alpha, get_total_util(taskset))
while True:
# print ("SECOND STEP")
i = 0
while i < len(taskset) - 1:
producer = taskset[i]
consumer = taskset[i + 1]

# print ("Iter ", i, taskset, end_to_end_delay_durr(taskset), loss_rate_ub(taskset, initial_budgets), get_total_util(taskset) * 100)
taskset2 = copy.deepcopy(taskset)

if producer[0] < (producer[1] // 2) and consumer[0] * 2 < consumer[1]:
# period of the producer is halved
producer = (producer[0], producer[1] // 2)
# budget of the consumer is doubled
consumer = (consumer[0] * 2, consumer[1])
taskset2[i] = producer
taskset2[i + 1] = consumer

if utilization_bound_test(taskset2):
# print ("2nd U:", get_total_util(taskset2), end_to_end_delay_durr(taskset2), loss_rate_ub(taskset2, budgets))
# print (taskset2)
taskset = copy.deepcopy(taskset2)
# taskset = make_taskset_harmonic(taskset)
at_least_one_pipe_changed = True
# Skip the next task because it is tuned
# i += 1 # Loss Rate Optimizer
# print ("S:", taskset, loss_rate_ub(taskset, initial_budgets), i)
# print (taskset, get_total_util(taskset))

if end_to_end_delay_durr(taskset) <= e2e_delay and loss_rate_ub(taskset, initial_budgets) <= Loss_UB:
# print ("Under e2e_delay threshold")
# print (taskset)
# print ("Second Stage Sched, E2E: ", end_to_end_delay_durr(taskset))
# print (taskset)
schedulable = True
is_second_stage_sched = True
return 2 # Second stage Schedulable
i += 1
# if it is already schedulable do not tune another task
if is_second_stage_sched:
break
elif not at_least_one_pipe_changed:
break
elif at_least_one_pipe_changed:
#change back the value to false
at_least_one_pipe_changed = False

if is_second_stage_sched:
break

# Third Stage
# print ("Third Stage", taskset)

#Stage 3
if utilization_bound_test(taskset):
# print ("Third Stage Entry: ", taskset, end_to_end_delay_durr(taskset), loss_rate_ub(taskset, initial_budgets), get_total_util(taskset) * 100)
# print (initial_budgets)
# print ("LR: ", loss_rate_ub(taskset, initial_budgets) * 100)
for i in range(len(taskset) - 1, -1, -1):
# print (i)
cur_budget = int(taskset[i][0])
cur_period = int(taskset[i][1])

initial_budget = int(single_set[i][0])
# print (cur_budget, cur_period, initial_budget)

while cur_budget // 2 >= initial_budget:
cur_budget = cur_budget // 2
cur_period = cur_period // 2
# print ("Halved budget and period", i + 1)
# taskset[i] = (cur_budget, cur_period)
# print (taskset, end_to_end_delay_durr(taskset), loss_rate_ub(taskset, initial_budgets), get_total_util(taskset) * 100)

taskset[i] = (cur_budget, cur_period)

# print ("3rd U:", get_total_util(taskset), end_to_end_delay_durr(taskset), loss_rate_ub(taskset, budgets))

if utilization_bound_test(taskset) and end_to_end_delay_durr(taskset) <= e2e_delay:
# print ("Third Stage Schedulable and under threshold")
# print (taskset, end_to_end_delay_durr(taskset), 100 * get_total_util(taskset))
cur_loss_rate = loss_rate_ub(taskset, initial_budgets)
# print ("LR: ", cur_loss_rate * 100, max(budgets), min(budgets))
# print (taskset, end_to_end_delay_durr(taskset), loss_rate_ub(taskset, initial_budgets), get_total_util(taskset) * 100)
# sys.exit(1)
if(cur_loss_rate <= Loss_UB):
schedulable = True
# prompt = 1
# if (cur_loss_rate == 0):
# input(prompt)
return 3
# else:
# sys.exit(1)
elif end_to_end_delay_durr(taskset) <= e2e_delay:
harm_taskset = make_taskset_harmonic(taskset)
taskset = harm_taskset
if utilization_bound_test(taskset) and end_to_end_delay_durr(taskset) <= e2e_delay:
cur_loss_rate = loss_rate_ub(taskset, initial_budgets)
# print ("LR: ", cur_loss_rate * 100)
# print (harm_taskset, initial_budgets)
# sys.exit(1)
if(cur_loss_rate <= Loss_UB):
schedulable = True
# sys.exit(1)
return 3

# print (taskset)
alpha = alpha - step

return 0

def main(argv):
global Loss_Rate, Loss_UB
Loss_Rate = 50 # In Percentage
loss_ub = float(Loss_Rate) / 100
accepted_num_iterations = []
accepted_time_taken = []
rejected_time_taken = []
Loss_UB = -1
loss_ub = -1
e2e_delay_factor = -1
no_tasks = -1

Expand All @@ -167,8 +36,8 @@ def main(argv):

for opt, arg in opts:
if opt == '-l':
Loss_UB = float(arg)
if Loss_UB > 1:
loss_ub = float(arg)
if loss_ub > 1:
print ("loss_rate cannot be more than 1. cannot proceed.")
sys.exit(1)
elif opt == '-e':
Expand All @@ -181,7 +50,7 @@ def main(argv):
print (usage)
sys.exit(1)

if Loss_UB == -1:
if loss_ub == -1:
print ("Loss Rate UB is not provided.")
print (usage)
sys.exit(1)
Expand All @@ -191,7 +60,7 @@ def main(argv):
print (usage)
sys.exit(1)

Loss_Rate = int(100 * Loss_UB)
Loss_Rate = int(100 * loss_ub)

random.seed(50)
no_tasksets = 1000
Expand Down Expand Up @@ -222,6 +91,7 @@ def main(argv):

done_tasksets = 0
for single_set in current_sets:
print ("single_set:", single_set)
budgets = [x[0] for x in single_set]
# budgets = [random.randint(5, 250) for x in single_set]
print ("Initial Budgets: ", budgets)
Expand All @@ -240,7 +110,7 @@ def main(argv):

print ("First stage:", taskset, end_to_end_delay_durr(taskset), loss_rate_ub(taskset, budgets), get_total_util(taskset) * 100)

if utilization_bound_test(taskset) and end_to_end_delay_durr(taskset) <= e2e_delay_ub and loss_rate_ub(taskset, budgets) <= Loss_UB:
if utilization_bound_test(taskset) and end_to_end_delay_durr(taskset) <= e2e_delay_ub and loss_rate_ub(taskset, budgets) <= loss_ub:
# print (get_total_util(taskset))
first_schedl += 1
done_tasksets += 1
Expand All @@ -249,7 +119,7 @@ def main(argv):
# print ("Second Stage", taskset, get_total_util(taskset))

#Step 2
opt_alpha = optimize_alpha(single_set, budgets, equal_period, e2e_delay_ub, starting_alpha = 2)
opt_alpha = optimize_alpha_all(single_set, budgets, equal_period, e2e_delay_ub, loss_ub, starting_alpha = 2)
# if opt_alpha > 1:
# print ("max, min:", max(budgets), min(budgets))

Expand Down
Loading

0 comments on commit e0ff56d

Please sign in to comment.