Skip to content

Commit f63804f

Browse files
cyb70289kou
authored andcommitted
ARROW-18162: [C++] Add Arm SVE compiler options (#14515)
As xsimd only supports fixed-size SVE, we have to specify vector size explicitly on command line. And the binary can only run on hardware with matched vector size. Otherwise, the code behaviour is undefined. E.g., `cmake -DARROW_SIMD_LEVEL=SVE256 ..` According macro `ARROW_HAVE_SVE256` and cmake variable are defined. We can also leverage compiler auto vectorization to generate size agnostic SVE code without specifying the vector size. E.g., `cmake -DARROW_SIMD_LEVEL=SVE ..` This PR also removes some unused Arm64 arch options. Authored-by: Yibo Cai <[email protected]> Signed-off-by: Yibo Cai <[email protected]>
1 parent 82cf616 commit f63804f

File tree

6 files changed

+26
-46
lines changed

6 files changed

+26
-46
lines changed

cpp/cmake_modules/DefineOptions.cmake

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ takes precedence over ccache if a storage backend is configured" ON)
185185
"AVX2"
186186
"AVX512"
187187
"NEON"
188+
"SVE" # size agnostic SVE
189+
"SVE128" # fixed size SVE
190+
"SVE256" # "
191+
"SVE512" # "
188192
"DEFAULT")
189193

190194
define_option_string(ARROW_RUNTIME_SIMD_LEVEL
@@ -196,17 +200,6 @@ takes precedence over ccache if a storage backend is configured" ON)
196200
"AVX512"
197201
"MAX")
198202

199-
# Arm64 architectures and extensions can lead to exploding combinations.
200-
# So set it directly through cmake command line.
201-
#
202-
# If you change this, you need to change the definition in
203-
# python/CMakeLists.txt too.
204-
define_option_string(ARROW_ARMV8_ARCH
205-
"Arm64 arch and extensions"
206-
"armv8-a" # Default
207-
"armv8-a"
208-
"armv8-a+crc+crypto")
209-
210203
define_option(ARROW_ALTIVEC "Build with Altivec if compiler has support" ON)
211204

212205
define_option(ARROW_RPATH_ORIGIN "Build Arrow libraries with RATH set to \$ORIGIN" OFF)

cpp/cmake_modules/SetupCxxFlags.cmake

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ elseif(ARROW_CPU_FLAG STREQUAL "ppc")
110110
endif()
111111
elseif(ARROW_CPU_FLAG STREQUAL "armv8")
112112
# Arm64 compiler flags, gcc/clang only
113-
set(ARROW_ARMV8_ARCH_FLAG "-march=${ARROW_ARMV8_ARCH}")
114-
check_cxx_compiler_flag(${ARROW_ARMV8_ARCH_FLAG} CXX_SUPPORTS_ARMV8_ARCH)
113+
set(ARROW_ARMV8_MARCH "armv8-a")
114+
check_cxx_compiler_flag("-march=${ARROW_ARMV8_MARCH}+sve" CXX_SUPPORTS_SVE)
115115
if(ARROW_SIMD_LEVEL STREQUAL "DEFAULT")
116116
set(ARROW_SIMD_LEVEL "NEON")
117117
endif()
@@ -485,26 +485,27 @@ if(ARROW_CPU_FLAG STREQUAL "ppc")
485485
endif()
486486

