Skip to content

fix(dynamic_batching): potential hang due to duration calculation - #2976

Open
simshi wants to merge 1 commit into
NVIDIA:mainfrom
simshi:main
Open

simshi wants to merge 1 commit into
NVIDIA:mainfrom
simshi:main

Conversation

@simshi

@simshi simshi commented Nov 1, 2026

Copy link
Copy Markdown

Problem

gpu_time_keeper tracked the remaining deadline inint32_t microseconds. Between twohas_time() checks the elapsed time was computed as:

static_cast<int32_t>((timestamp_ns_` - prev_timestamp) / 1000ull);

When the interval between two checks is less than 1 µs, the/ 1000 integer division rounds the delta down to0 , solocal_remaining_time_us_ never decreases. If the device keeps polling faster than once per microsecond, the deadline is never reached and thegather_inputs kernel can spin (hang) indefinitely.

Fix

Track remaining time in nanoseconds asint64_t local_remaining_time_ns_ .

@copy-pr-bot

copy-pr-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Nov 1, 2026

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: NVIDIA/cuvs
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 44df703
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: e62aa40d-40c7-4060-9203-6c7daaf6183b
Commits

Reviewing files that changed from the base of the PR and between 44df703 and eb44963.

Files selected for processing: 1
  • cpp/src/neighbors/detail/dynamic_batching.cuh

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Improved timeout handling for GPU batching by tracking remaining time with finer precision. This helps batches respond more accurately to remaining time limits, including when combining locally tracked deadlines with time limits supplied by the CPU.

The dynamic batching GPU time keeper now tracks local remaining time in signed 64-bit nanoseconds. It subtracts elapsed nanoseconds and converts the CPU-provided remaining time from microseconds before comparing deadlines.

Changes: Dynamic batching timeout tracking

Layer / File(s) Summary
Track and check remaining time
cpp/src/neighbors/detail/dynamic_batching.cuh
The local remaining-time counter changes from signed 32-bit microseconds to signed 64-bit nanoseconds. Elapsed time is subtracted in nanoseconds, and CPU-provided remaining time is converted to nanoseconds before the minimum is taken. Timeout checks use the nanosecond counter.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Possibly related issues

Suggested labels: bug, C++, non-breaking

Suggested reviewers: achirkin

Merge Risk: Minimal · up to eb449

No actionable merge-blocking risk was identified in the reviewed change.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the fix (a potential hang) and the component it touches (dynamic_batching). It also names the cause (a duration calculation). The raw summary confirms the change converts the remaining…
Description check Passed The description states the problem: gpu_time_keeper stored remaining time in int32_t microseconds. Integer division rounded sub-microsecond deltas to zero, so the deadline never decreased and gather_i…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the fix (a potential hang) and the component it touches (dynamic_batching). It also names the cause (a duration calculation). The raw summary confirms the change converts the remaining-time tracking in gpu_time_keeper from 32-bit microseconds to 64-bit nanoseconds, which addresses that calculation. The title is specific and matches the main change.

Full details: Description check

Explanation

The description states the problem: gpu_time_keeper stored remaining time in int32_t microseconds. Integer division rounded sub-microsecond deltas to zero, so the deadline never decreased and gather_inputs could spin. It also states the fix: track remaining time as int64_t local_remaining_time_ns_. This matches the file-level summary and the PR objectives.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 0 files. (1 skipped: 1 unsupported.)

Finishing Touches
Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant