Skip to content

Commit

Permalink
Add riscv64 CI on GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
luhenry committed Nov 10, 2023
1 parent 46230a3 commit 55fd453
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 4 deletions.
36 changes: 34 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
run: sudo apt-get update -y -qq && sudo apt-get install -y -qq build-essential clang curl ninja-build libgmp-dev libmpfr-dev

- name: Build native
shell: bash -ex -o pipefail {0}
run: |
set -x
EXTRA_CMAKE_FLAGS="-DENFORCE_SSE2=ON -DENFORCE_SSE4=ON -DENFORCE_AVX=ON -DENFORCE_AVX=ON -DENFORCE_AVX2=ON -DENFORCE_AVX512F=ON -DENFORCE_FMA4=ON"
cmake -S . -B _build-native -GNinja \
-DCMAKE_INSTALL_PREFIX=$(pwd)/_install-native \
Expand Down Expand Up @@ -108,6 +108,8 @@ jobs:
package: -powerpc64le-linux-gnu
# IBM Z
- arch: s390x
# RISC-V
- arch: riscv64

name: build-${{ matrix.arch }}
steps:
Expand All @@ -120,6 +122,14 @@ jobs:
sudo apt-get update -y -qq
sudo apt-get install -y -qq build-essential clang curl ninja-build libgmp-dev libmpfr-dev gcc${{ matrix.package || format('-{0}-linux-gnu', matrix.arch) }}
- name: Download riscv-gnu-toolchain's LLVM build
env:
RISCV_GNU_TOOLCHAIN_TAG: "2023.10.18"
run: |
curl -L https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/${RISCV_GNU_TOOLCHAIN_TAG}/riscv64-glibc-ubuntu-20.04-llvm-nightly-${RISCV_GNU_TOOLCHAIN_TAG}-nightly.tar.gz |
tar xzf - -C /opt
if: ${{ matrix.arch == 'riscv64' }}

- name: Download build-native artifacts
uses: actions/download-artifact@v3
with:
Expand All @@ -130,8 +140,13 @@ jobs:
chmod +x _build-native/bin/*
- name: Build ${{ matrix.arch }}
shell: bash -ex -o pipefail {0}
run: |
set -x
# Add riscv-gnu-toolchain to PATH
if [[ ${{ matrix.arch }} = "riscv64" ]]; then
export PATH="/opt/riscv/bin:$PATH"
fi
EXTRA_CMAKE_FLAGS=""
if [[ ${{ matrix.arch }} = "aarch64" ]]; then
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DENFORCE_SVE=ON"
Expand All @@ -144,6 +159,14 @@ jobs:
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DENFORCE_VXE=ON"
# Disable VXE2 support, QEMU doesn't support it
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DDISABLE_VXE2=ON"
elif [[ ${{ matrix.arch }} = "riscv64" ]]; then
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DENFORCE_RVVM1=ON -DENFORCE_RVVM2=ON"
# Disable inline headers, they just don't compile on riscv64
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DBUILD_INLINE_HEADERS=OFF"
# Disable dft, it fails with linker error to `cexp`
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DBUILD_DFT=OFF"
# Disable quad, it's missing the `Sleef_quad` function
EXTRA_CMAKE_FLAGS="${EXTRA_CMAKE_FLAGS} -DBUILD_QUAD=OFF"
fi
cmake -S . -B _build-${{ matrix.arch }} -GNinja \
-DCMAKE_INSTALL_PREFIX="$(pwd)/_install-${{ matrix.arch }}" \
Expand Down Expand Up @@ -190,6 +213,15 @@ jobs:
# IBM Z
# TODO: figure out qemu_cpu variable to make tests pass on QEMU
- arch: s390x
# RISC-V
- arch: riscv64
qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=false"
- arch: riscv64
qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=128,elen=64,vext_spec=v1.0"
- arch: riscv64
qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=256,elen=64,vext_spec=v1.0"
- arch: riscv64
qemu_cpu: "rv64,zba=true,zbb=true,zbs=true,v=true,vlen=512,elen=64,vext_spec=v1.0"

name: "test-${{ matrix.arch }} (qemu_cpu: \"${{ matrix.qemu_cpu }}\")"
steps:
Expand Down
38 changes: 36 additions & 2 deletions Configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,6 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "s390x")
set(CLANG_FLAGS_ENABLE_PURECFMA_SCALAR "-march=z14;-mzvector")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "riscv64")
set(SLEEF_ARCH_RISCV64 ON CACHE INTERNAL "True for RISCV64 architecture.")
set(COMPILER_SUPPORTS_RVVM1 1)
set(COMPILER_SUPPORTS_RVVM2 1)
endif()

set(COMPILER_SUPPORTS_PUREC_SCALAR 1)
Expand Down Expand Up @@ -623,6 +621,42 @@ if (ENFORCE_VXE2 AND NOT COMPILER_SUPPORTS_VXE2)
message(FATAL_ERROR "ENFORCE_VXE2 is specified and that feature is disabled or not supported by the compiler")
endif()

# RVVM1

option(DISABLE_RVVM1 "Disable RVVM1" OFF)
option(ENFORCE_RVVM1 "Build fails if RVVM1 is not supported by the compiler" OFF)

if(SLEEF_ARCH_RISCV64 AND NOT DISABLE_RVVM1)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_RVVM1}")
CHECK_C_SOURCE_COMPILES("
#include <riscv_vector.h>
int main() {
vint32m1_t r = __riscv_vmv_v_x_i32m1(1, __riscv_v_min_vlen / 32); }"
COMPILER_SUPPORTS_RVVM1)
endif()

if (ENFORCE_RVVM1 AND NOT COMPILER_SUPPORTS_RVVM1)
message(FATAL_ERROR "ENFORCE_RVVM1 is specified and that feature is disabled or not supported by the compiler")
endif()

# RVVM2

option(DISABLE_RVVM2 "Disable RVVM2" OFF)
option(ENFORCE_RVVM2 "Build fails if RVVM2 is not supported by the compiler" OFF)

if(SLEEF_ARCH_RISCV64 AND NOT DISABLE_RVVM2)
string (REPLACE ";" " " CMAKE_REQUIRED_FLAGS "${FLAGS_ENABLE_RVVM2}")
CHECK_C_SOURCE_COMPILES("
#include <riscv_vector.h>
int main() {
vint32m2_t r = __riscv_vmv_v_x_i32m2(1, __riscv_v_min_vlen / 32); }"
COMPILER_SUPPORTS_RVVM2)
endif()

if (ENFORCE_RVVM2 AND NOT COMPILER_SUPPORTS_RVVM2)
message(FATAL_ERROR "ENFORCE_RVVM2 is specified and that feature is disabled or not supported by the compiler")
endif()

# CUDA

option(ENFORCE_CUDA "Build fails if CUDA is not supported" OFF)
Expand Down

0 comments on commit 55fd453

Please sign in to comment.