|
16 | 16 | import torch |
17 | 17 | from executorch.backends.arm.common.arm_compile_spec import ArmCompileSpec |
18 | 18 | from executorch.backends.arm.test import common |
| 19 | +from executorch.backends.arm.test.runner_utils import dbg_tosa_fb_to_json |
19 | 20 | from executorch.backends.arm.test.tester.test_pipeline import ( |
20 | 21 | EthosU55PipelineINT, |
21 | 22 | TosaPipelineFP, |
@@ -238,25 +239,47 @@ def test_dump_tosa_debug_json(test_data: input_t1): |
238 | 239 |
|
239 | 240 | @common.parametrize("test_data", Linear.inputs) |
240 | 241 | 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" |
252 | 243 |
|
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 | + ) |
255 | 255 |
|
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") |
257 | 281 |
|
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) |
260 | 283 |
|
261 | 284 |
|
262 | 285 | @common.parametrize("test_data", Linear.inputs) |
|
0 commit comments