JuliaLinearAlgebra / libblastrampoline

Using PLT trampolines to provide a BLAS and LAPACK demuxing library.
MIT License
66 stars 17 forks source link

Add riscv64 support #68

Closed alexfanqi closed 2 years ago

alexfanqi commented 2 years ago

Hi,

This adds riscv64 trampoline and gnu/musl ILP64/LP64 support (in lapack terms, not to be confused with riscv abi name). I tested on gentoo glibc with lapack. The trampoline assembly is universal and should also work with musl.

staticfloat commented 2 years ago

Hello Alex, thank you for your contribution!

I'm afraid that I am very much out of my depth with RISCV. A few questions for you:

1) Are there OpenBLAS binaries that can be tested against on RISCV? It would give me a lot of confidence if LBT could be tested against something like OpenBLAS. I know the test suite of LBT itself uses Julia, which is perhaps not the most helpful thing, considering you need LBT to build Julia..... but I can help you to compile some simple tests, it's mostly just a matter of compiling directories such as the sdot_test with the correct compiler flags.

2) Is there a convenient QEMU setup or something that I can use to test/try this out? If we get RISCV support working well, I'd like to eventually add CI for it via a QEMU setup.

3) Are you using LBT for your own project, or trying to port Julia or what? :D

alexfanqi commented 2 years ago

Hi, thanks for the reply.

  1. yes, openblas supports riscv from 2018. Major distros all have support for riscv and should provide openblas binaries including Ubuntu, Archlinux, Fedora, etc. And thanks for the testing tips. I previously used the test commands demonstrated on the julia talk https://www.youtube.com/watch?app=desktop&v=t6hptekOR7s . I have tested with openblas

    $ export LBT_DEFAULT_LIBS=/usr/lib64/libopenblas64.so
    $ gcc -o sdot_test -DILP64 sdot_test.c -L../../src/build -lblastrampoline
    $ export LD_LIBRARY_PATH=../../src/build
    $ ./sdot_test 
    C is:   1.9900
  2. I primarily use Gentoo, the stage3 tarball is directly bootable on qemu after being decompressed with minor config in /etc. For binary distros, Fedora image might be simple to setup. https://fedoraproject.org/wiki/Architectures/RISC-V/Installing. And Ubuntu as well, https://wiki.ubuntu.com/RISC-V. I also saw there is this rocksdb issue where there are lots of details setting up qemu for riscv dev. For ci integration afaik, PLCT lab offers free riscv hardware access by request. They have lots of sifive unmatched and d1 boards. rocksdb and prolog community are using it. https://github.com/plctlab/riscv-lab-access

  3. I am looking to port Julia by first clearing up all its dependencies, but not fully committed to it. just hope this can reduce a little bit work of others porting julia. It seems to me in the past arm gained Julia support not very difficultly. LLVM 14 also has orc jit support for riscv.

staticfloat commented 2 years ago

Sounds good! I'll merge this, but I'd love to get some kind of RISC-V CI setup eventually.