← Back to C-Kernel-Engine Docs Doxygen Source Documentation
Loading...
Searching...
No Matches
frame_token_grid_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_frame_token_grid_bf16_checked (const uint16_t *grid, const uint16_t *newline, const uint16_t *separator, uint16_t *out, size_t input_elements, size_t output_elements, size_t height, size_t width, size_t channels)
static int overlaps (const uint16_t *a, size_t n, const uint16_t *b, size_t m)
static int valid (const uint16_t *p, size_t elements)

Function Documentation

◆ ck_frame_token_grid_bf16_checked()

int ck_frame_token_grid_bf16_checked ( const uint16_t * grid,
const uint16_t * newline,
const uint16_t * separator,
uint16_t * out,
size_t input_elements,
size_t output_elements,
size_t height,
size_t width,
size_t channels )

Definition at line 17 of file frame_token_grid_bf16_checked.c.

20{
21 if (!height || height > 64 || !width || width > 64 || !channels || channels > 4096 ||
22 input_elements != height*width*channels ||
23 output_elements != (height*(width+1)+1)*channels)
24 return -2;
25 if (!valid(grid,input_elements) || !valid(newline,channels) || !valid(separator,channels) ||
26 !valid(out,output_elements) || overlaps(out,output_elements,grid,input_elements) ||
27 overlaps(out,output_elements,newline,channels) || overlaps(out,output_elements,separator,channels))
28 return -1;
29 for (size_t y = 0; y < height; ++y) {
30 memcpy(out+y*(width+1)*channels,grid+y*width*channels,width*channels*sizeof(*grid));
31 memcpy(out+(y*(width+1)+width)*channels,newline,channels*sizeof(*newline));
32 }
33 memcpy(out+height*(width+1)*channels,separator,channels*sizeof(*separator));
34 return 0;
35}
static int overlaps(const uint16_t *a, size_t n, const uint16_t *b, size_t m)
static int valid(const uint16_t *p, size_t elements)

References overlaps(), and valid().

◆ overlaps()

int overlaps ( const uint16_t * a,
size_t n,
const uint16_t * b,
size_t m )
static

Definition at line 11 of file frame_token_grid_bf16_checked.c.

12{
13 return (uintptr_t)a < (uintptr_t)b+m*sizeof(*b) &&
14 (uintptr_t)b < (uintptr_t)a+n*sizeof(*a);
15}

Referenced by ck_frame_token_grid_bf16_checked().

◆ valid()

int valid ( const uint16_t * p,
size_t elements )
static

Definition at line 5 of file frame_token_grid_bf16_checked.c.

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

Referenced by ck_frame_token_grid_bf16_checked(), deepseek_csa_attention_f32(), gated_deltanet_chunked_prefill(), pointwise_range(), and project_panels().