Skip to content

Conversation

@Vinkle-hzt
Copy link
Collaborator

For asynchronous H2D operations, we should hold the host memory to prevent modifications between kernel launch and execution.

Copilot AI review requested due to automatic review settings November 28, 2025 03:48
@Vinkle-hzt Vinkle-hzt requested a review from LLLLKKKK as a code owner November 28, 2025 03:48
Copilot finished reviewing on behalf of Vinkle-hzt November 28, 2025 04:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a critical memory safety issue for asynchronous Host-to-Device (H2D) operations in GPU kernels. The changes introduce a ModelBufferHolder mechanism to ensure host memory buffers remain valid throughout async copy operations, preventing potential data corruption or use-after-free bugs.

Key changes:

  • Introduces ModelBufferHolder struct to hold references to host buffers and tensors until async operations complete
  • Replaces temporary std::vector + vector2Buffer() pattern with explicitly allocated host buffers
  • Adds releaseBuffers() calls at strategic points to manage buffer lifecycle
  • Adds synchronization check in model initialization for residual scale buffer

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
rtp_llm/cpp/models/GptModel.h Defines ModelBufferHolder struct and adds buffer management methods (releaseBuffers(), holdInputsHostBuffers())
rtp_llm/cpp/models/GptModel.cc Refactors host buffer allocation to use explicit buffers instead of temporary vectors; implements buffer holding throughout forward pass; adds sync point in constructor
rtp_llm/cpp/normal_engine/NormalExecutor.cc Adds releaseBuffers() calls before forward pass and after processing; adds sync point for non-rank-0 paths
rtp_llm/cpp/embedding_engine/EmbeddingExecutor.cc Adds releaseBuffers() calls before and after forward pass

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

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.

1 participant