Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
951cac7
simd-backends: inital commit, added sleef and svml
tretre91 Apr 17, 2025
c4cb086
simd-backends: Make the library installable
tretre91 Apr 18, 2025
5fe50d1
simd-backends: add license headers
tretre91 Apr 18, 2025
e1811bb
simd-backends: add a README
tretre91 Apr 18, 2025
45fd12d
Fix a typo in the README
tretre91 May 21, 2025
70c71cc
Update README.md
tretre91 May 21, 2025
1e4e43c
Rename the Kokkos_* macros and options to CEXA_*
tretre91 Mar 3, 2026
4d6af24
Update the README
tretre91 Mar 6, 2026
44a28f2
Add comments explaining why some functions are ccommented out
tretre91 Mar 11, 2026
444f3f1
Update the copyright notice
tretre91 Mar 14, 2026
a3476a4
Overhaul the CMake files
tretre91 Mar 14, 2026
00da541
Include Kokkos_Macros instead of Kokkos_Core in the sleef wrapper
tretre91 Mar 14, 2026
001246e
Update the README
tretre91 Mar 14, 2026
1a6aef7
Add a CI
tretre91 Mar 14, 2026
90875f0
ci: fix some paths
tretre91 Mar 14, 2026
a8b494e
ci: Install sleef from source as the version from apt is too old
tretre91 Mar 14, 2026
73813ed
Mention the sleef version requirement in the README
tretre91 Mar 14, 2026
54e28f6
ci: cache sleef
tretre91 Mar 14, 2026
0a84af9
Link to the right sleef target
tretre91 Mar 14, 2026
7e9148d
ci: get the sleef libdir using find
tretre91 Mar 14, 2026
ff65bf5
ci: use quotes in the find argument
tretre91 Mar 14, 2026
2c395c9
ci: use Ninja as CMake generator
tretre91 Mar 14, 2026
88a80db
ci: add a find_package call when patching kokkos
tretre91 Mar 14, 2026
264f451
Don't use the CONFIG mode for find_package
tretre91 Mar 14, 2026
07550ac
Undef internal macros after their use
tretre91 Mar 31, 2026
dba1595
Update the accuracy test based on suggestions from review
tretre91 Mar 31, 2026
0ab44fd
Apply suggestions from review
tretre91 Apr 1, 2026
571a28f
Remove the `CEXA_SIMD_ENABLE_INSTALL` option
tretre91 Apr 1, 2026
812e0af
Use a more explicit ci step name than "Patch Kokkos"
tretre91 Apr 1, 2026
cf4b06f
Set the min kokkos version to 4.6
tretre91 Apr 1, 2026
e52c9eb
ci: checkout code before restoring the cache
tretre91 Apr 1, 2026
6a42646
Update the README
tretre91 Apr 1, 2026
f9a1342
ci: add a job running the Kokkos SIMD perf tests
tretre91 Apr 1, 2026
213e49b
ci: fix a path in the perf test job
tretre91 Apr 1, 2026
3bcf138
ci: activate the venv before running the comapre script
tretre91 Apr 1, 2026
7602685
ci: filter benchmarks to only run math functions
tretre91 Apr 1, 2026
be742a8
Update the README
tretre91 Apr 2, 2026
c22bf00
ci: exclude scalar benchmarks and increase the number of iterations
tretre91 Apr 2, 2026
a906d59
Fix a typo in th src CMakeLists
tretre91 Apr 2, 2026
ea5b136
ci: reorder the cmake configure arguments
tretre91 Apr 2, 2026
ddbc37b
ci: limit the number of parallel cmake jobs to `nproc`
tretre91 Apr 2, 2026
0a664ae
Guard exp, log and cbrt if using an intel compiler
tretre91 Apr 3, 2026
879bc5a
Apply suggestions from review
tretre91 Apr 3, 2026
8b7bf1d
Remove the AOCL header
tretre91 Apr 3, 2026
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
226 changes: 226 additions & 0 deletions .github/workflows/simd-backends.yml
Comment thread
tretre91 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
# SPDX-FileCopyrightText: 2026 CExA-project
# SPDX-License-Identifier: MIT or Apache-2.0 with LLVM-exception

name: SIMD Backends Tests

on:
pull_request:
paths:
- '.github/workflows/simd-backends.yml'
- 'simd-backends/**'
- '!simd-backends/README.md'
push:
branches:
- main

concurrency:
group: ${{ github.event_name }}-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
unit-tests:
continue-on-error: true

strategy:
matrix:
kokkos-version: [4.6.00, 5.1.0]

