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 / conv2_dw.cl
| 1 | #pragma OPENCL EXTENSION cl_khr_fp16 : enable |
| 2 | |
| 3 | kernel void kernel_conv2d_dw_f32_f32( |
| 4 | global const float * weights, |
| 5 | long weights_offset, |
| 6 | global const float * input, |
| 7 | long input_offset, |
| 8 | global float * output, |
| 9 | long output_offset, |
| 10 | long C, |
| 11 | long N, |
| 12 | long KW, |
| 13 | long KH, |
| 14 | long W, |
| 15 | long H, |
| 16 | long OW, |
| 17 | long OH, |
| 18 | int s0, |
| 19 | int s1, |
| 20 | int p0, |
| 21 | int p1, |
| 22 | int d0, |
| 23 | int d1, |
| 24 | long nb01, |
| 25 | long nb03, |
| 26 | long nb11, |
| 27 | long nb12, |
| 28 | long nb13, |
| 29 | long nb1, |
| 30 | long nb2, |
| 31 | long nb3 |
| 32 | ) { |
| 33 | weights = (global const float *) ((global const char *) weights + weights_offset); |
| 34 | input = (global const float *) ((global const char *) input + input_offset); |
| 35 | output = (global float *) ((global char *) output + output_offset); |
| 36 | |
| 37 | const long gid = get_global_id(0); |
| 38 | const long OHW = OH * OW; |
| 39 | const long COHW = C * OHW; |
| 40 | const long total = N * COHW; |
| 41 | if (gid >= total) { |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | const long n = gid / COHW; |
| 46 | const long c_rem = gid - n * COHW; |
| 47 | const long c = c_rem / OHW; |
| 48 | const long oh = (c_rem - c * OHW) / OW; |
| 49 | const long ow = c_rem - c * OHW - oh * OW; |
| 50 | |
| 51 | float sum = 0.0f; |
| 52 | for (long kh = 0; kh < KH; ++kh) { |
| 53 | const long ih = oh * s1 + kh * d1 - p1; |
| 54 | if (ih < 0 || ih >= H) { |
| 55 | continue; |
| 56 | } |
| 57 | for (long kw = 0; kw < KW; ++kw) { |
| 58 | const long iw = ow * s0 + kw * d0 - p0; |
| 59 | if (iw < 0 || iw >= W) { |
| 60 | continue; |
| 61 | } |
| 62 | const long weight_idx = kw + kh * nb01 + c * nb03; |
| 63 | const long input_idx = iw + ih * nb11 + c * nb12 + n * nb13; |
| 64 | sum += weights[weight_idx] * input[input_idx]; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | const long output_idx = ow + oh * nb1 + c * nb2 + n * nb3; |
| 69 | output[output_idx] = sum; |
| 70 | } |
| 71 | |
| 72 | kernel void kernel_conv2d_dwf16_f32( |
| 73 | global const half * weights, |
| 74 | long weights_offset, |
| 75 | global const float * input, |
| 76 | long input_offset, |
| 77 | global float * output, |
| 78 | long output_offset, |
| 79 | long C, |
| 80 | long N, |
| 81 | long KW, |
| 82 | long KH, |
| 83 | long W, |
| 84 | long H, |
| 85 | long OW, |
| 86 | long OH, |
| 87 | int s0, |
| 88 | int s1, |
| 89 | int p0, |
| 90 | int p1, |
| 91 | int d0, |
| 92 | int d1, |
| 93 | long nb01, |
| 94 | long nb03, |
| 95 | long nb11, |
| 96 | long nb12, |
| 97 | long nb13, |
| 98 | long nb1, |
| 99 | long nb2, |
| 100 | long nb3 |
| 101 | ) { |
| 102 | weights = (global const half *) ((global const char *) weights + weights_offset); |
| 103 | input = (global const float *) ((global const char *) input + input_offset); |
| 104 | output = (global float *) ((global char *) output + output_offset); |
| 105 | |
| 106 | const long gid = get_global_id(0); |
| 107 | const long OHW = OH * OW; |
| 108 | const long COHW = C * OHW; |
| 109 | const long total = N * COHW; |
| 110 | if (gid >= total) { |
| 111 | return; |
| 112 | } |
| 113 | |
| 114 | const long n = gid / COHW; |
| 115 | const long c_rem = gid - n * COHW; |
| 116 | const long c = c_rem / OHW; |
| 117 | const long oh = (c_rem - c * OHW) / OW; |
| 118 | const long ow = c_rem - c * OHW - oh * OW; |
| 119 | |
| 120 | float sum = 0.0f; |
| 121 | for (long kh = 0; kh < KH; ++kh) { |
| 122 | const long ih = oh * s1 + kh * d1 - p1; |
| 123 | if (ih < 0 || ih >= H) { |
| 124 | continue; |
| 125 | } |
| 126 | for (long kw = 0; kw < KW; ++kw) { |
| 127 | const long iw = ow * s0 + kw * d0 - p0; |
| 128 | if (iw < 0 || iw >= W) { |
| 129 | continue; |
| 130 | } |
| 131 | const long weight_idx = kw + kh * nb01 + c * nb03; |
| 132 | const long input_idx = iw + ih * nb11 + c * nb12 + n * nb13; |
| 133 | sum += (float) weights[weight_idx] * input[input_idx]; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | const long output_idx = ow + oh * nb1 + c * nb2 + n * nb3; |
| 138 | output[output_idx] = sum; |
| 139 | } |