23#if defined(__AVX__) || defined(__AVX2__) || defined(__AVX512F__)
27#if defined(__ARM_NEON) || defined(__aarch64__)
32static inline __m256 rmsnorm_square_avx2_no_contract(__m256 values)
34#if defined(__GNUC__) || defined(__clang__)
36 __asm__
volatile (
"vmulps %1, %1, %0" :
"=x"(squared) :
"x"(values));
41 _Alignas(32) volatile
float materialized[8];
42 _mm256_store_ps((
float *)materialized, _mm256_mul_ps(values, values));
43 return _mm256_load_ps((const
float *)materialized);
47static inline __m256 rmsnorm_add_avx2_ordered(__m256
left, __m256
right)
49#if defined(__GNUC__) || defined(__clang__)
51 __asm__
volatile (
"vaddps %2, %1, %0" :
"=x"(sum) :
"x"(
left),
"x"(
right));
54 _Alignas(32) volatile
float materialized[8];
55 _mm256_store_ps((
float *)materialized, _mm256_add_ps(
left,
right));
56 return _mm256_load_ps((const
float *)materialized);
60static inline __m256 rmsnorm_load_bf16_values_avx2(
const float *values)
62 _Alignas(32) float rounded[8];
63 for (
int lane = 0; lane < 8; ++lane) {
66 return _mm256_load_ps(rounded);
70#if defined(__i386__) || defined(__x86_64__)
71static inline float rmsnorm_div_f32_ordered(
float numerator,
float denominator)
73#if defined(__GNUC__) || defined(__clang__)
75 __asm__
volatile (
"vdivss %2, %1, %0"
77 :
"x"(numerator),
"x"(denominator));
80 volatile float ordered_numerator = numerator;
81 volatile float ordered_denominator = denominator;
82 return ordered_numerator / ordered_denominator;
91#if defined(__ARM_NEON) || defined(__aarch64__)
92static inline float hsum128_ps_rmsnorm(float32x4_t v) {
93 const float32x2_t lo = vget_low_f32(v);
94 const float32x2_t hi = vget_high_f32(v);
95 const float32x2_t sum2 = vadd_f32(lo, hi);
96 return vget_lane_f32(vpadd_f32(sum2, sum2), 0);
101#if defined(__AVX__) && !defined(__AVX512F__)
102static inline float hsum256_ps_rmsnorm(__m256 v) {
104 __m128 hi = _mm256_extractf128_ps(v, 1);
105 __m128 lo = _mm256_castps256_ps128(v);
106 __m128 sum128 = _mm_add_ps(lo, hi);
108 sum128 = _mm_hadd_ps(sum128, sum128);
109 sum128 = _mm_hadd_ps(sum128, sum128);
110 return _mm_cvtss_f32(sum128);
123 const float inv_d = 1.0f / (float)d_model;
124 for (
int t = 0; t < tokens; ++t) {
125 const float *x = input + (size_t)t * (
size_t)input_stride;
126 float *y = output + (size_t)t * (
size_t)output_stride;
129 for (
int d = 0; d < d_model; ++d) {
130 const float v = x[d];
133 const float mean_sq = sum_sq * inv_d;
134 const float rstd = 1.0f / sqrtf(mean_sq + eps);
136 rstd_cache[t] = rstd;
139 for (
int d = 0; d < d_model; ++d) {
140 const float x_hat = x[d] * rstd;
141 y[d] = x_hat * gamma[d];
143 for (
int d = d_model; d < output_stride; ++d) {
149#if defined(__clang__)
151#elif defined(__GNUC__)
152__attribute__((optimize(
"O1,no-tree-vectorize,no-tree-slp-vectorize"), noinline))
160 int aligned_embed_dim,
163 for (
int t = 0; t < tokens; ++t) {
164 const float *x = input + (size_t)t * (
size_t)aligned_embed_dim;
165 float *y = output + (size_t)t * (
size_t)aligned_embed_dim;
169 volatile double sum_sq = 0.0;
170 for (
int d = 0; d < d_model; ++d) {
171 const float square = x[d] * x[d];
172 sum_sq = sum_sq + (double)square;
174 const float mean_sq = (float)(sum_sq / (
double)d_model);
175 const float rstd = 1.0f / sqrtf(mean_sq + eps);
177 rstd_cache[t] = rstd;
179 for (
int d = 0; d < d_model; ++d) {
180 const float normalized = x[d] * rstd;
181 y[d] = normalized * gamma[d];
183 for (
int d = d_model; d < aligned_embed_dim; ++d) {
198#if defined(CK_TARGET_X86)
199 const __m128 value = _mm_set_ss(mean_eps);
200 const __m128 root = _mm_sqrt_ss(value);
201 return _mm_cvtss_f32(_mm_div_ss(_mm_set_ss(1.0f), root));
203 const volatile float root = sqrtf(mean_eps);
208#if defined(__clang__)
210#elif defined(__GNUC__)
211__attribute__((optimize(
"O1,no-tree-vectorize,no-tree-slp-vectorize"), noinline))
219 int aligned_embed_dim,
222 for (
int t = 0; t < tokens; ++t) {
223 const float *x = input + (size_t)t * (
size_t)aligned_embed_dim;
224 float *y = output + (size_t)t * (
size_t)aligned_embed_dim;
225 volatile double sum_sq = 0.0;
226 for (
int d = 0; d < d_model; ++d) {
227 const float square = x[d] * x[d];
228 sum_sq = sum_sq + (double)square;
230 const float mean_sq = (float)(sum_sq / (
double)d_model);
233 rstd_cache[t] = rstd;
235 for (
int d = 0; d < d_model; ++d) {
244 y[d] = x[d] * rstd * gamma[d];
246 for (
int d = d_model; d < aligned_embed_dim; ++d) {
283 for (
int t = 0; t < tokens; ++t) {
284 const float *x = input + (size_t)t * (
size_t)input_stride;
285 float *y = output + (size_t)t * (
size_t)output_stride;
298 for (
int hierarchy = 0; hierarchy < 4; ++hierarchy) {
299 for (
int stream = 0; stream < 4; ++stream) {
300 level[hierarchy][stream] = _mm256_setzero_ps();
304 const int vector_count = d_model / 8;
305 const int cascade_items = vector_count / 4;
307 if (cascade_items > 1) {
309 unsigned int value = (
unsigned int)(cascade_items - 1);
314 const int candidate = ceil_log2 / 4;
315 if (candidate > level_power) level_power = candidate;
317 const int level_step = 1 << level_power;
318 const int level_mask = level_step - 1;
320 for (; item + level_step <= cascade_items;) {
321 for (
int block = 0; block < level_step; ++block, ++item) {
322 for (
int stream = 0; stream < 4; ++stream) {
323 const int offset = (item * 4 + stream) * 8;
324 const __m256 values = rmsnorm_load_bf16_values_avx2(x + offset);
325 const __m256 squared = rmsnorm_square_avx2_no_contract(values);
326 level[0][stream] = rmsnorm_add_avx2_ordered(
327 level[0][stream], squared
331 for (
int hierarchy = 1; hierarchy < 4; ++hierarchy) {
332 for (
int stream = 0; stream < 4; ++stream) {
333 level[hierarchy][stream] = rmsnorm_add_avx2_ordered(
334 level[hierarchy][stream], level[hierarchy - 1][stream]
336 level[hierarchy - 1][stream] = _mm256_setzero_ps();
338 const int mask = level_mask << (hierarchy * level_power);
339 if ((item &
mask) != 0)
break;
342 for (; item < cascade_items; ++item) {
343 for (
int stream = 0; stream < 4; ++stream) {
344 const int offset = (item * 4 + stream) * 8;
345 const __m256 values = rmsnorm_load_bf16_values_avx2(x + offset);
346 const __m256 squared = rmsnorm_square_avx2_no_contract(values);
347 level[0][stream] = rmsnorm_add_avx2_ordered(
348 level[0][stream], squared
352 for (
int hierarchy = 1; hierarchy < 4; ++hierarchy) {
353 for (
int stream = 0; stream < 4; ++stream) {
354 level[0][stream] = rmsnorm_add_avx2_ordered(
355 level[0][stream], level[hierarchy][stream]
359 __m256 reduced = level[0][0];
360 for (
int stream = 1; stream < 4; ++stream) {
361 reduced = rmsnorm_add_avx2_ordered(reduced, level[0][stream]);
363 d = cascade_items * 4 * 8;
364 for (; d + 8 <= d_model; d += 8) {
365 const __m256 values = rmsnorm_load_bf16_values_avx2(x + d);
366 const __m256 squared = rmsnorm_square_avx2_no_contract(values);
367 reduced = rmsnorm_add_avx2_ordered(reduced, squared);
369 _Alignas(32)
float lanes[8];
370 _mm256_store_ps(lanes, reduced);
371 volatile float ordered_sum = 0.0f;
372 for (
int lane = 0; lane < 8; ++lane) {
373 ordered_sum = ordered_sum + lanes[lane];
375 sum_sq = ordered_sum;
376 for (; d < d_model; ++d) {
378 sum_sq += value * value;
381 for (
int d = 0; d < d_model; ++d) {
383 sum_sq += value * value;
387#if defined(__i386__) || defined(__x86_64__)
388 const float variance = rmsnorm_div_f32_ordered(sum_sq, (
float)d_model);
389 const float rstd = use_pow_inverse
390 ? powf(variance + eps, -0.5f)
391 : rmsnorm_div_f32_ordered(1.0f, sqrtf(variance + eps));
393 const float variance = sum_sq / (float)d_model;
394 const float rstd = use_pow_inverse
395 ? powf(variance + eps, -0.5f)
396 : 1.0f / sqrtf(variance + eps);
398 if (rstd_cache) rstd_cache[t] = rstd;
399 for (
int d = 0; d < d_model; ++d) {
401 if (weight_mode == 3) {
405 }
else if (weight_mode == 2) {
409 (value * rstd) * (1.0f + gamma[d])));
410 }
else if (weight_mode == 1) {
413 (value * rstd) * gamma[d]));
417 const float normalized =
422 for (
int d = d_model; d < output_stride; ++d) y[d] = 0.0f;
432 int aligned_embed_dim,
436 input, gamma, output, rstd_cache, tokens, d_model,
437 aligned_embed_dim, aligned_embed_dim, eps, 0, 0);
451 input, gamma, output, rstd_cache, tokens, d_model,
452 input_stride, output_stride, eps, 0, 0);
462 int aligned_embed_dim,
466 input, gamma, output, rstd_cache, tokens, d_model,
467 aligned_embed_dim, aligned_embed_dim, eps, 1, 0);
472 const float *zero_centered_weight,
477 int aligned_embed_dim,
481 input, zero_centered_weight, output, rstd_cache, tokens, d_model,
482 aligned_embed_dim, aligned_embed_dim, eps, 2, 0);
492 int aligned_embed_dim,
496 input, weight, output, rstd_cache, tokens, d_model,
497 aligned_embed_dim, aligned_embed_dim, eps, 1, 0);
506 int aligned_embed_dim,
510 input, NULL, output, rstd_cache, tokens, d_model,
511 aligned_embed_dim, aligned_embed_dim, eps, 3, 0);
517 const float *rstd_cache,
522 int aligned_embed_dim)
524 const float inv_d = 1.0f / (float)d_model;
525 for (
int d = 0; d < d_model; ++d) {
529 for (
int t = 0; t < tokens; ++t) {
530 const float *x = input + (size_t)t * (
size_t)aligned_embed_dim;
531 const float *dY = d_output + (size_t)t * (
size_t)aligned_embed_dim;
532 float *dX = d_input + (size_t)t * (
size_t)aligned_embed_dim;
533 const float rstd = rstd_cache[t];
535 float sum_dY_g_xhat = 0.0f;
536 for (
int d = 0; d < d_model; ++d) {
537 const float x_hat = x[d] * rstd;
538 const float grad_x_hat = dY[d] * gamma[d];
539 sum_dY_g_xhat += x_hat * grad_x_hat;
542 for (
int d = 0; d < d_model; ++d) {
543 const float x_hat = x[d] * rstd;
544 const float grad_x_hat = dY[d] * gamma[d];
545 dX[d] = (grad_x_hat - (x_hat * inv_d) * sum_dY_g_xhat) * rstd;
546 d_gamma[d] += dY[d] * x_hat;
548 for (
int d = d_model; d < aligned_embed_dim; ++d) {
580 const char *exact_env = getenv(
"CK_RMSNORM_EXACT");
583 input, gamma, output, rstd_cache, T, D, input_stride, output_stride, eps
588 for (
int t = 0; t < T; ++t) {
589 const float *x = input + (size_t)t * (
size_t)input_stride;
590 float *y = output + (size_t)t * (
size_t)output_stride;
592#if defined(__AVX512F__)
594 __m512 sum_sq_vec = _mm512_setzero_ps();
598 for (; d + 16 <= D; d += 16) {
599 __m512 xv = _mm512_loadu_ps(&x[d]);
600 sum_sq_vec = _mm512_fmadd_ps(xv, xv, sum_sq_vec);
602 float sum_sq = _mm512_reduce_add_ps(sum_sq_vec);
606 sum_sq += x[d] * x[d];
609 float mean_sq = sum_sq / (float)D;
610 float rstd = 1.0f / sqrtf(mean_sq + eps);
612 rstd_cache[t] = rstd;
616 __m512 rstd_vec = _mm512_set1_ps(rstd);
618 for (; d + 16 <= D; d += 16) {
619 __m512 xv = _mm512_loadu_ps(&x[d]);
620 __m512 gv = _mm512_loadu_ps(&gamma[d]);
621 __m512 x_hat = _mm512_mul_ps(xv, rstd_vec);
622 __m512 yv = _mm512_mul_ps(x_hat, gv);
623 _mm512_storeu_ps(&y[d], yv);
627 y[d] = x[d] * rstd * gamma[d];
630#elif defined(__AVX__)
632 __m256 sum_sq_vec = _mm256_setzero_ps();
636 for (; d + 8 <= D; d += 8) {
637 __m256 xv = _mm256_loadu_ps(&x[d]);
638 __m256 xv_sq = _mm256_mul_ps(xv, xv);
639 sum_sq_vec = _mm256_add_ps(sum_sq_vec, xv_sq);
641 float sum_sq = hsum256_ps_rmsnorm(sum_sq_vec);
645 sum_sq += x[d] * x[d];
648 float mean_sq = sum_sq / (float)D;
649 float rstd = 1.0f / sqrtf(mean_sq + eps);
651 rstd_cache[t] = rstd;
655 __m256 rstd_vec = _mm256_set1_ps(rstd);
657 for (; d + 8 <= D; d += 8) {
658 __m256 xv = _mm256_loadu_ps(&x[d]);
659 __m256 gv = _mm256_loadu_ps(&gamma[d]);
660 __m256 x_hat = _mm256_mul_ps(xv, rstd_vec);
661 __m256 yv = _mm256_mul_ps(x_hat, gv);
662 _mm256_storeu_ps(&y[d], yv);
666 y[d] = x[d] * rstd * gamma[d];
669#elif defined(__ARM_NEON) || defined(__aarch64__)
675 float32x4_t sum_sq_vec = vdupq_n_f32(0.0f);
678 for (; d + 4 <= D; d += 4) {
679 const float32x4_t xv = vld1q_f32(&x[d]);
680 sum_sq_vec = vfmaq_f32(sum_sq_vec, xv, xv);
682 float sum_sq = hsum128_ps_rmsnorm(sum_sq_vec);
685 sum_sq += x[d] * x[d];
688 float mean_sq = sum_sq / (float)D;
689 float rstd = 1.0f / sqrtf(mean_sq + eps);
691 rstd_cache[t] = rstd;
694 const float32x4_t rstd_vec = vdupq_n_f32(rstd);
696 for (; d + 4 <= D; d += 4) {
697 const float32x4_t xv = vld1q_f32(&x[d]);
698 const float32x4_t gv = vld1q_f32(&gamma[d]);
701 const float32x4_t x_hat = vmulq_f32(xv, rstd_vec);
702 vst1q_f32(&y[d], vmulq_f32(x_hat, gv));
705 y[d] = x[d] * rstd * gamma[d];
711 for (
int d = 0; d < D; ++d) {
715 float mean_sq = sum_sq / (float)D;
716 float rstd = 1.0f / sqrtf(mean_sq + eps);
718 rstd_cache[t] = rstd;
722 for (
int d = 0; d < D; ++d) {
723 float x_hat = x[d] * rstd;
724 y[d] = x_hat * gamma[d];
729 for (
int d = D; d < output_stride; ++d) {
741 int aligned_embed_dim,
763 int aligned_embed_dim,
766 rmsnorm_forward(input, gamma, output, rstd_cache, tokens, d_model, aligned_embed_dim, eps);
774 int aligned_embed_dim,
777 if (!input || !output || tokens <= 0 || d_model <= 0 || aligned_embed_dim <= 0) {
780 const float inv_d = 1.0f / (float)d_model;
781 for (
int t = 0; t < tokens; ++t) {
782 const float *x = input + (size_t)t * (
size_t)aligned_embed_dim;
783 float *y = output + (size_t)t * (
size_t)aligned_embed_dim;
785 for (
int d = 0; d < d_model; ++d) {
786 sum_sq += (double)x[d] * (
double)x[d];
788 const float rstd = 1.0f / sqrtf((
float)(sum_sq * (
double)inv_d) + eps);
790 rstd_cache[t] = rstd;
792 for (
int d = 0; d < d_model; ++d) {
795 for (
int d = d_model; d < aligned_embed_dim; ++d) {
801#if defined(__clang__)
803#elif defined(__GNUC__)
804__attribute__((optimize(
"O1,no-tree-vectorize,no-tree-slp-vectorize"), noinline))
811 int aligned_embed_dim,
814 if (!input || !output || tokens <= 0 || d_model <= 0 || aligned_embed_dim < d_model) {
817 for (
int t = 0; t < tokens; ++t) {
818 const float *x = input + (size_t)t * (
size_t)aligned_embed_dim;
819 float *y = output + (size_t)t * (
size_t)aligned_embed_dim;
820 volatile double sum_sq = 0.0;
821 for (
int d = 0; d < d_model; ++d) {
822 const float square = x[d] * x[d];
823 sum_sq = sum_sq + (double)square;
825 const float mean_sq = (float)(sum_sq / (
double)d_model);
828 rstd_cache[t] = rstd;
830 for (
int d = 0; d < d_model; ++d) {
833 for (
int d = d_model; d < aligned_embed_dim; ++d) {
847 if (!input || !output || tokens <= 0 || num_kv_heads <= 0 || head_dim <= 0) {
851 input, output, rstd_cache,
852 tokens * num_kv_heads, head_dim, head_dim, eps);
861 const char *exact_env = getenv(
"CK_RMSNORM_EXACT");
863 return "rmsnorm_strict_scalar";
865#if defined(__AVX512F__)
866 return "rmsnorm_avx512";
867#elif defined(__AVX__)
868 return "rmsnorm_avx";
869#elif defined(__ARM_NEON) || defined(__aarch64__)
870 return "rmsnorm_neon";
872 return "rmsnorm_scalar";
891 const float *rstd_cache,
896 int aligned_embed_dim)
900 int aligned = aligned_embed_dim;
908#if defined(__AVX512F__)
911 for (; d + 16 <= D; d += 16) {
912 _mm512_storeu_ps(&d_gamma[d], _mm512_setzero_ps());
918#elif defined(__AVX__)
921 for (; d + 8 <= D; d += 8) {
922 _mm256_storeu_ps(&d_gamma[d], _mm256_setzero_ps());
929 for (
int d = 0; d < D; ++d) {
934 for (
int t = 0; t < T; ++t) {
935 const float *x = input + (size_t)t * aligned;
936 const float *dY = d_output + (size_t)t * aligned;
937 float *dX = d_input + (size_t)t * aligned;
939 float rstd = rstd_cache[t];
941#if defined(__AVX512F__)
943 __m512 rstd_vec = _mm512_set1_ps(rstd);
944 __m512 sum_vec = _mm512_setzero_ps();
947 for (; d + 16 <= D; d += 16) {
948 __m512 xv = _mm512_loadu_ps(&x[d]);
949 __m512 dyv = _mm512_loadu_ps(&dY[d]);
950 __m512 gv = _mm512_loadu_ps(&gamma[d]);
951 __m512 x_hat = _mm512_mul_ps(xv, rstd_vec);
953 __m512 prod = _mm512_mul_ps(dyv, gv);
954 sum_vec = _mm512_fmadd_ps(prod, x_hat, sum_vec);
956 float sum_dY_g_xhat = _mm512_reduce_add_ps(sum_vec);
960 float x_hat = x[d] * rstd;
961 sum_dY_g_xhat += dY[d] * gamma[d] * x_hat;
963 float m = sum_dY_g_xhat / (float)D;
966 __m512 m_vec = _mm512_set1_ps(m);
968 for (; d + 16 <= D; d += 16) {
969 __m512 xv = _mm512_loadu_ps(&x[d]);
970 __m512 dyv = _mm512_loadu_ps(&dY[d]);
971 __m512 gv = _mm512_loadu_ps(&gamma[d]);
972 __m512 dgv = _mm512_loadu_ps(&d_gamma[d]);
974 __m512 x_hat = _mm512_mul_ps(xv, rstd_vec);
977 __m512 dy_g = _mm512_mul_ps(dyv, gv);
978 __m512 xhat_m = _mm512_mul_ps(x_hat, m_vec);
979 __m512 diff = _mm512_sub_ps(dy_g, xhat_m);
980 __m512 dxv = _mm512_mul_ps(rstd_vec, diff);
981 _mm512_storeu_ps(&dX[d], dxv);
984 dgv = _mm512_fmadd_ps(dyv, x_hat, dgv);
985 _mm512_storeu_ps(&d_gamma[d], dgv);
989 float x_hat = x[d] * rstd;
991 dX[d] = rstd * (dy * gamma[d] - x_hat * m);
992 d_gamma[d] += dy * x_hat;
995#elif defined(__AVX__)
997 __m256 rstd_vec = _mm256_set1_ps(rstd);
998 __m256 sum_vec = _mm256_setzero_ps();
1001 for (; d + 8 <= D; d += 8) {
1002 __m256 xv = _mm256_loadu_ps(&x[d]);
1003 __m256 dyv = _mm256_loadu_ps(&dY[d]);
1004 __m256 gv = _mm256_loadu_ps(&gamma[d]);
1005 __m256 x_hat = _mm256_mul_ps(xv, rstd_vec);
1007 __m256 prod = _mm256_mul_ps(dyv, gv);
1008 __m256 prod2 = _mm256_mul_ps(prod, x_hat);
1009 sum_vec = _mm256_add_ps(sum_vec, prod2);
1011 float sum_dY_g_xhat = hsum256_ps_rmsnorm(sum_vec);
1014 for (; d < D; ++d) {
1015 float x_hat = x[d] * rstd;
1016 sum_dY_g_xhat += dY[d] * gamma[d] * x_hat;
1018 float m = sum_dY_g_xhat / (float)D;
1021 __m256 m_vec = _mm256_set1_ps(m);
1023 for (; d + 8 <= D; d += 8) {
1024 __m256 xv = _mm256_loadu_ps(&x[d]);
1025 __m256 dyv = _mm256_loadu_ps(&dY[d]);
1026 __m256 gv = _mm256_loadu_ps(&gamma[d]);
1027 __m256 dgv = _mm256_loadu_ps(&d_gamma[d]);
1029 __m256 x_hat = _mm256_mul_ps(xv, rstd_vec);
1032 __m256 dy_g = _mm256_mul_ps(dyv, gv);
1033 __m256 xhat_m = _mm256_mul_ps(x_hat, m_vec);
1034 __m256 diff = _mm256_sub_ps(dy_g, xhat_m);
1035 __m256 dxv = _mm256_mul_ps(rstd_vec, diff);
1036 _mm256_storeu_ps(&dX[d], dxv);
1039 __m256 dy_xhat = _mm256_mul_ps(dyv, x_hat);
1040 dgv = _mm256_add_ps(dgv, dy_xhat);
1041 _mm256_storeu_ps(&d_gamma[d], dgv);
1044 for (; d < D; ++d) {
1045 float x_hat = x[d] * rstd;
1047 dX[d] = rstd * (dy * gamma[d] - x_hat * m);
1048 d_gamma[d] += dy * x_hat;
1054 float sum_dY_g_xhat = 0.0f;
1055 for (
int d = 0; d < D; ++d) {
1056 float x_hat = x[d] * rstd;
1057 sum_dY_g_xhat += dY[d] * gamma[d] * x_hat;
1059 float m = sum_dY_g_xhat / (float)D;
1062 for (
int d = 0; d < D; ++d) {
1063 float x_hat = x[d] * rstd;
1065 dX[d] = rstd * (dy * gamma[d] - x_hat * m);
1066 d_gamma[d] += dy * x_hat;
1071 for (
int d = D; d < aligned; ++d) {
static uint16_t float_to_bf16(float f)
static float bf16_to_float(uint16_t v)
int ck_strict_parity_enabled(void)
void rmsnorm_forward_no_weight(const float *input, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
void rmsnorm_forward_fp64_sum(const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
void rmsnorm_forward_qwen3next_pytorch_bf16_storage(const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
void rmsnorm_forward_llama_production(const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
void rmsnorm_forward_muse_weighted_pytorch_bf16_storage(const float *input, const float *weight, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
void rmsnorm_forward_muse_unweighted_pytorch_bf16_storage(const float *input, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
static void rmsnorm_forward_strict_scalar(const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int input_stride, int output_stride, float eps)
void rmsnorm_forward_pytorch_bf16_storage(const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
void rmsnorm_forward(const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
void rmsnorm_forward_strided_f32(const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int input_stride, int output_stride, float eps)
void rmsnorm_forward_kv_lora(const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
void gemma4_v_norm_forward(const float *input, float *output, float *rstd_cache, int tokens, int num_kv_heads, int head_dim, float eps)
static void rmsnorm_backward_strict_scalar(const float *d_output, const float *input, const float *gamma, const float *rstd_cache, float *d_input, float *d_gamma, int tokens, int d_model, int aligned_embed_dim)
void rmsnorm_forward_strided_pytorch_bf16_storage(const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int input_stride, int output_stride, float eps)
const char * ck_rmsnorm_provider_name(void)
void rmsnorm_backward(const float *d_output, const float *input, const float *gamma, const float *rstd_cache, float *d_input, float *d_gamma, int tokens, int d_model, int aligned_embed_dim)
static void rmsnorm_forward_pytorch_bf16_storage_impl(const float *input, const float *gamma, float *output, float *rstd_cache, int tokens, int d_model, int input_stride, int output_stride, float eps, int weight_mode, int use_pow_inverse)
static float rmsnorm_llama_production_rstd(float mean_eps)
void rmsnorm_forward_muse_centered_pytorch_bf16_storage(const float *input, const float *zero_centered_weight, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
void rmsnorm_forward_no_weight_llama_production(const float *input, float *output, float *rstd_cache, int tokens, int d_model, int aligned_embed_dim, float eps)
int32_t int32_t int32_t int32_t int32_t mask
__attribute__((visibility("default"))) CKTokenizer *ck_tokenizer_create(CKTokenizerType type)
const char const char * right