RISC-V Vector Extension (RVV) support for ATen - #46
Conversation
* Add RISC-V 64 BLOCK_LIST * Skip long time testcase Co-authored-by: Cursor <cursoragent@cursor.com>
* Add riscv64 ci with PR
⭐ Run Main Diff base and head Push to riscv From https://github.com/RuyiAI-Stack/pytorch * branch riscv -> FETCH_HEAD fatal: Not a valid object name origin/main Error: ❌ Failure - Main Diff base and head Error: exit status 128
* mklnn is unavailable on RISC-V * Remove test_cpu_select_algorithm from block_list * Fix block list format
These cases are too slow on riscv64, adding them to here simply Drop test_torch from the list because it is one core case
bytes_to_scalar previously round-tripped raw bytes through Python
float/complex values (via ctypes) before constructing the tensor. This
loses NaN bit patterns on architectures (such as RISC-V) that
canonicalize NaNs in floating-point loads/conversions, causing
test_bytes_to_scalar_cpu_{float32,float64,complex64,complex128} to
fail with mismatched storage bytes.
Construct the scalar tensor by writing the raw bytes directly into its
untyped storage so all input bit patterns (including NaN payloads) are
preserved exactly.
RISC-V converts non-finite floats to integers by saturating: -inf -> min, inf/nan -> max for wider int types. Add IS_RISCV64 flag and RISC-V-specific reference values. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
for action, these yaml must be merged first then take effect, so merge it skipping ci
Signed-off-by: Fei Zhang <zhangfei@iscas.ac.cn> Co-authored-by: Chung-Lin Tang <cltang@baylibre.com>
e4b937e to
ae1e2fb
Compare
|
@zhanghb97 后面该pr合并的要求是啥?后续我这里还要做啥? |
|
Hi, 感谢贡献 PR! 我个人先从 CI 的角度介绍下, 我们现在的 CI job 只开启了 好消息是这个 PR 看起来在 |
|
@zhangfeiv0 Hi 张老师,感谢您的工作!注意到 FindRVV.cmake 固定使用 -march=rv64gcv_zvl128b,且算子优化时默认VLEN=128。在 VLEN > 128 的机器上,部分算子优化性能不如编译器 RVV 自动向量化。是否考虑探测 VLEN ? |
之所以这么做,是因为pytorch vec后端框架的历史遗留问题导致的,其设计不适合vector length agnostic,目前上游 SVE 和 本 PR增添的rvv都是 vls设计,相关讨论可见: 好像目前上游对VLA的推动比较缓慢?这个推进可能会影响更多的架构和需要详细的验证。 |
cfb52d8 to
b8e4232
Compare
|
注意到您向上游提交patch时附带了性能测试结果 |
0ca63b6 to
2349b8f
Compare
测试平台sg2044,编译器gcc-15,以下是我的测试结果: 测试内容覆盖与总体对比
总体效果可能会掩盖部分算子的情况,以下是更进一步的测试: 逐元素操作性能对比
模型与训练
可以看到还是有许多退化的用例,由于我这个pr写于几年前,在此期间RISE也没有进一步优化,因此这需要后期不断的进行优化,我也很乐意RuyiAI团队能够在此基础上持续优化;同时vec rvv后端支持也是必须的,如果自动矢量化更优,那么其他架构在vec后端支持也毫无意义。 |
|
能否改写成用户自行配置使用自动向量化还是使用intrinsic的分发逻辑? |
关于这个问题,我认为当前代码就支持用户自行配置编译选项和使用default默认后端,理由如下: 1.pytorch目前支持"同一份 kernel 编译多个版本,再由 DispatchStub 选择"的方式,上游说明也记录了这种机制(https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/cpu/README.md); 例如,同一份 因此对于用户来说即使编译使用了此版本的RVV wheel,仍能控制其走不同的实现,使用方式如下: 也可以在 Python 程序开头设置: 具体实际分发矩阵如下:
2.假如用户用
3.除此之外,我在最新的提交中引入了官方提供的宏 综上,主要有两个开关可供使用: |


嗨, 我是软件所的张飞, 我之前有做过 pytorch 相关工作:
pytorch#127867
pytorch#143979
pytorch#166602
pytorch#135570
其中, pytorch#135570 的工作并没有受上游太重视且审核缓慢, 希望这个 PR 内容能够合并到 RuyiAI, , 希望随着你们的 ci 等推进一并合并到上游。
变更说明 / Summary
为 pytorch vec 后端添加了
rvv后端支持, 且该 PR 已适配到最新的上游代码关联 Issue / Related issue
下面是提交给上游的pr(均未合并), 因长时间未改动已被关闭, 其中一个是联合
RISE提交的:pytorch#175746
pytorch#135570
验证方式 / Validation
gcc: gcc-15
平台: sg2044
vec库功能测试:
./build/bin/vec_test_all_types_RVV, 结果均已通过:检查清单 / Checklist