-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_chain_dp_vec.py
88 lines (77 loc) · 2.81 KB
/
test_chain_dp_vec.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
# Copyright 2023 Janos Czentye
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import math
import random
from slambuc.alg.chain.path.dp import vec_chain_partitioning
from slambuc.alg.util import split_chain
from slambuc.misc.util import evaluate_chain_partitioning, print_chain_summary
def run_test(runtime: list, memory: list, rate: list, M: int = math.inf, N: int = math.inf,
L: int = math.inf, start: int = 0, end: int = None, delay: int = 1, unit: int = 100):
barr, opt_cost, opt_lat = vec_chain_partitioning(runtime, memory, rate, M, N, L, start, end, delay, unit)
partition = split_chain(barr, len(runtime)) if barr else []
evaluate_chain_partitioning(partition, opt_cost, opt_lat, runtime, memory, rate, M, N, L, start, end, delay, unit)
return partition, opt_cost, opt_lat
def test_single_chain():
runtime = [20, 40, 50, 20, 70, 40, 50, 60, 40, 10]
memory = [3, 3, 2, 1, 2, 1, 2, 1, 2, 3]
rate = [1, 1, 2, 2, 1, 3, 1, 2, 1, 3]
delay = 10
M = 6
N = 3
L = 500
start = 0
end = len(runtime) - 1
unit = 100
print_chain_summary(runtime, memory, rate)
run_test(**locals())
def test_random_chain():
runtime = [random.randint(10, 100) for _ in range(10)]
memory = [random.randint(1, 3) for _ in range(10)]
rate = [random.randint(1, 3) for _ in range(10)]
delay = 10
M = 6
N = 3
L = sum(runtime) + 1 + delay * random.randint(len(runtime) // 4, len(runtime) // 2)
start = 0
end = len(runtime) - 1
unit = 100
print_chain_summary(runtime, memory, rate)
run_test(**locals())
def test_partial_chain():
runtime = [20, 40, 50, 20, 70, 40, 50, 60, 40, 10]
memory = [3, 3, 2, 1, 2, 1, 2, 1, 2, 3]
rate = [1, 1, 2, 2, 1, 3, 1, 2, 1, 3]
delay = 10
M = 6
N = 3
start = 1
end = 8
unit = 100
print_chain_summary(runtime, memory, rate)
# No restriction
L = sum(runtime[start:end + 1]) + delay * 4
run_test(**locals())
# Optimal
L = sum(runtime[start:end + 1]) + delay * 3
run_test(**locals())
# Forces to reduce blocks
L = sum(runtime[start:end + 1]) + delay * 2
run_test(**locals())
# Infeasible due to M
L = sum(runtime[start:end + 1]) + delay * 1
run_test(**locals())
if __name__ == '__main__':
test_single_chain()
# test_random_chain()
test_partial_chain()