Skip to content

[Kineto] Add lookback window and sampling interval as config options - #1561

Merged
ryanzhang22 merged 10 commits into
pytorch:mainfrom
ryanzhang22:pm-sampling-config
Sep 23, 2026
Merged

ryanzhang22 merged 10 commits into
pytorch:mainfrom
ryanzhang22:pm-sampling-config

Conversation

@ryanzhang22

@ryanzhang22 ryanzhang22 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

These were introduced as inputs in pytorch/pytorch#196065, but are not yet being parsed by Kineto (only cupti monitor/cuspy).

Lookback window is a proxy for buffer capacity, which we previously fixed as maxSamplesForDecode but is now calculated as max(1, lookbackWindow / samplingInterval).

@meta-cla meta-cla Bot added the cla signed label Sep 9, 2026
@ryanzhang22
ryanzhang22 marked this pull request as ready for review September 9, 2026 18:04
Comment thread libkineto/src/Config.cpp Outdated
std::optional<nanoseconds> parseMilliseconds(std::string_view text) noexcept {
double count = 0;
const auto [parseEnd, error] =
std::from_chars(text.begin(), text.end(), count);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

from_chars needs raw pointers. string_view::begin()/end() are not raw pointers on MSVC, so this breaks the Windows build. Please use text.data() and text.data() + text.size().

Comment thread libkineto/src/CuptiPMSamplingApi.cpp Outdated
counterDataSize.pMetricNames = metricNamePtrs_.data();
counterDataSize.numMetrics = metricNamePtrs_.size();
counterDataSize.maxSamples = kMaxSamplesPerDecode;
counterDataSize.maxSamples = static_cast<uint32_t>(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maxSamples is a uint32_t, but this calculation can be much larger. A large lookback or tiny interval can wrap, possibly to zero, or request a huge buffer. Can we validate it before casting?

Comment thread libkineto/src/CuptiPMSamplingApi.cpp Outdated
counterDataSize.numMetrics = metricNamePtrs_.size();
counterDataSize.maxSamples = kMaxSamplesPerDecode;
counterDataSize.maxSamples = static_cast<uint32_t>(
std::max<int64_t>(1, config_.lookbackWindow / config_.samplingInterval));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

GA100 uses the fixed 1M-cycle interval, but this sizes the buffer using the requested nanosecond interval, which GA100 ignores. This makes the lookback inaccurate, and zero causes division by zero. Can we use the effective GA100 cadence or reject this setting?

int32_t performanceMetricsDeviceId_{-1};
std::chrono::nanoseconds performanceMetricsSamplingInterval_{
std::chrono::milliseconds{1}};
std::chrono::nanoseconds performanceMetricsLookbackWindow_{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: With the 1ms interval above, this 10-second default increases capacity from 1,024 to 10,000 samples. Do we have memory and decode-cost measurements for this increase?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks, updated. This was being used as the default for cuspy but we shouldn't need such a big buffer here.

@ryanzhang22
ryanzhang22 merged commit fcda441 into pytorch:main Sep 23, 2026
10 checks passed
pytorchmergebot pushed a commit to pytorch/pytorch that referenced this pull request Sep 25, 2026
Last one!

Includes the following commits:

- [Kineto] Exclude test on windows (pytorch/kineto#1575) 638a3ef
- Opt-in per-thread activity buffers on the ROCm HIP path (pytorch/kineto#1573) 5dc9333
- Parse DISABLE_CUPTI_LAZY_REINIT by value (pytorch/kineto#1568) f140a13
- [Kineto] Add lookback window and sampling interval as config options (pytorch/kineto#1561) fcda441
- [xpupti] Don't emit ac2g flow endpoints on XPU_DRIVER records (pytorch/kineto#1549) f0df071
Pull Request resolved: #198560
Approved by: https://github.com/sanrise

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants