【训练营】BF16 Kernel 优化 - #230
Open
shsaihdsaiudh wants to merge 2 commits into
Open
shsaihdsaiudh wants to merge 2 commits into
shsaihdsaiudh wants to merge 2 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
2026 夏季训练营项目阶段提交(选题一:BF16 核函数优化),ID: yangyeyuan。
本 PR 包含两个提交:
a3a44b8(可配置 CUDA 架构等构建设置,优化代码的依赖)+663b9f2(BF16 训练核函数优化本体)。完整总结报告(含优化历程、ncu/nsys 分析):projects/bf16_kernel_opt/docs/report.zh-CN.md,PyTorch 对照基线与 profiler 原始数据在同目录results/下。优化内容概览
elementwise.cu):删除病态的 TwoPassHist(工作区流量达真实数据 6–12 倍),改为形态分类 + 共享内存 FP32 直方图行广播 kernel + warp 归约列广播 kernel,128-bit 向量化。bf16 行广播提速 19.5–86×,反超 PyTorch 约 2×。cuda_guard_impl.cc):pincudaMemPoolAttrReleaseThreshold=UINT64_MAX,消除 profiler 同步后 WSL2 物理页重映射(单项 BF16 步时 -32%)。gelu.cu+autograd::NewGELU):消灭被 FP32 化的 7-pass GELU 链,与 PyTorchgelu(tanh)舍入点对齐,bf16 前向与旧链逐位一致。embedding.cu):1 block → block-per-token + float4 原子加,4.6 ms → 0.41 ms/步(11×)。端到端结果(GPT2 124M,batch 4×seq 64,30 步中位)
优化前 profiler 开启时 BF16 反而比 FP32 慢 5%(cast 风暴 × 逐 kernel 同步的开销放大);优化后各配置下 BF16 均快于 FP32,FP32 性能无明显下降。微基准正确性检查全 PASS,详细数据与分析见报告。