Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/actions/arm-setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: arm-setup
description: Install the PRISM build dependencies on an Ubuntu arm64 runner.

inputs:
llvm:
description: LLVM major version, installed from apt.llvm.org.
required: true
qemu:
description: Also install qemu-user-static.
default: "false"

runs:
using: composite
steps:
- name: Install build tools
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y autoconf automake libtool parallel wget
- name: Install LLVM ${{ inputs.llvm }}
shell: bash
# Prefer Ubuntu's packages: mixing them with apt.llvm.org's for the same
# version breaks (e.g. the runner's libllvm18 vs apt.llvm.org's
# llvm-18-dev). Versions Ubuntu does not ship come from apt.llvm.org.
run: |
v=${{ inputs.llvm }}
if ! sudo apt-get install -y clang-$v llvm-$v llvm-$v-dev; then
wget -qO /tmp/llvm.sh https://apt.llvm.org/llvm.sh
sudo bash /tmp/llvm.sh $v
sudo apt-get install -y llvm-$v-dev
fi
/usr/lib/llvm-$v/bin/clang --version
- name: Install Bazelisk
shell: bash
run: |
sudo curl -fsSL -o /usr/local/bin/bazel \
https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-arm64
sudo chmod +x /usr/local/bin/bazel
- name: Install QEMU
if: inputs.qemu == 'true'
shell: bash
run: sudo apt-get install -y qemu-user-static
103 changes: 103 additions & 0 deletions .github/workflows/arm-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: arm

# Experimental Arm (aarch64) support. NEON is the default on aarch64; SVE is
# opt-in (--enable-experimental-sve) and its jobs may fail without failing the
# workflow. GitHub's arm64 runners have 128-bit SVE vectors, so wider vectors
# are covered by running the tests under QEMU.

on:
workflow_dispatch:
push:
branches: ["main"]
pull_request:
branches: ["*"]

env:
# Highway generates SVE code only with clang >= 22.
SVE_LLVM: 22

jobs:
neon:
name: neon (llvm ${{ matrix.llvm }})
runs-on: ubuntu-24.04-arm
strategy:
fail-fast: false
matrix:
llvm: [18, 20]
steps:
- uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/arm-setup
with:
llvm: ${{ matrix.llvm }}
- name: Configure
run: |
./autogen.sh
LLVM_PATH=/usr/lib/llvm-${{ matrix.llvm }} ./configure || { cat config.log; exit 1; }
- name: Report targets
run: make target-info
- name: Run tests
run: bazel test --test_output=errors tests:all

sve:
name: sve (llvm 22, experimental)
runs-on: ubuntu-24.04-arm
continue-on-error: true
steps:
- uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/arm-setup
with:
llvm: ${{ env.SVE_LLVM }}
- name: Configure
run: |
./autogen.sh
LLVM_PATH=/usr/lib/llvm-$SVE_LLVM ./configure \
--enable-experimental-sve --with-arch=armv9-a+sve2 \
|| { cat config.log; exit 1; }
- name: Report targets
run: make target-info
- name: Run tests
# More Highway targets (SVE, SVE2, SVE2_128, SVE_256) make the
# accuracy tests slower than on x86.
run: bazel test --test_output=errors --test_timeout=60,900,1800,3600 tests:all

sve-qemu:
name: sve ${{ matrix.vector_bits }}-bit (qemu, experimental)
runs-on: ubuntu-24.04-arm
continue-on-error: true
strategy:
fail-fast: false
matrix:
vector_bits: [256, 512]
steps:
- uses: actions/checkout@v4
- name: Install dependencies
uses: ./.github/actions/arm-setup
with:
llvm: ${{ env.SVE_LLVM }}
qemu: true
- name: Configure
run: |
./autogen.sh
LLVM_PATH=/usr/lib/llvm-$SVE_LLVM ./configure \
--enable-experimental-sve --with-arch=armv9-a+sve2 \
|| { cat config.log; exit 1; }
- name: Report targets
run: |
bazel build src:prism-target-info
qemu-aarch64-static -cpu max,sve-default-vector-length=$(( ${{ matrix.vector_bits }} / 8 )) \
bazel-bin/src/prism-target-info
- name: Run tests under QEMU
# The statistical accuracy tests are too slow to emulate.
run: |
bazel test --test_output=errors --test_timeout=600,1800,3600,3600 \
"--run_under=qemu-aarch64-static -cpu max,sve-default-vector-length=$(( ${{ matrix.vector_bits }} / 8 ))" \
//tests/array:all \
//tests/vector:test_dekkerprod //tests/vector:test_fma \
//tests/vector:test_get_exponent //tests/vector:test_get_pow2 \
//tests/vector:test_rn_mode //tests/vector:test_split \
//tests/vector:test_splitbit //tests/vector:test_twosum \
//tests/vector:seed-api //tests/vector:thread \
//tests/vector:thread-static //tests/vector:xoshiro \
//tests/vector:xoshiro-api
8 changes: 7 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Include macros from the m4 directory
ACLOCAL_AMFLAGS = -I m4