487487
if(ARROW_CPU_FLAG STREQUAL "armv8")
488-
if(ARROW_SIMD_LEVEL STREQUAL "NEON")
488+
if(ARROW_SIMD_LEVEL MATCHES "NEON|SVE[0-9]*")
489489
set(ARROW_HAVE_NEON ON)
490-
491-
if(NOT CXX_SUPPORTS_ARMV8_ARCH)
492-
message(FATAL_ERROR "Unsupported arch flag: ${ARROW_ARMV8_ARCH_FLAG}.")
493-
endif()
494-
if(ARROW_ARMV8_ARCH_FLAG MATCHES "native")
495-
message(FATAL_ERROR "native arch not allowed, please specify arch explicitly.")
496-
endif()
497-
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} ${ARROW_ARMV8_ARCH_FLAG}")
498-
499490
add_definitions(-DARROW_HAVE_NEON)
500-
501-
if(ARROW_ARMV8_ARCH_FLAG MATCHES "\\+crypto")
502-
add_definitions(-DARROW_HAVE_ARMV8_CRYPTO)
503-
endif()
504-
# armv8.1+ implies crc support
505-
if(ARROW_ARMV8_ARCH_FLAG MATCHES "armv8\\.[1-9]|\\+crc")
506-
add_definitions(-DARROW_HAVE_ARMV8_CRC)
491+
if(ARROW_SIMD_LEVEL MATCHES "SVE[0-9]*")
492+
if(NOT CXX_SUPPORTS_SVE)
493+
message(FATAL_ERROR "SVE required but compiler doesn't support it.")
494+
endif()
495+
# -march=armv8-a+sve
496+
set(ARROW_ARMV8_MARCH "${ARROW_ARMV8_MARCH}+sve")
497+
string(REGEX MATCH "[0-9]+" SVE_VECTOR_BITS ${ARROW_SIMD_LEVEL})
498+
if(SVE_VECTOR_BITS)
499+
set(ARROW_HAVE_SVE${SVE_VECTOR_BITS} ON)
500+
add_definitions(-DARROW_HAVE_SVE${SVE_VECTOR_BITS})
501+
# -msve-vector-bits=256
502+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -msve-vector-bits=${SVE_VECTOR_BITS}")
503+
else()
504+
set(ARROW_HAVE_SVE_SIZELESS ON)
505+
add_definitions(-DARROW_HAVE_SVE_SIZELSS)
506+
endif()
507507
endif()
508+
set(CXX_COMMON_FLAGS "${CXX_COMMON_FLAGS} -march=${ARROW_ARMV8_MARCH}")
508509
elseif(NOT ARROW_SIMD_LEVEL STREQUAL "NONE")
509510
message(WARNING "ARROW_SIMD_LEVEL=${ARROW_SIMD_LEVEL} not supported by Arm.")
510511
endif()

cpp/src/arrow/io/memory_benchmark.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ static void StreamReadWrite(void* src, void* dst, size_t size) {
154154

155155
#endif // ARROW_HAVE_SSE4_2
156156

157-
#ifdef ARROW_HAVE_ARMV8_CRYPTO
157+
#ifdef ARROW_HAVE_NEON
158158

159159
using VectorType = uint8x16_t;
160160
using VectorTypeDual = uint8x16x2_t;
@@ -237,7 +237,7 @@ static void StreamReadWrite(void* src, void* dst, size_t size) {
237237
}
238238
}
239239

240-
#endif // ARROW_HAVE_ARMV8_CRYPTO
240+
#endif // ARROW_HAVE_NEON
241241

242242
static void PlatformMemcpy(void* src, void* dst, size_t size) { memcpy(src, dst, size); }
243243

cpp/src/arrow/util/simd.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,4 @@
4141
#include <arm_neon.h>
4242
#endif
4343

44-
#ifdef ARROW_HAVE_ARMV8_CRC
45-
#include <arm_acle.h>
46-
#endif
47-
4844
#endif

dev/tasks/conda-recipes/arrow-cpp/build-pyarrow.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ else
3030
export PYARROW_WITH_CUDA=0
3131
fi
3232

33-
# Resolve: Make Error at cmake_modules/SetupCxxFlags.cmake:338 (message): Unsupported arch flag: -march=.
34-
if [[ "${target_platform}" == "linux-aarch64" ]]; then
35-
export PYARROW_CMAKE_OPTIONS="-DARROW_ARMV8_ARCH=armv8-a ${PYARROW_CMAKE_OPTIONS}"
36-
fi
37-
3833
if [[ "${target_platform}" == osx-* ]]; then
3934
# See https://conda-forge.org/docs/maintainer/knowledge_base.html#newer-c-features-with-old-sdk
4035
CXXFLAGS="${CXXFLAGS} -D_LIBCPP_DISABLE_AVAILABILITY"

python/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,6 @@ if(NOT DEFINED ARROW_RUNTIME_SIMD_LEVEL)
126126
"MAX"
127127
CACHE STRING "Max runtime SIMD optimization level")
128128
endif()
129-
if(NOT DEFINED ARROW_ARMV8_ARCH)
130-
set(ARROW_ARMV8_ARCH
131-
"armv8-a"
132-
CACHE STRING "Arm64 arch and extensions: armv8-a, armv8-a or armv8-a+crc+crypto")
133-
endif()
134129
include(SetupCxxFlags)
135130

136131
# Add common flags

0 commit comments

Comments
 (0)