13 ref_filename = test_name +
".ref." + suffix
14 ref_datapath = os.path.join(path, ref_filename)
22 refnum_filepath = ref_datapath + str(num_data)
23 if (
not os.path.isfile(refnum_filepath)):
25 with open(refnum_filepath,
"r")
as ref_file:
26 lines = ref_file.readlines()
27 assert len(lines) >= 3,
"Invalid file: " + ref_filename + str(num_data)
28 print(
"load reference data from", test_name)
29 shape = [int(i)
for i
in lines[0].split(
",")]
30 dtype = lines[1].strip(
"\r\n \t")
31 if dtype ==
"float32":
32 value = [float(i)
for i
in lines[2].split(
",")]
34 assert False,
"Unsupported data type: " + dtype
39 num_elements = num_elements * dim
40 if num_elements != len(value):
41 assert False,
"Number of value elements do not match with shape"
43 parse_shape.append(shape)
44 parse_dtype.append(dtype)
45 parse_value.append(value)
47 num_data = num_data + 1
49 return num_data, parse_shape, parse_dtype, parse_value
62 circle_inputpath = os.path.join(path, test_name +
".circle.input")
63 for index
in range(0, num_inputs):
65 if input_dtype[index] ==
"float32":
66 nps = np.asarray(input_data[index], dtype=np.float32)
67 nps.tofile(circle_inputpath + str(index))
69 assert False,
"Unsupported data type: " + input_dtype[index]
71 nps = np.asarray(input_shape[index], dtype=np.short)
72 nps.tofile(circle_inputpath + str(index) +
".shape", sep=
",")
74 with open(circle_inputpath + str(index) +
".dtype",
"w")
as dtype_file:
75 dtype_file.write(input_dtype[index])
79 circle_model = os.path.join(binary_path, test_name +
".circle")
82 binary_path, test_name)
83 assert num_inputs > 0,
"No valid reference input file"
88 binary_path, test_name)
89 assert num_ouputs > 0,
"No valid reference output file"
93 eval_driver, circle_model,
94 str(num_inputs), circle_model +
".input", circle_model +
".output"
99 for idx
in range(num_ouputs):
100 luci_output_data = np.fromfile(circle_model +
".output" + str(idx),
102 luci_output_data = np.reshape(luci_output_data, output_shape[idx])
103 ref_output_data = np.reshape(output_data[idx], output_shape[idx])
105 show_vals_and_stop =
False
106 if output_dtype[idx] ==
"float32":
108 luci_output_data, ref_output_data, rtol=rtolf32, atol=atolf32):
109 show_vals_and_stop =
True
111 assert False,
"Unsupported data type: " + output_dtype[idx]
113 if show_vals_and_stop:
114 print(
"\nreference:\n", ref_output_data)
115 print(
"luci:\n", luci_output_data)
116 message =
"Execution result of " + test_name +
" does not match with reference"
117 assert False, message
127 rtolf32: str, atolf32: str):
128 luci_eval_verify(tol_test_name, binary_path, eval_driver_path, float(rtolf32),