官方 github 仓库CI 起了一个 ubuntu RISC-V 的 docker,使用 gcc14 和 python 3.12,但是 fail 很久了没修。 配置文件链接
x86 cross 酸鸽给 ArchLinux RISC-V python-pytorch 2.6.0 打了包,patch 文件链接
在 K1 上安装试了一下,不能直接用。
Python 3.13.11 (main, Dec 17 2025, 07:50:59) [GCC 15.2.1 20251112] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import torch Traceback (most recent call last): File "<python-input-0>", line 1, in <module> import torch File "/usr/lib/python3.13/site-packages/torch/__init__.py", line 405, in <module> from torch._C import * # noqa: F403 ^^^^^^^^^^^^^^^^^^^^^^ ImportError: libprotobuf.so.29.2.0: cannot open shared object file: No such file or directory 经查询 ArchLinux 上的 libprotobuf 版本为 31,但是进行软链接仍找不到,于是尝试重新构建。
既然已经打成功了早期版本的包,何不复用。于是学习了 ArchLinux 打包指南 其中 asp 已不可用,使用pkgctl repo clone --protocol=https python-pytorch获取最新版 ArchLinux 官方 PKGBUILD。根据酸鸽的riscv64 patch进行修改。
主要是禁用了 cuda 删除了一些 RISC-V 中没有的包依赖。
跑了一整天摸鱼之后发现,-march=rv64gc 被错误地 parse 了。
copying torch/utils/data/datapipes/datapipe.pyi -> build/lib.linux-riscv64-cpython-313/torch/utils/data/datapipes running build_ext -- Building with NumPy bindings -- Not using cuDNN -- Not using CUDA -- Not using XPU -- Not using MKLDNN -- Not using NCCL -- Building with distributed package: -- USE_TENSORPIPE=True -- USE_GLOO=True -- USE_MPI=False -- Not using ITT Copying functorch._C from functorch/functorch.so to /build/python-pytorch/src/pytorch/build/lib.linux-riscv64-cpython-313/functorch/_C.cpython-313-riscv64-linux-gnu.so copying functorch/functorch.so -> /build/python-pytorch/src/pytorch/build/lib.linux-riscv64-cpython-313/functorch/_C.cpython-313-riscv64-linux-gnu.so building 'torch._C' extension creating build/temp.linux-riscv64-cpython-313/torch/csrc -march=rv64gc -mabi=lp64d -O2 -pipe -fno-plt -fexceptions -Wp,-D_FORTIFY_SOURCE=3 -Wformat -Werror=format-security -fstack-clash-protection -fno-omit-frame-pointer -fPIC -I/usr/include/python3.13 -c torch/csrc/stub.c -o build/temp.linux-riscv64-cpython-313/torch/csrc/stub.o -Wall -Wextra -Wno-strict-overflow -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unknown-pragmas -fno-strict-aliasing error: command '-march=rv64gc' failed: No such file or directory ERROR Backend subprocess exited when trying to invoke build_wheel ==> ERROR: A failure occurred in build(). Aborting... ==> ERROR: Build failed, check /var/lib/archbuild/extra-riscv64/xyenchi/build 于是删了 PKGBUILD 中加 add_definition 到 cmake 里面的方法,写了 CFLAGS 和 CXXFLAGS,重新跑。
看起来还是会把 CFLAGS 识别错误,可能原本的 CC 不存在,改成 /usr/bin/gcc 试试。
改 /usr/bin/gcc 挺成功的,就是找不到 ROCm 相关的 .so 文件。 貌似 ROCm 不支持 RISC-V 但是旧版本的打出来了。禁用掉试试。
使用该 PKGBUILD 可以打出 pytorch 2.9.1,但仍需从 ArchLinux 官方 GitLab 仓库拉取相应 patch。
...