已合并
feat: 北林数据结构-课外实验4.1-低精度矩阵乘法优化实验 #500
feat: 北林数据结构-课外实验4.1-低精度矩阵乘法优化实验 #500
已合并
Lexie创建于 7月31日
Lexie
Lexie
7月31日

描述

在“面向高性能计算的数据结构”课程中新增第四章“算子开发”的课内实验 04.01“低精度矩阵乘法优化实验”。

本实验围绕稠密矩阵乘法 GEMM 展开,首先在 CPU 上实现串行 FP64 GEMM,作为正确性和性能基线;随后基于 Ascend C 静态 Tensor 编程方式,在昇腾 NPU 的 AI Vector 核上分别实现 FP32 和 FP16 GEMM,比较不同计算精度对数据存储、数据搬运、数值误差和执行性能的影响。

实验主要包含以下内容:

  • 在 Host 侧生成确定性的 FP64 输入矩阵,并从同一组输入分别转换得到 FP32 和 FP16 数据;
  • 使用 CPU FP64 串行 GEMM 生成参考结果;
  • 在 AI Vector 核上实现 FP32 和 FP16 GEMM;
  • 使用行方向任务划分、列方向分块和多核并行完成矩阵计算;
  • FP32 和 FP16 核函数分别保持对应精度的乘法、累加和输出;
  • 使用最大绝对误差和最大相对误差验证低精度计算结果;
  • 使用端到端总时间和相对 CPU FP64 基线的加速比分析性能;
  • Notebook 通过 %%writefile 生成完整实验工程,包括公共源码、Host 程序、Device 核函数、CMake 配置和运行脚本。

FP32 与 FP16 实现采用相同的 Vector 计算流程,但根据数据类型和数据搬运对齐要求使用不同的分块参数:

  • FP32:行块大小为 8,连续搬运按照 8 个元素对齐;
  • FP16:行块大小为 16,连续搬运按照 16 个元素对齐;
  • 正式实验矩阵规模为 (M=N=K=4096);
  • 随机种子为 20260717
  • NPU 核函数预热 5 次,重复运行 30 次。

关联的Issue

无。

测试

Notebook 检查

  • Notebook 文件能够正常解析,是有效的 JSON 文件;
  • Notebook 共包含 58 个单元;
  • 提交前已清除所有 code cell 的保存输出,保存输出数量为 0;
  • 未发现对外部 ./images./src../images../src 路径的依赖;
  • Notebook 内通过 %%writefile 提供实验所需的完整工程文件。
likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 Lexie 的贡献)
LexieLexie
7月31日 创建了 pull request,commit 96a74085
CANN-robotCANN-robot成员
7月31日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
7月31日 评论:

CLA Signature Pass

m0_73961305, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
CANN-robot
CANN-robot成员
7月31日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-cann/cann-learning-hub fuyangchenghu, waimaidaole (2/2) fuyangchenghu (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

m0_73961305, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
Lexie
Lexie
8月1日 评论:

已通过机器人审核,请人工审核

likedislike
LexieLexie
8月7日 update merge request[project id: 9260575, iid: 500, commit_id: bb5059cca88858bec82a3cb37f93f91079a12429] virtual merging success
LexieLexie
8月7日 强制推送  52 个提交:939dca06-51 commits from branch testbb9c0b7d-feat: 北林数据结构-课外实验4.1-低精度矩阵乘法优化实验
LexieLexie
8月7日 update merge request[project id: 9260575, iid: 500, commit_id: eb6fc67108a7a06504d7d5224109aadc879139f5] virtual merging success
CANN-robotCANN-robot成员
8月7日 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
8月7日 添加了label:cann-cla/yes
chenmingyu
chenmingyu成员
27 天前 评论:

较长的代码可以适当添加一点注解,等pull423 问题修复之后可以一起合入

likedislike
chenmingyuchenmingyu成员
26 天前 将chenmingyu设为审查人
LexieLexie
26 天前 update merge request[project id: 9260575, iid: 500, commit_id: b24d05fc6143f99885ca3c922f57fd112ea87705] virtual merging success
LexieLexie
26 天前 强制推送  25 个提交:081de504-24 commits from branch testb3b754b4-feat: 北林数据结构-课外实验4.1-低精度矩阵乘法优化实验
LexieLexie
26 天前 update merge request[project id: 9260575, iid: 500, commit_id: b811e0d3a0139675572ed59efceacecdfaac3b8b] virtual merging success
CANN-robotCANN-robot成员
26 天前 删除了label:cann-cla/yes
CANN-robotCANN-robot成员
26 天前 添加了label:cann-cla/yes
fuyangchenghu成员
25 天前 评论:

/lgtm
/approve

likedislike
CANN-robotCANN-robot成员
25 天前 添加了label:approved
meme成员
25 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
25 天前 添加了label:lgtm
CANN-robotCANN-robot成员
25 天前 合入了pull request