Skip to content

Commit 2ed6d6a

Browse files
authored
Arm backend: Pass location as string instead of TosaOpLocation (#15994)
* Fixes issue with serialization * Update TOSA schema
1 parent 3654113 commit 2ed6d6a

File tree

3 files changed

+63
-21
lines changed

3 files changed

+63
-21
lines changed

backends/arm/operators/node_visitor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def _serialize_operator(
8787
None: Mutates ``tosa_graph`` in place.
8888
8989
"""
90-
op_location = ts.TosaOpLocation()
90+
op_location = None
9191
if self.debug_hook:
9292
debug_info = self.debug_hook.add(
9393
node,
@@ -96,7 +96,7 @@ def _serialize_operator(
9696
)
9797

9898
if self.debug_hook.mode == ArmCompileSpec.DebugMode.TOSA:
99-
op_location.text = json.dumps(debug_info.to_dict())
99+
op_location = json.dumps(debug_info.to_dict())
100100

101101
tosa_graph.addOperator(
102102
tosa_op,

backends/arm/test/misc/test_debug_feats.py

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import torch
1717
from executorch.backends.arm.common.arm_compile_spec import ArmCompileSpec
1818
from executorch.backends.arm.test import common
19+
from executorch.backends.arm.test.runner_utils import dbg_tosa_fb_to_json
1920
from executorch.backends.arm.test.tester.test_pipeline import (
2021
EthosU55PipelineINT,
2122
TosaPipelineFP,
@@ -238,25 +239,47 @@ def test_dump_tosa_debug_json(test_data: input_t1):
238239

239240
@common.parametrize("test_data", Linear.inputs)
240241
def test_dump_tosa_debug_tosa(test_data: input_t1):
241-
with tempfile.TemporaryDirectory() as tmpdir:
242-
aten_ops: list[str] = []
243-
exir_ops: list[str] = []
244-
pipeline = TosaPipelineINT[input_t1](
245-
module=Linear(),
246-
test_data=test_data,
247-
aten_op=aten_ops,
248-
exir_op=exir_ops,
249-
custom_path=tmpdir,
250-
tosa_debug_mode=ArmCompileSpec.DebugMode.TOSA,
251-
)
242+
output_dir = "test_dump_tosa_debug"
252243

253-
pipeline.pop_stage("run_method_and_compare_outputs")
254-
pipeline.run()
244+
aten_ops: list[str] = []
245+
exir_ops: list[str] = []
246+
pipeline = TosaPipelineFP[input_t1](
247+
module=Linear(),
248+
test_data=test_data,
249+
use_to_edge_transform_and_lower=True,
250+
aten_op=aten_ops,
251+
exir_op=exir_ops,
252+
custom_path=output_dir,
253+
tosa_debug_mode=ArmCompileSpec.DebugMode.TOSA,
254+
)
255255

256-
json_output_path = Path(tmpdir) / "debug.json"
256+
pipeline.pop_stage("run_method_and_compare_outputs")
257+
pipeline.run()
258+
259+
output_path = Path(output_dir)
260+
json_output_path = output_path / "debug.json"
261+
262+
# A JSON file should not be created when TOSA mode used
263+
assert not json_output_path.exists()
264+
265+
# At least one TOSA file should exist
266+
tosa_files = list(output_path.glob("*.tosa"))
267+
assert len(tosa_files) > 0
268+
269+
tosa_file = tosa_files[0]
270+
with tosa_file.open("rb") as f:
271+
tosa_json = dbg_tosa_fb_to_json(f.read())
272+
273+
# Check all non-empty JSON strings are valid
274+
ops = tosa_json["regions"][0]["blocks"][0]["operators"]
275+
for op in ops:
276+
if op["location"]["text"]:
277+
try:
278+
json.loads(op["location"]["text"])
279+
except json.JSONDecodeError:
280+
pytest.fail("Failed to load debug JSON string")
257281

258-
# A JSON file should not be created when TOSA mode used
259-
assert not json_output_path.exists()
282+
shutil.rmtree(output_dir, ignore_errors=True)
260283

261284

262285
@common.parametrize("test_data", Linear.inputs)

backends/arm/tosa/schemas/tosa_1.0.fbs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,13 +510,31 @@ table TosaTensor {
510510
variable: bool; // is this a variable tensor
511511
is_unranked: bool; // whether this is an unranked tensor
512512
variable_name:string; // name for variable attribute
513+
514+
// In a model that is larger than 2GB, then tensors instead uses the following
515+
// attributes to find stored data, which is outside of flatbuffers
516+
// the offset is calculated relative to the beginning of the file and is only
517+
// valid if > 1.
518+
offset: ulong;
519+
size: ulong;
520+
}
521+
522+
table TosaShape {
523+
name: string; // name of the shape
524+
rank: uint32; // rank of the shape
525+
data: [ubyte] (force_align: 8); // raw data array if it's a constant shape
526+
}
527+
528+
table OpLocation {
529+
text: string; // Opaque string, interpretted by user
513530
}
514531

515532
table TosaOperator {
516533
op:Op; // operator enum
517534
attribute:Attribute; // union structure. operator attribute
518-
inputs:[string]; // list of input tensor names
519-
outputs:[string]; // list of output tensor names
535+
inputs:[string]; // list of input tensor or shape names
536+
outputs:[string]; // list of output tensor or shape names
537+
location: OpLocation; // location of this Op in mlir
520538
}
521539

522540
table TosaBasicBlock {
@@ -525,6 +543,7 @@ table TosaBasicBlock {
525543
tensors:[TosaTensor]; // tensors array
526544
inputs:[string]; // name of graph inputs
527545
outputs:[string]; // name of graph outputs
546+
shapes:[TosaShape]; // shapes array
528547
}
529548

530549
table TosaRegion {
@@ -537,4 +556,4 @@ table TosaGraph {
537556
regions:[TosaRegion]; // regions array
538557
}
539558

540-
root_type TosaGraph;
559+
root_type TosaGraph;

0 commit comments

Comments
 (0)