项目文件夹

文件
wehub-resource-sync ec436095dd
Book-CI / test (macos-latest) (push) Has been cancelled
Book-CI / test (ubuntu-latest) (push) Has been cancelled
Book-CI / test (windows-latest) (push) Has been cancelled
Release Fake Tag / publish (push) Has been cancelled
Deploy / deploy (macos-latest) (push) Has been cancelled
Deploy / deploy (ubuntu-latest) (push) Has been cancelled
Deploy / deploy (windows-latest) (push) Has been cancelled
Release to PyPI / Build & publish sglang-kt (push) Has been cancelled
Release to PyPI / Build kt-kernel (Python 3.11) (push) Has been cancelled
Release to PyPI / Build kt-kernel (Python 3.12) (push) Has been cancelled
Release to PyPI / Publish kt-kernel to PyPI (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:30:03 +08:00

29 行
1015 B
C++

此文件含有模棱两可的 Unicode 字符
此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。
#pragma once
// #include <arm_sve.h>
#include <cstdint>
#include <cstring>
// 简单截断模式:直接丢弃低 16 位
static inline uint16_t float_to_bf16_trunc(float f) {
uint32_t u;
// 按位拷贝,避免 strictaliasing UB
memcpy(&u, &f, sizeof(u)); // :contentReference[oaicite:3]{index=3}
return (uint16_t)(u >> 16); // 截断得到高 16 位 :contentReference[oaicite:4]{index=4}
}
static inline void convert_32fp32_to_32bf16_pure_c(const float* src, uint16_t* dst) {
// src 已偏移至 token_nth * hidden_size
for (int e = 0; e < 32; e++) { // 共 32 个元素
// 选择截断或四舍五入
dst[e] = float_to_bf16_trunc(src[e]);
}
}
// 把 32 个 bf16 元素转换成 32 个 fp32 元素
static inline void convert_32bf16_to_32fp32_pure_c(const uint16_t* src, float* dst) {
for (int e = 0; e < 32; e++) {
uint32_t temp = ((uint32_t)src[e]) << 16; // 将 BF16 左移 16 位
memcpy(&dst[e], &temp, sizeof(float)); // 将结果复制到 FP32 变量中
}
}