Skip to content

Conversation

@FindHao
Copy link
Member

@FindHao FindHao commented Dec 2, 2025

Summary

This PR adds support for reproducing kernel launches by kernel name and launch ID, eliminating the need to manually find line numbers in trace files.

Changes

  • reproducer/cli.py:

    • Added --kernel argument (str, default=None)
    • Added --launch-id argument (int, default=0, 0-based)
    • Updated --line help text to indicate mutual exclusivity
  • reproducer/orchestrator.py:

    • Extended reproduce() function signature:
      • line_index: int (required, maintains backward compatibility)
      • out_dir: str (required, no default value)
      • template: str (required, no default value)
      • kernel_name: Optional[str] = None (new, placed after required params)
      • launch_id: int = 0 (new)
    • Implemented kernel lookup logic: if kernel_name is provided, uses find_launch_index_by_kernel() to find the actual line_index
    • Updated docstring to document support for .ndjson, .ndjson.gz, and .bin.ndjson formats
  • cli.py:

    • Added mutual exclusivity check: error if both --kernel and --line (non-zero) are provided
    • Updated reproduce() call to pass new parameters using unified calling pattern
  • tests/test_tritonparse.py:

    • Added helper methods to TestTritonparseCPU class:
      • _get_test_ndjson_file(): Get test file path
      • setup_temp_reproduce_dir(): Create temporary directory
      • cleanup_temp_reproduce_dir(): Cleanup temporary directory
    • Added 5 unit tests:
      • test_reproduce_mutual_exclusivity(): Test parameter mutual exclusivity
      • test_reproduce_kernel_default_launch_id(): Test default launch_id
      • test_reproduce_kernel_launch_id(): End-to-end integration test
      • test_reproduce_kernel_not_found(): Test error handling
      • test_reproduce_launch_id_out_of_range(): Test boundary conditions
    • Refactored tests to use helper methods, following TestTritonparseCUDA pattern
    • Added imports at module level: Path and tritonparse.reproducer.orchestrator

Usage

# Existing: use line number (0-based)
tritonparseoss reproduce trace.ndjson --line 4

# NEW: use kernel name + launch id (0-based)
tritonparseoss reproduce trace.ndjson --kernel matmul_kernel --launch-id 2

# Also works with .ndjson.gz and .bin.ndjson files
tritonparseoss reproduce trace.ndjson.gz --kernel matmul_kernel --launch-id 0

Testing

Tests use real data from tests/example_output/parsed_output_complex/dedicated_log_triton_trace_findhao__mapped.ndjson.gz when possible, mock data for edge cases.

Notes

  • All indices are 0-based for consistency with Python conventions
  • Kernel name matching is case-sensitive (exact match only)
  • Backward compatible: existing --line usage continues to work
  • Error messages include helpful hints (valid range, similar kernel suggestions)

- Support .ndjson.gz (gzip compressed) files
- Support .bin.ndjson (gzip member concatenation) files
- Add _is_gzip_file() helper function
- Add test using existing .ndjson.gz test file
- Create tritonparse/info/ module with kernel_query.py
- Implement list_kernels() to list all kernels with launch counts
- Implement find_launch_index_by_kernel() to find launch events by kernel name and launch ID
- Add KernelSummary and LaunchInfo dataclasses
- Add 6 unit tests in TestTritonparseCPU class
- Tests use real data from example_output when possible, mock data otherwise

This is PR3 from the design doc, providing the foundation for PR4 (reproduce --kernel/--launch-id).
- Moved the import of `find_launch_index_by_kernel` to the correct location in `tritonparse/info/__init__.py`.
- Removed an unnecessary empty line in `tritonparse/info/kernel_query.py`.

This change improves code organization and maintains clarity in the module's interface.
- Add --kernel and --launch-id CLI arguments to reproducer
- Add mutual exclusivity check between --line and --kernel/--launch-id
- Extend reproduce() function to support kernel name lookup
- Use find_launch_index_by_kernel() from info module to find launch events
- Add 5 unit tests for new functionality
- Refactor tests to use helper methods following TestTritonparseCUDA pattern
- Update docstring to document support for .ndjson, .ndjson.gz, and .bin.ndjson formats

This is PR4 from the design doc, enabling users to reproduce kernels by name
and launch ID instead of manually finding line numbers.
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants