Skip to content

fix(ck-tile): use __builtin_memcpy for buffer resource casts in device code - #13393

Merged
illsilin merged 2 commits into
ROCm:developfrom
0xDELUXA:ck-tile-builtin-memcpy-rsrc
Oct 10, 2026
Merged

illsilin merged 2 commits into
ROCm:developfrom
0xDELUXA:ck-tile-builtin-memcpy-rsrc

Conversation

@0xDELUXA

@0xDELUXA 0xDELUXA commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

cast_to_amdgpu_buffer_rsrc_t copies the buffer descriptor with std::memcpy inside a CK_TILE_DEVICE function. With the MSVC C runtime on Windows, memcpy has no device overload, so every ck_tile kernel that goes through the buffer addressing path fails to compile with reference to __host__ function 'memcpy' in __device__ function. This blocks CK tile kernels in downstream projects such as aiter on Windows.

Fixes #10079

Technical Details

Both definitions, in amd_buffer_addressing.hpp and amd_buffer_addressing_builtins.hpp, now use __builtin_memcpy, as amd_wave_read_first_lane.hpp already does. On Linux it lowers to the same intrinsic as before. This is the same change as #10067, which was closed as stale, without the added test scaffolding.

Test Plan

On Windows with gfx1200 and the ROCm 10.2 nightly, built a minimal HIP program that makes a wave buffer resource, casts it with cast_to_amdgpu_buffer_rsrc_t, and does one in-range and one out-of-range raw_buffer_load. Also rebuilt the aiter CK tile layernorm2d instances against the patched headers.

Test Result

Before the change the program and the layernorm instances fail to compile with the error above. After it, both build, the in-range load returns the expected value and the out-of-range load returns 0, so the descriptor's base address and num_records survive the copy.

Submission Checklist

@therock-pr-bot

therock-pr-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

✅ All Checks Passed — Ready for Review

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/composablekernel/include/ck_tile/core/arch/amd_buffer_addressing.hpp, projects/composablekernel/include/ck_tile/core/arch/amd_buffer_addressing_builtins.hpp; no test file found
🔎 pre-commit ✅ Pass —
🚫 Draft PR 🔜 To Be Enabled —
🚩 Feature Flag 🔜 To Be Enabled —
📊 Code Coverage 🔜 To Be Enabled —
🤖 therock-pr-bot ✅ Pass —

🎉 All checks passed! This PR is ready for review.

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

🙋 Wish to Override Policy?

@assistant-librarian assistant-librarian Bot added the external contribution Code contribution from users community.. label Oct 9, 2026
@therock-pr-bot

therock-pr-bot Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

🎉 All checks passed! This PR is ready for review.

@illsilin
illsilin enabled auto-merge (squash) October 10, 2026 01:46
@illsilin
illsilin merged commit 6dbe3aa into ROCm:develop Oct 10, 2026
101 checks passed
assistant-librarian Bot pushed a commit to ROCm/composable_kernel that referenced this pull request Oct 10, 2026
fix(ck-tile): use __builtin_memcpy for buffer resource casts
 in device code (#13393)

## Motivation

`cast_to_amdgpu_buffer_rsrc_t` copies the buffer descriptor with
`std::memcpy` inside a `CK_TILE_DEVICE` function. With the MSVC C
runtime on Windows, `memcpy` has no device overload, so every ck_tile
kernel that goes through the buffer addressing path fails to compile
with `reference to __host__ function 'memcpy' in __device__ function`.
This blocks CK tile kernels in downstream projects such as aiter on
Windows.

Fixes #10079

## Technical Details

Both definitions, in `amd_buffer_addressing.hpp` and
`amd_buffer_addressing_builtins.hpp`, now use `__builtin_memcpy`, as
`amd_wave_read_first_lane.hpp` already does. On Linux it lowers to the
same intrinsic as before. This is the same change as #10067, which was
closed as stale, without the added test scaffolding.

## Test Plan

On Windows with gfx1200 and the ROCm 10.2 nightly, built a minimal HIP
program that makes a wave buffer resource, casts it with
`cast_to_amdgpu_buffer_rsrc_t`, and does one in-range and one
out-of-range `raw_buffer_load`. Also rebuilt the aiter CK tile
layernorm2d instances against the patched headers.

## Test Result

Before the change the program and the layernorm instances fail to
compile with the error above. After it, both build, the in-range load
returns the expected value and the out-of-range load returns 0, so the
descriptor's base address and `num_records` survive the copy.

## Submission Checklist

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

Co-authored-by: Illia Silin <98187287+illsilin@users.noreply.github.com>
@assistant-librarian

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

Labels

external contribution Code contribution from users community.. project: composablekernel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ck_tile] std::memcpy in device code breaks all ck_tile builds with the MSVC STL

2 participants