all: highway prism
all: highway prism target-info

highway:
$(BAZEL) build @hwy
Expand All @@ -12,6 +12,12 @@ highway:
prism:
$(BAZEL) build src:prism-all lib:shared-libraries

# Print the Highway targets PRISM was built for.
target-info:
@$(BAZEL) run --ui_event_filters=-info --noshow_progress src:prism-target-info

.PHONY: highway prism target-info

bazel-bin/prism-dynamic.ll:
$(BAZEL) build :prism_ir

Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ bazel test tests:all

## Current status

The library has only been tested on X86-64 architectures for the moment.
The library is tested on x86-64. Arm (aarch64) support is **experimental**:

- NEON targets are built by default.
- SVE targets are opt-in with `./configure --enable-experimental-sve` and need clang >= 22 (Highway generates no SVE code with older clang; clang 21 only supports `SVE2_128`).
- `-march=native` falls back to a generic armv8 CPU when clang does not know the host CPU; pass `--with-arch` (e.g. `armv9-a+sve2`) in that case.

`make target-info` prints the Highway targets the static and dynamic libraries were built for.

## Publications

Expand Down
1 change: 1 addition & 0 deletions config.bzl.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ CXX = "@CLANGXX_PATH@"
LINK = "@LLVMLINK_PATH@"
BAZEL = "@BAZEL@"
MARCH_FLAG = "@MARCH_FLAG@"
EXPERIMENTAL_SVE = @PRISM_EXPERIMENTAL_SVE@
72 changes: 69 additions & 3 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ AC_PROG_LN_S
AC_PROG_MAKE_SET

dnl Bridge LLVM_PATH → with_llvm so AX_LLVM finds llvm-config from the same
dnl installation used for CC/CXX above. Only applied when --with-llvm is absent.
if test "x$with_llvm" = "xyes" && test -n "$LLVM_PATH"; then
dnl installation used for CC/CXX above. Only applied when --with-llvm is absent
dnl (AC_ARG_WITH in AX_LLVM treats a preset with_llvm as given).
if test -z "${with_llvm+set}" && test -n "$LLVM_PATH"; then
with_llvm="$LLVM_PATH"
fi
AX_LLVM([4.0],[20.1.8],[all])
dnl LLVM 21+ is only exercised by the aarch64 SVE CI job so far.
AX_LLVM([4.0],[23.99.99],[all])

AC_SUBST(LLVM_CPPFLAGS, $LLVM_CPPFLAGS)
AC_SUBST(LLVM_LDFLAGS, $LLVM_LDFLAGS)
Expand Down Expand Up @@ -121,6 +123,70 @@ fi
AC_DEFINE_UNQUOTED([MARCH_FLAG], ["$MARCH_FLAG"], [Target architecture flag])
AC_SUBST([MARCH_FLAG])

dnl Experimental Arm support: NEON by default, SVE on request.
AC_ARG_ENABLE(
[experimental-sve],
[AS_HELP_STRING([--enable-experimental-sve], [also build Arm SVE targets (experimental; default: NEON only)])],
[],
[enable_experimental_sve=no]
)
AS_CASE(
["$enable_experimental_sve"],
[yes], [PRISM_EXPERIMENTAL_SVE=True],
[no], [PRISM_EXPERIMENTAL_SVE=False],
[AC_MSG_ERROR([--enable-experimental-sve takes no value])]
)
AC_SUBST([PRISM_EXPERIMENTAL_SVE])

AC_MSG_CHECKING([whether the target is aarch64])
AS_CASE(
[`$CLANG -dumpmachine 2>/dev/null`],
[aarch64*|arm64*], [prism_aarch64=yes],
[prism_aarch64=no]
)
AC_MSG_RESULT([$prism_aarch64])

if test "x$prism_aarch64" = "xyes"; then
AC_MSG_WARN([Arm (aarch64) support is experimental])

dnl -march=native silently falls back to a generic armv8 CPU when clang does
dnl not know the host CPU, which leaves the static library at baseline NEON.
dnl Compare predefined macros: target-cpu alone is not enough, since some
dnl clang versions report "generic" but still enable the detected features.
if test "x$PRISM_ARCH" = "xnative"; then
prism_native_macros=`$CLANG -march=native -dM -E -x c /dev/null 2>/dev/null | sort`
prism_armv8_macros=`$CLANG -march=armv8-a -dM -E -x c /dev/null 2>/dev/null | sort`
if test "x$prism_native_macros" = "x$prism_armv8_macros"; then
AC_MSG_WARN([$CLANG does not recognize this CPU: -march=native targets a generic armv8 CPU. Pass --with-arch (e.g. armv8.2-a+fp16+dotprod, armv9-a+sve2) to target its features.])
fi
fi

