Skip to content

TritonParse is a tool designed to help developers analyze and debug Triton kernels by visualizing the compilation process and source code mappings.

License

Notifications You must be signed in to change notification settings

pytorch-labs/tritonparse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

54 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

TritonParse

License: BSD-3 GitHub Pages

A comprehensive visualization and analysis tool for Triton IR files, designed to help developers analyze, debug, and understand Triton kernel compilation processes.

πŸš€ Features

Visualization & Analysis

  • Interactive Kernel Explorer: Display detailed kernel information and stack traces
  • Multi-format IR Support: View and explore multiple Triton IR formats:
    • TTGIR (Triton GPU IR)
    • TTIR (Triton IR)
    • LLIR (LLVM IR)
    • PTX (Parallel Thread Execution)
    • AMDGCN (AMD GPU IR)
  • Side-by-side Comparison: Compare TTGIR and PTX code with synchronized highlighting
  • Interactive Code Views: Click-to-highlight corresponding lines across different formats
  • Source Mapping: Trace relationships between different compilation stages

Structured Logging

  • Compilation Tracing: Capture detailed Triton compilation events
  • Stack Trace Integration: Full Python stack traces for compilation events
  • Metadata Extraction: Comprehensive kernel metadata and compilation statistics
  • NDJSON Output: Structured logging format for easy processing

Website Deployment Options

  • GitHub Pages: Automatic deployment with GitHub Actions
  • Standalone Build: Single HTML file with all assets inlined
  • Local Development: Full development environment setup

πŸ› οΈ Tech Stack

Frontend:

  • React 19 with TypeScript
  • Vite for build tooling
  • Tailwind CSS for styling
  • Monaco Editor for code display
  • React Syntax Highlighter for syntax highlighting
  • React Resizable Panels for layout

Backend/Processing:

  • Python with Triton integration
  • Structured logging and event tracing
  • Source mapping extraction utilities

πŸ“¦ Installation

For Users (Trace Generation Only)

Prerequisites:

  • Python >= 3.8
  • Triton >= 3.3.1

Quick Start:

# Clone the repository
git clone https://github.com/pytorch-labs/tritonparse.git
cd tritonparse

# Install Python dependencies
pip install -e .

For Website Developers (Optional)

Additional Prerequisites:

  • Node.js >= 18.0.0
  • npm

Website Setup:

# Install website dependencies
cd website
npm install

🎯 Usage

1. Generate Triton Trace Files

First, integrate TritonParse with your Triton/PyTorch code to generate trace files:

import torch
import tritonparse.structured_logging

# Initialize structured logging to capture Triton compilation events
tritonparse.structured_logging.init("./logs/")

# Example: Using with torch.compile
def your_kernel():
    # Your PyTorch/Triton kernel code
    pass

compiled_kernel = torch.compile(your_kernel)
result = compiled_kernel()  # This will generate trace logs in ./logs/

# The trace files can then be analyzed using the web interface

2. Analyze with Web Interface

Option A: Online Interface (Recommended)

Visit https://pytorch-labs.github.io/tritonparse/ to use the tool directly in your browser:

  1. Open your local trace file directly in the browser
  2. Explore the visualization using the Overview and Code Comparison tabs

Option B: Local Development (For Contributors)

For contributors working on the website:

cd website
npm run dev

Access the application at http://localhost:5173

Available Scripts:

  • npm run build - Standard build
  • npm run build:single - Standalone HTML file
  • npm run preview - Preview production build

πŸ“ Project Structure

tritonparse/
β”œβ”€β”€ tritonparse/              # Python package
β”‚   β”œβ”€β”€ structured_logging.py # Main logging infrastructure
β”‚   β”œβ”€β”€ extract_source_mappings.py # Source mapping utilities
β”‚   β”œβ”€β”€ source_type.py        # Source type definitions
β”‚   β”œβ”€β”€ utils.py              # Helper utilities
β”‚   β”œβ”€β”€ common.py             # Common functions
β”‚   └── tp_logger.py          # Logger configuration
β”œβ”€β”€ website/                  # React web application
β”‚   β”œβ”€β”€ src/                  # React source code
β”‚   β”œβ”€β”€ public/               # Static assets and example files
β”‚   β”œβ”€β”€ scripts/              # Build utilities (inline-html.js)
β”‚   β”œβ”€β”€ node_modules/         # Dependencies
β”‚   β”œβ”€β”€ package.json          # Node.js dependencies
β”‚   β”œβ”€β”€ vite.config.ts        # Vite configuration
β”‚   └── dist/                 # Built application (after build)
β”œβ”€β”€ tests/                    # Test files and example traces
β”‚   β”œβ”€β”€ test_add.py           # Example Triton kernel test
β”‚   β”œβ”€β”€ unit_tests.py         # Unit tests
β”‚   └── *.ndjson              # Example trace files
β”œβ”€β”€ run.py                    # Main runner script
β”œβ”€β”€ pyproject.toml            # Python package configuration
β”œβ”€β”€ LICENSE                   # BSD-3 license
β”œβ”€β”€ CONTRIBUTING.md           # Contribution guidelines
└── CODE_OF_CONDUCT.md        # Code of conduct

πŸ”§ Development

Python Development

Install in development mode:

pip install -e .

Example test:

cd tests
python test_add.py

Website Development (For Contributors)

Start development server:

cd website
npm run dev

Available Scripts:

  • npm run dev - Start development server
  • npm run build - Production build
  • npm run build:single - Standalone HTML build
  • npm run lint - Run ESLint
  • npm run preview - Preview production build

πŸš€ Deployment

Live Website

The TritonParse visualization tool is automatically deployed and available at: https://pytorch-labs.github.io/tritonparse/

For Contributors: Local Deployment

Build standalone version:

cd website
npm run build:single

The dist/standalone.html file contains the entire application and can be deployed anywhere.

πŸ“Š Understanding Triton Compilation

TritonParse helps visualize the Triton compilation pipeline:

  1. Python Source β†’ Triton kernel functions
  2. TTIR β†’ Triton's high-level IR
  3. TTGIR β†’ GPU-specific Triton IR
  4. LLIR β†’ LLVM IR representation
  5. PTX β†’ NVIDIA PTX assembly
  6. AMDGCN β†’ AMD GPU IR

Each stage can be inspected and compared to understand optimization transformations.

πŸ” Advanced Features

Environment Variables

  • TRITONPARSE_DEBUG=1 - Enable debug logging
  • TRITONPARSE_NDJSON=1 - Output in NDJSON format (default)

Custom Log Directory

tritonparse.structured_logging.init("/custom/log/path/")

Source Mapping Extraction

python tritonparse/extract_source_mappings.py input.ndjson output_mapped.ndjson

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes
  4. Run tests: npm test (website) and python -m pytest (Python)
  5. Submit a pull request

πŸ“ License

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

πŸ”— Related Projects

  • OpenAI Triton - The Triton compiler and language
  • PyTorch - Deep learning framework with Triton integration

πŸ“ž Support


Note: This tool is designed for developers working with Triton kernels and GPU computing. Basic familiarity with CUDA, GPU programming concepts, and the Triton language is recommended for effective use.

About

TritonParse is a tool designed to help developers analyze and debug Triton kernels by visualizing the compilation process and source code mappings.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •