-
Notifications
You must be signed in to change notification settings - Fork 13.4k
ggml webgpu: support for rope,div,sub,glu,scale,cont operators #16187
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
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f0fc822
Work on rope
reeselevine 0dd415f
Simplify inplace operation generation and combine mul/add generation
reeselevine 89f6cef
Work on rope variants
reeselevine 5f83354
implement neox rope
reeselevine 8c189d3
rope complete
reeselevine 415b2d5
Add sub,div,glu operators
reeselevine a7c9d33
implement scale op
reeselevine eee4e4d
Update cpy shader to handle cont/more types
reeselevine 7c26442
formatting
reeselevine 672544e
Merge remote-tracking branch 'upstream/master'
reeselevine 7eb9468
Update test vars printing for rope,rms_norm
reeselevine 4703c75
Merge remote-tracking branch 'upstream/master'
reeselevine aaf3908
Avoid ROPE hardcoded constants
reeselevine 227ac87
Add TODO to change ROPE constants to enum
reeselevine d760c10
fix TODO comment
reeselevine 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,188 @@ | ||
#define(VARIANTS) | ||
|
||
[ | ||
{ | ||
"SHADER_NAME": "add_f32", | ||
"REPLS": { | ||
"TYPE" : "f32", | ||
"OP": "+" | ||
}, | ||
"DECLS": ["NOT_INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "add_f16", | ||
"REPLS": { | ||
"TYPE" : "f16", | ||
"OP": "+" | ||
}, | ||
"DECLS": ["NOT_INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "add_f32_inplace", | ||
"REPLS": { | ||
"TYPE" : "f32", | ||
"OP": "+" | ||
}, | ||
"DECLS": ["INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "add_f16_inplace", | ||
"REPLS": { | ||
"TYPE" : "f16", | ||
"OP": "+" | ||
}, | ||
"DECLS": ["INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "mul_f32", | ||
"REPLS": { | ||
"TYPE" : "f32", | ||
"OP": "*" | ||
}, | ||
"DECLS": ["NOT_INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "mul_f16", | ||
"REPLS": { | ||
"TYPE" : "f16", | ||
"OP": "*" | ||
}, | ||
"DECLS": ["NOT_INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "mul_f32_inplace", | ||
"REPLS": { | ||
"TYPE" : "f32", | ||
"OP": "*" | ||
}, | ||
"DECLS": ["INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "mul_f16_inplace", | ||
"REPLS": { | ||
"TYPE" : "f16", | ||
"OP": "*" | ||
}, | ||
"DECLS": ["INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "sub_f32", | ||
"REPLS": { | ||
"TYPE" : "f32", | ||
"OP": "-" | ||
}, | ||
"DECLS": ["NOT_INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "sub_f16", | ||
"REPLS": { | ||
"TYPE" : "f16", | ||
"OP": "-" | ||
}, | ||
"DECLS": ["NOT_INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "sub_f32_inplace", | ||
"REPLS": { | ||
"TYPE" : "f32", | ||
"OP": "-" | ||
}, | ||
"DECLS": ["INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "sub_f16_inplace", | ||
"REPLS": { | ||
"TYPE" : "f16", | ||
"OP": "-" | ||
}, | ||
"DECLS": ["INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "div_f32", | ||
"REPLS": { | ||
"TYPE" : "f32", | ||
"OP": "/" | ||
}, | ||
"DECLS": ["NOT_INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "div_f16", | ||
"REPLS": { | ||
"TYPE" : "f16", | ||
"OP": "/" | ||
}, | ||
"DECLS": ["NOT_INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "div_f32_inplace", | ||
"REPLS": { | ||
"TYPE" : "f32", | ||
"OP": "/" | ||
}, | ||
"DECLS": ["INPLACE"] | ||
}, | ||
{ | ||
"SHADER_NAME": "div_f16_inplace", | ||
"REPLS": { | ||
"TYPE" : "f16", | ||
"OP": "/" | ||
}, | ||
"DECLS": ["INPLACE"] | ||
} | ||
] | ||
|
||
#end(VARIANTS) | ||
|
||
#define(DECLS) | ||
|
||
#decl(NOT_INPLACE) | ||
|
||
fn update(dst_i: u32, src0_i: u32, src1_i: u32) { | ||
dst[dst_i] = src0[src0_i] {{OP}} src1[src1_i]; | ||
} | ||
|
||
@group(0) @binding(2) | ||
var<storage, read_write> dst: array<{{TYPE}}>; | ||
|
||
@group(0) @binding(3) | ||
var<uniform> params: Params; | ||
|
||
#enddecl(NOT_INPLACE) | ||
|
||
#decl(INPLACE) | ||
|
||
fn update(dst_i: u32, src0_i: u32, src1_i: u32) { | ||
src0[dst_i] = src0[src0_i] {{OP}} src1[src1_i]; | ||
} | ||
|
||
@group(0) @binding(2) | ||
var<uniform> params: Params; | ||
|
||
#enddecl(INPLACE) | ||
|
||
#end(DECLS) | ||
|
||
|
||
#define(SHADER) | ||
|
||
enable f16; | ||
|
||
#include "binary_head.tmpl" | ||
|
||
@group(0) @binding(0) | ||
var<storage, read_write> src0: array<{{TYPE}}>; | ||
|
||
@group(0) @binding(1) | ||
var<storage, read_write> src1: array<{{TYPE}}>; | ||
|
||
DECLS | ||
|
||
override wg_size: u32; | ||
@compute @workgroup_size(wg_size) | ||
fn main(@builtin(global_invocation_id) gid: vec3<u32>) { | ||
if (gid.x < params.ne) { | ||
update(params.offset_dst + gid.x, params.offset_src0 + gid.x, params.offset_src1 + src1_index(gid.x)); | ||
} | ||
} | ||
|
||
#end(SHADER) |
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,101 @@ | ||
#define(VARIANTS) | ||
|
||
[ | ||
{ | ||
"REPLS": { | ||
"SRC_TYPE": "f32", | ||
"DST_TYPE": "f32" | ||
} | ||
}, | ||
{ | ||
"REPLS": { | ||
"SRC_TYPE": "f32", | ||
"DST_TYPE": "f16" | ||
} | ||
}, | ||
{ | ||
"REPLS": { | ||
"SRC_TYPE": "f16", | ||
"DST_TYPE": "f16" | ||
} | ||
}, | ||
{ | ||
"REPLS": { | ||
"SRC_TYPE": "f16", | ||
"DST_TYPE": "f32" | ||
} | ||
} | ||
] | ||
|
||
#end(VARIANTS) | ||
|
||
#define(SHADER) | ||
enable f16; | ||
|
||
@group(0) @binding(0) | ||
var<storage, read_write> src: array<{{SRC_TYPE}}>; | ||
|
||
@group(0) @binding(1) | ||
var<storage, read_write> dst: array<{{DST_TYPE}}>; | ||
|
||
struct Params { | ||
ne: u32, // total number of elements | ||
offset_src: u32, // in elements | ||
offset_dst: u32, // in elements | ||
|
||
// Strides (in elements) — may be permuted | ||
stride_src0: u32, | ||
stride_src1: u32, | ||
stride_src2: u32, | ||
stride_src3: u32, | ||
|
||
stride_dst0: u32, | ||
stride_dst1: u32, | ||
stride_dst2: u32, | ||
stride_dst3: u32, | ||
|
||
// Logical shapes | ||
src_ne0: u32, | ||
src_ne1: u32, | ||
src_ne2: u32, | ||
|
||
dst_ne0: u32, | ||
dst_ne1: u32, | ||
dst_ne2: u32 | ||
}; | ||
|
||
@group(0) @binding(2) | ||
var<uniform> params: Params; | ||
|
||
override wg_size: u32; | ||
@compute @workgroup_size(wg_size) | ||
fn main(@builtin(global_invocation_id) gid: vec3<u32>) { | ||
if (gid.x >= params.ne) { | ||
return; | ||
} | ||
|
||
var i = gid.x; | ||
let i3 = i / (params.src_ne2 * params.src_ne1 * params.src_ne0); | ||
i = i % (params.src_ne2 * params.src_ne1 * params.src_ne0); | ||
let i2 = i / (params.src_ne1 * params.src_ne0); | ||
i = i % (params.src_ne1 * params.src_ne0); | ||
let i1 = i / params.src_ne0; | ||
let i0 = i % params.src_ne0; | ||
|
||
var j = gid.x; | ||
let j3 = j / (params.dst_ne2 * params.dst_ne1 * params.dst_ne0); | ||
j = j % (params.dst_ne2 * params.dst_ne1 * params.dst_ne0); | ||
let j2 = j / (params.dst_ne1 * params.dst_ne0); | ||
j = j % (params.dst_ne1 * params.dst_ne0); | ||
let j1 = j / params.dst_ne0; | ||
let j0 = j % params.dst_ne0; | ||
|
||
let src_idx = i0 * params.stride_src0 + i1 * params.stride_src1 + | ||
i2 * params.stride_src2 + i3 * params.stride_src3; | ||
|
||
let dst_idx = j0 * params.stride_dst0 + j1 * params.stride_dst1 + | ||
j2 * params.stride_dst2 + j3 * params.stride_dst3; | ||
|
||
dst[params.offset_dst + dst_idx] = {{DST_TYPE}}((src[params.offset_src + src_idx])); | ||
} | ||
#end(SHADER) |
Oops, something went wrong.
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.