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/argmax.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 / argmax.cl` 55 lines ยท 2043 bytes Raw Blame History 1 #define ARGMAX_LANES_PER_ROW 32 2 #define ARGMAX_ROWS_PER_GROUP 2 3 #define ARGMAX_BLOCK_SIZE (ARGMAX_LANES_PER_ROW * ARGMAX_ROWS_PER_GROUP) 4 5 kernel void kernel_argmax_f32_i32( 6 global const char * src0, 7 ulong offset0, 8 global char * dst, 9 ulong offsetd, 10 int ne00, 11 int nrows) { 12 const int local_id = get_local_id(0); 13 const int col = local_id % ARGMAX_LANES_PER_ROW; 14 const int row = get_group_id(1) * ARGMAX_ROWS_PER_GROUP + local_id / ARGMAX_LANES_PER_ROW; 15 16 float max_value = -INFINITY; 17 int max_index = 0; 18 19 if (row < nrows) { 20 global const float * src_row = (global const float *) (src0 + offset0) + row * ne00; 21 for (int i = col; i < ne00; i += ARGMAX_LANES_PER_ROW) { 22 const float value = src_row[i]; 23 if (value > max_value || (value == max_value && i > max_index)) { 24 max_value = value; 25 max_index = i; 26 } 27 } 28 } 29 30 local float max_values[ARGMAX_BLOCK_SIZE]; 31 local int max_indices[ARGMAX_BLOCK_SIZE]; 32 33 max_values[local_id] = max_value; 34 max_indices[local_id] = max_index; 35 36 barrier(CLK_LOCAL_MEM_FENCE); 37 38 const int row_offset = local_id / ARGMAX_LANES_PER_ROW * ARGMAX_LANES_PER_ROW; 39 for (int stride = ARGMAX_LANES_PER_ROW / 2; stride > 0; stride /= 2) { 40 if (col < stride) { 41 const float value = max_values[row_offset + col + stride]; 42 const int index = max_indices[row_offset + col + stride]; 43 if (value > max_values[row_offset + col] || (value == max_values[row_offset + col] && index > max_indices[row_offset + col])) { 44 max_values[row_offset + col] = value; 45 max_indices[row_offset + col] = index; 46 } 47 } 48 barrier(CLK_LOCAL_MEM_FENCE); 49 } 50 51 if (col == 0 && row < nrows) { 52 global int * dst_row = (global int *) (dst + offsetd) + row; 53 dst_row[0] = max_indices[row_offset]; 54 } 55 }