26 with open(file_path,
'r')
as dtype_file:
27 dtype_str = dtype_file.read()
28 if dtype_str ==
"float32":
30 if dtype_str ==
"uint8":
32 if dtype_str ==
"int16":
34 if dtype_str ==
"int32":
36 if dtype_str ==
"int64":
38 if dtype_str ==
"bool":
40 raise SystemExit(
"Unsupported dtype from file", dtype_str)
43parser = argparse.ArgumentParser()
44parser.add_argument(
'--driver', type=str, required=
True)
45parser.add_argument(
'--model_ref', type=str, required=
True)
46parser.add_argument(
'--work_path', type=str, required=
True)
47parser.add_argument(
'--rtolf32', type=str, required=
False)
48parser.add_argument(
'--atolf32', type=str, required=
False)
49args = parser.parse_args()
52circle_model_ref = args.model_ref +
".circle"
53circle_model = args.work_path +
".circle"
62 if args.rtolf32 !=
None:
63 rtolf32 = float(args.rtolf32)
64 rtolint = int(rtolf32)
65 if args.atolf32 !=
None:
66 atolf32 = float(args.atolf32)
67 atolint = int(atolf32)
69 print(
"rtolf32 or atolf32 is not a number")
75 input_file_path = circle_model_ref +
".input" +
str(check_input)
76 if not os.path.isfile(input_file_path):
77 num_inputs = check_input
79 check_input = check_input + 1
82 print(
"input file not exist for", circle_model_ref)
88 output_file_path = circle_model_ref +
".output" +
str(check_output)
89 if not os.path.isfile(output_file_path):
90 num_outputs = check_output
92 check_output = check_output + 1
95 print(
"output file not exist for", circle_model_ref)
100 driver, circle_model_ref,
101 str(num_inputs), circle_model_ref +
".input", circle_model +
".output"
106for idx
in range(num_outputs):
108 shape_file = open(circle_model_ref +
".output" +
str(idx) +
".shape",
'r')
109 output_shape = [int(i)
for i
in shape_file.read().split(
',')]
111 output_data_ref = np.fromfile(circle_model_ref +
".output" +
str(idx), output_dtype)
112 luci_output_data_ref = np.reshape(output_data_ref, output_shape)
114 output_data = np.fromfile(circle_model +
".output" +
str(idx), output_dtype)
115 luci_output_data = np.reshape(output_data, output_shape)
118 if output_dtype == np.uint8:
119 if np.allclose(luci_output_data,
120 luci_output_data_ref,
122 atol=atolint) ==
False:
123 print(
"luci_output_data_ref", luci_output_data_ref)
124 print(
"luci_output_data", luci_output_data)
125 raise SystemExit(
"Execution result of " + circle_model_ref +
126 " does not match with " + circle_model)
127 elif output_dtype == np.float32:
128 if np.allclose(luci_output_data,
129 luci_output_data_ref,
131 atol=atolf32) ==
False:
132 print(
"luci_output_data_ref", luci_output_data_ref)
133 print(
"luci_output_data", luci_output_data)
134 raise SystemExit(
"Execution result of " + circle_model_ref +
135 " does not match with " + circle_model)
136 elif output_dtype == np.int64:
137 if np.allclose(luci_output_data,
138 luci_output_data_ref,
140 atol=atolint) ==
False:
141 print(
"luci_output_data_ref", luci_output_data_ref)
142 print(
"luci_output_data", luci_output_data)
143 raise SystemExit(
"Execution result of " + circle_model_ref +
144 " does not match with " + circle_model)
145 elif output_dtype == np.int32:
146 if np.allclose(luci_output_data,
147 luci_output_data_ref,
149 atol=atolint) ==
False:
150 print(
"luci_output_data_ref", luci_output_data_ref)
151 print(
"luci_output_data", luci_output_data)
152 raise SystemExit(
"Execution result of " + circle_model_ref +
153 " does not match with " + circle_model)
154 elif output_dtype == np.int16:
155 if np.allclose(luci_output_data,
156 luci_output_data_ref,
158 atol=atolint) ==
False:
159 print(
"luci_output_data_ref", luci_output_data_ref)
160 print(
"luci_output_data", luci_output_data)
161 raise SystemExit(
"Execution result of " + circle_model_ref +
162 " does not match with " + circle_model)
163 elif output_dtype == np.bool_:
164 if np.allclose(luci_output_data, luci_output_data_ref, rtol=0,
166 raise SystemExit(
"Execution result of " + circle_model_ref +
167 " does not match with " + circle_model)
169 raise SystemExit(
"Unsupported data type: ", output_dtype)
171 print(traceback.format_exc())
dtype_from_file(file_path)