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 / im2col_3d_f32.cl
| 1 | #pragma OPENCL EXTENSION cl_khr_fp16 : enable |
| 2 | |
| 3 | kernel void kernel_im2col_3d_f32( |
| 4 | global float * src1, |
| 5 | ulong offset1, |
| 6 | global float * dst, |
| 7 | ulong offsetd, |
| 8 | long IC, |
| 9 | long ID, |
| 10 | long IH, |
| 11 | long IW, |
| 12 | long KD, |
| 13 | long KH, |
| 14 | long KW, |
| 15 | long OD, |
| 16 | long OH, |
| 17 | long OW, |
| 18 | long N, |
| 19 | long stride_x, |
| 20 | long stride_y, |
| 21 | long stride_z, |
| 22 | long stride_q, |
| 23 | int s0, |
| 24 | int s1, |
| 25 | int s2, |
| 26 | int p0, |
| 27 | int p1, |
| 28 | int p2, |
| 29 | int d0, |
| 30 | int d1, |
| 31 | int d2 |
| 32 | ) { |
| 33 | const int ic = (int)IC; |
| 34 | const int kd = (int)KD; |
| 35 | const int kh = (int)KH; |
| 36 | const int kw = (int)KW; |
| 37 | const int od = (int)OD; |
| 38 | const int oh = (int)OH; |
| 39 | const int ow = (int)OW; |
| 40 | const int n = (int)N; |
| 41 | |
| 42 | const int KD_KH_KW = kd * kh * kw; |
| 43 | const int KH_KW = kh * kw; |
| 44 | const int IC_KD_KH_KW = ic * KD_KH_KW; |
| 45 | |
| 46 | const int i = (int)get_global_id(0); |
| 47 | if (i >= IC_KD_KH_KW) { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | const int iow = (int)get_global_id(1); |
| 52 | if (iow >= ow) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | const int OD_OH = od * oh; |
| 57 | const int iz = (int)get_global_id(2); |
| 58 | if (iz >= n * OD_OH) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | src1 = (global float*)((global char*)src1 + offset1); |
| 63 | dst = (global float*)((global char*)dst + offsetd); |
| 64 | |
| 65 | const int iic = i / KD_KH_KW; |
| 66 | const int ikd = (i - iic * KD_KH_KW) / KH_KW; |
| 67 | const int ikh = (i - iic * KD_KH_KW - ikd * KH_KW) / kw; |
| 68 | const int ikw = i % kw; |
| 69 | |
| 70 | const int in = iz / OD_OH; |
| 71 | const int iod = (iz - in * OD_OH) / oh; |
| 72 | const int ioh = iz % oh; |
| 73 | |
| 74 | const int iiw = iow * s0 + ikw * d0 - p0; |
| 75 | const int iih = ioh * s1 + ikh * d1 - p1; |
| 76 | const int iid = iod * s2 + ikd * d2 - p2; |
| 77 | |
| 78 | const long offset_dst = |
| 79 | (long)(iz * ow + iow) * (long)IC_KD_KH_KW + |
| 80 | (long)(iic * KD_KH_KW + ikd * KH_KW + ikh * kw + ikw); |
| 81 | |
| 82 | if (iih < 0 || iih >= IH || iiw < 0 || iiw >= IW || iid < 0 || iid >= ID) { |
| 83 | dst[offset_dst] = 0.0f; |
| 84 | } else { |
| 85 | const long offset_src = |
| 86 | (long)(in * ic + iic) * stride_q + (long)iid * stride_z + |
| 87 | (long)iih * stride_y + (long)iiw * stride_x; |
| 88 | dst[offset_dst] = src1[offset_src]; |
| 89 | } |
| 90 | } |