AC_MSG_CHECKING([whether $MARCH_FLAG enables SVE])
if $CLANG $MARCH_FLAG -dM -E -x c /dev/null 2>/dev/null |
grep -q '__ARM_FEATURE_SVE '; then
prism_march_sve=yes
else
prism_march_sve=no
fi
AC_MSG_RESULT([$prism_march_sve])
if test "x$prism_march_sve" = "xyes" && test "x$enable_experimental_sve" != "xyes"; then
AC_MSG_WARN([$MARCH_FLAG enables SVE, but SVE targets are disabled: the static library uses NEON. Use --enable-experimental-sve to build SVE targets.])
fi

dnl Highway only generates SVE code with clang >= 21 (SVE2_128) or >= 22
dnl (SVE, SVE2, SVE_256); see HWY_BROKEN_SVE* in hwy/detect_targets.h.
if test "x$enable_experimental_sve" = "xyes"; then
prism_clang_major=`$CLANG -dumpversion 2>/dev/null | cut -d. -f1`
if test -n "$prism_clang_major" && test "$prism_clang_major" -lt 21; then
AC_MSG_WARN([clang $prism_clang_major is too old for Highway SVE targets (clang >= 22 required, >= 21 for SVE2_128): no SVE code will be generated])
elif test -n "$prism_clang_major" && test "$prism_clang_major" -lt 22; then
AC_MSG_WARN([clang $prism_clang_major only supports the SVE2_128 Highway target (clang >= 22 for SVE, SVE2 and SVE_256)])
fi
fi
elif test "x$enable_experimental_sve" = "xyes"; then
AC_MSG_WARN([--enable-experimental-sve has no effect on non-aarch64 targets])
fi

# Generate config files
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([.bazelrc config.bzl])
Expand Down
11 changes: 9 additions & 2 deletions constants.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
"""

load("//:config.bzl", "MARCH_FLAG")
load("//:config.bzl", "EXPERIMENTAL_SVE", "MARCH_FLAG")

# Compiler options

Expand All @@ -15,13 +15,20 @@ RANDOM_PARTIALBITS_COPTS = [
"-UPRISM_RANDOM_FULLBITS",
]

# Arm SVE targets are experimental and opt-in (./configure
# --enable-experimental-sve). When disabled, aarch64 builds use NEON only. This
# is a no-op on other architectures.
TARGET_COPTS = [] if EXPERIMENTAL_SVE else [
"-DHWY_DISABLED_TARGETS=HWY_ALL_SVE",
]

COPTS = [
"-std=c++17",
"-Wfatal-errors",
"-O2",
"-Wall",
"-Wno-psabi",
] + RANDOM_PARTIALBITS_COPTS
] + RANDOM_PARTIALBITS_COPTS + TARGET_COPTS

NATIVE_COPTS = [
MARCH_FLAG,
Expand Down
32 changes: 32 additions & 0 deletions src/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@rules_cc//cc:cc_library.bzl", "cc_library")
load("@rules_cc//cc:cc_binary.bzl", "cc_binary")
load("//:constants.bzl", "COPTS", "DEBUG_COPTS", "DYNAMIC_COPTS", "RANDOM_FULLBITS_COPTS", "RANDOM_PARTIALBITS_COPTS", "STATIC_COPTS")

exports_files([
Expand Down Expand Up @@ -79,6 +80,7 @@ filegroup(
exclude = [
"*static*",
"prism_config.cpp",
"target_info*",
],
),
visibility = ["//visibility:public"],
Expand All @@ -96,6 +98,7 @@ filegroup(
exclude = [
"*dynamic*",
"prism_config.cpp",
"target_info*",
],
),
visibility = ["//visibility:public"],
Expand Down Expand Up @@ -270,3 +273,32 @@ filegroup(
":prism-static-dbg",
],
)

# Reports the Highway targets of the static and dynamic libraries
# (`make target-info`): useful where -march=native may not mean what it says.

cc_library(
name = "target-info-static",
srcs = ["target_info_static.cpp"],
hdrs = ["target_info.h"],
copts = COPTS + STATIC_COPTS,
deps = ["@hwy"],
)

cc_library(
name = "target-info-dynamic",
srcs = ["target_info_dynamic.cpp"],
hdrs = ["target_info.h"],
copts = COPTS + DYNAMIC_COPTS,
deps = ["@hwy"],
)

cc_binary(
name = "prism-target-info",
srcs = ["target_info_main.cpp"],
copts = COPTS,
deps = [
":target-info-dynamic",
":target-info-static",
],
)
Loading
Loading