Skip to content

refactor(rocr): abstract thunk loader platform-specific code - #7125

Merged
amd-hsivasun merged 6 commits into
developfrom
users/sdashmiz/abstract-thunk-loader
Sep 30, 2026
Merged

amd-hsivasun merged 6 commits into
developfrom
users/sdashmiz/abstract-thunk-loader

Conversation

@shadidashmiz

@shadidashmiz shadidashmiz commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor
  • AIRUNTIME-2002

  • remove if defs

  • Abstract platform specific functions

Motivation

Remove if defs from the body of code

Technical Details

Separate Linux and Win specific functions so the thunk loader is opaque

JIRA ID: AIRUNTIME-2002

Test Plan

Hip Rocr tests

Test Result

PSDB

Submission Checklist

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.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@dayatsin-amd
dayatsin-amd self-requested a review June 12, 2026 01:46

@dayatsin-amd dayatsin-amd 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.

Please change licence for header to MIT.

/*

  • Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
  • SPDX-License-Identifier: MIT
    */

@shadidashmiz
shadidashmiz force-pushed the users/sdashmiz/abstract-thunk-loader branch 2 times, most recently from bb96266 to 17c5cb3 Compare June 12, 2026 14:44
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

This pull request has been inactive for 25 days and will be marked as stale.

If you would like to keep this PR open, please:

  • Add new commits
  • Add a comment explaining why it should remain open

This PR will be automatically closed in 5 days if no further activity occurs.

@github-actions github-actions Bot added the Stale PR has no activity for 25+ days label Jul 8, 2026

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

thunk_loader.cpp, thunk_loader_linux.cpp, thunk_loader_win.cpp, and thunk_loader_platform.h look correct — behavior for all four call sites is preserved: DTIF detection, DXG detection (Linux /dev/dxg + flag, Windows unconditional), dynamic API loading, and static API binding.

@shadidashmiz
shadidashmiz force-pushed the users/sdashmiz/abstract-thunk-loader branch from 17c5cb3 to 5d0d48e Compare July 8, 2026 14:26
@therock-pr-bot

therock-pr-bot Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

✅ All Policy Checks Passed

Check Status Details
📝 PR Description ✅ Pass —
⛔ Forbidden Files ✅ Pass —
🧪 Unit Test ⚠️ Warning 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/rocr-runtime/runtime/hsa-runtime/core/driver/kfd/amd_kfd_driver.cpp, projects/rocr-runtime/runtime/hsa-runtime/core/inc/thunk_loader.h, projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_memory_region.cpp, projects/rocr-runtime/runtime/hsa-runtime/core/runtime/amd_topology.cpp, projects/rocr-runtime/runtime/hsa-runtime/core/runtime/runtime.cpp (+4 more); no test file found
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —

🎉 All policy checks passed!

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

🙋 Wish to Override Policy?

@therock-pr-bot

therock-pr-bot Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

🚫 Please fix the failed policies before requesting reviews.

The following policy checks failed:

  • ❌ PR Description

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

@shadidashmiz
shadidashmiz force-pushed the users/sdashmiz/abstract-thunk-loader branch 2 times, most recently from 2022324 to 5236ef0 Compare July 8, 2026 18:35
@shadidashmiz shadidashmiz changed the title AIRUNTIME-2002 - Abstract thrunk loader ROCR Abstract thrunk loader by refactoring Jul 8, 2026
@shadidashmiz shadidashmiz changed the title ROCR Abstract thrunk loader by refactoring refactor(rocr): abstract thunk loader platform-specific code Jul 9, 2026
@github-actions github-actions Bot removed the Stale PR has no activity for 25+ days label Jul 10, 2026
@shadidashmiz
shadidashmiz force-pushed the users/sdashmiz/abstract-thunk-loader branch from 57403d8 to 39de11d Compare July 13, 2026 14:59
@shadidashmiz

Copy link
Copy Markdown
Contributor Author

@cfreeamd can you please review this change as well thanks

@shadidashmiz

Copy link
Copy Markdown
Contributor Author

@cfreeamd can you please review this change

@shadidashmiz

Copy link
Copy Markdown
Contributor Author

@cfreeamd can you please review this change

Please change licence for header to MIT.

/*

  • Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
  • SPDX-License-Identifier: MIT
    */

it is done

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

🤖 AI-assisted pre-review (for @cfreeamd) — follow-up after author update

Prior items resolved: license headers now use SPDX-License-Identifier: MIT (addresses the earlier CHANGES_REQUESTED), and the earlier question about DetectDxgDriver() on Windows was clarified as intentional. The refactor has since grown to also collapse is_win_dxg_/is_wsl_dxg_ into a single is_dxg_; left two follow-up notes on the resulting behavior change.

