Skip to content

Add new hostcall implementation#8409

Open
b-sumner wants to merge 7 commits into
developfrom
users/b-sumner/add-new-hostcall-impl
Open

Add new hostcall implementation#8409
b-sumner wants to merge 7 commits into
developfrom
users/b-sumner/add-new-hostcall-impl

Conversation

@b-sumner

Copy link
Copy Markdown
Contributor

Motivation

This adds a new hostcall implementation, guarded by USE_NEW_HOSTCALL_IMPL

Technical Details

Adds a new implementation based on the approach developed by Joseph Huber.

JIRA ID

N/A

Test Plan

Run any programs using hostcall and verify correct execution. Run benchmarks to verify improved performance

Test Result

All runs successful.

Submission Checklist

Copilot AI review requested due to automatic review settings July 10, 2026 16:21
@b-sumner
b-sumner requested review from a team as code owners July 10, 2026 16:21
@therock-pr-bot

Copy link
Copy Markdown

❌ PR Check — Action Required

Check Status Details
🌿 Branch Name ✅ Pass
📝 PR Title/Description ❌ Fail Error: Title does not follow Conventional Commits style.
Expected: start with a valid type (feat, fix, docs, …).
Desired format: type(optional-scope): short description
───
Error: PR description must reference a JIRA ID, ISSUE ID, or a GitHub closing keyword.
Expected: include a JIRA ID / ISSUE ID line (separator : or -, or omitted; value may be a JIRA key, a number with/without #, or a link), OR a closing keyword + issue reference. Accepted examples:
JIRA ID : TESTAUTO-6039
JIRA ID - #330
JIRA ID #330
ISSUE ID : TESTUTO-3334
ISSUE ID #3334
ISSUE ID - TESTAUTO-3433
ISSUE ID : https://github.com/<org_name>/<repo_name>/issues/1234
Closes #10
Fixes octo-org/octo-repo#100
Resolves: #123
#123
https://github.com/<org_name>/<repo_name>/issues/123
Current: no valid JIRA/ISSUE/closing-keyword reference found
Forbidden Files ✅ Pass
🧪 Unit Test ❌ Fail Error: Source/code files changed without an accompanying unit test.
Expected: add at least one test file named like test_<name>.py / test_<name>.cpp (or <name>_test.*).
Current: code file(s) changed: projects/clr/rocclr/device/devhostcall.cpp, projects/clr/rocclr/device/devhostcall.hpp, projects/clr/rocclr/device/pal/palvirtual.cpp, projects/clr/rocclr/device/rocm/rocvirtual.cpp; no test file found
🔎 pre-commit ⏳ Pending ⏳ Still running…
🚫 Draft PR 🔜 To Be Enabled
🚩 Feature Flag 🔜 To Be Enabled
📊 Code Coverage 🔜 To Be Enabled

⚠️ 2 policy check(s) failed. Please address the issues above before this PR can be Reviewed.

🚫 Please fix the failed policies

  • ❌ PR Title/Description
  • ❌ Unit Test

The Not ready to Review label was added to this PR. Once all policies pass, the label is removed automatically.

📖 Need help? See the Policy FAQ for details on every check and how to fix failures.

@therock-pr-bot

Copy link
Copy Markdown

🚫 Please fix the failed policies before requesting reviews.

The following policy checks failed:

  • ❌ PR Title/Description
  • ❌ Unit Test

The Not ready to Review label has been added to this PR.
Once all policies pass, the label will be removed automatically.

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.

Pull request overview

Adds an alternative hostcall buffer implementation (phase/occupancy-based), gated behind USE_NEW_HOSTCALL_IMPL, and wires it into both ROCm and PAL virtual GPU hostcall buffer setup along with build-system toggles.

Changes:

  • Introduces a new hostcall buffer layout and processing path based on per-packet device/host phase arrays plus a device-local “occupied” bitfield.
  • Updates ROCm and PAL VirtualGPU::getOrCreateHostcallBuffer() to allocate/initialize the occupied bitfield and call the new enableHostcalls overload when enabled.
  • Adds a CMake option and compile definition plumbing to turn the new implementation on/off at build time.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
projects/clr/rocclr/device/rocm/rocvirtual.cpp Allocates and zero-initializes an occupied bitfield buffer and uses the new enableHostcalls overload under USE_NEW_HOSTCALL_IMPL.
projects/clr/rocclr/device/pal/palvirtual.cpp Same hostcall occupied-bitfield setup and new enableHostcalls overload for PAL path.
projects/clr/rocclr/device/devhostcall.hpp Adds new enableHostcalls overload and introduces the new hostcall buffer/header layout under USE_NEW_HOSTCALL_IMPL.
projects/clr/rocclr/device/devhostcall.cpp Implements the new hostcall buffer sizing/initialization and a new listener consumption loop under USE_NEW_HOSTCALL_IMPL.
projects/clr/rocclr/cmake/ROCclr.cmake Propagates USE_NEW_HOSTCALL_IMPL as a compile definition to rocclr when enabled.
projects/clr/CMakeLists.txt Adds the USE_NEW_HOSTCALL_IMPL CMake option.

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

Comment thread projects/clr/rocclr/device/devhostcall.hpp
Comment thread projects/clr/rocclr/device/devhostcall.cpp
@b-sumner

Copy link
Copy Markdown
Contributor Author

@chrispaquot would you mind checking this? It is the "improve hostcall performance patch" but now as an added implementation so it can be toggled on at ROCm build time.

b-sumner added a commit to ROCm/TheRock that referenced this pull request Jul 14, 2026
## Motivation

Temporary switch to enable the new hostcall version before fully
commiting it

## Technical Details

Adds a new THEROCK cmake variable and propagates it to the submodules
using it.

## Test Plan

Build with variable set to OFF and ON

## Test Result

Verified correct build operation

## Submission Checklist

- [x ] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.

Pre-req: ROCm/llvm-project#3311 and
ROCm/rocm-systems#8409
@b-sumner

Copy link
Copy Markdown
Contributor Author

TheRock and device libs patches have landed. Could I get a review for this one too?

@gandryey gandryey 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.

Findings

Finding 1 — fillBuffer synchrony unverified (palvirtual.cpp:4027, rocvirtual.cpp:5288)

blitMgr().fillBuffer() to zero occupiedBuf may be GPU-async. If the zero-fill hasn't completed before enableHostcalls returns, the first kernel sees a garbage occupied bitfield — silent corruption. Please add a comment confirming this is synchronous, or add an explicit flush/wait.

Finding 2 — Drain scan fires unconditionally under zero load (devhostcall.cpp:440–448)

After the spin loop, resetScanLimit + full processPackets under listenerLock always runs — even when the spin found no work at all. In the idle case this fires a full num_packets-wide scan under lock every 1 ms for nothing. Add a was_busy flag; only drain when the spin actually found work.

Finding 3 — Dead nullptr check after new (devhostcall.cpp:617)

hostcallListener = new HostcallListener();
if (!hostcallListener) { ... } // unreachable: plain new throws, never returns null

Remove the check or switch to new (std::nothrow) if a non-throwing path is intended.

Finding 4 — Old PAL path leaks hostcallBuffer_ on enableHostcalls failure (palvirtual.cpp)

The new path correctly calls svmFree(hostcallBuffer_) on failure. The old #else path does not. Pre-existing bug, but now clearly visible by comparison — worth fixing here.

Finding 5 — Device-side ordering contract undocumented (devhostcall.cpp — processPackets)

The phase protocol relies on the device doing a store-release to device_phase_[i] after writing payload/header. The struct comment says "Shared prefix: must match device-side layout" but doesn't name the device-side header or assert the offsets. Please add a comment naming the contract and where the device-side definition lives.

Finding 6 — Missing EOF newline (devhostcall.hpp:239)

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.

4 participants