-
Notifications
You must be signed in to change notification settings - Fork 13.5k
sycl: add ROLL operation support #16665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NeoZhangJianyu
merged 6 commits into
ggml-org:master
from
tamarPal:feature/sycl-roll-sync
Oct 27, 2025
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4b76ed1
sycl: add ROLL operation support
c44a4df
Merge remote-tracking branch 'upstream/master' into feature/sycl-roll…
dea85e1
fix: remove trailing whitespace from roll.cpp
386db09
ci: retrigger
710405b
sycl: remove wait() calls from ROLL operation
b979308
fix: editorconfig — LF endings + final newline for roll.hpp
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #include "roll.hpp" | ||
| #include "common.hpp" | ||
|
|
||
| using namespace sycl; | ||
|
|
||
| static void kernel_roll_multi_axis(queue &q, const ggml_tensor *src, ggml_tensor *dst, | ||
| int shift0, int shift1, int shift2, int shift3) { | ||
| if (!src || !dst) throw std::runtime_error("null tensor"); | ||
| if (src->type != GGML_TYPE_F32 || dst->type != GGML_TYPE_F32) | ||
| throw std::runtime_error("only F32 supported in SYCL roll"); | ||
|
|
||
| const int64_t ne0 = dst->ne[0]; | ||
| const int64_t ne1 = dst->ne[1]; | ||
| const int64_t ne2 = dst->ne[2]; | ||
| const int64_t ne3 = dst->ne[3]; | ||
|
|
||
| if (ne0 != src->ne[0] || ne1 != src->ne[1] || ne2 != src->ne[2] || ne3 != src->ne[3]) | ||
| throw std::runtime_error("src/dst shape mismatch"); | ||
|
|
||
| // Normalize shifts to be within bounds | ||
| const int64_t sh0 = ne0 > 0 ? ((int64_t)shift0 % ne0 + ne0) % ne0 : 0; | ||
| const int64_t sh1 = ne1 > 0 ? ((int64_t)shift1 % ne1 + ne1) % ne1 : 0; | ||
| const int64_t sh2 = ne2 > 0 ? ((int64_t)shift2 % ne2 + ne2) % ne2 : 0; | ||
| const int64_t sh3 = ne3 > 0 ? ((int64_t)shift3 % ne3 + ne3) % ne3 : 0; | ||
|
|
||
| const float *src_d = (const float*) src->data; | ||
| float *dst_d = (float*) dst->data; | ||
|
|
||
| if (!src_d || !dst_d) throw std::runtime_error("null data pointers"); | ||
|
|
||
| q.submit([&](handler &h) { | ||
| range<3> r((size_t)ne3, (size_t)ne2, (size_t)ne1); | ||
| h.parallel_for(r, [=](id<3> idx) { | ||
| const int64_t i3 = idx[0]; | ||
| const int64_t i2 = idx[1]; | ||
| const int64_t i1 = idx[2]; | ||
|
|
||
| for (int64_t i0 = 0; i0 < ne0; i0++) { | ||
| const int64_t idx_dst = i0 + i1 * ne0 + i2 * ne0 * ne1 + i3 * ne0 * ne1 * ne2; | ||
|
|
||
| // Apply shift to each dimension | ||
| const int64_t src_i0 = (i0 - sh0 + ne0) % ne0; | ||
| const int64_t src_i1 = (i1 - sh1 + ne1) % ne1; | ||
| const int64_t src_i2 = (i2 - sh2 + ne2) % ne2; | ||
| const int64_t src_i3 = (i3 - sh3 + ne3) % ne3; | ||
|
|
||
| const int64_t idx_src = src_i0 + src_i1 * ne0 + | ||
| src_i2 * ne0 * ne1 + src_i3 * ne0 * ne1 * ne2; | ||
|
|
||
| dst_d[idx_dst] = src_d[idx_src]; | ||
| } | ||
| }); | ||
| }).wait(); | ||
| } | ||
|
|
||
| void ggml_sycl_roll(ggml_backend_sycl_context & ctx, ggml_tensor *dst) { | ||
| GGML_ASSERT(dst->type == GGML_TYPE_F32); | ||
|
|
||
| const ggml_tensor *src = dst->src[0]; | ||
|
|
||
| const int32_t *params = (const int32_t *)dst->op_params; | ||
| const int shift0 = params[0]; | ||
| const int shift1 = params[1]; | ||
| const int shift2 = params[2]; | ||
| const int shift3 = params[3]; | ||
|
|
||
| // Check if all shifts are zero | ||
| if (shift0 == 0 && shift1 == 0 && shift2 == 0 && shift3 == 0) { | ||
| const size_t nb = ggml_nbytes(src); | ||
| queue *q = ctx.stream(); | ||
| SYCL_CHECK(CHECK_TRY_ERROR(q->memcpy(dst->data, src->data, nb).wait())); | ||
NeoZhangJianyu marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
|
|
||
| try { | ||
| queue *q = ctx.stream(); | ||
| kernel_roll_multi_axis(*q, src, dst, shift0, shift1, shift2, shift3); | ||
| } catch (const std::exception &e) { | ||
| std::fprintf(stderr, "[SYCL-ROLL] ERROR: %s\n", e.what()); | ||
| throw; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // | ||
| // MIT license | ||
| // Copyright (C) 2024 Intel Corporation | ||
| // SPDX-License-Identifier: MIT | ||
| // | ||
|
|
||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
|
|
||
| #ifndef GGML_SYCL_ROLL_HPP | ||
| #define GGML_SYCL_ROLL_HPP | ||
|
|
||
| #include "common.hpp" | ||
|
|
||
| void ggml_sycl_roll(ggml_backend_sycl_context & ctx, ggml_tensor *dst); | ||
|
|
||
| #endif // GGML_SYCL_ROLL_HPP |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.