← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
layout_kernels.c
Go to the documentation of this file.
1/* Exact physical-layout conversions used when no direct-layout provider wins. */
2
3#include <stddef.h>
4#include <string.h>
5
6void ck_layout_token_to_head_f32(const float *src, float *dst,
7 int tokens, int heads, int head_dim)
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}
18
19void ck_layout_head_to_token_f32(const float *src, float *dst,
20 int heads, int tokens, int head_dim)
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}
void ck_layout_token_to_head_f32(const float *src, float *dst, int tokens, int heads, int head_dim)
void ck_layout_head_to_token_f32(const float *src, float *dst, int heads, int tokens, int head_dim)