mirror of
https://github.com/pithings/unkernel.git
synced 2026-12-04 03:50:09 +08:00
20 lines
622 B
Plaintext
20 lines
622 B
Plaintext
// SPDX-License-Identifier: MIT
|
|
// Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>
|
|
#version 450
|
|
// 512 invocations reducing through shared memory (ggml's norm family): on a
|
|
// device allowing 256 the translator runs each invocation as 2 virtual ones
|
|
// (vk/naga/src/virt.rs), so the pipeline is made and the sum is right.
|
|
layout(local_size_x = 512) in;
|
|
layout(set = 0, binding = 0) buffer B { float v[]; } b;
|
|
shared float s[512];
|
|
void main() {
|
|
uint i = gl_LocalInvocationID.x;
|
|
s[i] = b.v[i];
|
|
barrier();
|
|
for (uint k = 256u; k > 0u; k >>= 1) {
|
|
if (i < k) s[i] += s[i + k];
|
|
barrier();
|
|
}
|
|
if (i == 0u) b.v[0] = s[0];
|
|
}
|