Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVE backend #2148

Merged
merged 16 commits into from
Aug 3, 2023
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
20 changes: 18 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,29 @@ set(arbor_supported_components)
# Target microarchitecture for building arbor libraries, tests and examples
#---------------------------------------------------------------------------

set(ARB_SVE_WIDTH "auto" CACHE STRING "Default SVE vector length in bits. Default: auto (detection during configure time).")
mark_as_advanced(ARB_SVE_WIDTH)
if (ARB_SVE_WIDTH STREQUAL "auto")
get_sve_length(ARB_HAS_SVE ARB_SVE_BITS)
if (ARB_HAS_SVE)
message(STATUS "SVE detected with vector size = ${ARB_SVE_BITS} bits")
set(ARB_CXX_SVE_FLAGS " -msve-vector-bits=${ARB_SVE_BITS}")
else()
message(STATUS "NO SVE detected")
set(ARB_CXX_SVE_FLAGS "")
endif()
else()
set(ARB_SVE_BITS ${ARB_SVE_WIDTH})
set(ARB_CXX_SVE_FLAGS " -msve-vector-bits=${ARB_SVE_BITS}")
endif()

# Set the full set of target flags in ARB_CXX_FLAGS_TARGET_FULL, which
# will include target-specific -march flags if ARB_ARCH is not "none".
if(ARB_ARCH STREQUAL "none")
set(ARB_CXX_FLAGS_TARGET_FULL ${ARB_CXX_FLAGS_TARGET})
set(ARB_CXX_FLAGS_TARGET_FULL ${ARB_CXX_FLAGS_TARGET} ${ARB_CXX_SVE_FLAGS})
else()
set_arch_target(ARB_CXXOPT_ARCH ${ARB_ARCH})
set(ARB_CXX_FLAGS_TARGET_FULL ${ARB_CXX_FLAGS_TARGET} ${ARB_CXXOPT_ARCH})
set(ARB_CXX_FLAGS_TARGET_FULL ${ARB_CXX_FLAGS_TARGET} ${ARB_CXXOPT_ARCH} ${ARB_CXX_SVE_FLAGS})
endif()

# Compile with `-fvisibility=hidden` to ensure that the symbols of the generated
Expand Down
16 changes: 16 additions & 0 deletions arbor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,20 @@ export_visibility(arbor)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/arbor/export.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arbor)

configure_file(
${PROJECT_SOURCE_DIR}/cmake/vls_sve_bits.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/include/arbor/simd/vls_sve_bits.hpp
@ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/arbor/simd/vls_sve_bits.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arbor/simd)

configure_file(
${PROJECT_SOURCE_DIR}/cmake/sve_bits.hpp.in
${CMAKE_CURRENT_BINARY_DIR}/include/arbor/simd/sve_bits.hpp
@ONLY)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/include/arbor/simd/sve_bits.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/arbor/simd)

install(TARGETS arbor EXPORT arbor-targets ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
5 changes: 3 additions & 2 deletions arbor/include/arbor/simd/native.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,9 @@ ARB_DEF_NATIVE_SIMD_(double, 8, avx512)
#if defined(__ARM_FEATURE_SVE)

#include "sve.hpp"
ARB_DEF_NATIVE_SIMD_(int, 0, sve)
ARB_DEF_NATIVE_SIMD_(double, 0, sve)
#include "vls_sve.hpp"
ARB_DEF_NATIVE_SIMD_(int, detail::vls_sve_width, vls_sve)
ARB_DEF_NATIVE_SIMD_(double, detail::vls_sve_width, vls_sve)

#elif defined(__ARM_NEON)

Expand Down
4 changes: 2 additions & 2 deletions arbor/include/arbor/simd/simd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ namespace detail {
template <typename V>
friend class indirect_expression;

simd_impl() = default;
constexpr simd_impl() = default;

// Construct by filling with scalar value.
simd_impl(const scalar_type& x) {
Expand Down Expand Up @@ -751,7 +751,7 @@ namespace detail {
using base::width;
using base::value_;

simd_mask_impl() = default;
constexpr simd_mask_impl() = default;

// Construct by filling with scalar value.
simd_mask_impl(bool b) {
Expand Down
12 changes: 8 additions & 4 deletions arbor/include/arbor/simd/sve.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <cstdint>
#include <iostream>

#include <arbor/simd/sve_bits.hpp>
#include <arbor/util/pp_util.hpp>

#include "approx.hpp"
Expand All @@ -17,6 +18,9 @@ namespace arb {
namespace simd {
namespace detail {

// number of elements in a vector
static constexpr unsigned max_sve_width = sve_bits/64;

struct sve_double;
struct sve_int;
struct sve_mask;
Expand All @@ -33,7 +37,7 @@ template<> struct is_sve<svbool_t> : std::true_type {};

template <>
struct simd_traits<sve_mask> {
static constexpr unsigned width = 8;
static constexpr unsigned width = max_sve_width;
using scalar_type = bool;
using vector_type = svbool_t;
using mask_impl = sve_mask;
Expand All @@ -43,7 +47,7 @@ struct simd_traits<sve_mask> {

template <>
struct simd_traits<sve_double> {
static constexpr unsigned width = 8;
static constexpr unsigned width = max_sve_width;
using scalar_type = double;
using vector_type = svfloat64_t;
using mask_impl = sve_mask;
Expand All @@ -53,7 +57,7 @@ struct simd_traits<sve_double> {

template <>
struct simd_traits<sve_int> {
static constexpr unsigned width = 8;
static constexpr unsigned width = max_sve_width;
using scalar_type = int32_t;
using vector_type = svint64_t;
using mask_impl = sve_mask;
Expand Down Expand Up @@ -453,7 +457,7 @@ struct sve_double {

// Compute n and g.

auto n = svrintz_f64_z(svptrue_b64(), add(mul(broadcast(ln2inv), x), broadcast(0.5)));
auto n = svrintm_f64_z(svptrue_b64(), add(mul(broadcast(ln2inv), x), broadcast(0.5)));

auto g = fma(n, broadcast(-ln2C1), x);
g = fma(n, broadcast(-ln2C2), g);
Expand Down
Loading