a89002f07b
* ggml webgpu: add SOFTPLUS unary operator Implements SOFTPLUS (log(1 + exp(x))) with f16/f32 support. Uses f32 precision for intermediate calculations to prevent f16 overflow. * Add shader implementation and 4 variants (f32/f16, inplace/non-inplace) * Register pipelines and device support * Follow Vulkan backend numerical stability pattern * ggml webgpu: add EXPM1 unary operator Implements EXPM1 (exp(x) - 1) with f16/f32 support. * Add shader implementation and 4 variants (f32/f16, inplace/non-inplace) * Register pipelines and device support * ggml webgpu: add FLOOR unary operator Implements FLOOR (rounds down to nearest integer) with f16/f32 support. * Add shader implementation and 4 variants (f32/f16, inplace/non-inplace) * Register pipelines and device support * ggml webgpu: add CEIL unary operator Implements CEIL (rounds up to nearest integer) with f16/f32 support. * Add shader implementation and 4 variants (f32/f16, inplace/non-inplace) * Register pipelines and device support * ggml webgpu: add ROUND unary operator Implements ROUND (rounds to nearest integer) with f16/f32 support. * Add shader implementation and 4 variants (f32/f16, inplace/non-inplace) * Register pipelines and device support * ggml webgpu: add TRUNC unary operator Implements TRUNC (truncates towards zero) with f16/f32 support. * Add shader implementation and 4 variants (f32/f16, inplace/non-inplace) * Register pipelines and device support * docs : update WebGPU support for unary operators (FLOOR, CEIL, ROUND, TRUNC, EXPM1, SOFTPLUS) * Updates to webgpu get_memory * Add argmax * Add argmax,cumsum,sum,sum_rows * Add necessary CPY/GET_ROWS operators * Support for argsort using multi-pass strategy * Update set_rows for i32 indices, move to pre-wgsl * Port unary operators to pre-wgsl and support FILL * Implement PAD * Add support for top-k * clean up, scope pipeline init mutex * fix newline * Add support for log * Update LOG for better precision, and ops doc --------- Co-authored-by: Abhijit Ramesh <abhijitramesh2k@gmail.com>
56 lines
1.4 KiB
WebGPU Shading Language
56 lines
1.4 KiB
WebGPU Shading Language
@group(0) @binding(0)
|
|
var<storage, read_write> src: array<f32>;
|
|
|
|
@group(0) @binding(1)
|
|
var<storage, read_write> dst: array<f32>;
|
|
|
|
struct Params {
|
|
offset_src: u32, // in elements
|
|
offset_dst: u32, // in elements
|
|
|
|
// Strides (in elements)
|
|
stride_src1: u32,
|
|
stride_src2: u32,
|
|
stride_src3: u32,
|
|
|
|
ne0: u32,
|
|
ne1: u32,
|
|
ne2: u32
|
|
};
|
|
|
|
@group(0) @binding(2)
|
|
var<uniform> params: Params;
|
|
|
|
var<workgroup> shared_sum: array<f32, WG_SIZE>;
|
|
|
|
@compute @workgroup_size(WG_SIZE)
|
|
fn main(@builtin(workgroup_id) wid: vec3<u32>,
|
|
@builtin(local_invocation_id) lid: vec3<u32>) {
|
|
|
|
var i = wid.x;
|
|
let i3 = i / (params.ne2 * params.ne1);
|
|
i = i % (params.ne2 * params.ne1);
|
|
let i2 = i / params.ne1;
|
|
let i1 = i % params.ne1;
|
|
let i_src_row = params.offset_src + i3 * params.stride_src3 + i2 * params.stride_src2 + i1 * params.stride_src1;
|
|
var local_sum: f32 = 0.0;
|
|
for (var col = lid.x; col < params.ne0; col += WG_SIZE) {
|
|
local_sum += src[i_src_row + col];
|
|
}
|
|
shared_sum[lid.x] = local_sum;
|
|
workgroupBarrier();
|
|
// reduce within workgroup
|
|
var offset: u32 = WG_SIZE >> 1;
|
|
while (offset > 0) {
|
|
if (lid.x < offset) {
|
|
shared_sum[lid.x] = shared_sum[lid.x] + shared_sum[lid.x + offset];
|
|
}
|
|
workgroupBarrier();
|
|
offset >>= 1;
|
|
}
|
|
|
|
if (lid.x == 0) {
|
|
dst[params.offset_dst + wid.x] = shared_sum[0];
|
|
}
|
|
}
|