Skip to content

Conversation

@FindHao
Copy link
Member

@FindHao FindHao commented Dec 2, 2025

Summary

This PR creates the info/ module as the core query layer for kernel information from NDJSON trace files. This is an internal infrastructure PR that will be used by PR4 (reproduce --kernel/--launch-id) and PR5 (info CLI).

Changes

  • tritonparse/info/__init__.py: Module initialization, exports core functions

  • tritonparse/info/kernel_query.py: Core query functions:

    • KernelSummary dataclass: kernel name, hash, total launches
    • LaunchInfo dataclass: launch ID, line index, grid (for PR5)
    • list_kernels(events): List all kernels with their launch counts
    • find_launch_index_by_kernel(events, kernel_name, launch_id): Find 0-based line index for a kernel's N-th launch
  • tests/test_tritonparse.py: Added 6 unit tests in TestTritonparseCPU:

    • test_list_kernels_empty(): Empty events list
    • test_list_kernels_single(): Single kernel with multiple launches
    • test_list_kernels_multiple(): Multiple different kernels
    • test_find_launch_index_valid(): Valid kernel name and launch_id
    • test_find_launch_index_kernel_not_found(): Raises ValueError when kernel not found
    • test_find_launch_index_out_of_range(): Raises ValueError with valid range hint

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 (empty list, non-existent kernel, out-of-range launch_id).

Notes

  • This PR does NOT create CLI. It's purely internal infrastructure.
  • All indices are 0-based for consistency with Python conventions.
  • Kernel name matching is case-sensitive (exact match only).

- 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).
@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 2, 2025
- 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.
@FindHao FindHao marked this pull request as ready for review December 2, 2025 17:07
@meta-codesync
Copy link

meta-codesync bot commented Dec 2, 2025

@FindHao has imported this pull request. If you are a Meta employee, you can view this in D88171102.

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