Skip to content

Commit

Permalink
[luci/service] add include
Browse files Browse the repository at this point in the history
This commit add include.

ONE-DCO-1.0-Signed-off-by: bokyeong lee <[email protected]>
  • Loading branch information
kyeong8139 committed Sep 11, 2024
1 parent ffa0ce8 commit 21cc930
Show file tree
Hide file tree
Showing 120 changed files with 1,565 additions and 2,015 deletions.
33 changes: 18 additions & 15 deletions compiler/bcq-tools/generate_bcq_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ def _get_parser():
description=("Command line tool to generate metadata of BCQ nodes"))

# Input and output path.
parser.add_argument("-i",
"--input_path",
type=str,
help="Full filepath of the input file.",
required=True)
parser.add_argument("-o",
"--output_path",
type=str,
help="Full filepath of the output file.",
required=True)
parser.add_argument("-O",
"--output_arrays",
type=str,
help="Original model output arrays",
required=True)
parser.add_argument(
"-i",
"--input_path",
type=str,
help="Full filepath of the input file.",
required=True)
parser.add_argument(
"-o",
"--output_path",
type=str,
help="Full filepath of the output file.",
required=True)
parser.add_argument(
"-O",
"--output_arrays",
type=str,
help="Original model output arrays",
required=True)

return parser

Expand Down
5 changes: 2 additions & 3 deletions compiler/circle-part-value-py-test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ def extract_test_args(s):
def pytest_addoption(parser):
parser.addoption("--test_list", action="store", help="Path to test list")
parser.addoption("--bin_dir", action="store", help="Directory including artifacts")
parser.addoption("--circle_part_driver",
action="store",
help="Path to circle part driver")
parser.addoption(
"--circle_part_driver", action="store", help="Path to circle part driver")


