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

Go to the source code of this file.

Functions

void ck_layout_head_to_token_f32 (const float *src, float *dst, int heads, int tokens, int head_dim)
 
void ck_layout_token_to_head_f32 (const float *src, float *dst, int tokens, int heads, int head_dim)
 

Function Documentation

◆ ck_layout_head_to_token_f32()

void ck_layout_head_to_token_f32 ( const float *  src,
float *  dst,
int  heads,
int  tokens,
int  head_dim 
)

Definition at line 19 of file layout_kernels.c.

21{
22 if (!src || !dst || heads <= 0 || tokens <= 0 || head_dim <= 0) return;
23 for (int h = 0; h < heads; ++h) {
24 for (int t = 0; t < tokens; ++t) {
25 memcpy(dst + ((size_t)t * (size_t)heads + (size_t)h) * (size_t)head_dim,
26 src + ((size_t)h * (size_t)tokens + (size_t)t) * (size_t)head_dim,
27 (size_t)head_dim * sizeof(float));
28 }
29 }
30}

◆ ck_layout_token_to_head_f32()

void ck_layout_token_to_head_f32 ( const float *  src,
float *  dst,
int  tokens,
int  heads,
int  head_dim 
)

Definition at line 6 of file layout_kernels.c.

8{
9 if (!src || !dst || tokens <= 0 || heads <= 0 || head_dim <= 0) return;
10 for (int t = 0; t < tokens; ++t) {
11 for (int h = 0; h < heads; ++h) {
12 memcpy(dst + ((size_t)h * (size_t)tokens + (size_t)t) * (size_t)head_dim,
13 src + ((size_t)t * (size_t)heads + (size_t)h) * (size_t)head_dim,
14 (size_t)head_dim * sizeof(float));
15 }
16 }
17}