ggml
[Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685)
Brought by drakestapleton
ggml / src / ggml-opencl / kernels / fwht.cl
| 1 | #pragma OPENCL EXTENSION cl_khr_fp16 : enable |
| 2 | |
| 3 | kernel void kernel_fwht( |
| 4 | global const char * src, |
| 5 | ulong offset_src, |
| 6 | global char * dst, |
| 7 | ulong offset_dst, |
| 8 | int n, |
| 9 | ulong ne1, |
| 10 | ulong ne2, |
| 11 | ulong nb1, |
| 12 | ulong nb2, |
| 13 | ulong nb3, |
| 14 | float scale, |
| 15 | local float * work) { |
| 16 | const ulong row = get_group_id(1); |
| 17 | const ulong i1 = row % ne1; |
| 18 | const ulong i2 = row / ne1 % ne2; |
| 19 | const ulong i3 = row / ne1 / ne2; |
| 20 | global const SRC_TYPE * x = (global const SRC_TYPE *)(src + offset_src + i1*nb1 + i2*nb2 + i3*nb3); |
| 21 | global float * y = (global float *)(dst + offset_dst) + row*n; |
| 22 | const int tid = get_local_id(0); |
| 23 | const int nth = get_local_size(0); |
| 24 | |
| 25 | for (int i = tid; i < n; i += nth) { |
| 26 | work[i] = (float)x[i] * scale; |
| 27 | } |
| 28 | barrier(CLK_LOCAL_MEM_FENCE); |
| 29 | |
| 30 | for (int h = 1; h < n; h *= 2) { |
| 31 | for (int i = tid; i < n/2; i += nth) { |
| 32 | const int j = 2*i - (i & (h - 1)); |
| 33 | const float a = work[j]; |
| 34 | const float b = work[j + h]; |
| 35 | work[j] = a + b; |
| 36 | work[j + h] = a - b; |
| 37 | } |
| 38 | barrier(CLK_LOCAL_MEM_FENCE); |
| 39 | } |
| 40 | |
| 41 | for (int i = tid; i < n; i += nth) { |
| 42 | y[i] = work[i]; |
| 43 | } |
| 44 | } |