runs-on: ubuntu-latest

env:
CMAKE_GENERATOR: Ninja
Kokkos_ROOT: ${{ github.workspace }}/opt/kokkos
sleef_ROOT: ${{ github.workspace }}/opt/sleef
CexaSimdBackends_ROOT: ${{ github.workspace }}/simd-backends/install
steps:
- name: Checkout Code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
id: cache-sleef
with:
path: opt/sleef
key: simd-backends-sleef-ubuntu-latest
- name: Checkout Sleef
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: steps.cache-sleef.outputs.cache-hit != 'true'
with:
repository: shibatch/sleef
ref: 3.9.0
path: sleef
- name: Install Sleef
if: steps.cache-sleef.outputs.cache-hit != 'true'
run: |
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_INSTALL_PREFIX="$sleef_ROOT" \
-DSLEEF_BUILD_GNUABI_LIBS=OFF \
-DSLEEF_BUILD_TESTS=OFF \
-DSLEEF_ENABLE_TLFLOAT=OFF \
-DSLEEF_ENABLE_FFTW=OFF \
-DSLEEF_ENABLE_MPFR=OFF \
-B sleef/build -S sleef
cmake --build sleef/build -j $(nproc) --target install
- name: Checkout Kokkos
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: kokkos/kokkos
ref: ${{ matrix.kokkos-version }}
path: kokkos
- name: Install kokkos
run: |
cmake \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_INSTALL_PREFIX="$Kokkos_ROOT" \
-DKokkos_ARCH_NATIVE=ON \
-B kokkos/build -S kokkos
cmake --build kokkos/build -j $(nproc) --target install
- name: Configure
working-directory: ${{ github.workspace }}/simd-backends
run:
cmake
-DCMAKE_CXX_COMPILER=g++
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DCMAKE_INSTALL_PREFIX="$CexaSimdBackends_ROOT"
-DCEXA_SIMD_ENABLE_SLEEF=ON
-DCEXA_SIMD_ENABLE_TESTS=ON
-B build -S .
- name: Build
working-directory: ${{ github.workspace }}/simd-backends
run: cmake --build build -j $(nproc)
- name: Install
working-directory: ${{ github.workspace }}/simd-backends
run: cmake --install build
- name: Test install
working-directory: ${{ github.workspace }}/simd-backends/test/install_test
run: |
cmake \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-B build -S .
cmake --build build -j $(nproc)
./build/main
- name: Patch the Kokkos SIMD unit tests to use the Sleef backend
working-directory: ${{ github.workspace }}/kokkos/simd/unit_tests
run: |
cp "$CexaSimdBackends_ROOT/include/CEXA_SIMD_SLEEF.hpp" include
sed -i '/kokkos_add_executable_and_test/a find_package(sleef REQUIRED)\ntarget_link_libraries(Kokkos_UnitTest_SIMD PRIVATE sleef::sleef)' CMakeLists.txt
sed -i '/include <Kokkos_SIMD.hpp>/a #include <CEXA_SIMD_SLEEF.hpp>' include/TestSIMD_MathOps.hpp
- name: Run the Kokkos SIMD unit tests using the Sleef backend
working-directory: ${{ github.workspace }}/kokkos
run: |
cmake \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DKokkos_ARCH_NATIVE=ON \
-DKokkos_ENABLE_TESTS=ON \
-B build -S .
cmake --build build -j $(nproc) --target Kokkos_UnitTest_SIMD
ctest --test-dir build --output-on-failure -R SIMD

performance-tests:
continue-on-error: true

runs-on: ubuntu-latest

