Skip to content

Commit

Permalink
#306: Added autogeneration of ttnn binaries based on system desc file…
Browse files Browse the repository at this point in the history
… from lit cfg (#309)
  • Loading branch information
tapspatel authored Aug 7, 2024
1 parent 2bdb825 commit 47a7453
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 103 deletions.
3 changes: 2 additions & 1 deletion docs/src/ttrt.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,5 @@ d = ttrt.binary.as_dict(fbb)
```

## bonus
artifacts are saved in ttrt-artifacts directory if the option `--save-artifacts` is provided
- artifacts are saved in ttrt-artifacts directory if the option `--save-artifacts` is provided
- you can specify `SYSTEM_DESC_PATH` with the path to your ttsys file, and lit will automatically generate all the flatbuffer binaries for that system
11 changes: 8 additions & 3 deletions runtime/tools/python/ttrt/common/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,18 @@ def run(args):
print("executing constraint for all provided flatbuffers")
system_desc, device_ids = ttrt.runtime.get_current_system_desc()
program_indices = []
cleaned_binaries = []
for binary in binaries:
check_file_exists(binary)
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(system_desc)["system_desc"]
), f"system descriptor for binary and system mismatch!"
if fbb_dict["system_desc"] != system_desc_as_dict(system_desc)["system_desc"]:
print(
f"system descriptor for binary and system mismatch, ignoring test={binary}"
)
continue

if arg_program_index != "all":
program_index = int(arg_program_index)
Expand All @@ -145,6 +148,8 @@ def run(args):
program_indices,
)
)
cleaned_binaries.append(binary)
binaries = cleaned_binaries

# execution
print("executing action for all provided flatbuffers")
Expand Down
31 changes: 19 additions & 12 deletions runtime/tools/python/ttrt/common/perf_trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,22 +156,10 @@ def save_perf_artifacts(perf_folder):
tracy_file = f"{TT_METAL_HOME}/generated/profiler/.logs/{TRACY_FILE_NAME}"

try:
# check_file_exists(profiler_device_side_log_file)
# check_file_exists(profiler_host_device_sync_info_file)
# check_file_exists(profiler_log_location_record_file)
check_file_exists(tracy_ops_times_file)
check_file_exists(tracy_ops_data_file)
check_file_exists(tracy_file)

# shutil.copy(profiler_device_side_log_file, os.path.join(perf_folder, "profiler_device_side_log_file.csv"))
# print(f"File '{profiler_device_side_log_file}' copied to '{perf_folder}' successfully.")

# shutil.copy(profiler_host_device_sync_info_file, os.path.join(perf_folder, "profiler_host_device_sync_info_file.csv"))
# print(f"File '{profiler_host_device_sync_info_file}' copied to '{perf_folder}' successfully.")

# shutil.copy(profiler_log_location_record_file, os.path.join(perf_folder, "profiler_log_location_record_file.log"))
# print(f"File '{profiler_log_location_record_file}' copied to '{perf_folder}' successfully.")

shutil.copy(
tracy_ops_times_file, os.path.join(perf_folder, "tracy_ops_times_file.csv")
)
Expand All @@ -187,3 +175,22 @@ def save_perf_artifacts(perf_folder):

except Exception as e:
print(f"An unexpected error occurred: {e}")

# Copy datetime folder files into root perf directory
for root, dirs, files in os.walk(perf_folder, topdown=False):
if root == perf_folder:
continue

for file_name in files:
# Full path of the file
file_path = os.path.join(root, file_name)
# Destination path in the parent folder
dest_path = os.path.join(perf_folder, file_name)

# Move the file
shutil.move(file_path, dest_path)
print(f"Moved {file_path} to {dest_path}")

# Remove the subfolder after moving the files
if not os.listdir(root): # Check if the directory is empty
os.rmdir(root)
4 changes: 4 additions & 0 deletions test/lit.cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@
# test_exec_root: The root path where tests should be run.
config.test_exec_root = os.path.join(config.ttmlir_obj_root, "test")

# system_desc_path: The system desc that is to be used to generate the binary files.
config.system_desc_path = os.getenv("SYSTEM_DESC_PATH", "")

config.substitutions.append(("%PATH%", config.environment["PATH"]))
config.substitutions.append(("%shlibext", config.llvm_shlib_ext))
config.substitutions.append(("%system_desc_path%", config.system_desc_path))

llvm_config.with_system_environment(["HOME", "INCLUDE", "LIB", "TMP", "TEMP"])

Expand Down
30 changes: 0 additions & 30 deletions test/ttmlir/Silicon/TTNN/multiple_add_with_loc.mlir

This file was deleted.

31 changes: 0 additions & 31 deletions test/ttmlir/Silicon/TTNN/multiple_add_with_loc_grid_override.mlir

This file was deleted.

2 changes: 1 addition & 1 deletion test/ttmlir/Silicon/TTNN/simple_eltwise.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: ttmlir-opt --ttir-load-system-desc --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: ttmlir-opt --ttir-load-system-desc="path=%system_desc_path%" --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: FileCheck %s --input-file=%t.mlir
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn

Expand Down
2 changes: 1 addition & 1 deletion test/ttmlir/Silicon/TTNN/simple_ge.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: ttmlir-opt --ttir-load-system-desc --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: ttmlir-opt --ttir-load-system-desc="path=%system_desc_path%" --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: FileCheck %s --input-file=%t.mlir
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn

Expand Down
2 changes: 1 addition & 1 deletion test/ttmlir/Silicon/TTNN/simple_matmul.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: ttmlir-opt --ttir-load-system-desc --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: ttmlir-opt --ttir-load-system-desc="path=%system_desc_path%" --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: FileCheck %s --input-file=%t.mlir
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn

Expand Down
2 changes: 1 addition & 1 deletion test/ttmlir/Silicon/TTNN/simple_multiply.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: ttmlir-opt --ttir-load-system-desc --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: ttmlir-opt --ttir-load-system-desc="path=%system_desc_path%" --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: FileCheck %s --input-file=%t.mlir
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn

Expand Down
2 changes: 1 addition & 1 deletion test/ttmlir/Silicon/TTNN/simple_relu.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: ttmlir-opt --ttir-load-system-desc --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: ttmlir-opt --ttir-load-system-desc="path=%system_desc_path%" --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: FileCheck %s --input-file=%t.mlir
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn

Expand Down
2 changes: 1 addition & 1 deletion test/ttmlir/Silicon/TTNN/simple_subtract.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: ttmlir-opt --ttir-load-system-desc --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: ttmlir-opt --ttir-load-system-desc="path=%system_desc_path%" --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: FileCheck %s --input-file=%t.mlir
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn

Expand Down
2 changes: 1 addition & 1 deletion test/ttmlir/Silicon/TTNN/simple_sum.mlir
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: ttmlir-opt --ttir-load-system-desc --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: ttmlir-opt --ttir-load-system-desc="path=%system_desc_path%" --ttir-implicit-device --ttir-layout --ttnn-open-device --convert-ttir-to-ttnn %s > %t.mlir
// RUN: FileCheck %s --input-file=%t.mlir
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn

Expand Down
18 changes: 0 additions & 18 deletions test/ttmlir/Silicon/TTNN/ttir_to_ttnn_pipeline.mlir

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: ttmlir-opt --ttir-to-ttnn-backend-pipeline="enable-grid-set=false" %s > %t.mlir
// RUN: ttmlir-opt --ttir-load-system-desc="path=%system_desc_path%" --ttir-to-ttnn-backend-pipeline="enable-grid-set=false" %s > %t.mlir
// RUN: FileCheck %s --input-file=%t.mlir
// RUN: ttmlir-translate --ttnn-to-flatbuffer %t.mlir > %t.ttnn

Expand Down

0 comments on commit 47a7453

Please sign in to comment.