MNN/source/backend/vulkan/execution/glsl/unaryBuffer.comp

54 lines
1.0 KiB
Plaintext

#version 440 core
layout(set=0, binding=0) writeonly buffer sourceBuffer{
vec4 data[];
} uOutput;
layout(set=0, binding=1) readonly buffer destBuffer{
vec4 data[];
}uInput;
layout(set=0, binding=2) uniform constBuffer{
ivec4 size; // NCHW
ivec4 stride; // NCHW
} uConstant;
layout (local_size_x = 256, local_size_y = 1, local_size_z = 1) in;
void main()
{
ivec3 posTmp = ivec3(gl_GlobalInvocationID);
if (posTmp.x < uConstant.size.x) {
vec4 value = uInput.data[posTmp.x];
#ifdef NEG
value = -value;
#endif
#ifdef EXP
value = exp(value);
#endif
#ifdef SIGN
value = sign(value);
#endif
#ifdef SQRT
value = sqrt(value);
#endif
#ifdef RSQRT
value = inversesqrt(value);
#endif
#ifdef ABS
value = abs(value);
#endif
#ifdef TANH
value = tanh(value);
#endif
#ifdef SQUARE
value = value * value;
#endif
#ifdef LOG
value = log(value);
#endif
#ifdef SIGMOID
value = 1.f / (1.f + exp(-value));
#endif
uOutput.data[posTmp.x] = value;
}
}