已合并
feat(rot): 新增 arch35 平台 aclblasSrot 算子接口 #233
陈思创建于 6月30日
feat(rot): 新增 arch35 平台 aclblasSrot 算子接口 #233
已合并
陈思创建于 6月30日
陈思
陈思成员
6月30日

描述

为 arch35(Ascend 950PR / 950DT)平台新增 BLAS Level-1 aclblasSrot 接口,实现 Givens 平面旋转:对 FP32 向量 x、y 按标量 c=cosθ、s=sinθ 原地旋转

  • x[i] = c·x[i] + s·y[i]
  • y[i] = c·y[i] − s·x[i](使用原始 x[i])

改动原因

ops-blas 当前缺少面向 arch35 的 SROT 实现。

改动方法

  • 新增 arch35 算子源码 blas/rot/arch35/:host(参数校验、c/s 指针 Host/Device 自动判定、tiling、kernel 启动)、kernel(连续 SIMD / stride SIMT 双路径)、tiling data
  • include/cann_ops_blas.h 注册 aclblasSrot 接口声明(同时补充 aclblasSrotm 前置声明,留待后续实现)
  • 按 stride 连续性分两条 kernel 路径:连续路径(incx==1 && incy==1)走 AIV SIMD(UB 三 buffer 分块,tileSize = UB_SIZE/(3·sizeof(float)));其余走 SIMT grid-stride,支持负 stride(尾端起算)与零 stride(单线程串行,复现 netlib 语义)
  • host 用 aclrtPointerGetAttributes 对 c、s 各自独立判定 Host/Device 内存;n≤0 短路返回 SUCCESS;(n−1)·stride 超 int32 范围返回 INVALID_VALUE
  • 连续路径刻意避免 FMA,对齐 OpenBLAS 精度(MARE ≤ 10·2⁻¹³,MERE ≤ 2⁻¹³)

关联的Issue

测试

test/rot/srot/ 新增 CSV 驱动测试(约 48 用例),覆盖:

  • L0 基线:x/y nullptr、连续 n=64/1024、45° 旋转、stride incx2/incy3、非对齐尾 n=33
  • L1 边界:n=0/n<0 no-op、n=1、零 stride(x/y/both)、负 stride(含正负混合)、单位旋转 c1s0、纯交换 c0s1、Inf+单位、NaN、大向量 n=1048576
  • c/s 指针模式:host / device / mixed(c 在 host、s 在 device,验证独立判定)
    精度校验对齐 OpenBLAS cblas_srot,按数据特征选 NaN 逐元素、单位+Inf 位级 EXACT、默认 MERE/MARE 三种模式。

readme中示例代码本地验证通过:
image.png

文档更新

  • blas/rot/README.md:新增 aclblasSrot 章节(产品支持表 950PR/950DT、函数原型、参数说明、约束、可编译调用示例)
  • docs/zh/develop/compile_and_run_example.mdblas/asum|nrm2|scal|scalex/README.md:随附的调用示例 RAII 类型安全重构(std::remove_pointer_t + 自定义 deleter).

类型标签

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 陈思 的贡献)
CANN-robotCANN-robot成员
6月30日 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
6月30日 评论:

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/ops-blas 王子韬, xutianze (2/2) 王子韬 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
陈思
陈思成员
6月30日 评论:

compile

likedislike
atomgit-bot
atomgit-bot
6月30日 评论:

变更摘要

此 PR 为 arch35 (ascend950) 平台新增了 aclblasSrot 接口,实现 BLAS Level-1 的 Givens 平面旋转(x[i] = c*x[i] + s*y[i], y[i] = c*y[i] - s*x[i])。核心设计包含两条计算路径:当 incx==1 && incy==1 时走连续 SIMD membase 路径,否则走 SIMT 网格步长路径。此外,cs 参数支持独立的主机指针或设备指针位置检测(通过 aclrtPointerGetAttributes),设备指针直接透传给 kernel 在 GM 上读取。测试套件覆盖了 host/device/mixed 三种 csPtrMode、NaN 传播、恒等旋转精确校验以及零步长的 netlib 串行回退等场景。

主要改动

  • 新增 aclblasSrot 公共 API:在 include/cann_ops_blas.h 中声明,由 blas/rot/arch35/srot_host.cpp 实现完整的主机端入口,包含参数校验、handle 空指针检测、n<=0 快速返回,以及调用 LaunchSrotKernel 进行 tiling 计算与异步内核启动。

  • 双路径内核设计srot_kernel.cpp 通过 tilingKey 选择路径——tilingKey==0 使用 SrotAIV 类走 SIMD membase(DataCopy/DataCopyPad + Muls/Axpy 向量计算,分 tile 循环处理);tilingKey==1 使用 srot_simt_kernel 走 SIMT 网格步长循环(asc_vf_call),支持负步长和零步长。零步长场景通过仅 block0.thread0 串行执行来匹配 netlib 的语义。

  • c/s 指针位置独立检测PrepareSrotCsSource 通过 aclrtPointerGetAttributes 分别查询 cs 的指针位置(主机或设备)。主机指针在主机端解引用一次,标量值写入 tiling 数据广播;设备指针则原样透传 GM_ADDR 给 kernel 在 GM 上读取,无需 D2H 拷贝或流同步。两个指针相互独立(允许 c 在主机、s 在设备的混合模式)。

  • Tiling 数据结构 SrotTilingData:定义于 srot_tiling_data.h,通过常量引用传递给 kernel(无 GM tiling 缓冲区、无 H2D 拷贝)。包含 tilingKeytotalNcosValue/sinValuecIsDevice/sIsDevice 标志、连续路径的 perCoreN/remainder/tileSize 以及步长路径的 incx/incyint32_t 支持负步长)。步长偏移量在主机端以 int64_t 计算并做溢出检查。

  • 测试套件与 NPU 包装器srot_npu_wrapper.h 实现 aclblasSrot_npu,根据 csPtrMode(host/device/mixed)将 c/s 标量分配到主机栈或设备 HBM,并管理 x/y 的设备缓冲区分配、H2D/D2H 拷贝和资源释放。srot_test.cpp 包含空句柄测试和 CSV 驱动测试,针对 NaN 输入直接验证 std::isnan 传播,针对 c==1 && s==0 恒等旋转进行 EXACT 精确校验,其余情况使用 MERE/MARE 相对误差验证;srot_golden.hcblas_srot 作为 CPU 参考实现。

likedislike
不准确?
CANN-robotCANN-robot成员
6月30日 添加了label:ci-pipeline-running
此处折叠了68条消息 查看更多
CANN-robotCANN-robot成员
7月3日 添加了label:approved
xutianze
xutianze成员
7月3日 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
7月3日 添加了label:lgtm
CANN-robotCANN-robot成员
7月3日 关闭了关联的issue
CANN-robotCANN-robot成员
7月3日 合入了pull request