← Back to C-Kernel-Engine Docs Doxygen Source Documentation
Loading...
Searching...
No Matches
message_control_rows_checked.c File Reference
#include "checked_float_buffer.h"
#include <float.h>
#include <string.h>

Go to the source code of this file.

Functions

int concat_feature_rows_checked_f32 (const float *left, size_t left_elements, const float *right, size_t right_elements, float *output, size_t output_elements, size_t rows, size_t left_width, size_t right_width, size_t width)
int message_control_rows_checked_f32 (const float *input, size_t input_elements, const float *message, size_t message_elements, const float *forget, size_t forget_elements, const float *gain, size_t gain_elements, float *output, size_t output_elements, size_t elements)
static double mix (float input, float message, float forget, float gain)
int rms_pair_concat_rows_checked_f32 (const float *left, size_t left_elements, const float *right, size_t right_elements, float *output, size_t output_elements, size_t rows, size_t width, size_t joined_width, float epsilon)

Function Documentation

◆ concat_feature_rows_checked_f32()

int concat_feature_rows_checked_f32 ( const float * left,
size_t left_elements,
const float * right,
size_t right_elements,
float * output,
size_t output_elements,
size_t rows,
size_t left_width,
size_t right_width,
size_t width )

Definition at line 68 of file message_control_rows_checked.c.

72{
73 size_t l, r, o;
74 if (!left_width || !right_width || left_width > SIZE_MAX - right_width ||
75 width != left_width + right_width ||
76 !ck_checked_span(rows, left_width, left_width, &l) ||
77 !ck_checked_span(rows, right_width, right_width, &r) ||
78 !ck_checked_span(rows, width, width, &o) ||
79 left_elements < l || right_elements < r || output_elements < o) return -2;
81 !ck_checked_region(output, o) || ck_checked_overlap(left, l, output, o) ||
82 ck_checked_overlap(right, r, output, o)) return -1;
83 if (!ck_checked_finite(left, l) || !ck_checked_finite(right, r)) return -3;
84 for (size_t row = 0; row < rows; ++row) {
85 memcpy(output + row * width, left + row * left_width, left_width * sizeof(float));
86 memcpy(output + row * width + left_width, right + row * right_width, right_width * sizeof(float));
87 }
88 return 0;
89}
static int ck_checked_finite(const float *ptr, size_t n)
static int ck_checked_span(size_t rows, size_t width, size_t stride, size_t *span)
static int ck_checked_region(const float *ptr, size_t n)
static int ck_checked_overlap(const float *a, size_t na, const float *b, size_t nb)
const char * left
Definition true_bpe.h:140
const char const char * right
Definition true_bpe.h:141

References ck_checked_finite(), ck_checked_overlap(), ck_checked_region(), ck_checked_span(), left, and right.

◆ message_control_rows_checked_f32()

int message_control_rows_checked_f32 ( const float * input,
size_t input_elements,
const float * message,
size_t message_elements,
const float * forget,
size_t forget_elements,
const float * gain,
size_t gain_elements,
float * output,
size_t output_elements,
size_t elements )

Definition at line 43 of file message_control_rows_checked.c.

48{
49 if (!elements || input_elements < elements || message_elements < elements ||
50 forget_elements < elements || gain_elements < elements || output_elements < elements)
51 return -2;
52 if (!ck_checked_region(output, elements)) return -1;
53 const float *inputs[] = {input, message, forget, gain};
54 for (size_t i = 0; i < sizeof(inputs) / sizeof(inputs[0]); ++i) {
55 if (!ck_checked_region(inputs[i], elements) ||
56 ck_checked_overlap(inputs[i], elements, output, elements)) return -1;
57 if (!ck_checked_finite(inputs[i], elements)) return -3;
58 }
59 for (size_t i = 0; i < elements; ++i) {
60 if (fabsf(forget[i]) > 1.0f || fabsf(gain[i]) > 1.0f ||
61 fabs(mix(input[i], message[i], forget[i], gain[i])) > FLT_MAX) return -3;
62 }
63 for (size_t i = 0; i < elements; ++i)
64 output[i] = (float)mix(input[i], message[i], forget[i], gain[i]);
65 return 0;
66}
static double mix(float input, float message, float forget, float gain)

References ck_checked_finite(), ck_checked_overlap(), ck_checked_region(), and mix().

◆ mix()

double mix ( float input,
float message,
float forget,
float gain )
static

Definition at line 38 of file message_control_rows_checked.c.

39{
40 return (1.0 - (double)forget) * input + (double)gain * message;
41}

Referenced by deepseek_mhc_mix_backward_f32(), deepseek_mhc_mix_f32(), farskip_swiglu_shared_combine_pytorch_bf16_storage_parallel_dispatch(), and message_control_rows_checked_f32().

◆ rms_pair_concat_rows_checked_f32()

int rms_pair_concat_rows_checked_f32 ( const float * left,
size_t left_elements,
const float * right,
size_t right_elements,
float * output,
size_t output_elements,
size_t rows,
size_t width,
size_t joined_width,
float epsilon )

Definition at line 6 of file message_control_rows_checked.c.

10{
11 size_t elements, joined;
12 if (!width || width > SIZE_MAX / 2 || joined_width != width * 2 ||
13 !isfinite(epsilon) || epsilon <= 0.0f ||
14 !ck_checked_span(rows, width, width, &elements) ||
15 !ck_checked_span(rows, joined_width, joined_width, &joined) ||
16 left_elements < elements || right_elements < elements || output_elements < joined)
17 return -2;
18 if (!ck_checked_region(left, elements) || !ck_checked_region(right, elements) ||
19 !ck_checked_region(output, joined) ||
20 ck_checked_overlap(left, elements, output, joined) ||
21 ck_checked_overlap(right, elements, output, joined)) return -1;
22 if (!ck_checked_finite(left, elements) || !ck_checked_finite(right, elements)) return -3;
23
24 for (size_t row = 0; row < rows; ++row) {
25 const float *inputs[] = {left + row * width, right + row * width};
26 for (size_t side = 0; side < 2; ++side) {
27 const float *x = inputs[side];
28 double squared = 0.0;
29 for (size_t i = 0; i < width; ++i) squared += (double)x[i] * x[i];
30 const double scale = 1.0 / sqrt(squared / (double)width + epsilon);
31 for (size_t i = 0; i < width; ++i)
32 output[row * joined_width + side * width + i] = (float)(x[i] * scale);
33 }
34 }
35 return 0;
36}

References ck_checked_finite(), ck_checked_overlap(), ck_checked_region(), ck_checked_span(), left, and right.