-
Notifications
You must be signed in to change notification settings - Fork 26
04. Developer Guide
This guide is for developers who want to contribute to TritonParse, understand its architecture, or extend its functionality.
TritonParse consists of three main components:
ββββββββββββββββββββββββ ββββββββββββββββββββββββ ββββββββββββββββββββββββ
β Python Backend β β Processing β β Frontend UI β
β β β β β β
β β’ Structured Logging ββββΆβ β’ Log Parsing ββββΆβ β’ React Interface β
β β’ Triton Hooks β β β’ Source Mapping β β β’ IR Visualization β
β β’ Trace Generation β β β’ Data Compression β β β’ Code Comparison β
β β β β’ Launch Analysis β β β’ File Diff View β
ββββββββββββββββββββββββ ββββββββββββββββββββββββ ββββββββββββββββββββββββ
β β
β βΌ
β ββββββββββββββββββββββββ
β β Reproducer β
β β β
βββββββββββββββββββΆβ β’ Script Generation β
β β’ Tensor Rebuilding β
β β’ Template System β
β β’ Context Bundling β
ββββββββββββββββββββββββ
Python Backend - Captures Triton compilation events and generates structured logs. Core logic for IR parsing, trace processing, and source mapping.
Processing Pipeline - Transforms raw NDJSON logs into structured, compressed data with source mappings and launch analysis.
Frontend UI - React/TypeScript web application for interactive visualization using Monaco Editor for code display.
Reproducer System - Generates standalone Python scripts to reproduce kernel executions from trace files with full context.
π‘ See Project Structure below for detailed file organization.
tritonparse/
βββ tritonparse/ # Python package
β βββ __init__.py
β βββ __main__.py # CLI entry point
β βββ cli.py # CLI argument parsing (parse, reproduce, info, diff, bisect, compat-build)
β βββ structured_logging.py # Core logging infrastructure to capture events
β βββ context_manager.py # TritonParseManager context manager
β βββ shared_vars.py # Shared state and variables for the package
β βββ tp_logger.py # Logger configuration
β βββ _json_compat.py # JSON serialization compatibility
β βββ clp.py # CLP (Compressed Log Processor) format support
β β
β βββ parse/ # Core parsing logic
β β βββ common.py # Common utilities and helper functions
β β βββ utils.py # Main parsing entrypoint (`unified_parse`, `oss_run`)
β β βββ trace_processor.py # Processes raw trace files, groups events
β β βββ ir_parser.py # Extracts source location from various IRs
β β βββ ir_analysis.py # IR analysis utilities
β β βββ mapper.py # Bidirectional mappings between IRs and Python source
β β βββ extract_source_mappings.py # Source mapping extraction
β β βββ event_diff.py # Launch event comparison
β β βββ source_type.py # Source type definitions (TTIR, PTX, etc.)
β β βββ sourcemap_utils.py # Source mapping helper functions
β β
β βββ info/ # Kernel query and info CLI
β β βββ cli.py # Info subcommand CLI
β β βββ kernel_query.py # Kernel lookup by name
β β βββ parse_helper.py # Parsing utilities for info command
β β
β βββ diff/ # Compilation event comparison/diffing
β β βββ cli.py # Diff subcommand CLI
β β βββ core/ # Core diff logic
β β β βββ diff_engine.py # Single event comparison
β β β βββ trace_diff_engine.py # Trace-level comparison
β β β βββ event_matcher.py # Event matching
β β β βββ kernel_matcher.py # Kernel matching
β β β βββ diff_types.py # Type definitions
β β βββ output/ # Output formatting
β β βββ event_writer.py # Write diff events
β β βββ summary_formatter.py # Format summaries
β β
β βββ bisect/ # Triton/LLVM/PyTorch regression bisection
β β βββ cli.py # Bisect subcommand CLI
β β βββ base_bisector.py # Base bisector class
β β βββ triton_bisector.py # Triton commit bisection
β β βββ torch_bisector.py # PyTorch commit bisection
β β βββ llvm_bisector.py # LLVM commit bisection
β β βββ commit_detector.py # Detect LLVM bumps in Triton
β β βββ pair_tester.py # Test (Triton, LLVM) commit pairs
β β βββ env_manager.py # Environment setup
β β βββ state.py # Bisect state management
β β βββ scripts/ # Bash scripts for bisection
β β
β βββ compat_builder/ # LLVM compatibility map builder
β β βββ cli.py # Compat-build subcommand CLI
β β βββ ... # Builder logic with AI-assisted fixes
β β
β βββ reproducer/ # Reproducer system for generating standalone scripts
β β βββ orchestrator.py # Main reproducer entry point (`reproduce()`)
β β βββ cli.py # CLI argument handling for reproduce command
β β βββ placeholder_replacer.py # Template placeholder substitution
β β βββ utils.py # Tensor creation and path utilities
β β βββ types.py # Type definitions (KernelImportMode enum)
β β βββ ast_analyzer.py # AST analysis for kernel code
β β βββ function_extractor.py # Extract kernel functions
β β βββ import_parser.py # Parse import statements
β β βββ import_resolver.py # Resolve import paths
β β βββ multi_file_analyzer.py # Multi-file analysis
β β βββ stub_generator.py # Generate stubs for missing dependencies
β β βββ ingestion/ # Trace file parsing
β β β βββ ndjson.py # NDJSON trace parsing and context extraction
β β βββ templates/ # Code generation templates
β β βββ loader.py # Template loading utilities
β β βββ example.py # Default reproducer template
β β βββ tritonbench.py # TritonBench-compatible template
β β
β βββ ai/ # LLM client abstraction
β β βββ client.py # Unified LLM client interface
β β βββ parsers.py # Response parsers
β β βββ utils.py # AI utilities
β β
β βββ validation/ # JSON schema validation
β β βββ schemas/ # JSON schemas for events
β β βββ compilation.schema.json
β β βββ launch.schema.json
β β
β βββ tools/ # Utility tools
β βββ decompress_bin_ndjson.py # Decompress .bin.ndjson files
β βββ disasm.py # Disassembly utilities
β βββ extract_irs.py # Extract IRs from trace files
β βββ load_tensor.py # Load tensor blob files
β βββ prettify_ndjson.py # Pretty-print NDJSON
β
βββ website/ # React web application for visualization
β βββ src/
β β βββ components/ # Reusable React components
β β β βββ ArgumentViewer.tsx # Displays kernel arguments with expandable details
β β β βββ Callstack.tsx # Call stack visualization
β β β βββ CodeViewer.tsx # Displays IR code with Monaco editor
β β β βββ CodeComparisonView.tsx # Side-by-side IR viewing with line mappings
β β β βββ CompilationInfo.tsx # Compilation metadata display
β β β βββ CopyCodeButton.tsx # Copy-to-clipboard button
β β β βββ DataSourceSelector.tsx # File/URL source selector
β β β βββ DiffViewer.tsx # Side-by-side diff view for text
β β β βββ DiffComparisonView.tsx # File diff comparison component
β β β βββ ExternalLink.tsx # External link component
β β β βββ SingleCodeViewer.tsx # Single IR code viewer
β β β βββ StackDiffViewer.tsx # Stack diff visualization
β β β βββ ToggleSwitch.tsx # Toggle switch UI component
β β β βββ TritonIRs.tsx # IR navigation links
β β β βββ WelcomeScreen.tsx # Initial welcome/loading screen
β β βββ pages/ # Main application pages
β β β βββ KernelOverview.tsx # Main analysis view for a kernel
β β β βββ CodeView.tsx # Focused view for a single IR file
β β β βββ FileDiffView.tsx # File diff page for cross-trace comparison
β β β βββ IRAnalysis.tsx # IR analysis page
β β βββ context/ # React context providers
β β β βββ FileDiffSession.tsx # File diff state management
β β βββ utils/ # Utility functions
β β β βββ dataLoader.ts # Data loading and processing from parsed logs
β β β βββ fbDetection.ts # Meta internal environment detection
β β β βββ safeImport.ts # Safe dynamic imports
β β β βββ tensor.ts # Tensor data utilities
β β βββ App.tsx # Main application component with routing
β β βββ main.tsx # Application entry point
β βββ public/ # Static assets and sample data
β βββ scripts/ # Build and deployment scripts
β βββ package.json # Frontend dependencies and scripts
β βββ vite.config.ts # Vite build configuration
β
βββ tests/ # Test suite for the Python package
β βββ __init__.py
β βββ test_tritonparse.py # Main test suite (CPU and CUDA tests)
β βββ test_add.py # Manual test example
β βββ example_output/ # Sample output data
β βββ README.md # Test documentation
β
βββ run.py # Main CLI entry point with argparse subcommands
βββ pyproject.toml # Python project configuration
βββ Makefile # Development commands
βββ README.md # Project overview
βββ CHANGELOG.md # Version history
βββ CONTRIBUTING.md # Contribution guidelines
βββ CODE_OF_CONDUCT.md # Code of conduct
βββ LICENSE # BSD-3 license
- Python >= 3.10
- Node.js >= 22.0.0
- Triton >= 3.4.0 (latest version recommended)
- Git for version control
# 1. Clone repository
git clone https://github.com/meta-pytorch/tritonparse.git
cd tritonparse
# 2. Install Python dependencies
make install-dev
# 3. Install website dependencies
cd website
npm install# Python: Check formatting and run tests
make format-check
make test
# Website: Start dev server
cd website
npm run devWe use a comprehensive formatting pipeline:
| Tool | Purpose | Configuration |
|---|---|---|
| Black | Code formatting | pyproject.toml |
| usort | Import sorting | pyproject.toml |
| Ruff | Linting | Built-in rules |
# Format code
make format
# Check formatting
make format-check
# Run linting
make lint-check
# Run tests (CPU only)
make test
# Run all tests (including CUDA)
make test-cuda
# Website development
cd website && npm run devBefore committing, ensure:
-
Code is formatted:
make format -
Linting passes:
make lint-check -
Tests pass:
make test -
Website builds:
cd website && npm run build
Structured Logging (structured_logging.py) - Captures Triton compilation and launch events. Main functions: init() and init_with_env() for initialization.
Log Processing (utils.py) - Transforms raw logs into analyzable format. Entry point: unified_parse() for parsing NDJSON logs, extracting source mappings, and compressing data.
Source Mapping (extract_source_mappings.py) - Correlates lines between different IR stages (TTIR, TTGIR, LLIR, PTX, AMDGCN).
π‘ See inline code documentation for detailed function signatures and parameters.
- Define the new data: Determine what new information needs to be captured.
-
Update
structured_logging.py: Add logic to capture the new data within the appropriate hooks (e.g., pre-compilation, post-compilation). -
Modify
trace_processor.py: If the new data requires special processing or aggregation (like the launch analysis), add the logic here. -
Update
unified_parse(): Ensure the new data is handled correctly during the main parsing routine. -
Write tests: Add unit and integration tests to
tests/to validate the new feature.
The CLI uses argparse with two main subcommands: parse and reproduce.
# Parse subcommand
tritonparseoss parse ./logs/ --out ./parsed_output
# Reproduce subcommand
tritonparseoss reproduce trace.ndjson --line 1 --out-dir repro_outputImplementation Files:
-
run.py- Main CLI with argparse subparsers -
__main__.py- Entry point that callsrun.main() -
utils.py-_add_parse_args()function -
reproducer/cli.py-_add_reproducer_args()function
π‘ See Usage Guide for complete CLI reference and parameters.
Generates standalone Python scripts from trace files.
Core Components:
-
Orchestrator - Main
reproduce()function, loads events and generates scripts - Ingestion - Extracts kernel context, arguments, and metadata from NDJSON
-
Templates - Customizable code templates (default:
example.py) - Placeholder Replacement - Substitutes template placeholders for imports, invocations, paths
- Utils - Rebuilds kernel arguments from JSON, handles tensor creation
Custom Templates Example:
# my_template.py
import torch
# {{KERNEL_IMPORT_PLACEHOLDER}}
if __name__ == "__main__":
# {{KERNEL_INVOCATION_PLACEHOLDER}}
print("Custom execution!")Use with: tritonparseoss reproduce trace.ndjson --line 1 --template my_template.py
π‘ See Reproducer Guide for comprehensive documentation on templates, tensor reconstruction, and advanced usage.
- React 19 - UI framework
- TypeScript - Type safety
- Vite - Build tool and dev server
- Tailwind CSS - Styling
- Monaco Editor - IDE-quality code display
Data Loading (utils/dataLoader.ts) - Loads and processes trace files from URLs or local files.
Code Viewer (components/CodeViewer.tsx) - Displays IR code with syntax highlighting, line numbers, and source mapping.
IR Code View (components/CodeComparisonView.tsx) - Side-by-side IR viewing with synchronized scrolling and interactive line mapping.
File Diff View (pages/FileDiffView.tsx) - Cross-trace kernel comparison with customizable diff options.
-
Update data loader - Modify
dataLoader.tsfor new data fields -
Create components - Add React components in
website/src/components/ -
Integrate - Add components to pages (e.g.,
KernelOverview.tsx) - Style - Use Tailwind CSS for consistent styling
-
Test - Verify with
npm run buildand manual testing
cd website
# Development server
npm run dev
# Type checking
npm run build
# Linting
npm run lint
# Test with sample data
# Load ./public/f0_fc0_a0_cai-.ndjson in browserPython Code
β
βΌ
Triton Compilation
(triggers Hook Events)
β
βΌ
Structured Logging
β
βΌ
Raw NDJSON Logs
β
βΌ
Log Processing
- Source Mapping
- Launch Analysis
β
βΌ
Compressed Data (.gz)
β
βΌ
Web Interface
β
βΌ
Interactive Visualization
π‘ Data Format: Events are logged as NDJSON, processed into structured format with IR files and source mappings, then compressed as
.ndjson.gzfor the web interface.
# Enable debug logging
export TRITONPARSE_DEBUG=1
# Run with debug output
python your_script.py# Check log file contents
head -n 10 ./logs/*.ndjson
# Inspect compressed data
zcat ./parsed_output/*.gz | head -n 20
# Test parsing pipeline
python -c "
import tritonparse.parse.utils
tritonparse.parse.utils.unified_parse('./logs/', './test_output/', verbose=True)
"// Enable frontend debug logging
localStorage.setItem('tritonparse-debug', 'true');
// Inspect loaded data
console.log(window.tritonparseData);
// Test data processing
import { processKernelData } from './utils/dataLoader';
console.log(processKernelData(rawData));tests/
βββ cpu/ # CPU-only tests (no GPU required)
βββ gpu/ # GPU tests (require CUDA)
βββ ai/ # AI module tests
βββ test_add.py # Manual test example
βββ example_output/ # Sample data
# CPU-only tests
make test
# All tests including CUDA (requires GPU)
make test-cuda
# Manual test
cd tests
TORCHINDUCTOR_FX_GRAPH_CACHE=0 python test_add.pyFollow this workflow when adding end-to-end tests in TestTritonparseCUDA:
-
Define test method - Create method starting with
test_ - Define Triton kernel - Write kernel to test feature
-
Setup environment - Create temp directories with
tempfile.mkdtemp() -
Initialize logging - Call
tritonparse.structured_logging.init() - Run kernel - Execute to generate compilation/launch events
-
Parse logs - Call
tritonparse.parse.utils.unified_parse() - Assert results - Verify output files and contents
-
Cleanup - Use
try...finallyto remove temp directories
Example Structure:
@unittest.skipUnless(torch.cuda.is_available(), "CUDA not available")
def test_new_feature(self):
temp_dir = tempfile.mkdtemp()
tritonparse.structured_logging.init(temp_dir + "/logs", enable_trace_launch=True)
try:
# Run kernel and generate logs
kernel[(grid,)](args, BLOCK_SIZE=128)
# Parse and verify
tritonparse.parse.utils.unified_parse(source=log_path, out=parsed_path)
self.assertGreater(len(os.listdir(parsed_path)), 0)
finally:
shutil.rmtree(temp_dir)
tritonparse.structured_logging.clear_logging_config()π‘ See existing tests in
tests/test_tritonparse.pyfor complete examples.
Versions are managed in:
-
pyproject.toml- Python package version -
website/package.json- Frontend version
- Update version numbers
- Update CHANGELOG.md
- Run full test suite
- Build and test website
- Create GitHub release
- Deploy to GitHub Pages
CI/CD pipeline includes:
- Format checking - Code style validation
- Linting - Code quality checks
- Testing - Python and frontend tests
- Website deployment - Automatic GitHub Pages deployment
- Fork the repository
-
Create feature branch:
git checkout -b feature-name - Make changes following coding standards
- Add tests for new functionality
-
Run formatting:
make format -
Run tests:
make format-check && make test - Submit pull request
- All PRs require review by core maintainers
- CI checks must pass before merge
- Documentation updates required for new features
- Tests required for new functionality
When reporting issues:
- Use issue templates provided
- Include system information
- Provide reproduction steps
- Include error messages and logs
- Code Formatting Guide - Detailed formatting standards
- Python API Reference - Complete API documentation
- Environment Variables Reference - Configuration options
- Reproducer Guide - Reproducer system documentation
- GitHub Discussions - Community Q&A
- GitHub Issues - Bug reports and feature requests
- Triton Documentation - Official Triton docs
- React Documentation - React development guide
- TypeScript Documentation - TypeScript reference
For new developers:
- Complete the Installation Guide
- Read the Usage Guide to understand the tool
- Explore the codebase starting with simple components
- Run the test suite to verify your setup
- Join GitHub Discussions for community support
For experienced contributors:
- Check GitHub Issues for open tasks
- Review the Architecture Deep Dive for advanced topics
- Contribute to documentation improvements
- Propose new features through GitHub Discussions