This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pipe_config_group.py
118 lines (97 loc) · 3.32 KB
/
pipe_config_group.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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
'''
this py can generate group graph configs
'''
import sys
import csv
import imp
import pipe_config
imp.reload(pipe_config)
def param_parse(params):
'''param parse.'''
if 'x' in params:
res = params.split('x')
if len(res) == 2 and res[0].isdigit() and res[1].isdigit():
return [int(res[0]), int(res[1])]
return None
return None
def param_check(in_res, out_main, out_vf, line_num):
'''param check.'''
ret = True
if in_res is None or out_main is None:
print("line: %d, input and out_main error" % (line_num))
ret = False
elif out_vf is None:
if in_res[0] < out_main[0] or in_res[1] < out_main[1]:
print("line: %d, size should be input > vf" % (line_num))
ret = False
if out_main[0] % 64 != 0 or out_main[1] % 4 != 0:
print("out width shoule be multiple of 64, height should be multiple of 4")
ret = false
else:
if in_res[0] < out_main[0] or in_res[1] < out_main[1]:
print("line: %d, size should be input > main > vf" % (line_num))
ret = False
elif out_main[0] < out_vf[0] or out_main[1] < out_vf[1]:
print("line: %d, size should be input > main > vf" % (line_num))
ret = False
if out_main[0] % 64 != 0 or out_main[1] % 4 != 0 or \
out_vf[0] % 64 != 0 or out_vf[1] % 4 != 0:
print("out/vf width shoule be multiple of 64, height should be multiple of 4")
ret = false
return ret
def need_check_reslut(expect_values):
'''if need check reslut.'''
for i in expect_values:
if i == '':
return False
return True
def check_reslut(expect_values, actual_values):
'''check reslut.'''
results = ['same']
for i in range(0, 6):
if expect_values[i] != actual_values[i]:
results = ['diff']
break
return results
def pipe_config_gen(input_csv):
'''pipe config generate'''
input_file = open(input_csv, 'r')
lines = input_file.readlines()
input_file.close()
output_name = 'result_' + input_csv
with open(output_name, 'w', newline='')as output_file:
writer = csv.writer(output_file)
row = []
curr_line = 0
for line in lines[:2]:
curr_line += 1
row = line.split(',')
writer.writerow(row)
for line in lines[2:]:
curr_line += 1
result = ['same']
row = line.split(',')
input_res = param_parse(row[0])
out_main = param_parse(row[1])
if row[2] == '':
out_vf = None
else:
out_vf = param_parse(row[2])
if not param_check(input_res, out_main, out_vf, curr_line):
row[15] = 'param error'
print(row)
writer.writerow(row)
continue
actual_val = pipe_config.pipe_conf_api(input_res, out_main, out_vf)
row = row[:9]
row += actual_val
if need_check_reslut(row[3:9]):
result = check_reslut(row[3:9], row[9:15])
row += result
print(row)
writer.writerow(row)
output_file.close()
if __name__ == "__main__":
pipe_config_gen(sys.argv[1])