Skip to content

Run staging copies on the per-thread stream - #234

Merged
derobins merged 2 commits into
developfrom
derobins/per_stream
Oct 15, 2026
Merged

derobins merged 2 commits into
developfrom
derobins/per_stream

Conversation

@derobins

Copy link
Copy Markdown
Collaborator

The staging copies for buffers that are staged through host memory (hipObjGet(), hipObjPut(), and hipObjBufSync()) now use hipStreamPerThread instead of the null stream, for both the copy and the event that tracks it. Work on the null stream waits for every other blocking stream on the device, so copies from different threads waited for each other. As a result, the copies no longer wait for GPU work that the application queued on streams it created.

The documentation of hipObjGet(), hipObjPut(), and hipObjBufSync() in hipobj.h now says what GPU work has to finish before each call. Only comments change in the header.

FakeHip records the streams that memcpyAsync() and eventRecord() are given, and a new staging test checks that both get hipStreamPerThread.

AGENTS.md now says that the API in the public header needs permission to change, but its documentation comments don't. It also says which header changes need a changelog entry.

The staging copies for buffers that are staged through host memory
(hipObjGet(), hipObjPut(), and hipObjBufSync()) now use
hipStreamPerThread instead of the null stream, for both the copy and
the event that tracks it. Work on the null stream waits for every other
blocking stream on the device, so copies from different threads waited
for each other. As a result, the copies no longer wait for GPU work
that the application queued on streams it created.

The documentation of hipObjGet(), hipObjPut(), and hipObjBufSync() in
hipobj.h now says what GPU work has to finish before each call. Only
comments change in the header.

FakeHip records the streams that memcpyAsync() and eventRecord() are
given, and a new staging test checks that both get hipStreamPerThread.

AGENTS.md now says that the API in the public header needs permission
to change, but its documentation comments don't. It also says which
header changes need a changelog entry.

Co-Authored-By: Claude <noreply@anthropic.com>

Copilot AI left a comment

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.

🟡 Changes recommended

The completion guarantee must exclude timeout returns that can leave a copy accessing the buffer.

1 open finding
What changed in this PR

Moves host-staging copies to the calling thread’s stream, avoiding null-stream synchronization with unrelated GPU work.

Changes:

  • Uses hipStreamPerThread for staging copies and completion events.
  • Records and tests stream selection.
  • Documents caller synchronization requirements and clarifies header-edit guidance.
File Description
test/​unit/​test-staging.cpp Tests copy and event stream selection.
test/​unit/​fake-device.h Adds recorded stream fields.
test/​unit/​fake-device.cpp Captures copy and event streams.
src/​hipobj.cpp Switches staging operations to the per-thread stream.
include/​hipobj.h Documents GPU synchronization requirements; declarations unchanged.
CHANGELOG.md Records the staging behavior change.
AGENTS.md Clarifies API and documentation change policies.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread include/hipobj.h Outdated
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor
Security scan found no critical or high findings on lines changed by this pull request

View the security scan run for complete reports.

“New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta.

When a staging copy doesn't finish within HIPOBJ_STAGE_TIMEOUT_MS,
hipObjGet(), hipObjPut(), and hipObjBufSync() return
hipObjInternalError and leave the copy running. The documentation of
hipObjBufSync() said the copy had always finished when the call
returned. It now says that's only true on success, and all three
functions say that a timed-out copy can still write the buffer (GET),
read it (PUT), or do either (hipObjBufSync()) after the call returns.

Co-Authored-By: Claude <noreply@anthropic.com>

Copilot AI left a comment

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.

🟢 Approval recommended

The focused implementation, regression coverage, and documentation are consistent, with no unresolved findings.

0 open findings

1 resolved since last review

🧠 Review effort: Balanced

@derobins
derobins merged commit d47a8f7 into develop Oct 15, 2026
33 checks passed
@derobins
derobins deleted the derobins/per_stream branch October 15, 2026 21:01
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.

2 participants