Skip to main content

A Python CLI wrapper for profiling Tenstorrent's TT-Metal tests

Project description

ttperf - TT-Metal Performance Profiler

Python License PyPI version GitHub issues GitHub stars

A streamlined CLI tool for profiling Tenstorrent's TT-Metal tests and extracting device kernel performance metrics

โœจ Features

  • Automated Profiling: Seamlessly runs Tenstorrent's TT-Metal profiler with pytest
  • CSV Analysis: Automatically extracts and parses performance CSV files
  • Real-time Output: Shows profiling progress in real-time
  • Performance Metrics: Calculates total DEVICE KERNEL DURATION
  • Simple CLI: Easy-to-use command-line interface
  • Flexible: Supports named profiles and various test paths
  • Operation-based Profiling: Profile specific operations by name (e.g., ttperf add)
  • Dynamic Configuration: Customize tensor shape, dtype, and layout for operations
  • Config File Support: Set defaults via ~/.ttperf.yaml or ./.ttperf.yaml
  • CI-friendly: --quiet flag suppresses decorative output; --verbose enables debug logging

๐Ÿš€ Quick Start

Installation

# Install from PyPI (recommended)
pip install ttperf

# With YAML config file support
pip install "ttperf[yaml]"

Or install from source:

git clone https://github.com/Aswincloud/ttperf.git
cd ttperf
pip install -e .

Configuration

ttperf automatically searches for your TT-Metal installation using a simple two-step process:

# Option 1: Set PYTHONPATH to your tt-metal location
export PYTHONPATH=/path/to/your/tt-metal
ttperf add

# Option 2: Run from within tt-metal directory (or any subdirectory)
cd /path/to/your/tt-metal
ttperf relu

tt-metal Path Search Order:

  1. PYTHONPATH environment variable (if specified)
  2. Current working directory (walks up directory tree to find tt-metal root)

Basic Usage

# Run profiling on a specific test
ttperf test_performance.py

# Run with a custom profile name
ttperf my_profile pytest test_performance.py

# Run on a specific test method
ttperf tests/test_ops.py::test_matmul

# Profile specific operations by name
ttperf add
ttperf relu
ttperf matmul

# Custom tensor configuration
ttperf add --shape 1,1,32,32 --dtype bfloat16 --layout tile
ttperf relu --shape 1,1,64,64 --dtype float32 --layout row_major

# Memory options
ttperf add --dram # Use DRAM memory (default)
ttperf relu --l1 # Use L1 memory

# CI-friendly (no emoji/decorative output)
ttperf --quiet add

# Copy CSV output to a directory
ttperf add --output-dir ./results/

# Enable verbose debug logging
ttperf --verbose add

๐Ÿ“‹ CLI Reference

ttperf [OPTIONS] [PROFILE_NAME] [pytest] <test_path_or_operation>

Options:
 --version Show version information
 --help, -h Show this help message
 --list-ops, -l List all supported operations
 --debug, -d Show real-time profiler output
 --verbose, -v Enable verbose logging (debug messages)
 --quiet, -q Suppress decorative/emoji output (for CI)
 --shape SHAPE Tensor shape (e.g., 1,1,32,32)
 --dtype DTYPE Data type: bfloat16/bf16, float32/fp32/f32, int32/i32
 --layout LAYOUT Memory layout: tile, row_major/rm
 --memory-config CONFIG Memory configuration: dram, l1
 --dram Use DRAM memory (default)
 --l1 Use L1 memory
 --output-dir DIR Copy generated CSV to this directory

โš™๏ธ Config File

Create ~/.ttperf.yaml (global) or ./.ttperf.yaml (project-local) to set defaults:

# ~/.ttperf.yaml
shape: 1,1,32,32
dtype: bfloat16
layout: tile
memory_config: dram
output_dir: ./results

CLI flags always override config file values.

๐Ÿ’ก Usage Examples

Test File Profiling

ttperf test_conv.py

Named Profile

ttperf conv_benchmark pytest test_conv.py

Specific Test Method

ttperf tests/ops/test_matmul.py::test_basic_matmul

Operation-based Profiling

# Basic operations
ttperf add
ttperf subtract
ttperf multiply

# Activation functions
ttperf relu
ttperf sigmoid
ttperf tanh
ttperf gelu

# Mathematical operations
ttperf sqrt
ttperf exp
ttperf log

# Comparison operations
ttperf gt
ttperf lt
ttperf eq

# Reduction operations
ttperf max
ttperf min
ttperf sum

# Backward operations
ttperf add_bw
ttperf relu_bw

Dynamic Configuration

ttperf add --shape 1,1,32,32
ttperf relu --shape 2,3,64,128
ttperf add --dtype float32
ttperf add --layout row_major
ttperf add --shape 1,1,64,64 --dtype float32 --layout row_major
ttperf add --dram --shape 1,1,128,128
ttperf relu --l1 --dtype float32

