Skip to content

Commit 70c62b6

Browse files
committed
Arm Backend: Expose Vela's Debug Database
Enables dumping of Vela's debug database to a specified directory. Change-Id: I10c7362e3f817bd09ceb5cca6dd0c18c548e48bf
1 parent ab31007 commit 70c62b6

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

backends/arm/arm_vela.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ def vela_bin_pack_io(prefix, data):
4646
# Output via Vela to binary stream for ArmBackendEthosU
4747
# WARNING: Do not change this without changing VelaBinStream.cpp as that
4848
# function consumes this format and the two need to align.
49-
def vela_compile(tosa_flatbuffer: bytes, args: List[str], verbose: bool = False):
49+
def vela_compile(
50+
tosa_flatbuffer: bytes,
51+
args: List[str],
52+
verbose: bool = False,
53+
intermediate_path: str | None = None,
54+
):
5055
"""
5156
Compile a TOSA graph to a binary stream for ArmBackendEthosU using Vela.
5257
"""
@@ -55,14 +60,14 @@ def vela_compile(tosa_flatbuffer: bytes, args: List[str], verbose: bool = False)
5560
"ethos-u-vela pip package couldn't be imported. Make sure it's installed!"
5661
)
5762

58-
with tempfile.TemporaryDirectory() as tmpdir:
63+
def run(dir: str) -> bytes:
5964
tosaname = "out.tosa"
60-
tosa_path = os.path.join(tmpdir, tosaname)
65+
tosa_path = os.path.join(dir, tosaname)
6166
with open(tosa_path, "wb") as f:
6267
f.write(tosa_flatbuffer)
6368

6469
# invoke vela
65-
output_dir = os.path.join(tmpdir, "output")
70+
output_dir = os.path.join(dir, "output")
6671
args.append(f"--output-dir={output_dir}")
6772
args.append(tosa_path)
6873
if verbose:
@@ -72,9 +77,9 @@ def vela_compile(tosa_flatbuffer: bytes, args: List[str], verbose: bool = False)
7277
if any("ethos-u85" in arg for arg in args) or any(
7378
"debug-force-regor" in arg for arg in args
7479
):
75-
np_path = os.path.join(tmpdir, "output", "out_vela.npz")
80+
np_path = os.path.join(dir, "output", "out_vela.npz")
7681
else:
77-
np_path = os.path.join(tmpdir, "output", "out_sg0_vela.npz")
82+
np_path = os.path.join(dir, "output", "out_sg0_vela.npz")
7883

7984
blocks = b""
8085
with np.load(np_path, allow_pickle=False) as data:
@@ -122,3 +127,9 @@ def vela_compile(tosa_flatbuffer: bytes, args: List[str], verbose: bool = False)
122127
blocks = blocks + block
123128

124129
return blocks
130+
131+
if intermediate_path is not None:
132+
return run(intermediate_path)
133+
else:
134+
with tempfile.TemporaryDirectory() as tmpdir:
135+
return run(tmpdir)

backends/arm/ethosu/backend.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def _compile_tosa_flatbuffer(
5656
tosa_flatbuffer,
5757
compile_flags,
5858
verbose=logger.getEffectiveLevel() == logging.INFO,
59+
intermediate_path=compile_spec.get_intermediate_path(),
5960
)
6061
return binary
6162

examples/arm/aot_arm_compiler.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,14 @@ def get_compile_spec(
420420
tosa_spec = TosaSpecification.create_from_string("TOSA-1.0+INT")
421421
compile_spec = TosaCompileSpec(tosa_spec)
422422
elif "ethos-u" in target:
423+
extra_flags = ["--verbose-operators", "--verbose-cycle-estimate"]
424+
if debug_mode is not None:
425+
extra_flags.append("--enable-debug-db")
423426
compile_spec = EthosUCompileSpec(
424427
target,
425428
system_config=system_config,
426429
memory_mode=memory_mode,
427-
extra_flags=["--verbose-operators", "--verbose-cycle-estimate"],
430+
extra_flags=extra_flags,
428431
config_ini=config,
429432
)
430433
elif "vgf" in target:
@@ -616,7 +619,7 @@ def get_args():
616619
"--config",
617620
required=False,
618621
default="Arm/vela.ini",
619-
help="Specify custom vela configuration file (vela.ini)",
622+
help="Specify custom vela configuration file (vela.ini) for Ethos-U targets.",
620623
)
621624
parser.add_argument(
622625
"--non_strict_export",
@@ -634,7 +637,7 @@ def get_args():
634637
"--enable_debug_mode",
635638
required=False,
636639
choices=["json", "tosa"],
637-
help="Flag to enable ATen-to-TOSA debug mode.",
640+
help="Flag to enable ATen-to-TOSA debug mode and dumping of Vela's debug database.",
638641
)
639642
args = parser.parse_args()
640643

0 commit comments

Comments
 (0)