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/clamp.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 / clamp.cl` 50 lines ยท 1482 bytes Raw Blame History 1 #pragma OPENCL EXTENSION cl_khr_fp16 : enable 2 3 //------------------------------------------------------------------------------ 4 // clamp 5 //------------------------------------------------------------------------------ 6 kernel void kernel_clamp( 7 global float * src0, 8 ulong offset0, 9 global float * dst, 10 ulong offsetd, 11 float min, 12 float max 13 ) { 14 src0 = (global float*)((global char*)src0 + offset0); 15 dst = (global float*)((global char*)dst + offsetd); 16 17 dst[get_global_id(0)] = src0[get_global_id(0)] < min ? 18 min : 19 (src0[get_global_id(0)] > max ? max : src0[get_global_id(0)]); 20 } 21 22 kernel void kernel_clamp_nc( 23 global const char * src0, 24 ulong offset0, 25 global char * dst, 26 ulong offsetd, 27 float min, 28 float max, 29 int ne00, 30 ulong nb00, 31 ulong nb01, 32 ulong nb02, 33 ulong nb03, 34 ulong nb0, 35 ulong nb1, 36 ulong nb2, 37 ulong nb3 38 ) { 39 src0 = src0 + offset0; 40 dst = dst + offsetd; 41 42 const int i3 = get_group_id(2); 43 const int i2 = get_group_id(1); 44 const int i1 = get_group_id(0); 45 46 for (int i0 = get_local_id(0); i0 < ne00; i0 += get_local_size(0)) { 47 const float x = *(global const float *)(src0 + i3*nb03 + i2*nb02 + i1*nb01 + i0*nb00); 48 *(global float *)(dst + i3*nb3 + i2*nb2 + i1*nb1 + i0*nb0) = x < min ? min : (x > max ? max : x); 49 } 50 }