Runtime::MappedHandleAllowedAgent::~MappedHandleAllowedAgent() {
if (targetAgent->device_type() == core::Agent::DeviceType::kAmdCpuDevice) {
if (core::Runtime::runtime_singleton_->thunkLoader()->IsWslDxg()) assert(!"Unimplemented");
if (core::Runtime::runtime_singleton_->thunkLoader()->IsDXG()) assert(!"Unimplemented");

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.

🤖 AI-assisted pre-review (for @cfreeamd)

[Question] This PR now collapses is_win_dxg_/is_wsl_dxg_ into a single is_dxg_ and replaces IsWinDxg()/IsWslDxg() with IsDXG(). That changes behavior at a few call sites vs. the original pure-refactor:

  • Here (and the other MappedHandleAllowedAgent guards) the predicate was IsWslDxg(), which was false on Windows-native DXG. It's now IsDXG(), so Windows-native DXG also takes the Unimplemented/return-error/skip path.
  • In amd_kfd_driver.cpp / amd_memory_region.cpp the predicate was IsWinDxg(), which was false under WSL2; it's now IsDXG(), so WSL2 now skips pinning and the per-region cap like Windows.

Both look reasonable (both paths are DXG/WDDM), but could you confirm the win-dxg/wsl-dxg merge is intentional and that no remaining caller needs to distinguish the two?

// is best-effort; WDDM will demand-page on GPU access.
const bool is_windxg =
core::Runtime::runtime_singleton_->thunkLoader()->IsWinDxg();
core::Runtime::runtime_singleton_->thunkLoader()->IsDXG();

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.

🤖 AI-assisted pre-review (for @cfreeamd)

[Nit] The local is still named is_windxg but is now assigned from IsDXG(), which is also true under WSL2 (/dev/dxg). Consider renaming to is_dxg here (and in amd_memory_region.cpp) so the name matches the broadened predicate.

@amd-justchen

Copy link
Copy Markdown
Contributor

My agent found this as a potential build failure:

TheRock CI gate fails on a genuine compile error caused by this PR's thunk-loader refactor:
amd_topology.cpp:320: error: 'const class rocr::core::ThunkLoader' has no member named 'IsWslDxg'
The refactor removed/renamed IsWslDxg but left the call site in amd_topology.cpp (a file the PR does not touch). All four Build Packages jobs fail in the compile step across every arch (gfx94X, gfx950, MI455, Windows).

Does this look related? @shadidashmiz

@shadidashmiz
shadidashmiz force-pushed the users/sdashmiz/abstract-thunk-loader branch from 1c71b88 to e45639c Compare September 15, 2026 19:21
- remove if defs

- Abstract platform specific functions

Signed-off-by: sdashmiz <shadi.dashmiz@amd.com>
@shadidashmiz
shadidashmiz force-pushed the users/sdashmiz/abstract-thunk-loader branch from e45639c to 0ebf3a1 Compare September 15, 2026 19:23
shadidashmiz and others added 5 commits September 25, 2026 12:39
The refactoring unified is_win_dxg_ and is_wsl_dxg_ into a single
is_dxg_ bool but amd_topology.cpp still needs to distinguish WSL DXG
from native Windows DXG for tool registration. Restore IsWslDxg() using
a compile-time #ifdef: on Linux is_dxg_ implies WSL, on Windows it does
not.

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
@amd-hsivasun
amd-hsivasun merged commit 058d216 into develop Sep 30, 2026
210 of 213 checks passed
@amd-hsivasun
amd-hsivasun deleted the users/sdashmiz/abstract-thunk-loader branch September 30, 2026 18:37
ihhethan added a commit that referenced this pull request Oct 1, 2026
Resolve thunk_loader.h against develop's thunk-loader platform split
(#7125) and the GL2 residency entry point (#10183): keep this branch's
nullptr-initialized table and add hsaKmtSetPersistingCacheSize to it.

Bind hsaKmtSetPersistingCacheSize as an optional entry point, like
hsaKmtSetSigbusDelay. librocdxg does not export it, so as a required
export it would make LoadThunkApiTable() fail and hsa_init() refuse to
start under WSL. The static path defaults it to the NOT_SUPPORTED stub
and the Linux BindPlatformStaticApis() binds the libhsakmt
implementation, which was otherwise left unbound.
@systems-assistant

Copy link
Copy Markdown
Contributor

TheRock Submodule Bump Activity

Newest first

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.

6 participants