ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-vulkan / vulkan-shaders / timestep_embedding.comp
| 1 | #version 450 |
| 2 | |
| 3 | #extension GL_EXT_shader_16bit_storage : require |
| 4 | |
| 5 | layout (push_constant) uniform parameter |
| 6 | { |
| 7 | uint nb1; |
| 8 | uint dim; |
| 9 | uint max_period; |
| 10 | } p; |
| 11 | |
| 12 | #include "types.glsl" |
| 13 | |
| 14 | #extension GL_EXT_control_flow_attributes : enable |
| 15 | #define BLOCK_SIZE 256 |
| 16 | |
| 17 | layout(local_size_x = BLOCK_SIZE, local_size_y = 1, local_size_z = 1) in; |
| 18 | |
| 19 | layout (binding = 0) readonly buffer X {A_TYPE data_a[];}; |
| 20 | layout (binding = 1) writeonly buffer D {D_TYPE data_d[];}; |
| 21 | |
| 22 | void main() { |
| 23 | const uint i = gl_WorkGroupID.y; |
| 24 | const uint j = gl_GlobalInvocationID.x; |
| 25 | const uint d_offset = i * p.nb1; |
| 26 | |
| 27 | const uint half_dim = p.dim / 2; |
| 28 | |
| 29 | if (p.dim % 2 != 0 && j == half_dim) { |
| 30 | data_d[d_offset + 2 * half_dim] = 0.f; |
| 31 | } |
| 32 | |
| 33 | if (j >= half_dim) { |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | const float timestep = float(data_a[i]); |
| 38 | const float freq = float(exp(-log(p.max_period) * j / half_dim)); |
| 39 | const float arg = timestep * freq; |
| 40 | data_d[d_offset + j] = D_TYPE(cos(arg)); |
| 41 | data_d[d_offset + j + half_dim] = D_TYPE(sin(arg)); |
| 42 | } |