Skip to content

Commit b7ac647

Browse files
jmahbszingo
andauthored
Arm Backend: Expose Vela's Debug Database (#14511)
Follow on from #14401 Enables dumping of Vela's debug database to a specified directory . This gives us generic information on operators in our model, and can be combined with the trace output to provide more detailed profiling analysis. Co-authored-by: Zingo Andersen <[email protected]>
1 parent b5308f5 commit b7ac647

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
@@ -49,7 +49,12 @@ def vela_bin_pack_io(prefix, data):
4949
# Output via Vela to binary stream for ArmBackendEthosU
5050
# WARNING: Do not change this without changing VelaBinStream.cpp as that
5151
# function consumes this format and the two need to align.
52-
def vela_compile(tosa_flatbuffer: bytes, args: List[str], verbose: bool = False):
52+
def vela_compile(
53+
tosa_flatbuffer: bytes,
54+
args: List[str],
55+
verbose: bool = False,
56+
intermediate_path: str | None = None,
57+
):
5358
"""
5459
Compile a TOSA graph to a binary stream for ArmBackendEthosU using Vela.
5560
"""
@@ -58,14 +63,14 @@ def vela_compile(tosa_flatbuffer: bytes, args: List[str], verbose: bool = False)
5863
"ethos-u-vela pip package couldn't be imported. Make sure it's installed!"
5964
)
6065

61-
with tempfile.TemporaryDirectory() as tmpdir:
66+
def run(dir: str) -> bytes:
6267
tosaname = "out.tosa"
63-
tosa_path = os.path.join(tmpdir, tosaname)
68+
tosa_path = os.path.join(dir, tosaname)
6469
with open(tosa_path, "wb") as f:
6570
f.write(tosa_flatbuffer)
6671

6772
# invoke vela
68-
output_dir = os.path.join(tmpdir, "output")
73+
output_dir = os.path.join(dir, "output")
6974
args.append(f"--output-dir={output_dir}")
7075
args.append(tosa_path)
7176
if verbose:
@@ -75,9 +80,9 @@ def vela_compile(tosa_flatbuffer: bytes, args: List[str], verbose: bool = False)
7580
if any("ethos-u85" in arg for arg in args) or any(
7681
"debug-force-regor" in arg for arg in args
7782
):
78-
np_path = os.path.join(tmpdir, "output", "out_vela.npz")
83+
np_path = os.path.join(dir, "output", "out_vela.npz")
7984
else:
80-
np_path = os.path.join(tmpdir, "output", "out_sg0_vela.npz")
85+
np_path = os.path.join(dir, "output", "out_sg0_vela.npz")
8186

8287
blocks = b""
8388
with np.load(np_path, allow_pickle=False) as data:
@@ -125,3 +130,9 @@ def vela_compile(tosa_flatbuffer: bytes, args: List[str], verbose: bool = False)
125130
blocks = blocks + block
126131

127132
return blocks
133+
134+
if intermediate_path is not None:
135+
return run(intermediate_path)
136+
else:
137+
with tempfile.TemporaryDirectory() as tmpdir:
138+
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
@@ -323,11 +323,14 @@ def get_compile_spec(
323323
tosa_spec = TosaSpecification.create_from_string("TOSA-1.0+INT")
324324
compile_spec = TosaCompileSpec(tosa_spec)
325325
elif "ethos-u" in target:
326+
extra_flags = ["--verbose-operators", "--verbose-cycle-estimate"]
327+
if debug_mode is not None:
328+
extra_flags.append("--enable-debug-db")
326329
compile_spec = EthosUCompileSpec(
327330
target,
328331
system_config=system_config,
329332
memory_mode=memory_mode,
330-
extra_flags=["--verbose-operators", "--verbose-cycle-estimate"],
333+
extra_flags=extra_flags,
331334
config_ini=config,
332335
)
333336
elif "vgf" in target:
@@ -473,7 +476,7 @@ def get_args():
473476
"--config",
474477
required=False,
475478
default="Arm/vela.ini",
476-
help="Specify custom vela configuration file (vela.ini)",
479+
help="Specify custom vela configuration file (vela.ini) for Ethos-U targets.",
477480
)
478481
parser.add_argument(
479482
"--non_strict_export",
@@ -491,7 +494,7 @@ def get_args():
491494
"--enable_debug_mode",
492495
required=False,
493496
choices=["json", "tosa"],
494-
help="Flag to enable ATen-to-TOSA debug mode.",
497+
help="Flag to enable ATen-to-TOSA debug mode and dumping of Vela's debug database.",
495498
)
496499
args = parser.parse_args()
497500

0 commit comments

Comments
 (0)