def pytest_generate_tests(metafunc):
Expand Down
24 changes: 14 additions & 10 deletions compiler/circle-part-value-py-test/test_circle_part_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,24 @@ def part_eval(test_name, bin_dir, circle_part_driver):
for i in range(num_inputs):
input_details = interpreter.get_input_details()[i]
if input_details["dtype"] == np.float32:
input_data = np.array(np.random.random_sample(input_details["shape"]),
input_details["dtype"])
input_data = np.array(
np.random.random_sample(input_details["shape"]), input_details["dtype"])
elif input_details["dtype"] == np.uint8:
input_data = np.array(np.random.randint(0, 256, size=input_details["shape"]),
input_details["dtype"])
input_data = np.array(
np.random.randint(0, 256, size=input_details["shape"]),
input_details["dtype"])
elif input_details["dtype"] == np.int16:
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
input_data = np.array(
np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
elif input_details["dtype"] == np.int32:
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
input_data = np.array(
np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
elif input_details["dtype"] == np.int64:
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
input_data = np.array(
np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
elif input_details["dtype"] == np.bool_:
input_data = np.array(
np.random.choice(a=[True, False], size=input_details["shape"]),
Expand Down
21 changes: 11 additions & 10 deletions compiler/circle-part-value-test/part_eval_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,18 @@
input_details_dtype = input_details["dtype"]
input_details_shape = input_details["shape"]
if input_details_dtype == np.float32:
input_data = np.array(np.random.random_sample(input_details_shape),
input_details_dtype)
input_data = np.array(
np.random.random_sample(input_details_shape), input_details_dtype)
elif input_details_dtype == np.int16:
input_data = np.array(np.random.randint(0, 100, size=input_details_shape),
input_details_dtype)
input_data = np.array(
np.random.randint(0, 100, size=input_details_shape), input_details_dtype)
elif input_details_dtype == np.uint8:
input_data = np.array(np.random.randint(0, 256, size=input_details_shape),
input_details_dtype)
input_data = np.array(
np.random.randint(0, 256, size=input_details_shape), input_details_dtype)
elif input_details_dtype == np.bool_:
input_data = np.array(np.random.choice(a=[True, False], size=input_details_shape),
input_details_dtype)
input_data = np.array(
np.random.choice(a=[True, False], size=input_details_shape),
input_details_dtype)
else:
raise SystemExit("Unsupported input dtype")

Expand Down Expand Up @@ -123,8 +124,8 @@
raise SystemExit("Execution result of " + tflite_model +
" does not match with " + circle_model)
elif output_dtype == np.float32:
if np.allclose(luci_output_data, intp_output_data, rtol=1.e-5,
atol=1.e-5) == False:
if np.allclose(
luci_output_data, intp_output_data, rtol=1.e-5, atol=1.e-5) == False:
raise SystemExit("Execution result of " + tflite_model +
" does not match with " + circle_model)
elif output_dtype == np.int64:
Expand Down
71 changes: 33 additions & 38 deletions compiler/fm-equalize/fm-equalize
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,14 @@ from pathlib import Path
def _get_parser():
parser = argparse.ArgumentParser(
description='Command line tool to equalize feature map (FM) value distribution')
parser.add_argument("-i",
"--input",
type=str,
help="Path to the input circle model.",
required=True)
parser.add_argument("-o",
"--output",
type=str,
help="Path to the output circle model.",
required=True)
parser.add_argument(
"-i", "--input", type=str, help="Path to the input circle model.", required=True)
parser.add_argument(
"-o",
"--output",
type=str,
help="Path to the output circle model.",
required=True)
parser.add_argument(
"-f",
"--fme_patterns",
Expand All @@ -62,18 +60,12 @@ def _get_parser():
help="Allow to create duplicate operations when a feature map matches "
"with multiple equalization patterns. This can increase the size of "
"the model. Default is false.")
parser.add_argument("--fme_detect",
type=str,
help="Path to fme-detect driver.",
required=False)
parser.add_argument("--dalgona",
type=str,
help="Path to dalgona driver.",
required=False)
parser.add_argument("--fme_apply",
type=str,
help="Path to fme-apply driver.",
required=False)
parser.add_argument(
"--fme_detect", type=str, help="Path to fme-detect driver.", required=False)
parser.add_argument(
"--dalgona", type=str, help="Path to dalgona driver.", required=False)
parser.add_argument(
"--fme_apply", type=str, help="Path to fme-apply driver.", required=False)
parser.add_argument('--verbose', action='store_true', help='Print logs')

return parser
Expand Down Expand Up @@ -160,35 +152,38 @@ def main():
Path(output_model).with_suffix('.fme_patterns.json').name)

# Step 1. Run fme-detect to find equalization patterns
_run_fme_detect(fme_detect_path,
str(input_model),
str(fme_patterns),
verbose=verbose,
allow_dup_op=allow_dup_op)
_run_fme_detect(
fme_detect_path,
str(input_model),
str(fme_patterns),
verbose=verbose,
allow_dup_op=allow_dup_op)

# Copy fme_patterns to the given path
if args.fme_patterns != None:
os.system(f'cp {fme_patterns} {args.fme_patterns}')

# Step 2. Run dalgona
_run_dalgona(dalgona_path,
str(input_model),
data,
str(dump_fme_param_py),
str(fme_patterns),
verbose=verbose)
_run_dalgona(
dalgona_path,
str(input_model),
data,
str(dump_fme_param_py),
str(fme_patterns),
verbose=verbose)

# Copy fme_patterns to the given path
# Why copy twice? To observe the result of fme-detect too
if args.fme_patterns != None:
os.system(f'cp {fme_patterns} {args.fme_patterns}')

# Step 3. Run fme-apply
_run_fme_apply(fme_apply_path,
str(input_model),
str(fme_patterns),
str(output_model),
verbose=verbose)
_run_fme_apply(
fme_apply_path,
str(input_model),
str(fme_patterns),
str(output_model),
verbose=verbose)


if __name__ == '__main__':
Expand Down
15 changes: 6 additions & 9 deletions compiler/luci-pass-value-py-test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,12 @@ def extract_test_args(s):

def pytest_addoption(parser):
parser.addoption("--test_list", action="store", help="Path to test list")
parser.addoption("--tflite_dir",
action="store",
help="Directory including tflite file")
parser.addoption("--circle_dir",
action="store",
help="Directory including circle file")
parser.addoption("--luci_eval_driver",
action="store",
help="Path to luci eval driver")
parser.addoption(
"--tflite_dir", action="store", help="Directory including tflite file")
parser.addoption(
"--circle_dir", action="store", help="Directory including circle file")
parser.addoption(
"--luci_eval_driver", action="store", help="Path to luci eval driver")


def pytest_generate_tests(metafunc):
Expand Down
69 changes: 32 additions & 37 deletions compiler/luci-pass-value-py-test/test_luci_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,24 @@ def luci_eval_verify(test_name,
for i in range(num_inputs):
input_details = interpreter.get_input_details()[i]
if input_details["dtype"] == np.float32:
input_data = np.array(np.random.random_sample(input_details["shape"]),
input_details["dtype"])
input_data = np.array(
np.random.random_sample(input_details["shape"]), input_details["dtype"])
elif input_details["dtype"] == np.uint8:
input_data = np.array(np.random.randint(0, 256, size=input_details["shape"]),
input_details["dtype"])
input_data = np.array(
np.random.randint(0, 256, size=input_details["shape"]),
input_details["dtype"])
elif input_details["dtype"] == np.int16:
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
input_data = np.array(
np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
elif input_details["dtype"] == np.int32:
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
input_data = np.array(
np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
elif input_details["dtype"] == np.int64:
input_data = np.array(np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
input_data = np.array(
np.random.randint(0, 100, size=input_details["shape"]),
input_details["dtype"])
elif input_details["dtype"] == np.bool_:
input_data = np.array(
np.random.choice(a=[True, False], size=input_details["shape"]),
Expand All @@ -66,11 +70,12 @@ def luci_eval_verify(test_name,
interpreter.invoke()

# Execute luci interpreter.
subprocess.run([
eval_driver, circle_model,
str(num_inputs), circle_model + ".input", circle_model + ".output"
],
check=True)
subprocess.run(
[
eval_driver, circle_model,
str(num_inputs), circle_model + ".input", circle_model + ".output"
],
check=True)

# Compare the results.
inpt_output_details = interpreter.get_output_details()
Expand All @@ -87,33 +92,23 @@ def luci_eval_verify(test_name,
intp_output_data = interpreter.get_tensor(output_tensor)
err_msg = "Execution result of " + tflite_model + " does not match with " + circle_model
if output_details["dtype"] == np.uint8:
assert np.allclose(luci_output_data,
intp_output_data,
rtol=rtolint,
atol=atolint), err_msg
assert np.allclose(
luci_output_data, intp_output_data, rtol=rtolint, atol=atolint), err_msg
elif output_details["dtype"] == np.float32:
assert np.allclose(luci_output_data,
intp_output_data,
rtol=rtolf32,
atol=atolf32), err_msg
assert np.allclose(
luci_output_data, intp_output_data, rtol=rtolf32, atol=atolf32), err_msg
elif output_details["dtype"] == np.int64:
assert np.allclose(luci_output_data,
intp_output_data,
rtol=rtolint,
atol=atolint), err_msg
assert np.allclose(
luci_output_data, intp_output_data, rtol=rtolint, atol=atolint), err_msg
elif output_details["dtype"] == np.int32:
assert np.allclose(luci_output_data,
intp_output_data,
rtol=rtolint,
atol=atolint), err_msg
assert np.allclose(
luci_output_data, intp_output_data, rtol=rtolint, atol=atolint), err_msg
elif output_details["dtype"] == np.int16:
assert np.allclose(luci_output_data,
intp_output_data,
rtol=rtolint,
atol=atolint), err_msg
assert np.allclose(
luci_output_data, intp_output_data, rtol=rtolint, atol=atolint), err_msg
elif output_details["dtype"] == np.bool_:
assert np.allclose(luci_output_data, intp_output_data, rtol=0,
atol=0), err_msg
assert np.allclose(
luci_output_data, intp_output_data, rtol=0, atol=0), err_msg
else:
assert False, "Unsupported data type: " + output_details["dtype"]

Expand Down
Loading

0 comments on commit 21cc930

Please sign in to comment.