Skip to content

Conversation

@mark14wu
Copy link
Collaborator

Add functionality to track for-loop iteration counts in the Profiler client to help identify loops that can potentially be unrolled.

Changes:

  • Add disable_for_loop_unroll_check parameter to Profiler.init
  • Implement register_for_loop_callback to track loop line numbers and step counts
  • Deduplicate loop tracking by line number (same loop executed in different blocks)
  • Display loop statistics in finalize() method
  • Add test_for_loop_statistics test to verify tracking functionality

Add functionality to track for-loop iteration counts in the Profiler client
to help identify loops that can potentially be unrolled.

Changes:
- Add disable_for_loop_unroll_check parameter to Profiler.__init__
- Implement register_for_loop_callback to track loop line numbers and step counts
- Deduplicate loop tracking by line number (same loop executed in different blocks)
- Display loop statistics in finalize() method
- Add test_for_loop_statistics test to verify tracking functionality
@mark14wu mark14wu marked this pull request as ready for review October 18, 2025 04:21
result = result + 1.0

# Second for-loop: 5 iterations
for j in range(5):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about tl.range and tl.static_range? If already static we don't need to unroll the loop

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Now the loop callback returns range type.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason the current for-loop callbacks are not managed by ClientManager but by class _CombinedLoopHooks. I will move those code back to ClientManager in the future refactoring.

- Extended for_loop_test_kernel to include tl.range and tl.static_range loops
- Updated test_for_loop_statistics to verify different range types (python_range, tl_range, tl_static_range)
- Modified test assertions to match new loop_info structure with range_type and length attributes
- Added validation for 4 different loop types with their expected iteration counts
@mark14wu
Copy link
Collaborator Author

mark14wu commented Nov 3, 2025

@Jokeren Please review the latest code.

@mark14wu mark14wu merged commit bd4447b into main Nov 4, 2025
1 check passed
@mark14wu mark14wu deleted the profiler/unroll_for_loop branch November 4, 2025 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants