← Back to C-Kernel-Engine Docs Doxygen Source Documentation
Loading...
Searching...
No Matches
concat_features_bf16_checked.c File Reference
#include <stddef.h>
#include <stdint.h>
#include <string.h>

Go to the source code of this file.

Functions

int ck_concat_features_bf16_checked (const uint16_t *left, const uint16_t *right, uint16_t *out, size_t rows, size_t left_width, size_t right_width, size_t left_elements, size_t right_elements, size_t out_elements, size_t out_width)
static int overlaps (const uint16_t *out, size_t out_elements, const uint16_t *in, size_t in_elements)
static int valid_span (const uint16_t *data, size_t elements)

Function Documentation

◆ ck_concat_features_bf16_checked()

int ck_concat_features_bf16_checked ( const uint16_t * left,
const uint16_t * right,
uint16_t * out,
size_t rows,
size_t left_width,
size_t right_width,
size_t left_elements,
size_t right_elements,
size_t out_elements,
size_t out_width )

Definition at line 18 of file concat_features_bf16_checked.c.

23{
24 if (!rows || !left_width || !right_width || left_width > SIZE_MAX - right_width)
25 return -2;
26 const size_t width = left_width + right_width;
27 if (out_width != width || rows > SIZE_MAX / width || left_elements != rows * left_width ||
28 right_elements != rows * right_width || out_elements != rows * width)
29 return -2;
30 if (!valid_span(left, left_elements) || !valid_span(right, right_elements) ||
31 !valid_span(out, out_elements) || overlaps(out, out_elements, left, left_elements) ||
32 overlaps(out, out_elements, right, right_elements))
33 return -1;
34 for (size_t row = 0; row < rows; ++row) {
35 memcpy(out + row * width, left + row * left_width, left_width * sizeof(*out));
36 memcpy(out + row * width + left_width, right + row * right_width, right_width * sizeof(*out));
37 }
38 return 0;
39}
static int valid_span(const uint16_t *data, size_t elements)
static int overlaps(const uint16_t *out, size_t out_elements, const uint16_t *in, size_t in_elements)
const char * left
Definition true_bpe.h:140
const char const char * right
Definition true_bpe.h:141

References left, overlaps(), right, and valid_span().

◆ overlaps()

int overlaps ( const uint16_t * out,
size_t out_elements,
const uint16_t * in,
size_t in_elements )
static

Definition at line 11 of file concat_features_bf16_checked.c.

13{
14 return (uintptr_t)out < (uintptr_t)in + in_elements * sizeof(*in) &&
15 (uintptr_t)in < (uintptr_t)out + out_elements * sizeof(*out);
16}

Referenced by ck_concat_features_bf16_checked().

◆ valid_span()

int valid_span ( const uint16_t * data,
size_t elements )
static

Definition at line 5 of file concat_features_bf16_checked.c.

6{
7 return data && (uintptr_t)data % _Alignof(uint16_t) == 0 &&
8 elements <= (UINTPTR_MAX - (uintptr_t)data) / sizeof(*data);
9}

Referenced by ck_concat_features_bf16_checked().