mirror of
https://github.com/ggerganov/llama.cpp.git
synced 2024-12-29 04:44:34 +00:00
f3f65429c4
* scripts : update sync [no ci] * files : relocate [no ci] * ci : disable kompute build [no ci] * cmake : fixes [no ci] * server : fix mingw build ggml-ci * cmake : minor [no ci] * cmake : link math library [no ci] * cmake : build normal ggml library (not object library) [no ci] * cmake : fix kompute build ggml-ci * make,cmake : fix LLAMA_CUDA + replace GGML_CDEF_PRIVATE ggml-ci * move public backend headers to the public include directory (#8122) * move public backend headers to the public include directory * nix test * spm : fix metal header --------- Co-authored-by: Georgi Gerganov <ggerganov@gmail.com> * scripts : fix sync paths [no ci] * scripts : sync ggml-blas.h [no ci] --------- Co-authored-by: slaren <slarengh@gmail.com>
85 lines
2.3 KiB
Plaintext
85 lines
2.3 KiB
Plaintext
#version 450
|
|
|
|
#include "common.comp"
|
|
|
|
layout(local_size_x = 256) in;
|
|
|
|
layout(binding = 0) buffer restrict readonly tensorIn { float in_[]; };
|
|
layout(binding = 1) buffer restrict tensorOut { float out_[]; };
|
|
|
|
layout(push_constant) uniform PushConstants {
|
|
uint inOff;
|
|
uint outOff;
|
|
uint ne00;
|
|
uint nb01;
|
|
float eps;
|
|
} pcs;
|
|
|
|
shared float sum[gl_WorkGroupSize.x];
|
|
|
|
void main() {
|
|
const uint x = (gl_WorkGroupID.x*pcs.nb01/4) + pcs.inOff; // Based from in_
|
|
// MEAN
|
|
// parallel sum
|
|
sum[gl_LocalInvocationID.x] = 0.0;
|
|
for (uint i00 = gl_LocalInvocationID.x; i00 < pcs.ne00; i00 += gl_WorkGroupSize.x) {
|
|
sum[gl_LocalInvocationID.x] += in_[x+i00];
|
|
}
|
|
|
|
// reduce
|
|
barrier();
|
|
memoryBarrierShared();
|
|
[[unroll]] for (uint i = gl_WorkGroupSize.x/2; i > 0; i /= 2) {
|
|
if (gl_LocalInvocationID.x < i) {
|
|
sum[gl_LocalInvocationID.x] += sum[gl_LocalInvocationID.x + i];
|
|
}
|
|
barrier();
|
|
memoryBarrierShared();
|
|
}
|
|
|
|
// broadcast
|
|
if (gl_LocalInvocationID.x == 0) {
|
|
sum[0] /= float(pcs.ne00);
|
|
}
|
|
barrier();
|
|
memoryBarrierShared();
|
|
const float mean = sum[0];
|
|
|
|
// recenter
|
|
const uint y = (gl_WorkGroupID.x*pcs.ne00) + pcs.outOff; // Based from out_
|
|
for (uint i00 = gl_LocalInvocationID.x; i00 < pcs.ne00; i00 += gl_WorkGroupSize.x) {
|
|
out_[y+i00] = in_[x+i00] - mean;
|
|
}
|
|
|
|
// VARIANCE
|
|
// parallel sum
|
|
sum[gl_LocalInvocationID.x] = 0.0;
|
|
for (uint i00 = gl_LocalInvocationID.x; i00 < pcs.ne00; i00 += gl_WorkGroupSize.x) {
|
|
sum[gl_LocalInvocationID.x] += out_[y+i00] * out_[y+i00];
|
|
}
|
|
|
|
// reduce
|
|
barrier();
|
|
memoryBarrierShared();
|
|
[[unroll]] for (uint i = gl_WorkGroupSize.x/2; i > 0; i /= 2) {
|
|
if (gl_LocalInvocationID.x < i) {
|
|
sum[gl_LocalInvocationID.x] += sum[gl_LocalInvocationID.x + i];
|
|
}
|
|
barrier();
|
|
memoryBarrierShared();
|
|
}
|
|
|
|
// broadcast
|
|
if (gl_LocalInvocationID.x == 0) {
|
|
sum[0] /= float(pcs.ne00);
|
|
}
|
|
barrier();
|
|
memoryBarrierShared();
|
|
const float variance = sum[0];
|
|
|
|
const float scale = 1.0f/sqrt(variance + pcs.eps);
|
|
for (uint i00 = gl_LocalInvocationID.x; i00 < pcs.ne00; i00 += gl_WorkGroupSize.x) {
|
|
out_[y+i00] *= scale;
|
|
}
|
|
}
|