From 26cd00aaca6e1ea8dddd20725ed148eebdf50210 Mon Sep 17 00:00:00 2001 From: Tapasvi Patel Date: Mon, 5 Aug 2024 20:53:03 +0000 Subject: [PATCH] #163: Added strict runtime checking for ttnn binary and system its running on --- docs/src/ttmlir-opt.md | 4 ++-- docs/src/ttmlir-translate.md | 6 +++--- docs/src/ttrt.md | 6 +++++- runtime/tools/python/ttrt/common/api.py | 6 ++++++ 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/src/ttmlir-opt.md b/docs/src/ttmlir-opt.md index fe14d2ff46..0b78301a05 100644 --- a/docs/src/ttmlir-opt.md +++ b/docs/src/ttmlir-opt.md @@ -5,7 +5,7 @@ The `ttmlir` optimizer driver. This tool is used to run the `ttmlir` compiler p ## Simple Test ```bash -./build/bin/ttmlir-opt --ttir-to-ttnn-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir +./build/bin/ttmlir-opt --ttir-load-system-desc --ttir-to-ttnn-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir # Or -./build/bin/ttmlir-opt --ttir-to-ttmetal-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir +./build/bin/ttmlir-opt --ttir-load-system-desc --ttir-to-ttmetal-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir ``` diff --git a/docs/src/ttmlir-translate.md b/docs/src/ttmlir-translate.md index fa6f0bef50..756ffd0bd9 100644 --- a/docs/src/ttmlir-translate.md +++ b/docs/src/ttmlir-translate.md @@ -5,7 +5,7 @@ The `ttmlir-translate` translation utility. Unlike `ttmlir-opt` tool which is us ```bash # First, let's run `ttmlir-opt` to convert to proper dialect -./build/bin/ttmlir-opt --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn --convert-ttnn-to-emitc test/ttmlir/Dialect/TTNN/simple_multiply.mlir -o c.mlir +./build/bin/ttmlir-opt --ttir-load-system-desc --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn --convert-ttnn-to-emitc test/ttmlir/Dialect/TTNN/simple_multiply.mlir -o c.mlir # Now run `ttmlir-translate` to produce C++ code ./build/bin/ttmlir-translate -mlir-to-cpp c.mlir -allow-unregistered-dialect @@ -14,7 +14,7 @@ The `ttmlir-translate` translation utility. Unlike `ttmlir-opt` tool which is us ## Generate flatbuffer file from MLIR ```bash # First run `ttmlir-opt` to convert to proper dialect -./build/bin/ttmlir-opt --ttir-to-ttnn-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir -o ttnn.mlir +./build/bin/ttmlir-opt --ttir-load-system-desc --ttir-to-ttnn-backend-pipeline test/ttmlir/Dialect/TTNN/simple_multiply.mlir -o ttnn.mlir # Now run `ttmlir-translate` to produce flatbuffer file ./build/bin/ttmlir-translate --ttnn-to-flatbuffer ttnn.mlir -o out.ttnn @@ -22,5 +22,5 @@ The `ttmlir-translate` translation utility. Unlike `ttmlir-opt` tool which is us Bonus: These two commands can be piped, to avoid writing a `mlir` file to disk, like so: ```bash -./build/bin/ttmlir-opt --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn --convert-ttnn-to-emitc test/ttmlir/Dialect/TTNN/simple_multiply.mlir | ./build/bin/ttmlir-translate -mlir-to-cpp -allow-unregistered-dialect +./build/bin/ttmlir-opt --ttir-load-system-desc --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn --convert-ttnn-to-emitc test/ttmlir/Dialect/TTNN/simple_multiply.mlir | ./build/bin/ttmlir-translate -mlir-to-cpp -allow-unregistered-dialect ``` diff --git a/docs/src/ttrt.md b/docs/src/ttrt.md index 4aee7e69bf..f43a4515ce 100644 --- a/docs/src/ttrt.md +++ b/docs/src/ttrt.md @@ -47,6 +47,7 @@ ttrt run out.ttnn --clean-artifacts ttrt run out.ttnn --save-artifacts ttrt run out.ttnn --loops 10 ttrt run --program-index 0 out.ttnn +ttrt run --program-index all out.ttnn ttrt run /dir/of/flatbuffers ttrt run /dir/of/flatbuffers --loops 10 ``` @@ -66,7 +67,7 @@ ttrt query --clean-artifacts ### perf Note: It's required to be on a system with silicon and to have a runtime enabled -build `-DTTMLIR_ENABLE_RUNTIME=ON`. Also need perf enabled build `-DTT_RUNTIME_ENABLE_PERF_TRACE=ON`. +build `-DTTMLIR_ENABLE_RUNTIME=ON`. Also need perf enabled build `-DTT_RUNTIME_ENABLE_PERF_TRACE=ON` with `export ENABLE_TRACY=1`. ```bash ttrt perf --help @@ -89,3 +90,6 @@ import ttrt.binary fbb = ttrt.binary.load_from_path("out.ttnn") d = ttrt.binary.as_dict(fbb) ``` + +## bonus +artifacts are saved in ttrt-artifacts directory if the option `--save-artifacts` is provided diff --git a/runtime/tools/python/ttrt/common/api.py b/runtime/tools/python/ttrt/common/api.py index 8f2de37384..2fb24114c6 100644 --- a/runtime/tools/python/ttrt/common/api.py +++ b/runtime/tools/python/ttrt/common/api.py @@ -121,6 +121,12 @@ def run(args): fbb = ttrt.binary.load_binary_from_path(binary) check_version(fbb.version) fbb_dict = ttrt.binary.as_dict(fbb) + assert ( + fbb_dict["system_desc"] + == system_desc_as_dict(ttrt.runtime.get_current_system_desc()[0])[ + "system_desc" + ] + ), f"system descriptor for binary and system mismatch!" fbb_list.append((os.path.splitext(os.path.basename(binary))[0], fbb, fbb_dict)) program_index = arg_program_index assert program_index <= len(