合并受阻
变更摘要
本 PR 新增面向 arch22 的 aclblasSspr 接口,用于实现单精度对称 packed rank-1 update(AP ← AP + α × x × xᵀ),覆盖 upper/lower packed 存储以及连续、非单位步长、负步长输入向量。改动包含 Host 端参数校验与 tiling 计算、Device Kernel 分路径实现与多核加权 column 划分,以及 NPU 测试封装和 CSV 驱动的 gtest 校验。
主要改动
- 新增 Host 端接口与参数校验:
sspr_host.cpp新增aclblasSspr,完成handle/n/uplo/incx/alpha/x/ap校验,并对n == 0和alpha == 0提前返回;根据incx与n计算useNumBlocks,填充SsprTilingData后调用sspr_kernel_do分发核函数。 - Device Kernel 分路径实现:
sspr_kernel.cpp新增sspr_kernel/sspr_kernel_do,对incx == 1走UnifiedContiguousColumns,对非单位或负步长走CachedStridedColumns(由CanonicalizeStridedRange在 Unified Buffer 内 gather/compact 生成逻辑x),超大 stride 或不可规范化时回退到ScalarColumns。 - 多核加权 column 划分: 新增
ColumnWorkPrefix/PartitionTarget/WeightedColumnBoundary,以kCostPerColumn、kCostPerElement、kCostPerTransfer构成的成本模型划分各 AIV core 独占的 packed columns 区间,使各 core 不写同一AP元素从而无需 atomic。 - 新增 tiling 结构与 UB 配置常量:
sspr_tiling_data.h定义SsprTilingData(含numThreads/columnsPerBlock/n/uplo/alpha/incx)以及UB_X_FLOATS、UB_THRESHOLD常量。 - 新增 NPU 测试与正确性校验:
sspr_npu_wrapper.h提供aclblasSspr_npu,封装设备内存分配、H2D/D2H 与同步;sspr_test.cpp通过 CSV 驱动 gtest 用例与 CPU golden 对比,并在alpha == 0时采用精确校验。


代码审查
我已完成对全部 6 个变更文件的逐一审查。
审查结论汇总
| 文件 | 审查结果 |
|---|---|
| blas/spr/arch22/sspr_host.cpp | 无独立问题(numThreads/columnsPerBlock 的计算冗余已并入 tiling_data 的 P3 清理项) |
| blas/spr/arch22/sspr_kernel.cpp | 1 个 P2:CachedStridedColumns 列数超限静默返回导致整块漏算 |
| blas/spr/arch22/sspr_tiling_data.h | 1 个 P3:未使用/误导性的 tiling 字段与 UB 阈值常量 |
| test/spr/arch22/sspr_npu_wrapper.h | 1 个 P2:对 INT_MIN 调 std::abs 触发未定义行为 |
| test/spr/arch22/sspr_test.cpp | 无问题(局部 xLen/absIncx 未使用属纯噪音,未上报) |
| test/spr/arch22/sspr_test.csv | 无问题 |
按优先级统计:P2 × 2,P3 × 1,P0/P1 × 0。
整体风险判断:核函数的核心计算逻辑(packed 上/下三角、正/负/非单位步长、加权列划分、UB 流水线)经逐段核对基本正确,与 CPU golden(cblas_sspr 的 Fortran 负步长约定)及 makeBlasStrided 布局一致;53/53 测试通过也佐证了这一点。主要风险集中在两处静默/未定义行为:一是 stride 快路径在极端列划分(AIV 核数 ≤ 5 等场景)下会静默漏算整块数据(P2,真实环境大概率不触发,属潜在正确性隐患);二是测试 wrapper 对 INT_MIN 取绝对值触发 UB(P2,仅影响测试代码)。整体属于可合入但建议修复上述 P2 项的新功能代码。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


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
⚠️ This PR does not yet meet the following requirements:lgtm (requires ≥ 2 person(s) per module)、approve (requires ≥ 1 person(s) per module)
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-cann/ops-blas | ❌ (0/2)(You can also ask: 尹祺然, 张浩, 唐超力, zizhongchen, 宋恺) | ❌ (0/1)(You can also ask: 宋恺, 尹祺然, 唐超力, zizhongchen, 张浩) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
guodong54_, thanks for your pull request. All authors of the commits have signed the CLA. 👍


