Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/ggml/blob/master/src/ggml-opencl/kernels/mul_mv_f16_f32_1row.cl # ggml [Ported from github.com/ggml-org/ggml] docs : sync ggml_type enum in gguf.md (#1685) Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `ggml / src / ggml-opencl / kernels / mul_mv_f16_f32_1row.cl` 101 lines ยท 3469 bytes Raw Blame History 1 #pragma OPENCL EXTENSION cl_khr_fp16 : enable 2 3 #ifdef cl_intel_subgroups 4 #pragma OPENCL EXTENSION cl_intel_subgroups : enable 5 #else 6 #pragma OPENCL EXTENSION cl_khr_subgroups : enable 7 #endif 8 9 #ifdef cl_intel_required_subgroup_size 10 #pragma OPENCL EXTENSION cl_intel_required_subgroup_size : enable 11 #define INTEL_GPU 1 12 #define REQD_SUBGROUP_SIZE_16 __attribute__((intel_reqd_sub_group_size(16))) 13 #define REQD_SUBGROUP_SIZE_32 __attribute__((intel_reqd_sub_group_size(32))) 14 #elif defined(cl_qcom_reqd_sub_group_size) 15 #pragma OPENCL EXTENSION cl_qcom_reqd_sub_group_size : enable 16 #define ADRENO_GPU 1 17 #define REQD_SUBGROUP_SIZE_64 __attribute__((qcom_reqd_sub_group_size("half"))) 18 #define REQD_SUBGROUP_SIZE_128 __attribute__((qcom_reqd_sub_group_size("full"))) 19 #endif 20 21 #ifdef ADRENO_GPU 22 REQD_SUBGROUP_SIZE_64 23 #endif 24 kernel void kernel_mul_mat_f16_f32_1row( 25 global char * src0, 26 ulong offset0, 27 global char * src1, 28 ulong offset1, 29 global float * dst, 30 ulong offsetd, 31 int ne00, 32 int ne01, 33 int ne02, 34 ulong nb00, 35 ulong nb01, 36 ulong nb02, 37 ulong nb03, 38 int ne10, 39 int ne11, 40 int ne12, 41 ulong nb10, 42 ulong nb11, 43 ulong nb12, 44 ulong nb13, 45 int ne0, 46 int ne1, 47 int r2, 48 int r3 49 ) { 50 src0 = (global char*)((global char*)src0 + offset0); 51 src1 = (global char*)((global char*)src1 + offset1); 52 dst = (global float*)((global char*)dst + offsetd); 53 54 int r0 = get_group_id(0); 55 int r1 = get_group_id(1); 56 int im = get_group_id(2); 57 58 int i12 = im%ne12; 59 int i13 = im/ne12; 60 61 ulong offset_src0 = r0*nb01 + (i12/r2)*nb02 + (i13/r3)*nb03; 62 ulong offset_src1 = r1*nb11 + (i12 )*nb12 + (i13 )*nb13; 63 64 global half * x = (global half *) (src0 + offset_src0); 65 global float * y = (global float *) (src1 + offset_src1); 66 67 // The vector path below casts the row pointers to half4/float4, which must be 8- and 68 // 16-byte aligned. A row address is r0*nb01 + ..., and a permuted or strided src leaves 69 // nb01/nb11 unconstrained -- an odd ne00, say, gives a row that is only 2-byte aligned. 70 // Take the vector path only when the rows this work-item touches are actually aligned; 71 // the scalar loop has no such requirement. 72 const bool row_aligned = (((ulong) x) & 7) == 0 && (((ulong) y) & 15) == 0; 73 74 float sumf = 0; 75 if (ne00 < 128 || !row_aligned) { 76 for (int i = get_sub_group_local_id(); i < ne00; i += get_max_sub_group_size()) { 77 sumf += (float) x[i] * (float) y[i]; 78 } 79 float all_sum = sub_group_reduce_add(sumf); 80 if (get_sub_group_local_id() == 0) { 81 dst[im*ne1*ne0 + r1*ne0 + r0] = all_sum; 82 } 83 } else { 84 global half4 * x4 = (global half4 *) x; 85 global float4 * y4 = (global float4 *) y; 86 for (int i = get_sub_group_local_id(); i < ne00/4; i += get_max_sub_group_size()) { 87 sumf += (float) x4[i].s0 * y4[i].s0; 88 sumf += (float) x4[i].s1 * y4[i].s1; 89 sumf += (float) x4[i].s2 * y4[i].s2; 90 sumf += (float) x4[i].s3 * y4[i].s3; 91 } 92 float all_sum = sub_group_reduce_add(sumf); 93 if (get_sub_group_local_id() == 0) { 94 for (int i = 4*(ne00/4); i < ne00; ++i) { 95 all_sum += (float) x[i] * y[i]; 96 } 97 dst[im*ne1*ne0 + r1*ne0 + r0] = all_sum; 98 } 99 } 100 101 }