List All Supported Operations

ttperf --list-ops
# or
ttperf -l

Output Example

Auto-generated profile name: temp_test_add
Running test...

============================================================
TEST SUMMARY
============================================================
Test: add
Status: PASSED
Configuration: shape=(1, 1, 32, 32), dtype=bfloat16, layout=tile, memory_config=dram (custom)
CSV Path: /path/to/profile_results.csv
DEVICE KERNEL DURATION [ns] total: 1234567.89 ns
============================================================

๐Ÿ” How It Works

  1. Command Parsing: Analyzes input arguments to determine profile name and test path/operation
  2. Config Loading: Reads ~/.ttperf.yaml or ./.ttperf.yaml for defaults (CLI flags take priority)
  3. Operation Detection: If an operation name is provided, maps it to the corresponding test method
  4. Dynamic Configuration: If custom configuration is provided, sets environment variables for the test
  5. Profile Execution: Runs the Tenstorrent's TT-Metal profiler with the specified test
  6. Output Monitoring: Streams profiling output in real-time (with --debug)
  7. CSV Extraction: Parses the output to find the generated CSV file path, verifies it exists
  8. Performance Analysis: Reads the CSV and calculates total device kernel duration
  9. Output Copy: Optionally copies the CSV to --output-dir if specified

๐Ÿ“Š Performance Metrics

The tool extracts the following key metrics:

  • DEVICE KERNEL DURATION [ns]: Total time spent in device kernels
  • CSV Path: Location of the detailed profiling results
  • Real-time Progress: Live output during profiling (with --debug)

๐Ÿ”ง Configuration Options

Shape Configuration

  • Format: Comma-separated integers (e.g., 1,1,32,32)
  • Default: (1, 1, 1024, 1024)
  • Example: --shape 2,3,64,128

Data Type Configuration

  • Valid Options: bfloat16 (or bf16), float32 (or fp32/f32), int32 (or i32)
  • Default: bfloat16
  • Example: --dtype float32

Layout Configuration

  • Valid Options: tile, row_major (or rm)
  • Default: tile
  • Example: --layout row_major

๐Ÿ“ฆ Requirements

  • Python 3.8+
  • pandas
  • Tenstorrent's TT-Metal development environment
  • pytest
  • PyYAML (optional, for config file support)

๐Ÿ—‚๏ธ Project Structure

ttperf/
โ”œโ”€โ”€ ttperf/
โ”‚ โ”œโ”€โ”€ __init__.py
โ”‚ โ”œโ”€โ”€ ttperf.py # Main CLI implementation
โ”‚ โ””โ”€โ”€ data/
โ”‚ โ”œโ”€โ”€ operation_configs.json
โ”‚ โ””โ”€โ”€ test_eltwise_operations.py
โ”œโ”€โ”€ tests/
โ”‚ โ””โ”€โ”€ test_ttperf.py # Unit tests
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ .gitignore

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This tool is an independent utility that interfaces with Tenstorrent's TT-Metal profiling tools. It is not affiliated with or endorsed by Tenstorrent Inc. The tool serves as a convenience wrapper around existing TT-Metal profiling infrastructure.

Issues

If you encounter any issues, please create an issue on GitHub.

Author

Aswin Z

๐Ÿ™ Acknowledgments

  • Tenstorrent's TT-Metal development team for the profiling tools
  • Python community for excellent libraries like pandas

๐Ÿ’™ Supported by

Termius

Termius โ€” Modern SSH client with cross-platform sync, team vaults, and one-click connections.


Made with care for the Tenstorrent TT-Metal community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ttperf-0.1.9.tar.gz (32.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ttperf-0.1.9-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file ttperf-0.1.9.tar.gz.

File metadata

  • Download URL: ttperf-0.1.9.tar.gz
  • Upload date:
  • Size: 32.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for ttperf-0.1.9.tar.gz
Algorithm Hash digest
SHA256 8b5bed91c43a320fc9708039d171bbaf018fcebcaeb200136da3c1f502ef2f5b
MD5 ea753f9477f87566cf4a466420b4c41c
BLAKE2b-256 9c48f01a070cb23f5937fc42afda5ad77fcea51afee9e379159e4f8c73541077

See more details on using hashes here.

File details

Details for the file ttperf-0.1.9-py3-none-any.whl.

File metadata

  • Download URL: ttperf-0.1.9-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.20

File hashes

Hashes for ttperf-0.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 85f525edf6c92732e1471dc16a99347d4f1c09f944ba2b4b4acccd24ba872d22
MD5 4d98fe7c3fa224b211fab5fdbfadc04e
BLAKE2b-256 5b8bdeeb6c525162975b7f5435787fd87b99fbdf7fe448d5bab78e995f50a90e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page