/check-cla


/compile


CLA检查已通过,详情可参考这里


流水线任务触发成功
任务链接 [ddbb761cfe2a43cabea110e92a0472c9][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_A2 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A2 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5 | ✅ SUCCESS | >>>>> | >>>>> |
| codecheck | ❌ FAILED | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_A2_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A2_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| codecheck_codestyle | ⚠️ WARNING | >>>>> | |
| precommit | ⚠️ WARNING | >>>>> | >>>>> |


🟡 Medium Priority
建议:删除未使用的 absIncx/xLen(第 39-40 行),或改为先判断 p.incx == INT_MIN 再计算,并将 (p.n - 1) * absIncx + 1 提升为 64 位运算避免有符号溢出。


/compile


流水线任务触发成功
任务链接 [579ee22dd82a41978e32cf30c775148a][流水线指导]
| 任务名称 | 状态 | 日志 | 下载链接 |
|---|---|---|---|
| Compile_Ascend_X86_A2 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A2 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5 | ✅ SUCCESS | >>>>> | >>>>> |
| codecheck | ✅ SUCCESS | >>>>> | |
| SCA | ✅ SUCCESS | >>>>> | |
| antipoison | ✅ SUCCESS | >>>>> | |
| pre_comment | ✅ SUCCESS | >>>>> | |
| Compile_Ascend_X86_A2_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_X86_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A2_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| Compile_Ascend_ARM_A5_ubuntu24 | ✅ SUCCESS | >>>>> | >>>>> |
| codecheck_codestyle | ⚠️ WARNING | >>>>> | |
| precommit | ⚠️ WARNING | >>>>> | >>>>> |
| PreSmoke_A900_npupool | ✅ SUCCESS | >>>>> |
[2026-08-14 16:47:47] CI执行结束


描述
新增面向 arch22 的
aclblasSspr接口、Host 端参数校验与核函数分发,以及 Device Kernel 实现。该接口实现单精度对称 packed rank-1 update:
其中
AP支持 upper 和 lower packed storage,输入向量支持连续、非单位步长及负步长。实现中按 packed column 划分多核所有权:每个 Vector Core 独占一段 packed columns,因此不同 core 不会写入同一
AP元素,无需 atomic 操作。特殊设计
1. 分路径的 packed-column 工作量模型
packed matrix 的第
j列长度随j改变,因此仅按 packed element 数量均分时,各 core 的实际执行时间并不均衡。实际工作量还包含:
因此实现使用如下加权模型划分 column 边界:
实验中发现,不同数据路径的固定开销不同,统一的 partition 参数会造成明显的尾部负载不均衡。因此保留以下分路径配置:
该设计不改变每个 core 独占 packed columns 的并发安全性,只调整各 core 的 column 边界。
在 Ascend 910B3 上,upper triangular contiguous path 的实测结果如下:
对于非单位和负步长输入,调整 partition grain 后也观察到改善:
incx上述收益来自多核 packed-column ownership 的负载均衡修正,而不是单条 Vector 指令或流水线的加速。
2. 连续与 strided vector 的 canonical representation
对于连续输入,kernel 按需缓存当前 column 和 row tile 中的
x数据。对于非单位或负步长输入,Host 端先按逻辑向量语义归一化负步长基址;Device Kernel 仅搬运逻辑向量所覆盖的准确 physical span,再在 Unified Buffer 内完成 gather 和 compact,生成连续的 logical
xrepresentation。该路径避免:
3. AP 分段流水线实验结论
实现保留 AP input queue 和 AP output queue 的深度为 1,即每个 packed segment 按以下顺序完成:
曾实现并测试仅针对 packed matrix 的双槽 prime/pump/drain pipeline。该版本通过全部正确性测试,但由于 Unified Buffer 容量限制,AP segment 从 8192 floats 缩小为 4096 floats,导致搬运段数翻倍。
在 large lower triangular cases 中,pipeline version 反而变慢:
因此未保留该流水线。当前实现优先保持更大的 AP transaction grain,并通过 weighted partition 改善多核尾部负载。
关联的Issue
测试
在 Ascend 910B3、CANN 9.0 环境完成 arch22 SSPR 公共测试:
最终结果:
覆盖范围包括:
文档更新
类型标签