-
Notifications
You must be signed in to change notification settings - Fork 13.8k
cuda: add SET operation support #16804
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
JohannesGaessler
merged 5 commits into
ggml-org:master
from
YaelGitAccount:feat/cuda-set-op
Oct 28, 2025
+57
−0
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4c8098c
feat(cuda): add GGML_OP_SET support
YaelGitAccount 955c06f
cuda(set): add I32 support; keep F32
YaelGitAccount 59fb14c
refactor(cuda): use ggml_cuda_cpy to unify SET operator logic and rem…
YaelGitAccount d25b5bc
Update ggml/src/ggml-cuda/ggml-cuda.cu
YaelGitAccount 15f7dc7
Update ggml/src/ggml-cuda/set.cu
YaelGitAccount 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include "set.cuh" | ||
| #include "cpy.cuh" | ||
|
|
||
| void ggml_cuda_op_set(ggml_backend_cuda_context & ctx, ggml_tensor * dst) { | ||
| const ggml_tensor * src0 = dst->src[0]; | ||
| const ggml_tensor * src1 = dst->src[1]; | ||
|
|
||
| GGML_ASSERT((src0->type == GGML_TYPE_F32 || src0->type == GGML_TYPE_I32)); | ||
| GGML_ASSERT(src1->type == src0->type); | ||
| GGML_ASSERT(dst ->type == src0->type); | ||
|
|
||
| GGML_ASSERT(ggml_is_contiguous(dst)); | ||
| GGML_ASSERT(ggml_is_contiguous(src0)); | ||
| GGML_ASSERT(ggml_is_contiguous(src1)); | ||
|
|
||
| const size_t nb1 = ((int32_t *) dst->op_params)[0]; | ||
| const size_t nb2 = ((int32_t *) dst->op_params)[1]; | ||
| const size_t nb3 = ((int32_t *) dst->op_params)[2]; | ||
| const size_t offset = ((int32_t *) dst->op_params)[3]; | ||
| const bool inplace= (bool) ((int32_t *) dst->op_params)[4]; | ||
|
|
||
| if (!inplace) { | ||
| ggml_cuda_cpy(ctx, src0, dst); | ||
| } | ||
|
|
||
| ggml_tensor dst_view = *dst; | ||
| dst_view.data = (void *)((char *)dst->data + offset); | ||
| dst_view.ne[0] = src1->ne[0]; | ||
| dst_view.ne[1] = src1->ne[1]; | ||
| dst_view.ne[2] = src1->ne[2]; | ||
| dst_view.ne[3] = src1->ne[3]; | ||
|
|
||
| dst_view.nb[0] = ggml_element_size(dst); | ||
| dst_view.nb[1] = nb1; | ||
| dst_view.nb[2] = nb2; | ||
| dst_view.nb[3] = nb3; | ||
|
|
||
| ggml_cuda_cpy(ctx, src1, &dst_view, true); | ||
| } | ||
YaelGitAccount marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
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,7 @@ | ||
| #pragma once | ||
|
|
||
| #include "common.cuh" | ||
|
|
||
| #define CUDA_SET_BLOCK_SIZE 256 | ||
|
|
||
| void ggml_cuda_op_set(ggml_backend_cuda_context & ctx, ggml_tensor * dst); |
Oops, something went wrong.
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.