env:
CMAKE_GENERATOR: Ninja
sleef_ROOT: ${{ github.workspace }}/opt/sleef
compare_ROOT: ${{ github.workspace }}/opt/compare
benchmark_VERSION: v1.9.5
steps:
- name: Checkout Code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
id: cache-sleef
with:
path: opt/sleef
key: simd-backends-sleef-ubuntu-latest
- name: Checkout Sleef
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: steps.cache-sleef.outputs.cache-hit != 'true'
with:
repository: shibatch/sleef
ref: 3.9.0
path: sleef
- name: Install Sleef
if: steps.cache-sleef.outputs.cache-hit != 'true'
run: |
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_C_COMPILER=gcc \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_INSTALL_PREFIX="$sleef_ROOT" \
-DSLEEF_BUILD_GNUABI_LIBS=OFF \
-DSLEEF_BUILD_TESTS=OFF \
-DSLEEF_ENABLE_TLFLOAT=OFF \
-DSLEEF_ENABLE_FFTW=OFF \
-DSLEEF_ENABLE_MPFR=OFF \
-B sleef/build -S sleef
cmake --build sleef/build -j $(nproc) --target install
- run: echo "PYTHON_VERSION=$(python3 --version | sed 's/ /_/')" >> $GITHUB_ENV
- uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
id: cache-gbench-compare
with:
path: ${{ env.compare_ROOT }}
key: simd-backends-gbench-ubuntu-latest-${{ env.benchmark_VERSION }}-${{ env.PYTHON_VERSION }}
- name: Checkout google benchmark
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: steps.cache-gbench-compare.outputs.cache-hit != 'true'
with:
repository: google/benchmark
ref: ${{ env.benchmark_VERSION }}
path: benchmark
- name: Get the compare script from google benchmark
if: steps.cache-gbench-compare.outputs.cache-hit != 'true'
run: |
mkdir -p ${{ env.compare_ROOT }}
cp -r benchmark/tools/* ${{ env.compare_ROOT }}
- name: Install python dependencies
working-directory: ${{ env.compare_ROOT }}
if: steps.cache-gbench-compare.outputs.cache-hit != 'true'
run: |
python3 -m venv ./venv
source ./venv/bin/activate
pip3 install -r ./requirements.txt
- name: Checkout Kokkos
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
repository: kokkos/kokkos
ref: 5.1.0
path: kokkos
- name: Run the Kokkos SIMD perf tests
# We use "math .[^c]" as benchmark_filter to only run benchmarks for
# math functions and to exclude the scalar ones, ".[^c]" will exclude
# "scalar" but not "avx", "neon" or "sve".
# We also increase the number of iterations to get more stable results,
# we can afford it since we don't run the scalar benchmarks.
working-directory: ${{ github.workspace }}/kokkos
run: |
sed -i 's/Iterations(3)/Iterations(300)/' simd/perf_tests/include/PerfTest_Host.hpp
cmake \
-DCMAKE_CXX_COMPILER=g++ \
-DCMAKE_BUILD_TYPE=Release \
-DKokkos_ARCH_NATIVE=ON \
-DKokkos_ENABLE_BENCHMARKS=ON \
-B build -S .
cmake --build build -j $(nproc) --target Kokkos_PerformanceTest_SIMD_Host
./build/simd/perf_tests/Kokkos_PerformanceTest_SIMD_Host --benchmark_out=baseline.json --benchmark_filter="math .[^c]"
- name: Patch the Kokkos SIMD perf tests to use the Sleef backend
working-directory: ${{ github.workspace }}/kokkos/simd/perf_tests
run: |
cp "${{ github.workspace }}/simd-backends/src/CEXA_SIMD_SLEEF.hpp" include
sed -i '/KOKKOS_IMPL_SIMD_DEVICE_PERFTEST/a find_package(sleef REQUIRED)\ntarget_link_libraries(Kokkos_PerformanceTest_SIMD_Host PRIVATE sleef::sleef)' CMakeLists.txt
sed -i '/include <Kokkos_SIMD.hpp>/a #include <CEXA_SIMD_SLEEF.hpp>' include/PerfTest_Host.hpp
- name: Run the Kokkos SIMD perf tests using the Sleef backend
working-directory: ${{ github.workspace }}/kokkos
run: |
cmake --build build -j $(nproc) --target Kokkos_PerformanceTest_SIMD_Host
./build/simd/perf_tests/Kokkos_PerformanceTest_SIMD_Host --benchmark_out=sleef.json --benchmark_filter="math .[^c]"
- name: Compare the perf test results
working-directory: ${{ github.workspace }}/kokkos
run: |
source ${{ env.compare_ROOT }}/venv/bin/activate
${{ env.compare_ROOT }}/compare.py benchmarks baseline.json sleef.json
90 changes: 90 additions & 0 deletions simd-backends/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# SPDX-FileCopyrightText: 2026 CExA-project
# SPDX-License-Identifier: MIT or Apache-2.0 with LLVM-exception

cmake_minimum_required(VERSION 3.23)

project(simd-backends VERSION 0.1.0)

find_package(Kokkos 4.6 REQUIRED)

option(
CEXA_SIMD_ENABLE_SLEEF
"Use the sleef library to implement the simd math functions"
OFF
)
option(CEXA_SIMD_ENABLE_SVML "Use the svml to implement the simd math functions" OFF)
option(CEXA_SIMD_ENABLE_TESTS "Enable accuracy tests" OFF)

if(CEXA_SIMD_ENABLE_SLEEF AND CEXA_SIMD_ENABLE_SVML)
message(FATAL_ERROR "Only one backend can be enabled at a time")
endif()

Comment on lines +10 to +21

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No AOCL-libm?

if(CEXA_SIMD_ENABLE_SLEEF)
find_package(sleef 3.6 QUIET)
if(NOT sleef_FOUND)
include(FetchContent)

set(SLEEF_BUILD_GNUABI_LIBS OFF)
set(SLEEF_BUILD_TESTS OFF)
set(SLEEF_ENABLE_TLFLOAT OFF)
set(SLEEF_ENABLE_FFTW OFF)
set(SLEEF_ENABLE_MPFR OFF)
list(APPEND CMAKE_MESSAGE_INDENT "[sleef] ")
FetchContent_Declare(
sleef
URL https://github.com/shibatch/sleef/archive/refs/tags/3.9.0.tar.gz
DOWNLOAD_EXTRACT_TIMESTAMP TRUE
DOWNLOAD_NO_PROGRESS TRUE
)
FetchContent_MakeAvailable(sleef)
list(POP_BACK CMAKE_MESSAGE_INDENT)
endif()
endif()

if(CEXA_SIMD_ENABLE_SVML AND NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL IntelLLVM)
message(
FATAL_ERROR
"The SVML simd backend is only available with Intel compilers"
)
endif()

add_subdirectory(src)

if(CEXA_SIMD_ENABLE_TESTS)
add_subdirectory(test)
endif()

# Install
include(GNUInstallDirs)

include(CMakePackageConfigHelpers)
write_basic_package_version_file(
CexaSimdBackendsConfigVersion.cmake
COMPATIBILITY AnyNewerVersion
)

install(
TARGETS simd-backends
EXPORT CexaSimdBackends
FILE_SET HEADERS
)

install(
EXPORT CexaSimdBackends
FILE CexaSimdBackendsTargets.cmake
NAMESPACE cexa::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CexaSimdBackends"
)

configure_package_config_file(
cmake/CexaSimdBackendsConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/CexaSimdBackendsConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CexaSimdBackends"
)

install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/CexaSimdBackendsConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/CexaSimdBackendsConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/CexaSimdBackends"
)
56 changes: 56 additions & 0 deletions simd-backends/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<!--
SPDX-FileCopyrightText: 2026 CExA-project

SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception
-->

# SIMD backends

This header only library provides an interface to replace the Kokkos math
functions for SIMD types with calls to different external libraries.

## Build

The available cmake configuration options are:
- `CEXA_SIMD_ENABLE_SLEEF`: use the sleef library
- `CEXA_SIMD_ENABLE_SVML`: use the Intel SVML library (only available with intel compilers)
- `CEXA_SIMD_ENABLE_TESTS`: build the tests

The sleef backend requires sleef v3.6.0 or later.

## Usage

With CMake, you can use the `find_package` command as shown in the
example below. If not installed to a system location, you should provide the
path to the library using the `-DCexaSimdBackends_ROOT=<path to the install location>`
option.

```cmake
cmake_minimum_required(VERSION 3.23)

project(test)

find_package(Kokkos REQUIRED)
find_package(CexaSimdBackends REQUIRED)

add_executable(main main.cpp)
target_link_libraries(main PRIVATE Kokkos::kokkos cexa::simd-backends)
```

You can then include `CEXA_SIMD_Backends.hpp` in your code and use the Kokkos simd math
functions as usual.

```cpp
#include <Kokkos_Core.hpp>
#include <Kokkos_SIMD.hpp>
#include <CEXA_SIMD_Backends.hpp>

int main(int argc, char* argv[]) {
Kokkos::ScopeGuard kokkos_scope(argc, argv);

Kokkos::Experimental::simd<float> vec(1.f);
vec = Kokkos::exp(vec);

return 0;
}
```
17 changes: 17 additions & 0 deletions simd-backends/cmake/CexaSimdBackendsConfig.cmake.in
Comment thread
tretre91 marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# SPDX-FileCopyrightText: 2026 CExA-project
# SPDX-License-Identifier: MIT or Apache-2.0 with LLVM-exception

@PACKAGE_INIT@

include(CMakeFindDependencyMacro)

find_dependency(Kokkos)

set(CEXA_SIMD_ENABLE_SLEEF @CEXA_SIMD_ENABLE_SLEEF@)
if(CEXA_SIMD_ENABLE_SLEEF)
find_dependency(sleef)
endif()

include("${CMAKE_CURRENT_LIST_DIR}/CexaSimdBackendsTargets.cmake")

check_required_components(CexaSimdBackends)
Loading