← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
recurrent_gate_kernels.c
Go to the documentation of this file.
1#ifndef _GNU_SOURCE
2#define _GNU_SOURCE
3#endif
4
5#include "bf16_utils.h"
6#include "ckernel_engine.h"
7#include "ck_threadpool.h"
8
9#include <dlfcn.h>
10#include <math.h>
11#include <pthread.h>
12#include <stdio.h>
13#include <stdlib.h>
14#if defined(__AVX2__) || defined(__AVX512F__)
15#include <immintrin.h>
16#endif
17
18typedef float (*ck_recurrent_libm_f32_fn)(float);
22static void *ck_recurrent_libm_handle = NULL;
23static pthread_once_t ck_recurrent_libm_once = PTHREAD_ONCE_INIT;
24
26{
27 ck_recurrent_libm_handle = dlopen("libm.so.6", RTLD_NOW | RTLD_LOCAL);
35 }
37 fprintf(stderr,
38 "HARD KERNEL CONTRACT FAULT: llama.cpp recurrent softplus "
39 "requires expf/logf from libm.so.6\n");
40 abort();
41 }
42}
43
44static inline float recurrent_softplus(float x) {
46 if (x > 20.0f) {
47 return x;
48 }
49 if (x < -20.0f) {
51 }
53}
54
55static inline float recurrent_sigmoid(float x) {
56 if (x >= 0.0f) {
57 float z = expf(-x);
58 return 1.0f / (1.0f + z);
59 }
60 {
61 float z = expf(x);
62 return z / (1.0f + z);
63 }
64}
65
66void recurrent_dt_gate_forward(const float *alpha,
67 const float *dt_bias,
68 const float *a,
69 float *gate,
70 int rows,
71 int num_heads,
72 int state_dim) {
73 const int dim = num_heads * state_dim;
74 for (int row = 0; row < rows; ++row) {
75 const float *alpha_row = alpha + (size_t) row * (size_t) dim;
76 float *gate_row = gate + (size_t) row * (size_t) dim;
77 for (int col = 0; col < dim; ++col) {
78 const float x = alpha_row[col] + dt_bias[col];
79 gate_row[col] = recurrent_softplus(x) * a[col];
80 }
81 }
82}
83
84void recurrent_dt_gate_expanded_forward(const float *alpha,
85 const float *dt_bias,
86 const float *a,
87 float *gate,
88 int rows,
89 int num_heads,
90 int state_dim) {
91 for (int row = 0; row < rows; ++row) {
92 const float *alpha_row = alpha + (size_t) row * (size_t) num_heads;
93 float *gate_row = gate + (size_t) row * (size_t) num_heads * (size_t) state_dim;
94 for (int h = 0; h < num_heads; ++h) {
95 const float sp = recurrent_softplus(alpha_row[h] + dt_bias[h]);
96 const float *a_head = a + (size_t) h * (size_t) state_dim;
97 float *gate_head = gate_row + (size_t) h * (size_t) state_dim;
98 for (int col = 0; col < state_dim; ++col) {
99 gate_head[col] = sp * a_head[col];
100 }
101 }
102 }
103}
104
105void recurrent_dt_gate_backward(const float *d_gate,
106 const float *alpha,
107 const float *dt_bias,
108 const float *a,
109 float *d_alpha,
110 float *d_dt_bias,
111 float *d_a,
112 int rows,
113 int dim) {
114 for (int col = 0; col < dim; ++col) {
115 d_dt_bias[col] = 0.0f;
116 d_a[col] = 0.0f;
117 }
118
119 for (int row = 0; row < rows; ++row) {
120 const float *d_gate_row = d_gate + (size_t) row * (size_t) dim;
121 const float *alpha_row = alpha + (size_t) row * (size_t) dim;
122 float *d_alpha_row = d_alpha + (size_t) row * (size_t) dim;
123 for (int col = 0; col < dim; ++col) {
124 const float x = alpha_row[col] + dt_bias[col];
125 const float sp = recurrent_softplus(x);
126 const float sig = recurrent_sigmoid(x);
127 const float d_out = d_gate_row[col];
128 d_a[col] += d_out * sp;
129 {
130 const float d_x = d_out * a[col] * sig;
131 d_alpha_row[col] = d_x;
132 d_dt_bias[col] += d_x;
133 }
134 }
135 }
136}
137
138void recurrent_silu_forward(const float *x,
139 float *out,
140 int rows,
141 int dim) {
142 for (int row = 0; row < rows; ++row) {
143 const float *x_row = x + (size_t) row * (size_t) dim;
144 float *out_row = out + (size_t) row * (size_t) dim;
145 for (int col = 0; col < dim; ++col) {
146 const float xv = x_row[col];
147 out_row[col] = xv * recurrent_sigmoid(xv);
148 }
149 }
150}
151
152#if defined(__AVX512F__)
153typedef __m512 (*ck_recurrent_sleef_expf16_fn)(__m512);
154typedef __m512 (*ck_recurrent_sleef_log1pf16_fn)(__m512);
155static ck_recurrent_sleef_expf16_fn ck_recurrent_pytorch_expf16 = NULL;
156static ck_recurrent_sleef_log1pf16_fn ck_recurrent_pytorch_log1pf16 = NULL;
157static void *ck_recurrent_sleef_handle = NULL;
158static pthread_once_t ck_recurrent_sleef_once = PTHREAD_ONCE_INIT;
159
160static void ck_bind_recurrent_pytorch_sleef(void)
161{
162 const char *library = getenv("CK_SLEEF_LIBRARY");
163 if (library && *library) {
164 ck_recurrent_sleef_handle = dlopen(library, RTLD_NOW | RTLD_LOCAL);
165 if (ck_recurrent_sleef_handle) {
166 ck_recurrent_pytorch_expf16 = (ck_recurrent_sleef_expf16_fn)dlsym(
167 ck_recurrent_sleef_handle, "Sleef_expf16_u10");
168 ck_recurrent_pytorch_log1pf16 = (ck_recurrent_sleef_log1pf16_fn)dlsym(
169 ck_recurrent_sleef_handle, "Sleef_log1pf16_u10");
170 }
171 } else {
172 ck_recurrent_pytorch_expf16 =
173 (ck_recurrent_sleef_expf16_fn)dlsym(RTLD_DEFAULT, "Sleef_expf16_u10");
174 ck_recurrent_pytorch_log1pf16 =
175 (ck_recurrent_sleef_log1pf16_fn)dlsym(RTLD_DEFAULT, "Sleef_log1pf16_u10");
176 }
177}
178#endif
179
181 const float *dt_bias,
182 const float *a,
183 float *gate,
184 int rows,
185 int num_heads,
186 int state_dim)
187{
188 if (!alpha || !dt_bias || !a || !gate || rows < 0 || num_heads < 0 || state_dim != 1) {
189 fprintf(stderr,
190 "HARD KERNEL CONTRACT FAULT: invalid PyTorch FP32 recurrent dt-gate arguments\n");
191 abort();
192 }
193#if defined(__AVX512F__)
194 pthread_once(&ck_recurrent_sleef_once, ck_bind_recurrent_pytorch_sleef);
195 if (!ck_recurrent_pytorch_expf16 || !ck_recurrent_pytorch_log1pf16) {
196 fprintf(stderr,
197 "HARD KERNEL CONTRACT FAULT: PyTorch FP32 recurrent dt gate requires "
198 "SLEEF Sleef_expf16_u10 and Sleef_log1pf16_u10; set CK_SLEEF_LIBRARY\n");
199 abort();
200 }
201 if ((num_heads & 15) != 0) {
202 fprintf(stderr,
203 "HARD KERNEL CONTRACT FAULT: PyTorch AVX-512 recurrent dt gate requires "
204 "a head count divisible by 16 (got %d)\n",
205 num_heads);
206 abort();
207 }
210 fprintf(stderr,
211 "HARD KERNEL CONTRACT FAULT: PyTorch FP32 recurrent dt gate requires "
212 "log1pf from libm.so.6\n");
213 abort();
214 }
215 const __m512 threshold = _mm512_set1_ps(20.0f);
216 const int count = rows * num_heads;
217 int index = 0;
218 for (; index + 32 <= count; index += 32) {
219 for (int half = 0; half < 2; ++half) {
220 float x_lanes[16] __attribute__((aligned(64)));
221 float a_lanes[16] __attribute__((aligned(64)));
222 const int base = index + half * 16;
223 for (int lane = 0; lane < 16; ++lane) {
224 const int head = (base + lane) % num_heads;
225 x_lanes[lane] = alpha[base + lane] + dt_bias[head];
226 a_lanes[lane] = a[head];
227 }
228 const __m512 x = _mm512_load_ps(x_lanes);
229 const __m512 softplus = _mm512_mask_blend_ps(
230 _mm512_cmp_ps_mask(x, threshold, _CMP_GT_OQ),
231 ck_recurrent_pytorch_log1pf16(ck_recurrent_pytorch_expf16(x)),
232 x);
233 _mm512_storeu_ps(
234 gate + base,
235 _mm512_mul_ps(softplus, _mm512_load_ps(a_lanes)));
236 }
237 }
238 for (; index < count; ++index) {
239 const int head = index % num_heads;
240 const float x = alpha[index] + dt_bias[head];
241 const float softplus = x > 20.0f
242 ? x
244 gate[index] = softplus * a[head];
245 }
246#else
247 fprintf(stderr,
248 "HARD KERNEL CONTRACT FAULT: PyTorch FP32 recurrent dt gate requires AVX-512\n");
249 abort();
250#endif
251}
252
254 float *out,
255 int rows,
256 int dim)
257{
258 if (!x || !out || rows < 0 || dim < 0) {
259 fprintf(stderr, "HARD KERNEL CONTRACT FAULT: invalid PyTorch BF16 recurrent SiLU arguments\n");
260 abort();
261 }
262#if defined(__AVX512F__)
263 pthread_once(&ck_recurrent_sleef_once, ck_bind_recurrent_pytorch_sleef);
264 if (!ck_recurrent_pytorch_expf16) {
265 fprintf(stderr,
266 "HARD KERNEL CONTRACT FAULT: PyTorch BF16 recurrent SiLU requires "
267 "SLEEF Sleef_expf16_u10; set CK_SLEEF_LIBRARY\n");
268 abort();
269 }
270#endif
271 for (int row = 0; row < rows; ++row) {
272 const float *src = x + (size_t)row * (size_t)dim;
273 float *dst = out + (size_t)row * (size_t)dim;
274 int col = 0;
275#if defined(__AVX512F__)
276 for (; col + 16 <= dim; col += 16) {
277 float lanes[16] __attribute__((aligned(64)));
278 for (int lane = 0; lane < 16; ++lane) {
279 lanes[lane] = bf16_to_float(float_to_bf16(src[col + lane]));
280 }
281 const __m512 values = _mm512_load_ps(lanes);
282 const __m512 denominator = _mm512_add_ps(
283 _mm512_set1_ps(1.0f),
284 ck_recurrent_pytorch_expf16(
285 _mm512_sub_ps(_mm512_setzero_ps(), values)));
286 _mm512_store_ps(lanes, _mm512_div_ps(values, denominator));
287 for (int lane = 0; lane < 16; ++lane) {
288 dst[col + lane] = bf16_to_float(float_to_bf16(lanes[lane]));
289 }
290 }
291#endif
292 for (; col < dim; ++col) {
293 const float value = bf16_to_float(float_to_bf16(src[col]));
294 const float silu = value / (1.0f + expf(-value));
295 dst[col] = bf16_to_float(float_to_bf16(silu));
296 }
297 }
298}
299
301 float *out,
302 int rows,
303 int dim)
304{
305 if (!x || !out || rows < 0 || dim < 0) {
306 fprintf(stderr, "HARD KERNEL CONTRACT FAULT: invalid BF16-input FP32-output SiLU arguments\n");
307 abort();
308 }
309#if defined(__AVX512F__)
310 pthread_once(&ck_recurrent_sleef_once, ck_bind_recurrent_pytorch_sleef);
311 if (!ck_recurrent_pytorch_expf16) {
312 fprintf(stderr,
313 "HARD KERNEL CONTRACT FAULT: PyTorch BF16-input SiLU requires "
314 "SLEEF Sleef_expf16_u10; set CK_SLEEF_LIBRARY\n");
315 abort();
316 }
317#endif
318 const int count = rows * dim;
319 int i = 0;
320#if defined(__AVX512F__)
321 for (; i + 16 <= count; i += 16) {
322 float lanes[16] __attribute__((aligned(64)));
323 for (int lane = 0; lane < 16; ++lane) {
324 lanes[lane] = bf16_to_float(float_to_bf16(x[i + lane]));
325 }
326 const __m512 values = _mm512_load_ps(lanes);
327 const __m512 denominator = _mm512_add_ps(
328 _mm512_set1_ps(1.0f),
329 ck_recurrent_pytorch_expf16(
330 _mm512_sub_ps(_mm512_setzero_ps(), values)));
331 _mm512_storeu_ps(out + i, _mm512_div_ps(values, denominator));
332 }
333#endif
334 for (; i < count; ++i) {
335 const float value = bf16_to_float(float_to_bf16(x[i]));
336 out[i] = value / (1.0f + expf(-value));
337 }
338}
339
341 const float *x,
342 float *out,
343 int rows,
344 int dim)
345{
346 if (!x || !out || rows < 0 || dim < 0) {
347 fprintf(stderr, "HARD KERNEL CONTRACT FAULT: invalid BF16-input FP32-output sigmoid arguments\n");
348 abort();
349 }
350#if defined(__AVX512F__)
351 pthread_once(&ck_recurrent_sleef_once, ck_bind_recurrent_pytorch_sleef);
352 if (!ck_recurrent_pytorch_expf16) {
353 fprintf(stderr,
354 "HARD KERNEL CONTRACT FAULT: PyTorch BF16-input sigmoid requires "
355 "SLEEF Sleef_expf16_u10; set CK_SLEEF_LIBRARY\n");
356 abort();
357 }
358#endif
359 const int count = rows * dim;
360 int i = 0;
361#if defined(__AVX512F__)
362 for (; i + 16 <= count; i += 16) {
363 float lanes[16] __attribute__((aligned(64)));
364 for (int lane = 0; lane < 16; ++lane) {
365 lanes[lane] = bf16_to_float(float_to_bf16(x[i + lane]));
366 }
367 const __m512 values = _mm512_load_ps(lanes);
368 const __m512 denominator = _mm512_add_ps(
369 _mm512_set1_ps(1.0f),
370 ck_recurrent_pytorch_expf16(
371 _mm512_sub_ps(_mm512_setzero_ps(), values)));
372 _mm512_storeu_ps(out + i,
373 _mm512_div_ps(_mm512_set1_ps(1.0f), denominator));
374 }
375#endif
376 for (; i < count; ++i) {
377 const float value = bf16_to_float(float_to_bf16(x[i]));
378 out[i] = 1.0f / (1.0f + expf(-value));
379 }
380}
381
382#if defined(__AVX512F__) && defined(__AVX512DQ__)
383/* Match ggml's AVX-512 exp approximation and instruction grouping exactly. */
384static inline __m512 recurrent_ggml_expf_avx512(__m512 x) {
385 const __m512 r = _mm512_set1_ps(0x1.8p23f);
386 const __m512 z = _mm512_fmadd_ps(x, _mm512_set1_ps(0x1.715476p+0f), r);
387 const __m512 n = _mm512_sub_ps(z, r);
388 const __m512 b = _mm512_fnmadd_ps(
389 n, _mm512_set1_ps(0x1.7f7d1cp-20f),
390 _mm512_fnmadd_ps(n, _mm512_set1_ps(0x1.62e4p-1f), x));
391 const __mmask16 d = _mm512_cmp_ps_mask(
392 _mm512_abs_ps(n), _mm512_set1_ps(192.0f), _CMP_GT_OQ);
393 const __m512 u = _mm512_mul_ps(b, b);
394 const __m512 j = _mm512_fmadd_ps(
395 _mm512_fmadd_ps(
396 _mm512_fmadd_ps(
397 _mm512_set1_ps(0x1.0e4020p-7f), b,
398 _mm512_set1_ps(0x1.573e2ep-5f)),
399 u,
400 _mm512_fmadd_ps(
401 _mm512_set1_ps(0x1.555e66p-3f), b,
402 _mm512_set1_ps(0x1.fffdb6p-2f))),
403 u,
404 _mm512_fmadd_ps(
405 _mm512_set1_ps(0x1.ffffecp-1f), b,
406 _mm512_set1_ps(1.0f)));
407 const __m512 res = _mm512_scalef_ps(j, n);
408 if (_mm512_kortestz(d, d)) {
409 return res;
410 }
411 const __m512 zero = _mm512_setzero_ps();
412 const __m512 alt = _mm512_mask_blend_ps(
413 _mm512_cmp_ps_mask(n, zero, _CMP_LE_OQ),
414 _mm512_set1_ps(INFINITY),
415 zero);
416 return _mm512_mask_blend_ps(d, res, alt);
417}
418#endif
419
420#if defined(__AVX2__) && defined(__FMA__)
421/* Match ggml's AVX2 exp approximation exactly; it is the fallback provider ABI. */
422static inline __m256 recurrent_ggml_expf_avx2(__m256 x) {
423 const __m256 r = _mm256_set1_ps(0x1.8p23f);
424 const __m256 z = _mm256_fmadd_ps(x, _mm256_set1_ps(0x1.715476p+0f), r);
425 const __m256 n = _mm256_sub_ps(z, r);
426 const __m256 b = _mm256_fnmadd_ps(
427 n, _mm256_set1_ps(0x1.7f7d1cp-20f),
428 _mm256_fnmadd_ps(n, _mm256_set1_ps(0x1.62e4p-1f), x));
429 const __m256i e = _mm256_slli_epi32(_mm256_castps_si256(z), 23);
430 const __m256 k = _mm256_castsi256_ps(
431 _mm256_add_epi32(e, _mm256_castps_si256(_mm256_set1_ps(1.0f))));
432 const __m256i c = _mm256_castps_si256(
433 _mm256_cmp_ps(_mm256_andnot_ps(_mm256_set1_ps(-0.0f), n),
434 _mm256_set1_ps(126.0f), _CMP_GT_OQ));
435 const __m256 u = _mm256_mul_ps(b, b);
436 const __m256 j = _mm256_fmadd_ps(
437 _mm256_fmadd_ps(
438 _mm256_fmadd_ps(_mm256_set1_ps(0x1.0e4020p-7f), b,
439 _mm256_set1_ps(0x1.573e2ep-5f)),
440 u,
441 _mm256_fmadd_ps(_mm256_set1_ps(0x1.555e66p-3f), b,
442 _mm256_set1_ps(0x1.fffdb6p-2f))),
443 u, _mm256_mul_ps(_mm256_set1_ps(0x1.ffffecp-1f), b));
444 if (!_mm256_movemask_ps(_mm256_castsi256_ps(c))) {
445 return _mm256_fmadd_ps(j, k, k);
446 }
447 const __m256i g = _mm256_and_si256(
448 _mm256_castps_si256(_mm256_cmp_ps(n, _mm256_setzero_ps(), _CMP_LE_OQ)),
449 _mm256_set1_epi32((int) 0x82000000u));
450 const __m256 s1 = _mm256_castsi256_ps(
451 _mm256_add_epi32(g, _mm256_set1_epi32(0x7f000000)));
452 const __m256 s2 = _mm256_castsi256_ps(_mm256_sub_epi32(e, g));
453 const __m256i d = _mm256_castps_si256(
454 _mm256_cmp_ps(_mm256_andnot_ps(_mm256_set1_ps(-0.0f), n),
455 _mm256_set1_ps(192.0f), _CMP_GT_OQ));
456 return _mm256_or_ps(
457 _mm256_and_ps(_mm256_castsi256_ps(d), _mm256_mul_ps(s1, s1)),
458 _mm256_andnot_ps(
459 _mm256_castsi256_ps(d),
460 _mm256_or_ps(
461 _mm256_and_ps(
462 _mm256_castsi256_ps(c),
463 _mm256_mul_ps(_mm256_fmadd_ps(s2, j, s2), s1)),
464 _mm256_andnot_ps(
465 _mm256_castsi256_ps(c), _mm256_fmadd_ps(k, j, k)))));
466}
467#endif
468
469typedef struct {
470 const float *x;
471 float *out;
472 int dim;
473} ck_recurrent_silu_ggml_args_t;
474
476 int end,
477 void *opaque) {
478 const ck_recurrent_silu_ggml_args_t *args =
479 (const ck_recurrent_silu_ggml_args_t *)opaque;
480 const int dim = args->dim;
481 for (int row = begin; row < end; ++row) {
482 const float *x_row = args->x + (size_t)row * (size_t)dim;
483 float *out_row = args->out + (size_t)row * (size_t)dim;
484 int col = 0;
485#if defined(__AVX512F__) && defined(__AVX512DQ__)
486 for (; col + 16 <= dim; col += 16) {
487 const __m512 xv = _mm512_loadu_ps(x_row + col);
488 const __m512 neg = _mm512_sub_ps(_mm512_setzero_ps(), xv);
489 const __m512 denom = _mm512_add_ps(
490 _mm512_set1_ps(1.0f), recurrent_ggml_expf_avx512(neg));
491 _mm512_storeu_ps(out_row + col, _mm512_div_ps(xv, denom));
492 }
493#elif defined(__AVX2__) && defined(__FMA__)
494 for (; col + 8 <= dim; col += 8) {
495 const __m256 xv = _mm256_loadu_ps(x_row + col);
496 const __m256 neg = _mm256_sub_ps(_mm256_setzero_ps(), xv);
497 const __m256 denom = _mm256_add_ps(
498 _mm256_set1_ps(1.0f), recurrent_ggml_expf_avx2(neg));
499 _mm256_storeu_ps(out_row + col, _mm256_div_ps(xv, denom));
500 }
501#endif
502 float (*volatile llama_expf)(float) = expf;
503 for (; col < dim; ++col) {
504 const float xv = x_row[col];
505 out_row[col] = xv / (1.0f + llama_expf(-xv));
506 }
507 }
508}
509
510void recurrent_silu_forward_ggml(const float *x,
511 float *out,
512 int rows,
513 int dim) {
514 if (!x || !out || rows <= 0 || dim <= 0) {
515 return;
516 }
517
518 ck_recurrent_silu_ggml_args_t args = {x, out, dim};
519 const size_t elements = (size_t)rows * (size_t)dim;
520 const size_t minimum_elements_per_thread = 65536u;
521 if (rows < 2 || elements < 2u * minimum_elements_per_thread) {
522 recurrent_silu_forward_ggml_rows(0, rows, &args);
523 return;
524 }
525
526 ck_threadpool_t *pool = ck_threadpool_global();
527 int active = pool ? ck_threadpool_n_threads(pool) : 1;
528 size_t useful_threads =
529 (elements + minimum_elements_per_thread - 1u) /
530 minimum_elements_per_thread;
531 if ((size_t)active > useful_threads) active = (int)useful_threads;
532 if (active > rows) active = rows;
533
534 if (active > 1 && ck_threadpool_thread_id(pool) <= 0) {
536 pool, active, 0, rows, 1,
538 } else {
539 recurrent_silu_forward_ggml_rows(0, rows, &args);
540 }
541}
542
544 float *out,
545 int rows,
546 int dim) {
547 float (*volatile llama_expf)(float) = expf;
548 for (int row = 0; row < rows; ++row) {
549 const float *x_row = x + (size_t) row * (size_t) dim;
550 float *out_row = out + (size_t) row * (size_t) dim;
551 for (int col = 0; col < dim; ++col) {
552 out_row[col] = 1.0f / (1.0f + llama_expf(-x_row[col]));
553 }
554 }
555}
556
557void recurrent_silu_backward(const float *d_out,
558 const float *x,
559 float *d_x,
560 int rows,
561 int dim) {
562 for (int row = 0; row < rows; ++row) {
563 const float *d_out_row = d_out + (size_t) row * (size_t) dim;
564 const float *x_row = x + (size_t) row * (size_t) dim;
565 float *d_x_row = d_x + (size_t) row * (size_t) dim;
566 for (int col = 0; col < dim; ++col) {
567 const float xv = x_row[col];
568 const float sig = recurrent_sigmoid(xv);
569 d_x_row[col] = d_out_row[col] * (sig + xv * sig * (1.0f - sig));
570 }
571 }
572}
#define RTLD_DEFAULT
static uint16_t float_to_bf16(float f)
Definition bf16_utils.h:90
static float bf16_to_float(uint16_t v)
Definition bf16_utils.h:38
Persistent pthread thread pool for CK-Engine inference.
void ck_threadpool_parallel_for_n(ck_threadpool_t *pool, int active_threads, int begin, int end, int grain_size, ck_range_fn_t fn, void *args)
ck_threadpool_t * ck_threadpool_global(void)
int ck_threadpool_thread_id(const ck_threadpool_t *pool)
int ck_threadpool_n_threads(const ck_threadpool_t *pool)
float(* ck_recurrent_libm_f32_fn)(float)
void recurrent_sigmoid_forward_ggml(const float *x, float *out, int rows, int dim)
static ck_recurrent_libm_f32_fn ck_recurrent_llama_logf
void recurrent_silu_forward_pytorch_bf16_input_fp32_output(const float *x, float *out, int rows, int dim)
void recurrent_dt_gate_expanded_forward(const float *alpha, const float *dt_bias, const float *a, float *gate, int rows, int num_heads, int state_dim)
static float recurrent_softplus(float x)
void recurrent_sigmoid_forward_pytorch_bf16_input_fp32_output(const float *x, float *out, int rows, int dim)
void recurrent_silu_forward_ggml(const float *x, float *out, int rows, int dim)
static void * ck_recurrent_libm_handle
static void recurrent_silu_forward_ggml_rows(int begin, int end, void *opaque)
void recurrent_silu_forward(const float *x, float *out, int rows, int dim)
static ck_recurrent_libm_f32_fn ck_recurrent_pytorch_log1pf
void recurrent_silu_forward_pytorch_bf16_storage(const float *x, float *out, int rows, int dim)
static void ck_bind_recurrent_llama_libm(void)
static float recurrent_sigmoid(float x)
void recurrent_dt_gate_forward_pytorch_fp32(const float *alpha, const float *dt_bias, const float *a, float *gate, int rows, int num_heads, int state_dim)
static ck_recurrent_libm_f32_fn ck_recurrent_llama_expf
void recurrent_silu_backward(const float *d_out, const float *x, float *d_x, int rows, int dim)
static pthread_once_t ck_recurrent_libm_once
void recurrent_dt_gate_backward(const float *d_gate, const float *alpha, const float *dt_bias, const float *a, float *d_alpha, float *d_dt_bias, float *d_a, int rows, int dim)
void recurrent_dt_gate_forward(const float *alpha, const float *dt_bias, const float *a, float *gate, int rows, int num_heads, int state_dim)
__attribute__((visibility("default"))) CKTokenizer *ck_tokenizer_create(CKTokenizerType type)
const uint8_t size_t count
Definition true_bpe.h:209
uint32_t end
Definition utf8.c:215
static void silu(float *x, int n)