-
Notifications
You must be signed in to change notification settings - Fork 19.2k
vulkan: fuse snake activation (mul, sin, sqr, mul, add) #22855
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
ServeurpersoCom
merged 5 commits into
ggml-org:master
from
ServeurpersoCom:ggml/vulkan-snake-fusion
May 21, 2026
+187
−2
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7e14e1a
vulkan: fuse snake activation (mul, sin, sqr, mul, add)
ServeurpersoCom 6f350d0
vulkan: address jeffbolznv review for fused snake activation
ServeurpersoCom 0048ab5
vulkan: tighten snake fusion type checks for all operands (address je…
ServeurpersoCom a4f2dd3
vulkan: reject snake fusion when ne[2] or ne[3] > 1 (address jeffbolz…
ServeurpersoCom 6d869a6
vulkan: address 0cc4m review for fused snake activation
ServeurpersoCom 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,49 @@ | ||
| #version 450 | ||
|
|
||
| #include "types.glsl" | ||
|
|
||
| // Fused snake activation: y = x + sin(b * x)^2 * c | ||
| // data_a [ne0, ne1] per element activation x (A_TYPE) | ||
| // data_b [1, ne1] per channel multiplier (float) | ||
| // data_c [1, ne1] per channel inverse scale (float, precomputed as 1 / freq) | ||
| // data_d [ne0, ne1] output y (D_TYPE) | ||
| layout (binding = 0) readonly buffer A {A_TYPE data_a[];}; | ||
| layout (binding = 1) readonly buffer B {float data_b[];}; | ||
| layout (binding = 2) readonly buffer C {float data_c[];}; | ||
| layout (binding = 3) writeonly buffer D {D_TYPE data_d[];}; | ||
|
|
||
| layout(local_size_x = 256, local_size_y = 1, local_size_z = 1) in; | ||
|
|
||
| layout (push_constant) uniform parameter { | ||
| uint32_t ne0; | ||
| uint32_t ne1; | ||
| } p; | ||
|
|
||
| // Load A_TYPE to float | ||
| float load_val(uint32_t idx) { | ||
| #if defined(DATA_A_BF16) | ||
| return bf16_to_fp32(uint32_t(data_a[idx])); | ||
| #else | ||
| return float(data_a[idx]); | ||
| #endif | ||
| } | ||
|
|
||
| // Store float as D_TYPE | ||
| void store_val(uint32_t idx, float v) { | ||
| #if defined(DATA_D_BF16) | ||
| data_d[idx] = D_TYPE(fp32_to_bf16(v)); | ||
| #else | ||
| data_d[idx] = D_TYPE(v); | ||
| #endif | ||
| } | ||
|
|
||
| void main() { | ||
| const uint32_t i0 = gl_GlobalInvocationID.x; | ||
| const uint32_t i1 = gl_GlobalInvocationID.y; | ||
| if (i0 >= p.ne0 || i1 >= p.ne1) return; | ||
|
|
||
| const uint32_t idx = i0 + i1 * p.ne0; | ||
| const float xi = load_val(idx); | ||
| const float s = sin(data_b[i1] * xi); | ||
| store_val(idx, xi + s * s * data_c[i1]); | ||
| } |
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
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.